-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakefile
97 lines (76 loc) · 3.43 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Makefile for Swarmulator
#
# Mario Coppola, 2017-2018
TARGET = swarmulator # application name
BUILD_FOLDER = build
SRC_FOLDER = sw
CONTROLLER?=aggregation
AGENT?=particle
CONTROLLER_INCLUDE=\"$(CONTROLLER).h\"
AGENT_INCLUDE=\"$(AGENT).h\"
# Compiler parameters
# -g adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
CC = g++ # chosen compiler
CFLAGS = -g -Wall -std=gnu++17 -D_GLIBCXX_USE_NANOSLEEP -DSWARMULATOR -DCONTROLLER=$(CONTROLLER) -DAGENT=$(AGENT) -DAGENT_INCLUDE=$(AGENT_INCLUDE) -DCONTROLLER_INCLUDE=$(CONTROLLER_INCLUDE) -D_GLIBCXX_USE_CXX11_ABI=0
OPT=-lglut -lGLU -lGL -lpthread -lxerces-c -Wno-deprecated-declarations -fno-inline-functions -lprotobuf -lboost_system -lboost_serialization -lboost_iostreams
ifeq ($(VERBOSE),ON)
CFLAGS += -DVERBOSE
endif
ifeq ($(ANIMATION),ON)
CFLAGS += -DANIMATION
endif
ifeq ($(LOG),ON)
CFLAGS += -DLOG
endif
CTRL_FOLDER = sw/simulation/controllers
AGNT_FOLDER = sw/simulation/agents
# General parameters to include all relevant cpp files and all subfolders
# INC_DIRS = $(shell find $(SRC_FOLDER) -path $(CTRL_FOLDER) -prune -o -type d)
INC_DIRS = $(shell find $(SRC_FOLDER) -type d)
SOURCES_CPP = $(shell find $(SRC_FOLDER) -path $(CTRL_FOLDER) -prune -o -path $(AGNT_FOLDER) -prune -o -name *.cpp -print) # Recursively find all cpp/c files
SOURCES_C = $(shell find $(SRC_FOLDER) -path $(CTRL_FOLDER) -prune -o -path $(AGNT_FOLDER) -prune -o -name *.c -print) # Recursively find all cpp/c files
### Select controller files
CTRL_INC = $(shell find $(SRC_FOLDER) -name $(CONTROLLER).cpp -printf '%h\n')
SOURCES_CPP += $(shell find $(CTRL_INC) -type f -name *.cpp -print)
SOURCES_C += $(shell find $(CTRL_INC) -type f -name *.c -print)
INC_DIRS += $(shell find $(CTRL_INC) -type d)
### Select agent files
AGNT_INC = $(shell find $(SRC_FOLDER) -name $(AGENT).cpp -printf '%h\n')
SOURCES_CPP += $(shell find $(AGNT_INC) -name *.cpp -print)
SOURCES_C += $(shell find $(AGNT_INC) -name *.c -print)
INC_DIRS += $(shell find $(AGNT_INC) -type d)
### External libraries
# If using pytorch, load the library!
ifeq ($(CONTROLLER),pytorch)
OPT += -L $(TORCH_LIB_HOME)/lib -lc10 -L $(TORCH_LIB_HOME)/lib -ltorch_cpu
INC_DIRS += $(shell find $(TORCH_LIB_HOME) -type d) ## Add torchlib include folder, if present
endif
# Prepare includes
INC_PARAMS = $(foreach d, $(INC_DIRS), -I$d) # Each include folder must have a -I before it
INC = -I. -I$(SRC_FOLDER) -I$(BUILD_FOLDER) $(INC_PARAMS) # All include paths
MAKE = $(CC) $(CFLAGS) $(INC)
OBJECTS_CPP=$(SOURCES_CPP:%.cpp=$(BUILD_FOLDER)/%.o)
OBJECTS_C=$(SOURCES_C:%.c=$(BUILD_FOLDER)/%.o)
# Build the executable
# Using @...; suppresses the output of the arguments
all: $(TARGET)
$(TARGET): xsd $(OBJECTS_C) $(OBJECTS_CPP)
# Building $(TARGET)
@$(MAKE) $(BUILD_FOLDER)/*.cxx $(OBJECTS_C) $(OBJECTS_CPP) -o $@ $(OPT);
xsd:
# Generating parameters file
@mkdir -p $(BUILD_FOLDER);
@xsdcxx cxx-tree --output-dir "$(BUILD_FOLDER)" --root-element-all conf/parameters.xsd;
$(BUILD_FOLDER)/%.o: %.cpp # This rule defines how to go from CPP file to Object file
# Compiling $<
@mkdir -p $(@D)
@$(MAKE) -c $< -o $@ $(OPT);
$(BUILD_FOLDER)/%.o: %.c # This rule defines how to go from C file to Object file
# Compiling $<
@mkdir -p $(@D)
@gcc -g -Wall -DDEBUG -DINFO -D_GLIBCXX_USE_NANOSLEEP -std=c11 $(INC) -c $< -o $@;
clean:
# Cleaning $(TARGET)...
@$(RM) -r $(BUILD_FOLDER); # Remove build folder
@$(RM) -r $(TARGET); # Remove application