-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathMakefile
57 lines (40 loc) · 1.3 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
# C++ version
CXXFLAGS += -std=c++14
# warning options
CXXFLAGS += -Wall -Wextra -pedantic-errors
# for dependency generation
CXXFLAGS += -MMD -MP
# include directories
INCLUDES += -Iinclude
DIRS := $(patsubst test/%, %, $(wildcard test/*))
SOURCES := $(wildcard test/*/*.cpp)
OBJECTS := $(patsubst test/%.cpp, build/%.o, $(SOURCES))
EXECUTABLES := $(patsubst test/%.cpp, bin/%, $(SOURCES))
DEPENDENCIES := $(patsubst test/%.cpp, build/%.d, $(SOURCES))
# prevent printing of recipes
.SILENT:
# keep intermediate object files after compilation
.SECONDARY: $(OBJECTS)
# include generated dependencies
-include $(DEPENDENCIES)
.PHONY: all
all: dirs $(EXECUTABLES)
build/%.o: test/%.cpp
printf '\e[94m%s\e[0m%s' 'Compiling test ' ': $@ ... '
$(CXX) -c $(CXXFLAGS) $(INCLUDES) -o $@ $<
printf '\e[92m%s\e[0m\n' 'Done!'
bin/%: build/%.o
printf '\e[96m%s\e[0m%s' 'Creating binary' ': $@ ... '
$(CXX) $(CXXFLAGS) -o $@ $<
printf '\e[92m%s\e[0m\n' 'Done!'
.PHONY: test
test: dirs $(EXECUTABLES)
find * -name *.test -exec sh -c "echo {}:; ./{}" \;
.PHONY: dirs
dirs:
mkdir -p $(patsubst %, build/%, $(DIRS)) $(patsubst %, bin/%, $(DIRS))
.PHONY: clean
clean:
printf "\e[91m%s\e[0m%s" 'Removing all binaries and build files' ' ... '
rm -f $(EXECUTABLES) $(OBJECTS) $(DEPENDENCIES)
printf '\e[92m%s\e[0m\n' 'Done!'