-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
124 lines (106 loc) · 3.36 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
INCDIRS :=
#-I${BAM}
CXX := $(if $(CXX),$(CXX),g++)
LINKER := $(if $(LINKER),$(LINKER),g++)
LDFLAGS := $(if $(LDFLAGS),$(LDFLAGS),-g)
LIBS := -lz
DMACH := $(shell ${CXX} -dumpmachine)
ifneq (, $(findstring mingw32, $(DMACH)))
WINDOWS=1
endif
ifneq (, $(findstring linux, $(DMACH)))
# -lrt only needed for Linux systems
LIBS+= -lrt
endif
# MinGW32 GCC 4.5 link problem fix
ifdef WINDOWS
DMACH := windows
ifeq ($(findstring 4.5.,$(shell ${CXX} -dumpversion)), 4.5.)
LDFLAGS += -static-libstdc++ -static-libgcc
endif
LIBS += -lregex -lws2_32
endif
# Misc. system commands
# assuming on Windows this is run under MSYS
RM = rm -f
# File endings
ifdef WINDOWS
EXE = .exe
else
EXE =
endif
BASEFLAGS := -std=c++11 -Wall -Wextra ${INCDIRS} $(MARCH) \
-D_REENTRANT -fno-exceptions -fno-rtti
GCCVER5 := $(shell expr `${CXX} -dumpversion | cut -f1 -d.` \>= 5)
ifeq "$(GCCVER5)" "1"
BASEFLAGS += -Wno-implicit-fallthrough
endif
GCCVER8 := $(shell expr `${CXX} -dumpversion | cut -f1 -d.` \>= 8)
ifeq "$(GCCVER8)" "1"
BASEFLAGS += -Wno-class-memaccess
endif
#add the link-time optimization flag if gcc version > 4.5
GCC_VERSION:=$(subst ., ,$(shell gcc -dumpversion))
GCC_MAJOR:=$(word 1,$(GCC_VERSION))
GCC_MINOR:=$(word 2,$(GCC_VERSION))
#GCC_SUB:=$(word 3,$(GCC_VERSION))
GCC_SUB:=x
ifneq (,$(filter %release %nodebug, $(MAKECMDGOALS)))
# -- release build
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS),-g -O3)
CXXFLAGS += -DNDEBUG $(BASEFLAGS)
else
ifneq (,$(filter %memcheck %tsan, $(MAKECMDGOALS)))
#use sanitizer in gcc 4.9+
GCCVER49 := $(shell expr `${CXX} -dumpversion | cut -f1,2 -d.` \>= 4.9)
ifeq "$(GCCVER49)" "0"
$(error gcc version 4.9 or greater is required for this build target)
endif
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS),-g -O0)
SANLIBS :=
ifneq (,$(filter %tsan %tcheck %thrcheck, $(MAKECMDGOALS)))
# thread sanitizer only (incompatible with address sanitizer)
CXXFLAGS += -fno-omit-frame-pointer -fsanitize=thread -fsanitize=undefined $(BASEFLAGS)
SANLIBS := -ltsan
else
# address sanitizer
CXXFLAGS += -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address $(BASEFLAGS)
SANLIBS := -lasan
endif
ifeq "$(GCCVER5)" "1"
CXXFLAGS += -fsanitize=bounds -fsanitize=float-divide-by-zero -fsanitize=vptr
CXXFLAGS += -fsanitize=float-cast-overflow -fsanitize=object-size
#CXXFLAGS += -fcheck-pointer-bounds -mmpx
endif
CXXFLAGS += -DDEBUG -D_DEBUG -DGDEBUG -fno-common -fstack-protector
LIBS := ${SANLIBS} -lubsan -ldl ${LIBS}
else
# -- plain debug build
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS), -O0 -g)
ifneq (, $(findstring darwin, $(DMACH)))
CXXFLAGS += -gdwarf-3
endif
CXXFLAGS += -DDEBUG -D_DEBUG -DGDEBUG $(BASEFLAGS)
endif
endif
%.o : %.cpp
${CXX} ${CXXFLAGS} -c $< -o $@
.PHONY : all
all: htest
memcheck tsan: all
#mdtest
nodebug: all
release: all
debug: all
OBJS := GBase.o GStr.o GArgs.o GResUsage.o
version: ; @echo "GCC Version is: "$(GCC_MAJOR)":"$(GCC_MINOR)":"$(GCC_SUB)
htest.o: htest.cpp GHashMap.hh
htest: $(OBJS) htest.o
${LINKER} ${LDFLAGS} -o $@ ${filter-out %.a %.so, $^} ${LIBS}
mdtest: $(OBJS) mdtest.o
${LINKER} ${LDFLAGS} -o $@ ${filter-out %.a %.so, $^} ${LIBS}
# target for removing all object files
.PHONY : clean
clean::
${RM} $(OBJS) *.o mdtest$(EXE) htest$(EXE)
${RM} core.*