forked from dist1ll/pomcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (63 loc) · 2.2 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
CC := $(CXX)
CFLAGS := -pthread
STD := c++17
SRCEXT := cpp
SRCDIR := src
TESTDIR := unit_test
BUILDDIR := build/src
TESTBUILD := build/unit_test
MAIN_TARGET := ./bin/exec
TEST_TARGET := ./bin/test
MAIN_SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
TEST_SOURCES := $(shell find $(TESTDIR) -type f -name *.$(SRCEXT))
SWITCH := $(addprefix build/,$(MAIN_SOURCES:.cpp=.o))
TWITCH := $(addprefix build/,$(TEST_SOURCES:.cpp=.o))
MAIN_OBJECTS := $(SWITCH)
MAIN_OBJS_NOMAIN := $(filter-out $(BUILDDIR)/main.o, $(MAIN_OBJECTS))
TEST_OBJECTS := $(TWITCH)
MODULE1 := bboard
MODULE2 := agents
INCL1 := $(SRCDIR)/$(MODULE1)
INCL2 := $(SRCDIR)/$(MODULE2)
INC := -I src/bboard -I src/agents
all: main test
main: $(MAIN_OBJECTS)
@mkdir -p bin
@$(CC) $(CFLAGS) -std=$(STD) $^ -o $(MAIN_TARGET)
test: $(TEST_OBJECTS)
@$(MAKE) main -s
@mkdir -p bin
@$(CC) $(CFLAGS) -std=$(STD) $^ -o $(TEST_TARGET) $(MAIN_OBJS_NOMAIN)
# build main test files
build/$(TESTDIR)/%.o: $(TESTDIR)/%.$(SRCEXT)
@echo "Building test"
@mkdir -p $(TESTBUILD)
@$(CC) $(CFLAGS) -std=$(STD) -c -o $@ $< $(INC) -I $(TESTDIR)
# build test files
build/$(TESTDIR)/$(MODULE1)/%.o: $(TESTDIR)/$(MODULE1)/%.$(SRCEXT)
@echo "Building test-case: " $@
@mkdir -p $(TESTBUILD) -p $(TESTBUILD)/$(MODULE1)
@$(CC) $(CFLAGS) -std=$(STD) -c -o $@ $< $(INC) -I $(TESTDIR)
# build main files
build/src/%.o: $(SRCDIR)/%.$(SRCEXT)
@echo "Building main"
@mkdir -p $(BUILDDIR)
@$(CC) $(CFLAGS) -std=$(STD) -c -o $@ $< $(INC)
build/src/$(MODULE1)/%.o: src/$(MODULE1)/%.$(SRCEXT)
@echo "Building bboard"
@mkdir -p $(BUILDDIR) -p $(BUILDDIR)/$(MODULE1)
@$(CC) $(CFLAGS) -std=$(STD) -c -o $@ $< $(INC)
build/src/$(MODULE2)/%.o: src/$(MODULE2)/%.$(SRCEXT)
@echo "Building agents"
@mkdir -p $(BUILDDIR) -p $(BUILDDIR)/$(MODULE2)
@$(CC) $(CFLAGS) -std=$(STD) -c -o $@ $< $(INC)
clean:
@echo " Cleaning...";
@echo " $(RM) -r $(BUILDDIR) $(MAIN_TARGET)"; $(RM) -r $(BUILDDIR) $(MAIN_TARGET)
@echo " Clean test files except test_main"; find $(TESTBUILD) $(TEST_TARGET) -type f -not -name 'test_main.o' -print0 | xargs -0 $(RM) --
@echo
# only cleans main
mclean:
@echo " Cleaning...";
@echo " $(RM) -r $(BUILDDIR) $(MAIN_TARGET)"; $(RM) -r $(BUILDDIR) $(MAIN_TARGET)
@echo