.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 := \
	$(wildcard cvodes/*.c) \
	$(wildcard sundials/*.c) \
	$(wildcard sunmatrix/band/[^f]*.c) \
	$(wildcard sunmatrix/dense/[^f]*.c) \
	$(wildcard sunlinsol/band/[^f]*.c) \
	$(wildcard sunlinsol/dense/[^f]*.c) \
	$(wildcard sunnonlinsol/newton/[^f]*.c) \
	$(wildcard sunnonlinsol/fixedpoint/[^f]*.c)

SUNDIALS_IDAS := \
	$(wildcard idas/*.c) \
	$(wildcard sundials/*.c) \
	$(wildcard sunmatrix/band/[^f]*.c) \
	$(wildcard sunmatrix/dense/[^f]*.c) \
	$(wildcard sunlinsol/band/[^f]*.c) \
	$(wildcard sunlinsol/dense/[^f]*.c) \
	$(wildcard sunnonlinsol/newton/[^f]*.c) \
	$(wildcard sunnonlinsol/fixedpoint/[^f]*.c)

SUNDIALS_KINSOL := \
	$(wildcard kinsol/*.c) \
	$(wildcard sundials/*.c) \
	$(wildcard sunmatrix/band/[^f]*.c) \
	$(wildcard sunmatrix/dense/[^f]*.c) \
	$(wildcard sunlinsol/band/[^f]*.c) \
	$(wildcard sunlinsol/dense/[^f]*.c) \
	$(wildcard sunnonlinsol/newton/[^f]*.c) \
	$(wildcard sunnonlinsol/fixedpoint/[^f]*.c)

SUNDIALS_NVECSERIAL := \
	$(addprefix , nvector/serial/nvector_serial.c sundials/sundials_math.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)
