-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
59 lines (47 loc) · 1.67 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
CC=g++
# Optimized:
#CXXFLAGS=-Wall -Wextra -pedantic -Werror -std=c++17 -O3
# For debugging:
CXXFLAGS=-Wall -Wextra -pedantic -Werror -std=c++17 -g -O0
sources=$(wildcard src/*.cpp)
objects=$(sources:src/%.cpp=obj/%.o)
headers=$(wildcard src/*.hpp)
precompiledheader=obj/stdafx.h.gch
executable=output/neural
resourcesrc=$(shell find resources/ -type f)
resourcedest=$(resourcesrc:resources/%=output/%)
# "|" signals an order-only prerequisite: the prereq must exist, but
# it won't cause the target to be recreated.
$(executable): $(precompiledheader) $(objects) Makefile | obj output $(resourcedest)
$(CC) $(CXXFLAGS) -o $(executable) \
$(objects)
$(resourcedest) : output/% : resources/% | output
mkdir -p $(dir $@);
cp -r $< $@;
obj output:
if [ ! -e $@ ]; then mkdir $@; fi;
reformat:
for file in $(sources) $(headers); do \
clang-format -i -style="$$(<style)" "$$file"; \
done;
# Static pattern rules. Take each object in the targets, create a "base"
# with it specified by % (removing the literal part '.o'), then
# use that base to generate the prerequisite. This generates
# several rules. For instance, main.o : "main".o : "main".cpp
# then refer to the left-most prerequisite with $<, and the target
# with $@ like usual.
$(objects) : obj/%.o : src/%.cpp $(headers) $(precompiledheader) Makefile | obj
$(CC) -c $(CXXFLAGS) \
$< -o $@
$(precompiledheader) : src/stdafx.hpp Makefile | obj
$(CC) $(CXXFLAGS) $< -o $@
clean :
rm -rf obj output
echo :
@echo sources $(sources)
@echo objects $(objects)
@echo headers $(headers) src/stdafx.hpp
@echo executable $(executable)
@echo resourcesrc $(resourcesrc)
@echo resourcedest $(resourcedest)
.PHONY : echo clean reformat