-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
95 lines (72 loc) · 2.89 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
COMPILER=/usr/bin/g++
CAIRO_PATH=/usr/include/cairo/
BOOST_PATH=~/boost_1_67_0
INCLUDE=-I . -isystem $(CAIRO_PATH) -isystem $(BOOST_PATH) -isystem core/util/outside/
GRAPHICS_LIB=-lcairo -lX11 -lmenu -lncurses
# default values
CPP=test.cpp
MAIN:=$(CPP:.cpp=)
EXEC=$(MAIN)
ASSEMBLY=$(MAIN).asm
MODE=debug
MAIN_CPP=$(CPP)
MAIN_I=$(MAIN).i
ifdef CONFIG
MYCONF=-DCONFIG='"$(CONFIG)"'
endif
# Look at -flto=n in case several translation units are identified
COMMON_PREFIX=$(COMPILER) -Wall -Wextra -Werror -fmax-errors=3 -std=c++11 -pedantic -Wno-sign-compare $(INCLUDE) $(MYCONF) $(ADD)
PREPROCESSOR_DEBUG=$(COMMON_PREFIX) -o $(MAIN_I) $(MAIN_CPP) -E
PREPROCESSOR_PRODUCTION=$(PREPROCESSOR_DEBUG) -DNDEBUG
MAKE_EXEC=$(COMMON_PREFIX) -fpreprocessed -o $(EXEC) $(MAIN_I) $(GRAPHICS_LIB)
# The following is for exploring how the compiler optimizes the code.
# http://www.systutorials.com/240/generate-a-mixed-source-and-assembly-listing-using-gcc/
MAKE_ASSEMBLY=$(COMMON_PREFIX) -fpreprocessed $(MAIN_I) $(GRAPHICS_LIB) -g -Wa,-adhln -fverbose-asm -O3 > $(ASSEMBLY)
MAKE_DEBUG_EXEC=$(MAKE_EXEC) -g -O0
MAKE_PRODUCTION_EXEC=$(MAKE_EXEC) -O3 #-g -fno-inline
HASH_SOURCE=.execs/last_hash_source
HASH_CODE=.execs/last_hash_code
default: debug
# Builds the executable based on MODE, CPP, CONFIG and ADD.
# Does not use OPT, which controls the run-time parameters.
# Begins by computing the name of executable containing the hash key. Defers the actual build to another instance of make in order to share the EXEC variable.
compute-hash:
@mkdir -p .execs
@$(COMMON_PREFIX) -E -fdirectives-only $(MAIN_CPP) -o $(HASH_SOURCE)
@echo $(MODE) >> $(HASH_SOURCE)
@cat symbols.cpp >> $(HASH_SOURCE)
@$(MAKE) 3>&2 2>&1 1>&3 build-exec EXEC=.execs/slb`md5sum $(HASH_SOURCE) | colrm 33 | tee $(HASH_CODE)`
# Both builds and executes.
run: compute-hash
@./last_exec $(OPT)
# Builds executable with the name computed by compute-hash. Does nothing if the executable exists already.
build-exec:
@test -e $(EXEC) || $(MAKE) $(MODE)
@ln -sf $(EXEC) last_exec
@touch $(EXEC)
preprocessor-debug: symbols
$(PREPROCESSOR_DEBUG)
./symbols $(MAIN_I)
preprocessor-production: symbols
$(PREPROCESSOR_PRODUCTION)
./symbols $(MAIN_I)
debug: preprocessor-debug
$(MAKE_DEBUG_EXEC)
production: preprocessor-production
$(MAKE_PRODUCTION_EXEC)
assembly: preprocessor-production
$(MAKE_ASSEMBLY)
symbols: symbols.cpp Makefile
$(COMMON_PREFIX) -O2 symbols.cpp -o symbols
symbols-debug: symbols.cpp Makefile
$(COMMON_PREFIX) -g symbols.cpp -o symbols
align: align.cpp Makefile
$(COMMON_PREFIX) -O2 align.cpp -o align
docs:
rm -rf documentation
doxygen doxygen.conf
cd documentation/latex; pdflatex refman.tex; pdflatex refman.tex
ln -fs documentation/latex/refman.pdf documentation.pdf
#Precompiled header is not currently used
#PRECOMPILED_HEADER=outside_headers.h
#COMMON_PRECOMPILE=$(COMMON_PREFIX) -o $(PRECOMPILED_HEADER).gch -c $(PRECOMPILED_HEADER)