Skip to content

Commit

Permalink
Merge pull request #576 from StochSS/makefile-improvements
Browse files Browse the repository at this point in the history
Clean up Makefile in `c_base` directory
  • Loading branch information
ethangreen-dev authored Jul 2, 2021
2 parents 7648c0b + 74ec50f commit 412ed07
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 58 deletions.
8 changes: 1 addition & 7 deletions gillespy2/solvers/cpp/build/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,11 @@ def __init__(self, makefile: str, output_dir: str, obj_dir: str = None):
self.output_file = Path(self.output_dir, self.output_file)

def prebuild(self):
self.__execute("prebuild")
self.__execute("build")

def build_simulation(self, simulation_name: str, **kwargs):
self.__execute(simulation_name, **kwargs)

def clean(self):
self.__execute("clean")

def clean_all(self):
self.__execute("clean_all")

def __execute(self, target: str, **kwargs):
# Default make arguments.
args_dict = {
Expand Down
2 changes: 2 additions & 0 deletions gillespy2/solvers/cpp/c_base/.env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Environment]::SetEnvironmentVariable("OBJ_DIR", "obj")
[Environment]::SetEnvironmentVariable("OUTPUT_DIR", "bin")
103 changes: 52 additions & 51 deletions gillespy2/solvers/cpp/c_base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
CXX := g++
CFLAGS := -Wall -O3
CXXFLAGS := -std=c++14 -Wall -O3
GPY_SOLVER ?= ssa
GPY_EXE_ARGS ?= --trajectories 1 --timesteps 21 --end 20
#######################################
.PHONY: run clean build profile ode ssa tau_leap

### Input directories ###
CBASE_DIR ?= .
Expand All @@ -17,10 +20,14 @@ TAU_LEAPING_SOLVER_PATH := $(CBASE_DIR)/tau_leaping_cpp_solver

### Output directories ###
OBJ_DIR ?= $(CBASE_DIR)
OUTPUT_DIR ?= $(CBASE_DIR)
OUTPUT_FILE ?= $(OUTPUT_DIR)/Simulation.out
SUNDIALS_OBJ ?= $(OBJ_DIR)
INCLUDES := -I$(CBASE_DIR) -I$(SUNDIALS_INC) -I$(TEMPLATE_DIR)
SUNDIALS_OBJ ?= $(OBJ_DIR)
OUTPUT_DIR ?= $(CBASE_DIR)
ifeq ($(OS),Windows_NT)
OUTPUT_FILE ?= $(OUTPUT_DIR)/Simulation.exe
else
OUTPUT_FILE ?= $(OUTPUT_DIR)/Simulation.out
endif
##########################

SUNOBJ = cvode_nls.o cvode_io.o sundials_iterative.o cvode_proj.o sundials_matrix.o sunmatrix_band.o sunmatrix_dense.o cvode_ls.o \
Expand All @@ -30,70 +37,64 @@ SUNOBJ_PATHS := $(SUNOBJ:%.o=$(SUNDIALS_OBJ)/%.o)

###################################
### SOLVER DEPENDENCIES COMPILE ###
$(OBJ_DIR)/model.o: $(CBASE_DIR)/model.cpp $(CBASE_DIR)/model.h
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/model.o $(CBASE_DIR)/model.cpp -I$(CBASE_DIR)
model: $(OBJ_DIR)/model.o ;

$(OBJ_DIR)/arg_parser.o: $(CBASE_DIR)/arg_parser.cpp $(CBASE_DIR)/arg_parser.h
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/arg_parser.o $(CBASE_DIR)/arg_parser.cpp $(INCLUDES)
arg_parser: $(OBJ_DIR)/arg_parser.o ;

$(SUNOBJ_PATHS): $(SUNDIALS_OBJ)/%.o: $(SUNDIALS_SRC)/%.c
$(CXX) -c -o $@ $< $(CFLAGS) -I$(SUNDIALS_INC)
sundials: $(SUNOBJ_PATHS) ;
### DEPENDENCIES FOR ALL SOLVERS ###
GPY_SRC = model.cpp arg_parser.cpp
GPY_OBJ := $(GPY_SRC:%.cpp=$(OBJ_DIR)/%.o)

#################################
### SOLVER ALGORITHM COMPILE ####
$(OBJ_DIR)/ODESolver.o: $(ODE_SOLVER_PATH)/ODESolver.cpp
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/ODESolver.o $(ODE_SOLVER_PATH)/ODESolver.cpp $(INCLUDES)
### DEPENDENCIES FOR ODE SOLVER ###
GPY_SRC_ODE = ODESimulation.cpp ODESolver.cpp
GPY_OBJ_ODE := $(GPY_SRC_ODE:%.cpp=$(OBJ_DIR)/%.o)

$(OBJ_DIR)/SSASolver.o: $(SSA_SOLVER_PATH)/SSASolver.cpp
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/SSASolver.o $(SSA_SOLVER_PATH)/SSASolver.cpp $(INCLUDES)
### DEPENDENCIES FOR SSA SOLVER ###
GPY_SRC_SSA = SSASimulation.cpp SSASolver.cpp
GPY_OBJ_SSA := $(GPY_SRC_SSA:%.cpp=$(OBJ_DIR)/%.o)

$(OBJ_DIR)/TauLeapingSolver.o: $(TAU_LEAPING_SOLVER_PATH)/TauLeapingSolver.cpp
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/TauLeapingSolver.o $(TAU_LEAPING_SOLVER_PATH)/TauLeapingSolver.cpp $(INCLUDES)
### DEPENDENCIES FOR TAU LEAPING SOLVER ###
GPY_SRC_TAU = TauLeapingSimulation.cpp TauLeapingSolver.cpp
GPY_OBJ_TAU := $(GPY_SRC_TAU:%.cpp=$(OBJ_DIR)/%.o)

%Solver.o: $(OBJ_DIR)/%Solver.o ;
$(GPY_OBJ): $(OBJ_DIR)/%.o: $(CBASE_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

#################################
### SOLVER SIMULATION COMPILE ###
$(GPY_OBJ_ODE): $(OBJ_DIR)/%.o: $(ODE_SOLVER_PATH)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(OBJ_DIR)/ODESimulation.o: $(ODE_SOLVER_PATH)/ODESimulation.cpp
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/ODESimulation.o $(ODE_SOLVER_PATH)/ODESimulation.cpp $(INCLUDES)
$(GPY_OBJ_SSA): $(OBJ_DIR)/%.o: $(SSA_SOLVER_PATH)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(OBJ_DIR)/SSASimulation.o: $(SSA_SOLVER_PATH)/SSASimulation.cpp
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/SSASimulation.o $(SSA_SOLVER_PATH)/SSASimulation.cpp $(INCLUDES)
$(GPY_OBJ_TAU): $(OBJ_DIR)/%.o: $(TAU_LEAPING_SOLVER_PATH)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(OBJ_DIR)/TauLeapingSimulation.o: $(TAU_LEAPING_SOLVER_PATH)/TauLeapingSimulation.cpp
$(CXX) $(CXXFLAGS) -c -o $(OBJ_DIR)/TauLeapingSimulation.o $(TAU_LEAPING_SOLVER_PATH)/TauLeapingSimulation.cpp $(INCLUDES)

%Simulation.o: $(OBJ_DIR)/%Simulation.o ;
$(SUNOBJ_PATHS): $(SUNDIALS_OBJ)/%.o: $(SUNDIALS_SRC)/%.c
$(CXX) -c -o $@ $< $(CFLAGS) -I$(SUNDIALS_INC)
sundials: $(SUNOBJ_PATHS) ;

#########################
### PRE-COMPILE RULES ###
prebuild_solvers: ODESolver.o SSASolver.o TauLeapingSolver.o ;
##########################
### FINAL COMPILATIONS ###
GPY_ALL_DEPS := $(GPY_OBJ) $(TEMPLATE_CPP)

prebuild_simulations: ODESimulation.o SSASimulation.o TauLeapingSimulation.o ;
ode: $(GPY_ALL_DEPS) $(GPY_OBJ_ODE) $(SUNOBJ_PATHS)
$(CXX) $(CXXFLAGS) -o $(OUTPUT_FILE) $^ $(INCLUDES)

prebuild: prebuild_solvers prebuild_simulations sundials arg_parser ;
ssa: $(GPY_ALL_DEPS) $(GPY_OBJ_SSA)
$(CXX) $(CXXFLAGS) -o $(OUTPUT_FILE) $^ $(INCLUDES)

#########################
tau_leap: $(GPY_ALL_DEPS) $(GPY_OBJ_TAU) $(TEMPLATE_CPP)
$(CXX) $(CXXFLAGS) -o $(OUTPUT_FILE) $^ $(INCLUDES)

##########################
### FINAL COMPILATIONS ###
COMPILATION_ARGS := $(CXXFLAGS) -o $(OUTPUT_FILE) $(TEMPLATE_CPP) $(OBJ_DIR)/model.o $(OBJ_DIR)/arg_parser.o $(INCLUDES)
build: $(GPY_ALL_DEPS) $(GPY_OBJ_SSA) $(GPY_OBJ_ODE) $(GPY_OBJ_TAU) ;

ode: ODESimulation.o ODESolver.o sundials model arg_parser $(TEMPLATE_CPP)
$(CXX) $(COMPILATION_ARGS) $(SUNOBJ_PATHS) $(OBJ_DIR)/ODESimulation.o $(OBJ_DIR)/ODESolver.o
run: $(GPY_SOLVER)
$(OUTPUT_FILE) $(GPY_EXE_ARGS)

ssa: SSASimulation.o SSASolver.o model arg_parser $(TEMPLATE_CPP)
$(CXX) $(COMPILATION_ARGS) $(OBJ_DIR)/SSASimulation.o $(OBJ_DIR)/SSASolver.o
debug: CXXFLAGS = -std=c++14 -Wall -g
debug: $(GPY_SOLVER)
gdb --args $(OUTPUT_FILE) $(GPY_EXE_ARGS)

tau_leap: TauLeapingSimulation.o TauLeapingSolver.o model arg_parser $(TEMPLATE_CPP)
$(CXX) $(COMPILATION_ARGS) $(OBJ_DIR)/TauLeapingSimulation.o $(OBJ_DIR)/TauLeapingSolver.o
profile: CXXFLAGS = -std=c++14 -Wall -pg
profile: $(GPY_SOLVER)
$(OUTPUT_FILE) $(GPY_EXE_ARGS)

clean:
rm -rf $(OUTPUT_DIR)/*.out

clean_all:
rm -rf $(OBJ_DIR)/*.o $(SUNDIALS_OBJ)/*.o $(OUTPUT_DIR)/*.out
rm -rf $(OUTPUT_DIR)/*.out $(SUNDIALS_OBJ)/*.o $(OBJ_DIR)/*.o

0 comments on commit 412ed07

Please sign in to comment.