forked from utexas-bwi/rl_pursuit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (103 loc) · 3.25 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# basic commands
CC = g++
RM = rm -f
# get some information about our system
ifeq ($(shell uname -m),x86_64)
ARCH=64
else
ARCH=32
endif
ifeq ($(shell bin/onLabMachine.sh),yes)
PYTHON_VERSION=2.6
else
PYTHON_VERSION=2.7
endif
# dirs
SOURCE_DIR := src
MAIN_DIR := $(SOURCE_DIR)/main
INCLUDE_DIR := include
LIBS_DIR := libs/$(ARCH)
BUILD_DIR := build/$(ARCH)
TARGET_DIR := targets
# targets
TARGET_MAKEFILES := $(wildcard $(TARGET_DIR)/*.mk)
TARGETS := $(patsubst $(TARGET_DIR)/%.mk, %, $(TARGET_MAKEFILES))
TEMPLATE_TARGETS := $(filter-out weka, $(TARGETS))
# sources
MODULES := common controller factory learning model planning
SOURCES := $(wildcard $(patsubst %, $(SOURCE_DIR)/%/*.cpp, $(MODULES)))
SOURCES := $(filter-out $(SOURCE_DIR)/learning/WekaBridge.cpp,$(SOURCES)) # don't compile weka bridge, it's an abomination and will be handled separately
# flags
FLAGS_NO_STD = -W -Wall -Werror -pedantic-errors -O3 -I$(SOURCE_DIR) -I$(INCLUDE_DIR) -I/usr/include/python$(PYTHON_VERSION)
FLAGS = $(FLAGS_NO_STD) -std=c++0x
STUDENT_FLAGS = -I$(SOURCE_DIR) -I$(INCLUDE_DIR)
LINK_FLAGS = -L$(LIBS_DIR) -ljson -lpython$(PYTHON_VERSION) -lboost_python -lgflags -llinear -lblas -lrt
default: all
include $(TARGET_MAKEFILES)
all: $(TARGETS)
.PHONY: clean fullclean fclean $(TARGETS)
define TARGET_template
# get the objects
override OBJS := $$(patsubst $(SOURCE_DIR)/%.cpp, $(BUILD_DIR)/%.o,$$($1_SOURCES))
# get the binary, defaulting to the name
ifeq ($$(strip $$($1_BIN)),)
override BIN := $$(patsubst %, bin/$(ARCH)/%, $1)
else
override BIN := $$(patsubst %, bin/$(ARCH)/%, $$($1_BIN))
endif
# get the link flags, defaulting to LINK_FLAGS
ifeq ($$(strip $$($1_LINK_FLAGS)),)
override LINK_FLAGS_TEMP := $$(LINK_FLAGS)
else
override LINK_FLAGS_TEMP := $$($1_LINK_FLAGS)
endif
# set up the rules
print_$1:
@echo $$($1_SOURCES)
$1: $$(BIN)
$$(BIN): $$(OBJS)
$$(BIN): LINK_FLAGS:=$$(LINK_FLAGS_TEMP)
DEPS := $$(DEPS) $$(OBJS:.o=.d)
OBJECTS := $$(OBJECTS) $$(OBJS)
override BINS := $$(BINS) $$(BIN)
endef
$(foreach target,$(TEMPLATE_TARGETS),$(eval $(call TARGET_template,$(target))))
OBJECTS_ALL = $(sort $(OBJECTS))
clean: cleandeps
$(RM) $(OBJECTS_ALL)
cleandeps:
$(RM) $(DEPS)
fullclean: clean
$(RM) $(BINS)
fclean: fullclean
# include dependencies for creating dependencies and objects
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),fullclean)
ifneq ($(MAKECMDGOALS),fclean)
ifneq ($(MAKECMDGOALS),cleandeps)
include $(DEPS)
endif
endif
endif
endif
# compile the objects
$(OBJECTS_ALL):
@mkdir -p $(dir $@)
@echo "Compiling $< for $(ARCH)"
@$(CC) $(FLAGS) -c $< -o $@
# calculate the dependencies, note that I hacked the sed line to make it correctly set the targets
$(BUILD_DIR)/%.d: $(SOURCE_DIR)/%.cpp
@mkdir -p $(dir $@)
@echo "Calculating the dependencies for $<"
@set -e; rm -f $@; \
$(CC) -MM $(FLAGS) $< > $@.$$$$; \
sed 's,\(.*\).o:,$(@:.d=.o) $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
bin/$(ARCH)/%:
@echo "Linking $@"
@$(CC) $(FLAGS) $^ $(LINK_FLAGS) -o $@
# Special finicky files:
$(BUILD_DIR)/learning/WekaClassifier.o: FLAGS := $(FLAGS) -D COMPILE_ARCH=$(ARCH)
$(BUILD_DIR)/learning/WekaClassifier.d: FLAGS := $(FLAGS) -D COMPILE_ARCH=$(ARCH)
$(BUILD_DIR)/learning/Communicator.o: FLAGS := $(FLAGS_NO_STD)
$(BUILD_DIR)/learning/libsvm.o: FLAGS = -O3 -w