-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·135 lines (108 loc) · 2.78 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
125
126
127
128
129
130
131
132
133
134
135
# please use one of the following commands:
# make PLATFORM=linux
# make PLATFORM=OSX
# make (default)
#
# also the linking option available:
# make LINKING=shared
# make LINKING=static (default)
#
# build variant as:
# make VARIANT=debug
# make VARIANT=release (default)
#
# platform as:
# make PLATFORM={OSX|linux}
# detect platform
ifdef PLATFORM
ifeq '${PLATFORM}' 'OSX'
platform:=OSX
else ifeq '${PLATFORM}' 'linux'
platform:=linux
else
$(error '${PLATFORM}' is unknown platform, expected: OSX or linux)
endif
else
# platform auto detection
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
ifeq '${uname_S}' 'Darwin'
platform:=OSX
else ifeq '${uname_S}' 'Linux'
platform:=linux
else
$(error '${uname_S}' is unknown platform)
endif
endif
# build variant
variant:=release
ifdef VARIANT
ifeq '${VARIANT}' 'release'
variant:=release
else ifeq '${VARIANT}' 'debug'
variant:=debug
else
$(error '${VARIANT}' is unknown variant, expected: release or debug)
endif
endif
# lib linking
linking:=static
ifdef LINKING
ifeq '${LINKING}' 'shared'
linking:=shared
else ifeq '${LINKING}' 'static'
linking:=static
else
$(error '${LINKING}' is unknown linking, expected: shared or static)
endif
endif
home_path:=.
include_dirs:=-I${home_path}/src
defines:=
shared_libs:=
ifeq '${variant}' 'debug'
defines+=-D_DEBUG -g
else # default
defines+=-DNDEBUG
endif
CXXFLAGS:=-Wall -O2 -Os ${include_dirs} ${defines}
CXXFLAGS+=-fdata-sections -ffunction-sections
LDFLAGS:=-L${env_path}/lib -Wl,--gc-sections
test_out:=test.exe
# omni source files
omni_src+=${home_path}/src/omni/calc.cpp
omni_src+=${home_path}/src/omni/util.cpp
omni_src+=${home_path}/src/omni/misc.cpp
# PCH header files
PCH_sources+=${home_path}/src/omni/defs.hpp
PCH_objects:=${PCH_sources:.hpp=.hpp.gch}
# expands to list of object files
test_sources+=${home_path}/src/test/test.cpp
test_sources+=${omni_src} ${home_path}/main_test.cpp
test_objects:=${test_sources:.cpp=.o}
all: ${test_out}
@strip -x ${test_out}
${test_out}: ${test_objects}
@ echo " [LN] $@"
@${CXX} -o $@ ${test_objects} ${LDFLAGS} ${shared_libs}
PCH: ${PCH_objects}
# rule to build gch files
%.hpp.gch: %.hpp
@echo "[CXX] $<"
@$(CXX) ${CXXFLAGS} -c $< -o $@
%.h.gch: %.h
@echo " [CC] $<"
@$(CC) ${CXXFLAGS} -c $< -o $@
# rules to build c/cpp files
%.o: %.cpp
@echo "[CXX] $<"
@${CXX} ${CXXFLAGS} -c $< -o $@
%.o: %.c
@echo " [CC] $<"
@${CC} ${CXXFLAGS} -c $< -o $@
clean:
@rm -f ${test_objects} ${test_out}
@rm -f ${PCH_objects}
version:
@echo "${variant} ${platform} ${linking}"
@echo ${test_objects}
.PHONY: clean PCH version