LIBSTAN_OFILES = bin/stan/agrad/agrad.o bin/stan/math/matrix.o bin/stan/agrad/matrix.o
bin/libstan.a : $(LIBSTAN_OFILES)
	@mkdir -p $(dir $@)
	$(AR) -rs bin/libstan.a $(LIBSTAN_OFILES)

TEMPLATE_INSTANTIATION := $(shell find src/stan/gm -type f -name '*_inst.cpp')
TEMPLATE_INSTANTIATION += $(shell find src/stan/gm -type f -name '*_def.cpp')
TEMPLATE_INSTANTIATION := $(TEMPLATE_INSTANTIATION:src/%.cpp=bin/%.o)
bin/libstanc.a : $(TEMPLATE_INSTANTIATION)
	@mkdir -p $(dir $@)
	$(AR) -rs bin/libstanc.a $(TEMPLATE_INSTANTIATION)


##
# Generate dependencies for libraries
##
ifneq (,$(filter-out clean%,$(MAKECMDGOALS)))
  -include $(addsuffix .d,$(basename $(LIBSTAN_OFILES)))
  -include $(addsuffix .d,$(basename $(TEMPLATE_INSTANTIATION)))
endif
