forked from gpertea/gclib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
120 lines (95 loc) · 2.68 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
INCDIRS := -I. -I${GDIR} -I${BAM}
CXX := $(if $(CXX),$(CXX),g++)
LINKER := $(if $(LINKER),$(LINKER),g++)
LDFLAGS := $(if $(LDFLAGS),$(LDFLAGS),-g)
LIBS :=
# A simple hack to check if we are on Windows or not (i.e. are we using mingw32-make?)
ifeq ($(findstring mingw32, $(MAKE)), mingw32)
WINDOWS=1
endif
# Compiler settings
TLIBS =
# Non-windows systems need pthread
ifndef WINDOWS
TLIBS += -lpthread
endif
DMACH := $(shell ${CXX} -dumpmachine)
# MinGW32 GCC 4.5 link problem fix
ifdef WINDOWS
DMACH := windows
ifeq ($(findstring 4.5.,$(shell g++ -dumpversion)), 4.5.)
LDFLAGS += -static-libstdc++ -static-libgcc
endif
endif
# Misc. system commands
ifdef WINDOWS
RM = del /Q
else
RM = rm -f
endif
# File endings
ifdef WINDOWS
EXE = .exe
else
EXE =
endif
CC := g++
BASEFLAGS := -Wall -Wextra ${INCDIRS} $(MARCH) \
-D_REENTRANT -fno-exceptions -fno-rtti
GCCVER5 := $(shell expr `g++ -dumpversion | cut -f1 -d.` \>= 5)
ifeq "$(GCCVER5)" "1"
BASEFLAGS += -Wno-implicit-fallthrough
endif
GCCVER8 := $(shell expr `g++ -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
GCC45OPTS :=
GCC45OPTMAIN :=
ifneq (,$(filter %release %nodebug, $(MAKECMDGOALS)))
# -- release build
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS),-g -O3)
CXXFLAGS += -DNDEBUG $(BASEFLAGS)
ifeq ($(shell expr $(GCC_MAJOR).$(GCC_MINOR) '>=' 4.5),1)
CXXFLAGS += -flto
GCC45OPTS := -flto
GCC45OPTMAIN := -fwhole-program
endif
else
# -- debug build
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS),-g -O0)
ifneq (, $(findstring darwin, $(DMACH)))
CXXFLAGS += -gdwarf-3
endif
CXXFLAGS += -DDEBUG -D_DEBUG -DGDEBUG $(BASEFLAGS)
endif
%.o : %.cpp
${CXX} ${CXXFLAGS} -c $< -o $@
OBJS := GBase.o GStr.o GArgs.o
.PHONY : all
all: gtest
nodebug: all
release: all
debug: all
#threads
version: ; @echo "GCC Version is: "$(GCC_MAJOR)":"$(GCC_MINOR)":"$(GCC_SUB)
@echo "> GCC Opt. string is: "$(GCC45OPTS)
gtest.o : GBase.h GArgs.h GVec.hh GList.hh GBitVec.h
GArgs.o : GArgs.h
gtest: $(OBJS) gtest.o
${LINKER} ${LDFLAGS} $(GCC45OPTS) $(GCC45OPTMAIN) -o $@ ${filter-out %.a %.so, $^} ${LIBS}
threads: GThreads.o threads.o
${LINKER} ${LDFLAGS} $(GCC45OPTS) $(GCC45OPTMAIN) -o $@ ${filter-out %.a %.so, $^} ${TLIBS} ${LIBS}
GThreads.o: GThreads.h GThreads.cpp
threads.o : GThreads.h GThreads.cpp
# target for removing all object files
.PHONY : clean
clean::
@${RM} $(OBJS) gtest.o GThreads.o threads.o threads$(EXE) gtest$(EXE)
@${RM} core.*