-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (87 loc) · 2.95 KB
/
Makefile
File metadata and controls
115 lines (87 loc) · 2.95 KB
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
# clang++ is a must for now
CXX := clang++
OPT_LVL := -O3
DBG_LVL := -g3
CFLAGS := -std=c++11 -fpic -march=native -Wall -Wextra -march=native
CFLAGS += $(OPT_LVL) $(DBG_LVL)
CFLAGS += -Werror-implicit-function-declaration -D_GNU_SOURCE
N_JOBS := $(shell echo $$((2 * `grep -c "^processor" /proc/cpuinfo`)))
# it is all of -std-compile-opts -std-link-opts without -internalize
OPT_OPTS := -adce -argpromotion -basicaa -basiccg -constmerge \
-correlated-propagation -deadargelim -domtree -dse -early-cse \
-functionattrs -globaldce -globalopt -globalsmodref-aa -gvn \
-indvars -inline -inline-cost -instcombine -ipsccp \
-jump-threading -lazy-value-info -lcssa -licm -loop-deletion \
-loop-idiom -loop-rotate -loops -loop-simplify -loop-unroll \
-loop-unswitch -memcpyopt -memdep -no-aa -notti -preverify \
-prune-eh -reassociate -scalar-evolution -sccp -simplifycfg -sroa \
-strip-dead-prototypes -tailcallelim -targetlibinfo -tbaa -verify
LTO :=
LTO := -emit-llvm
BUILD := build
SRC := src
LIBS := -lm -larmadillo -llapack -lblas -lntl
SOURCES := $(sort $(wildcard $(SRC)/*.cpp))
BYTECODES := $(addprefix $(BUILD)/,$(notdir $(SOURCES:.cpp=.bc)))
DEPENDS := $(BYTECODES:.bc=.d)
BINS := tester
LIB := snf.so
BIN_BASES := $(BINS)
BIN_SOURCES := $(addprefix $(BUILD)/,$(notdir $(BIN_BASES:=.cpp)))
BIN_BYTECODES := $(BIN_SOURCES:.cpp=.bc)
LIB_SOURCES := $(filter-out $(BIN_SOURCES),$(SOURCES))
LIB_BYTECODES := $(filter-out $(BIN_BYTECODES),$(BYTECODES))
LIB_BYTECODE := $(BUILD)/$(LIB:.so=.bc)
# re-expand variables in subsequent rules
.SECONDEXPANSION:
# parallel make all
pall:
make -j$(N_JOBS) all
all: $(BINS) $(LIB)
# add debug flag to flags, then compile with info
debug: CFLAGS += -DSMITH_DEBUG
debug: info
# parallel make debug
pdebug:
make -j$(N_JOBS) debug
# add info flag to flags, then compile
info: CFLAGS += -DSMITH_INFO
info: $(BINS)
# parallel make info
pinfo:
make -j$(N_JOBS) info
# add performance flag to flags, then compile
perf: CFLAGS += -DSMITH_PERFORMANCE
perf: $(BINS)
# parallel make perf
pperf:
make -j$(N_JOBS) perf
# include compiler-generated dependencies, so obj files get recompiled when
# their header changes
-include $(DEPENDS)
# -MMD generates $(BUILD)/%.d dependency file (only local header dependencies,
# -MD for system-wide header dependencies)
$(BUILD)/%.bc: $(SRC)/%.cpp Makefile | $(BUILD)
$(CXX) -c $(CFLAGS) $(LTO) -MMD -o $@ $<
$(BUILD):
mkdir $(BUILD)
# each binary depends on its own .bc file and the library bytecode
$(BINS): $(BUILD)/$$@.bc $(LIB_BYTECODE)
$(CXX) $(CFLAGS) $^ $(LIBS) -o $@
$(LIB): $(LIB_BYTECODE)
$(CXX) -shared -fPIC $^ -o $@
$(LIB_BYTECODE): $(LIB_BYTECODES)
llvm-link $^ -o $@
ifeq ($(OPT_LVL),-O3)
opt $(OPT_OPTS) $(OPT_LVL) $@ -o $@
endif
clean:
rm -rf $(BUILD) *.so *~ core $(BINS)
rm -f tests/*.o tests/*~ run_tests
show:
# $(SOURCES)
# $(BYTECODES)
# $(BIN_BASES)
# $(BIN_BYTECODES)
# $(OTHER_BYTECODES)
.PHONY: clean show all