.PHONY: static

CXX_STD = CXX17
PKG_CPPFLAGS = -DNO_FPRINTF_OUTPUT -I"../inst/include" -I"sundials" -include stan_sundials_printf_override.hpp
PKG_CPPFLAGS += -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR -D_REENTRANT -DSTAN_THREADS -DSTRICT_R_HEADERS
PKG_CXXFLAGS += -DSTRICT_R_HEADERS
PKG_CPPFLAGS += -DUSE_PTHREAD
SHLIB_LDFLAGS = $(SHLIB_CXXLDFLAGS)
SHLIB_LD = $(SHLIB_CXXLD)

#SUNDIALS_CVODES = cvodes/cvodes_spils.c cvodes/cvodes_io.c cvodes/cvodes_bbdpre.c cvodes/cvodes_nls_stg1.c cvodes/fmod/fcvodes_mod.c cvodes/cvodes.c cvodes/cvodes_nls_sim.c cvodes/cvodes_diag.c cvodes/cvodes_ls.c cvodes/cvodes_direct.c cvodes/cvodes_nls.c cvodes/cvodes_nls_stg.c cvodes/cvodea.c cvodes/cvodea_io.c cvodes/cvodes_bandpre.c sundials/sundials_matrix.c sundials/sundials_band.c sundials/sundials_math.c sundials/fmod/fsundials_futils_mod.c sundials/fmod/fsundials_nonlinearsolver_mod.c sundials/fmod/fsundials_types_mod.c sundials/fmod/fsundials_nvector_mod.c sundials/fmod/fsundials_matrix_mod.c sundials/fmod/fsundials_linearsolver_mod.c sundials/sundials_linearsolver.c sundials/sundials_nvector.c sundials/sundials_direct.c sundials/sundials_dense.c sundials/sundials_futils.c sundials/sundials_version.c sundials/sundials_iterative.c sundials/sundials_nvector_senswrapper.c sundials/sundials_nonlinearsolver.c sunmatrix/band/sunmatrix_band.c sunmatrix/dense/sunmatrix_dense.c sunlinsol/band/sunlinsol_band.c sunlinsol/dense/sunlinsol_dense.c sunnonlinsol/newton/sunnonlinsol_newton.c sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c
SUNDIALS_CVODES = cvodes/cvodes_spils.c cvodes/cvodes_io.c cvodes/cvodes_bbdpre.c cvodes/cvodes_nls_stg1.c cvodes/cvodes.c cvodes/cvodes_nls_sim.c cvodes/cvodes_diag.c cvodes/cvodes_ls.c cvodes/cvodes_direct.c cvodes/cvodes_nls.c cvodes/cvodes_nls_stg.c cvodes/cvodea.c cvodes/cvodea_io.c cvodes/cvodes_bandpre.c sundials/sundials_matrix.c sundials/sundials_band.c sundials/sundials_math.c sundials/sundials_linearsolver.c sundials/sundials_nvector.c sundials/sundials_direct.c sundials/sundials_dense.c sundials/sundials_version.c sundials/sundials_iterative.c sundials/sundials_nvector_senswrapper.c sundials/sundials_nonlinearsolver.c sunmatrix/band/sunmatrix_band.c sunmatrix/dense/sunmatrix_dense.c sunlinsol/band/sunlinsol_band.c sunlinsol/dense/sunlinsol_dense.c sunnonlinsol/newton/sunnonlinsol_newton.c sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c
#SUNDIALS_IDAS = idas/idas_io.c idas/idas_nls_sim.c idas/fmod/fidas_mod.c idas/idas_ls.c idas/idas_ic.c idas/idaa_io.c idas/idas_direct.c idas/idas_spils.c idas/idas_nls_stg.c idas/idas.c idas/idas_bbdpre.c idas/idas_nls.c idas/idaa.c
SUNDIALS_IDAS = idas/idas_io.c idas/idas_nls_sim.c idas/idas_ls.c idas/idas_ic.c idas/idaa_io.c idas/idas_direct.c idas/idas_spils.c idas/idas_nls_stg.c idas/idas.c idas/idas_bbdpre.c idas/idas_nls.c idas/idaa.c
SUNDIALS_KINSOL = kinsol/kinsol.c kinsol/kinsol_io.c kinsol/kinsol_bbdpre.c kinsol/kinsol_spils.c kinsol/kinsol_ls.c kinsol/kinsol_direct.c
SUNDIALS_NVECSERIAL = nvector/serial/nvector_serial.c

SOURCES = $(SUNDIALS_CVODES) $(SUNDIALS_IDAS) $(SUNDIALS_KINSOL) $(SUNDIALS_NVECSERIAL)
OBJECTS_C = $(SOURCES:.c=.o)
OBJECTS = $(OBJECTS_C:.cpp=.o)

static: $(OBJECTS)
	@mkdir -p ../lib
	$(AR) -rs ../lib/libStanHeaders.a $(OBJECTS)

clean:
	rm -rf ../lib
	rm $(OBJECTS)
