PKG_CPPFLAGS+=-I../src/inc -DR_NO_REMAP

SOURCES = $(wildcard *.cpp module_library/*.cpp framework/*.cpp framework/ode_solver_library/*.cpp framework/utils/*.cpp)
OBJECTS = $(SOURCES:.cpp=.o)





# The code below is a slightly modified version of the method for generating and
# using dependency files presented at
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation.
#
# Modifications include:
#
# 1. Ensuring "all" is the default target.
# 2. Setting a value for OUTPUT_OPTION (presumably needed, but not discussed in
#    the paper).
# 3. Replacing ".c" extensions with ".cpp".
# 4. Defining COMPILE.cpp to use compiler and flag variables more closely
#    matching what is given in the suffix rule for .cpp.o contained in the
#    Makeconf file.  (That rule is
#      .cpp.o:
#          $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
#    OUTPUT_OPTION corresponds to the "-o $@" at the end.)
# 5. Since this file is read in before Makeconf, we can't cancel the suffix rule
#    listed there for making %.o files from %.cpp files by using the recipe-less
#    rule "%.o : %.cpp", so we make our new rule for this into a static pattern
#    rule, which automatically gives it higher priority.
# 6. Modifying the recipe for making the directories that contain the dependency
#    files so that the subdirectory module_library is also made.
# 7. Changing the variable name SRCS to SOURCES to match what the
#    previously-existing version of this file used.
# 8. To ensure the object file generated in the compilation recipe
#    always has a more recent modification time than the dependency
#    file generated by the recipe, the POSTCOMPILE step has been added
#    to the recipe as explained in the section "Handling unusual
#    situations"
#    (https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#unusual).

.DEFAULT_GOAL := all

DEPDIR := .deps
DEPSUBDIRS = $(DEPDIR)/module_library $(DEPDIR)/framework $(DEPDIR)/framework/ode_solver_library $(DEPDIR)/framework/utils

DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td

POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@

OUTPUT_OPTION = -o $@
COMPILE.cpp = $(CXX) $(DEPFLAGS) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c

$(OBJECTS) : %.o : %.cpp $(DEPDIR)/%.d | $(DEPSUBDIRS)
	$(COMPILE.cpp) $(OUTPUT_OPTION) $<
	$(POSTCOMPILE)

$(DEPSUBDIRS):
	@mkdir -p $@

DEPFILES := $(SOURCES:%.cpp=$(DEPDIR)/%.d)
$(DEPFILES):

include $(wildcard $(DEPFILES))
