-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobal.mk
More file actions
199 lines (159 loc) · 4.16 KB
/
global.mk
File metadata and controls
199 lines (159 loc) · 4.16 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#
# Global variables
#
#
CC=gcc
CXX=g++
ifdef NO_YASM
ASM=nasm
else
ASM=yasm
endif
OPERATING_SYSTEM := $(shell uname -s)
ifeq ($(OPERATING_SYSTEM),Darwin)
BASE_OBJ_FORMAT := macho
OBJ_FORMAT := $(BASE_OBJ_FORMAT)32
OBJ_DEBUG_OPT :=
endif
ifeq ($(OPERATING_SYSTEM),Linux)
BASE_OBJ_FORMAT := elf
PLATFORM := $(shell uname -m | sed -e "s/i[3456]86/i386/")
OBJ_DEBUG_OPT := -g dwarf2
ifeq ($(PLATFORM),i386)
OBJ_FORMAT := $(BASE_OBJ_FORMAT)32
endif
ifeq ($(PLATFORM),x86_64)
OBJ_FORMAT := $(BASE_OBJ_FORMAT)64
endif
endif
ifdef NO_YASM
OBJ_FORMAT:=$(BASE_OBJ_FORMAT)
OBJ_DEBUG_OPT := -F stabs
endif
ifndef OBJ_FORMAT
ERROR_MSG:=The object format for this platform is unknown; this file needs updating
$(error $(ERROR_MSG))
endif
ifeq ($(Cfg),release32)
Out := build_rel32
Root := .
GLBL_CPPFLAGS := -DNDEBUG
GLBL_CFLAGS := -m32 -O2 -std=c89 -pedantic -Wall -Wextra
GLBL_CXXFLAGS := -m32 -O2 -std=c++98 -pedantic -Wall -Wextra
GLBL_LDFLAGS := -m32
GLBL_ASMFLAGS := -f $(BASE_OBJ_FORMAT)32
endif
ifeq ($(Cfg),debug32)
Out := build32
Root := .
GLBL_CPPFLAGS := -D_DEBUG
GLBL_CFLAGS := -m32 -g -std=c89 -pedantic -Wall -Wextra
GLBL_CXXFLAGS := -m32 -g -std=c++98 -pedantic -Wall -Wextra
GLBL_LDFLAGS := -m32
GLBL_ASMFLAGS := -f $(BASE_OBJ_FORMAT)32 $(OBJ_DEBUG_OPT)
endif
ifeq ($(Cfg),release)
Out := build_rel
Root := .
GLBL_CPPFLAGS := -DNDEBUG
GLBL_CFLAGS := -O2 -std=c89 -pedantic -Wall -Wextra
GLBL_CXXFLAGS := -O2 -std=c++98 -pedantic -Wall -Wextra
GLBL_ASMFLAGS := -f $(OBJ_FORMAT)
endif
ifeq ($(Cfg),cov)
Out := build_cov
Root := .
GLBL_CPPFLAGS := -D_DEBUG
GLBL_CFLAGS := -fprofile-arcs -ftest-coverage -std=c89 -pedantic -Wall -Wextra
GLBL_CXXFLAGS := -fprofile-arcs -ftest-coverage -std=c++98 -pedantic -Wall -Wextra
GLBL_LDLIBS := gcov
GLBL_ASMFLAGS := -f $(OBJ_FORMAT)
endif
ifndef Out
Out := build
Root := .
GLBL_CPPFLAGS := -D_DEBUG
GLBL_CFLAGS := -g -std=c89 -pedantic -Wall -Wextra
GLBL_CXXFLAGS := -g -std=c++98 -pedantic -Wall -Wextra
GLBL_ASMFLAGS := -f $(OBJ_FORMAT) $(OBJ_DEBUG_OPT)
endif
GLBL_LDPATH := $(Out)/lib
GLBL_LDRPATH := \$$ORIGIN/../lib
CLEAN_FILES :=
TEST_FILES :=
DEP_FILES :=
#
# Universal rules
#
.SECONDEXPANSION:
define makedir
@echo Making directory $(@D)
@mkdir -p $(@D)
@touch $@
endef
define makeso
@echo Linking shared library $@
@$(CC) -shared $(LDFLAGS) $(LDPATH:%=-L%) -o $@ $(OBJECTS) $(LDLIBS:%=-l%)
endef
define makecppso
@echo Linking shared library $@
@$(CXX) -shared $(LDFLAGS) $(LDPATH:%=-L%) -o $@ $(OBJECTS) $(LDLIBS:%=-l%)
endef
ifeq ($(OPERATING_SYSTEM),Darwin)
define makeexe
@echo Linking executable $@
@$(CC) $(LDFLAGS) $(LDPATH:%=-L%) -o $@ $(OBJECTS) $(LDLIBS:%=-l%)
endef
define makecppexe
@echo Linking executable $@
@$(CXX) $(LDFLAGS) $(LDPATH:%=-L%) -o $@ $(OBJECTS) $(LDLIBS:%=-l%)
endef
else
define makeexe
@echo Linking executable $@
@$(CC) $(LDFLAGS) $(LDRPATH:%=-Wl,-rpath,%) $(LDPATH:%=-L%) -o $@ $(OBJECTS) $(LDLIBS:%=-l%)
endef
define makecppexe
@echo Linking executable $@
@$(CXX) $(LDFLAGS) $(LDRPATH:%=-Wl,-rpath,%) $(LDPATH:%=-L%) -o $@ $(OBJECTS) $(LDLIBS:%=-l%)
endef
endif
define makelib
@echo Making library $@
@$(AR) rcs $@ $(OBJECTS)
endef
define compilec
@echo Compiling $< \(\$$stem=$(stem)\)
@$(CC) $(CPPFLAGS) $(INCLUDES:%=-I%) $(CFLAGS) -c -o $@ $<
endef
define compilecpp
@echo Compiling $< \(\$$stem=$(stem)\)
@$(CXX) $(CPPFLAGS) $(INCLUDES:%=-I%) $(CXXFLAGS) -c -o $@ $<
endef
ifdef NO_YASM
define assemble
@echo Assembling $<
@$(ASM) $(ASMFLAGS) $(CPPFLAGS) $(INCLUDES:%=-I%/) -I$(<D)/ -o $@ $<
endef
else
define assemble
@echo Assembling $<
@$(ASM) $(ASMFLAGS) $(CPPFLAGS) $(INCLUDES:%=-I%) -o $@ $<
endef
endif
define makecdep
@echo Generating dependencies for $<
@$(CC) $(CPPFLAGS) $(INCLUDES:%=-I%) -MF $@ -MM -MT $@ -MT $(basename $@).o $<
endef
define makecppdep
@echo Generating dependencies for $<
@$(CXX) $(CPPFLAGS) $(INCLUDES:%=-I%) -MF $@ -MM -MT $@ -MT $(basename $@).o $<
endef
define makeasmdep
@echo Generating dependencies for $<
@$(ASM) $(ASMFLAGS) $(CPPFLAGS) $(INCLUDES:%=-I%) -M $< | sed 's/^$(basename $(@F)).o/$(subst /,\/,$@) $(subst /,\/,$(basename $@)).o/;' >$@
endef
$(Out)/lib/.touch:
$(makedir)
$(Out)/bin/.touch:
$(makedir)