CXX_STD = CXX17
STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))" | tail -n 1)
PKG_CPPFLAGS = -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"${STANHEADERS_SRC}" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_REENTRANT -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -D_HAS_AUTO_PTR_ETC=0
PKG_CPPFLAGS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::CxxFlags()" | tail -n 1)
PKG_CXXFLAGS += -DRCPP_PARALLEL_USE_TBB=1 -DSTRICT_R_HEADERS
PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::RcppParallelLibs()" | tail -n 1)
SHLIB_LDFLAGS = $(SHLIB_CXXLDFLAGS)
SHLIB_LD = $(SHLIB_CXXLD)

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

SOURCES = $(filter-out stan_fit.cpp, $(wildcard *.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

