1 |
THISCODEDIR := . |
2 |
SEARCHDIRS := -I${THISCODEDIR} |
3 |
|
4 |
SYSTYPE := $(shell uname) |
5 |
|
6 |
# A simple hack to check if we are on Windows or not (i.e. are we using mingw32-make?) |
7 |
ifeq ($(findstring mingw32, $(MAKE)), mingw32) |
8 |
WINDOWS=1 |
9 |
endif |
10 |
|
11 |
|
12 |
# Compiler settings |
13 |
TLIBS = |
14 |
LDFLAGS = |
15 |
# Non-windows systems need pthread |
16 |
ifndef WINDOWS |
17 |
TLIBS += -lpthread |
18 |
endif |
19 |
|
20 |
# MinGW32 GCC 4.5 link problem fix |
21 |
ifdef WINDOWS |
22 |
ifeq ($(findstring 4.5.,$(shell g++ -dumpversion)), 4.5.) |
23 |
LDFLAGS += -static-libstdc++ -static-libgcc |
24 |
endif |
25 |
endif |
26 |
|
27 |
# Misc. system commands |
28 |
ifdef WINDOWS |
29 |
RM = del /Q |
30 |
else |
31 |
RM = rm -f |
32 |
endif |
33 |
|
34 |
# File endings |
35 |
ifdef WINDOWS |
36 |
EXE = .exe |
37 |
else |
38 |
EXE = |
39 |
endif |
40 |
|
41 |
CC := g++ |
42 |
|
43 |
BASEFLAGS := -Wall -Wextra ${SEARCHDIRS} $(MARCH) \ |
44 |
-D_REENTRANT -fno-exceptions -fno-rtti |
45 |
|
46 |
#add the link-time optimization flag if gcc version > 4.5 |
47 |
GCC_VERSION:=$(subst ., ,$(shell gcc -dumpversion)) |
48 |
GCC_MAJOR:=$(word 1,$(GCC_VERSION)) |
49 |
GCC_MINOR:=$(word 2,$(GCC_VERSION)) |
50 |
#GCC_SUB:=$(word 3,$(GCC_VERSION)) |
51 |
GCC_SUB:=x |
52 |
|
53 |
GCC45OPTS := |
54 |
GCC45OPTMAIN := |
55 |
|
56 |
ifeq ($(findstring debug,$(MAKECMDGOALS)),) |
57 |
CFLAGS := -O2 -DNDEBUG $(BASEFLAGS) |
58 |
ifeq ($(shell expr $(GCC_MAJOR).$(GCC_MINOR) '>=' 4.5),1) |
59 |
CFLAGS += -flto |
60 |
GCC45OPTS := -flto |
61 |
GCC45OPTMAIN := -fwhole-program |
62 |
endif |
63 |
else |
64 |
CFLAGS := -g -DDEBUG $(BASEFLAGS) |
65 |
LDFLAGS += -g |
66 |
endif |
67 |
|
68 |
%.o : %.cpp |
69 |
${CC} ${CFLAGS} -c $< -o $@ |
70 |
|
71 |
# C/C++ linker |
72 |
|
73 |
LINKER := g++ |
74 |
LIBS := |
75 |
OBJS := GBase.o GStr.o GArgs.o |
76 |
|
77 |
.PHONY : all |
78 |
all: gtest threads |
79 |
|
80 |
version: ; @echo "GCC Version is: "$(GCC_MAJOR)":"$(GCC_MINOR)":"$(GCC_SUB) |
81 |
@echo "> GCC Opt. string is: "$(GCC45OPTS) |
82 |
debug: gtest threads |
83 |
$(OBJS) : GBase.h GArgs.h |
84 |
gtest.o : GBase.h GArgs.h |
85 |
GArgs.o : GArgs.h |
86 |
gtest: $(OBJS) gtest.o |
87 |
${LINKER} ${LDFLAGS} $(GCC45OPTS) $(GCC45OPTMAIN) -o $@ ${filter-out %.a %.so, $^} ${LIBS} |
88 |
threads: GThreads.o threads.o |
89 |
${LINKER} ${LDFLAGS} $(GCC45OPTS) $(GCC45OPTMAIN) -o $@ ${filter-out %.a %.so, $^} ${TLIBS} ${LIBS} |
90 |
GThreads.o: GThreads.h GThreads.cpp |
91 |
threads.o : GThreads.h GThreads.cpp |
92 |
# target for removing all object files |
93 |
|
94 |
.PHONY : clean |
95 |
clean:: |
96 |
@${RM} $(OBJS) gtest.o GThreads.o threads.o threads$(EXE) gtest$(EXE) |
97 |
@${RM} core.* |