CXX_STD = CXX14
CXX14STD = -std=c++1y

PKG_CPPFLAGS = -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR -D_REENTRANT -DSTAN_THREADS 
PKG_CPPFLAGS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::CxxFlags()" | tail -n 1)
SHLIB_LDFLAGS = $(SHLIB_CXXLDFLAGS)
SHLIB_LD = $(SHLIB_CXXLD)
PKG_LIBS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::LdFlags()" | tail -n 1)

SOURCES_STATIC = stan_fit.cpp stan_fit_base.cpp
OBJECTS_STATIC = $(SOURCES_STATIC:.cpp=.o)

SOURCES = $(filter-out stan_fit.cpp, $(wildcard *.cpp) stan/lang/ast_def.cpp $(wildcard stan/lang/grammars/*.cpp))
OBJECTS = $(SOURCES:.cpp=.o)

all: $(SHLIB) $(OBJECTS_STATIC)
	@mkdir -p ../inst/lib/$(R_ARCH)
	$(AR) -rs ../inst/lib/$(R_ARCH)/libStanServices.a $(OBJECTS_STATIC)

.phony: all

.PHONY: print-%
print-%  : ; @echo $* = $($*)

