##
# Models (to be passed through stanc)
##
MODEL_HEADER := src/stan/model/model_header.hpp
.PRECIOUS: %.cpp %.o
$(patsubst %.stan,%,$(wildcard $(addsuffix .stan,$(MAKECMDGOALS)))) : %$(EXE): %.o bin/libstan.a
@echo ''
@echo '--- Linking C++ model ---'
$(LINK.c) -O$O $(OUTPUT_OPTION) $< $(LDLIBS)
src/%: src/%.o bin/libstan.a
@echo ''
@echo '--- Linking C++ model ---'
$(LINK.c) -O$O $(OUTPUT_OPTION) $< $(LDLIBS)
%.exe: %.o bin/libstan.a
@echo ''
@echo '--- Linking C++ model ---'
$(LINK.c) -O$O $(OUTPUT_OPTION) $< $(LDLIBS)
.PRECIOUS: %.cpp
%.cpp : %.stan $(MODEL_HEADER)$(PCH) bin/stanc$(EXE)
@echo ''
@echo '--- Translating Stan model to C++ code ---'
bin/stanc$(EXE) $< --o=$@
.PRECIOUS: models/speed/%.stan
models/speed/%.stan : src/models/speed/%.stan
@mkdir -p $(dir $@)
@echo ''
@echo '--- Copying model ---'
cp $< $@
@if test -f $(basename $<)*_generate_data.R; then \
echo '';\
echo '--- Copying generate script ---';\
cp $(wildcard $(basename $<)*_generate_data.R) $(dir $@);\
echo 'cp $(wildcard $(basename $<)*_generate_data.R) $(dir $@)';\
fi;
@if test -f $(basename $<)*.data.R; then \
echo '';\
echo '--- Copying data ---';\
cp $(wildcard $(basename $<)*.data.R) $(dir $@);\
echo 'cp $(wildcard $(basename $<)*.data.R) $(dir $@)';\
fi;
.PRECIOUS: models/%.stan models/%.data.R
models/%.stan : src/models/%.stan
@mkdir -p $(dir $@)
@echo ''
@echo '--- Copying model ---'
cp $< $@
@if test -f $(patsubst src/models/%.stan,src/models/%.data.R,$<); then \
echo '';\
echo '--- Copying data ---';\
cp $(addsuffix .data.R,$(basename $<)) $(addsuffix .data.R,$(basename $@));\
echo 'cp $(addsuffix .data.R,$(basename $<)) $(addsuffix .data.R,$(basename $@))';\
fi;
@if test -f $(patsubst src/models/%.stan,src/models/%.init.R,$<); then \
echo '';\
echo '--- Copying init ---';\
cp $(addsuffix .init.R,$(basename $<)) $(addsuffix .init.R,$(basename $@));\
echo 'cp $(addsuffix .init.R,$(basename $<)) $(addsuffix .init.R,$(basename $@))';\
fi;
#.PRECIOUS: %.cpp
#models/%$(EXE): models/%.o bin/libstan.a
# @echo ''
# @echo '--- Linking C++ model ---'
# $(LINK.c) $(OUTPUT_OPTION) $< $(LDLIBS)
$(MODEL_HEADER).gch : $(MODEL_HEADER)
@echo ''
@echo '--- Precompiling $(MODEL_HEADER) for g++ ---'
$(CC) $(CFLAGS) -O$O -c $(OUTPUT_OPTION) $<
$(MODEL_HEADER).pch : $(MODEL_HEADER)
@echo ''
@echo '--- Precompiling $(MODEL_HEADER) for clang++ ---'
$(CC) $(CFLAGS) -O$O -c $(OUTPUT_OPTION) $<
$(MODEL_HEADER).d : $(MODEL_HEADER)
@if test -d $(dir $@); \
then \
(set -e; \
rm -f $@; \
$(CC) $(CFLAGS) -O$O $(TARGET_ARCH) -MM $< > $@.$$$$; \
sed -e 's,\($(notdir $(basename $(MODEL_HEADER)))\)\.o[ :]*,$@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$ ); \
fi
##
# Will generate dependencies.
##
ifneq (,$(filter-out clean%,$(MAKECMDGOALS)))
-include $(MODEL_HEADER).d
endif