forked from dlang/druntime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposix.mak
360 lines (283 loc) · 9.32 KB
/
posix.mak
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# patched to work under windows aswell
#
# This makefile is designed to be run by gnu make.
# The default make program on FreeBSD 8.1 is not gnu make; to install gnu make:
# pkg_add -r gmake
# and then run as gmake rather than make.
QUIET:=@
OS:=
uname_S:=$(shell uname -s)
ifeq (Darwin,$(uname_S))
OS:=osx
endif
ifeq (Linux,$(uname_S))
OS:=linux
endif
ifeq (FreeBSD,$(uname_S))
OS:=freebsd
endif
ifeq (OpenBSD,$(uname_S))
OS:=openbsd
endif
ifeq (Solaris,$(uname_S))
OS:=solaris
endif
ifeq (SunOS,$(uname_S))
OS:=solaris
endif
ifeq (,$(OS))
$(error Unrecognized or unsupported OS for uname: $(uname_S))
endif
# normalize windows names, e.g. Windows_NT
ifeq (win,$(findstring win,$(OS)))
OS:=win32
endif
ifeq (Win,$(findstring Win,$(OS)))
OS:=win32
endif
DMD?=dmd
INSTALL_DIR=../install
MKDIR=mkdir
GREP=grep
DOCDIR=doc
IMPDIR=import
MODEL:=default
ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
endif
override PIC:=$(if $(PIC),-fPIC,)
ifeq (osx,$(OS))
DOTDLL:=.dylib
DOTLIB:=.a
else
DOTDLL:=.so
DOTLIB:=.a
endif
DFLAGS=$(MODEL_FLAG) $(OPTFLAGS) -w -Isrc -Iimport $(PIC) $(DMDEXTRAFLAGS)
UDFLAGS=$(MODEL_FLAG) $(OPTFLAGS) -w -Isrc -Iimport $(PIC) $(DMDEXTRAFLAGS)
DDOCFLAGS=-c -w -o- -Isrc -Iimport -version=CoreDdoc
CFLAGS=$(MODEL_FLAG) -O $(PIC)
ifeq ($(BUILD),debug)
OPTFLAGS=-g
CFLAGS += -g
else
OPTFLAGS=-O -release -inline
endif
ifeq (osx,$(OS))
ASMFLAGS =
else
ASMFLAGS = -Wa,--noexecstack
endif
ifeq (cl.exe,$(findstring cl.exe,$(CC)))
CFLAGS_O = $(subst -g,/Z7,$(CFLAGS)) /Zl -Fo
# OPTFLAGS := $(subst -g,,$(OPTFLAGS)) # no debug info yet
else
CFLAGS_O = $(CFLAGS) $(PIC) -o
endif
ifeq (/,findstring /,$(DMD))
DMDDEP = $(shell which $(DMD))
else
DMDDEP = $(DMD)
endif
OBJDIR=obj/$(MODEL)
DRUNTIME_BASE=druntime-$(OS)$(MODEL)
ifeq (win32,$(OS))
DRUNTIME=$(LIBDIR)/$(DRUNTIME_BASE).lib
else
DRUNTIME=$(LIBDIR)/lib$(DRUNTIME_BASE).a
endif
DRUNTIMESO=lib/lib$(DRUNTIME_BASE).so
DRUNTIMESOOBJ=lib/lib$(DRUNTIME_BASE)so.o
DRUNTIMESOLIB=lib/lib$(DRUNTIME_BASE)so.a
DOCFMT=
include mak/COPY
COPY:=$(subst \,/,$(COPY))
include mak/DOCS
DOCS:=$(subst \,/,$(DOCS))
include mak/IMPORTS
IMPORTS:=$(subst \,/,$(IMPORTS))
include mak/MANIFEST
MANIFEST:=$(subst \,/,$(MANIFEST))
include mak/SRCS
SRCS:=$(subst \,/,$(SRCS))
# NOTE: trace.d and cover.d are not necessary for a successful build
# as both are used for debugging features (profiling and coverage)
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for Linux
ifeq (win32,$(OS))
SRC_D_MODULES += $(SRC_D_MODULES_WIN) $(SRC_D_MODULES_WIN$(MODEL))
O = obj
DOTEXE = .exe
OBJS = $(OBJDIR)/errno_c.obj
ifeq ($(MODEL),32)
OBJS += src\rt\minit.obj
endif
ifeq ($(MODEL),32ms)
# OBJS += src\rt\minit_coff.obj
endif
else
SRC_D_MODULES += $(SRC_D_MODULES_POSIX)
DOTEXE =
O = o
OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o
endif
######################## All of'em ##############################
ifeq (linux,$(OS))
target : import copy dll $(DRUNTIME) doc
else
target : import copy $(DRUNTIME) doc
endif
######################## Doc .html file generation ##############################
doc: $(DOCS)
$(DOCDIR)/object.html : src/object_.d
$(DMD) $(DDOCFLAGS) -Df$@ $(DOCFMT) $<
$(DOCDIR)/core_%.html : src/core/%.di
$(DMD) $(DDOCFLAGS) -Df$@ $(DOCFMT) $<
$(DOCDIR)/core_%.html : src/core/%.d
$(DMD) $(DDOCFLAGS) -Df$@ $(DOCFMT) $<
$(DOCDIR)/core_sync_%.html : src/core/sync/%.d
$(DMD) $(DDOCFLAGS) -Df$@ $(DOCFMT) $<
######################## Header .di file generation ##############################
import: $(IMPORTS)
$(IMPDIR)/core/sync/%.di : src/core/sync/%.d
@$(MKDIR) -p $(dir $@).
$(DMD) -c -o- -Isrc -Iimport -Hf$@ $<
######################## Header .di file copy ##############################
copy: $(COPY)
$(IMPDIR)/%.di : src/%.di
@$(MKDIR) -p $(dir $@).
cp $< $@
$(IMPDIR)/%.d : src/%.d
@$(MKDIR) -p $(dir $@).
cp $< $@
ifeq (win32,$(OS))
# building on windows fails, but file is still generated
$(IMPDIR)/core/sys/freebsd/%.di : src/core/sys/freebsd/%.di
-$(DMD) -m$(MODEL) -c -d -o- -Isrc -Iimport -Hf$@ $<
endif
################### C/ASM Targets ############################
$(OBJDIR)/%.$O : src/rt/%.c
@$(MKDIR) -p $(dir $@).
$(CC) -c $(CFLAGS_O)$@ $<
$(OBJDIR)/errno_c.$O : src/core/stdc/errno.c
@$(MKDIR) -p $(OBJDIR)
$(CC) -c $(CFLAGS_O)$@ $<
$(OBJDIR)/threadasm.o : src/core/threadasm.S
@$(MKDIR) -p $(OBJDIR)
$(CC) $(ASMFLAGS) -c $(CFLAGS) $< -o$@
src\rt\minit.obj : src\rt\minit.asm
ml -c /omf /D_WIN32 /Fo$@ src\rt\minit.asm
src\rt\minit_coff.obj : src\rt\minit.asm
ml -c /D_WIN32 /DCOFF /Fo$@ src\rt\minit.asm
######################## Create a shared library ##############################
$(DRUNTIMESO) $(DRUNTIMESOLIB) dll: override PIC:=-fPIC
$(DRUNTIMESO) $(DRUNTIMESOLIB) dll: DFLAGS+=-version=Shared
dll: $(DRUNTIMESOLIB)
$(DRUNTIMESO): $(OBJS) $(SRCS)
$(DMD) -shared -debuglib= -defaultlib= -of$(DRUNTIMESO) $(DFLAGS) $(SRCS) $(OBJS) -L-ldl
$(DRUNTIMESOLIB): $(OBJS) $(SRCS)
$(DMD) -c -fPIC -of$(DRUNTIMESOOBJ) $(DFLAGS) $(SRCS)
$(DMD) -lib -of$(DRUNTIMESOLIB) $(DRUNTIMESOOBJ) $(OBJS)
################### Library generation #########################
$(DRUNTIME): $(OBJS) $(SRCS) posix.mak $(DMDDEP)
$(DMD) -lib -of$(DRUNTIME) -Xf$(JSONDIR)\druntime.json $(DFLAGS) $(SRCS) $(OBJS)
################### shared Library generation ##################
ADDITIONAL_TESTS:=test/init_fini test/exceptions
ADDITIONAL_TESTS+=$(if $(findstring $(OS),linux),test/shared,)
unittest : $(UT_MODULES) $(addsuffix /.run,$(ADDITIONAL_TESTS))
shared: $(LIBDIR)/$(DRUNTIME_BASE)_shared.dll
SDFLAGS = $(DFLAGS) -version=druntime_shared
ifeq (win32,$(OS))
SDFLAGS += -exportall -defaultlib=msvcrt -L/DLL
endif
$(LIBDIR)/$(DRUNTIME_BASE)_shared.dll : $(OBJS) $(SRCS) win64.mak
$(DMD) $(SDFLAGS) -of$@ src\rt\dllmain.d $(SRCS) $(OBJS) src\shared\dummy.def
################### unittests #########################
UT_MODULES:=$(patsubst src/%.d,$(OBJDIR)/%$(DOTEXE),$(SRCS))
unittest : $(UT_MODULES) $(DRUNTIME) $(OBJDIR)/emptymain.d
@echo done
ifeq ($(OS),freebsd)
DISABLED_TESTS =
else
DISABLED_TESTS =
endif
$(addprefix $(OBJDIR)/,$(DISABLED_TESTS)) :
@echo $@ - disabled
ifneq (linux,$(OS))
$(OBJDIR)/test_runner$(DOTEXE): $(OBJS) $(SRCS) src/test_runner.d
$(DMD) $(UDFLAGS) -version=druntime_unittest -unittest -of$@ src/test_runner.d $(SRCS) $(OBJS) -debuglib= -defaultlib=
else
UT_DRUNTIME:=$(OBJDIR)/lib$(DRUNTIME_BASE)-ut$(DOTDLL)
$(UT_DRUNTIME): override PIC:=-fPIC
$(UT_DRUNTIME): UDFLAGS+=-version=Shared
$(UT_DRUNTIME): $(OBJS) $(SRCS)
$(DMD) $(UDFLAGS) -shared -version=druntime_unittest -unittest -of$@ $(SRCS) $(OBJS) -L-ldl -debuglib= -defaultlib=
$(OBJDIR)/test_runner$(DOTEXE): $(UT_DRUNTIME) src/test_runner.d
$(DMD) $(UDFLAGS) -of$@ src/test_runner.d -L$(UT_DRUNTIME) -debuglib= -defaultlib=
endif
# macro that returns the module name given the src path
moduleName=$(subst rt.invariant,invariant,$(subst object_,object,$(subst /,.,$(1))))
$(OBJDIR)/% : $(OBJDIR)/test_runner$(DOTEXE)
@$(MKDIR) -p $(dir $@).
$(OBJDIR)/%$(DOTEXE) : src/%.d $(DRUNTIME) $(OBJDIR)/emptymain.d
ifeq (win32,$(OS))
@if $(GREP) -q unittest $< ; then \
echo Testing $@ && \
$(DMD) $(UDFLAGS) -version=druntime_unittest -unittest $(subst /,\\,-of$@ -map [email protected] $(OBJDIR)/emptymain.d) $< -debuglib=$(DRUNTIME_BASE) -defaultlib=$(DRUNTIME_BASE) && \
$(RUN) $@ ; \
else echo Skipping $< ; \
fi
else
@$(DMD) $(UDFLAGS) -version=druntime_unittest -unittest -of$@ $(OBJDIR)/emptymain.d $< -L-Llib -debuglib=$(DRUNTIME_BASE) -defaultlib=$(DRUNTIME_BASE)
# make the file very old so it builds and runs again if it fails
@touch -t 197001230123 $@
# run unittest in its own directory
@$(RUN) $@
# succeeded, render the file new again
@touch $@
endif
test/init_fini/.run test/exceptions/.run: $(DRUNTIME)
test/shared/.run: $(DRUNTIMESO)
test/%/.run: test/%/Makefile
$(QUIET)$(MAKE) -C test/$* MODEL=$(MODEL) OS=$(OS) DMD=$(abspath $(DMD)) \
DRUNTIME=$(abspath $(DRUNTIME)) DRUNTIMESO=$(abspath $(DRUNTIMESO)) QUIET=$(QUIET)
$(OBJDIR)/testall$(DOTEXE) : $(SRCS) $(DRUNTIME) $(OBJDIR)/emptymain.d
@echo Testing $@
ifeq (win32,$(OS))
@$(DMD) $(UDFLAGS) -version=druntime_unittest -unittest $(subst /,\,-of$@ -map [email protected] $(OBJDIR)/emptymain.d) $(SRCS) -debuglib=$(DRUNTIME_BASE) -defaultlib=$(DRUNTIME_BASE)
@$(RUN) $@
else
$(QUIET)$(DMD) $(UDFLAGS) -version=druntime_unittest -unittest -of$@ $(OBJDIR)/emptymain.d $< -L-Llib -debuglib=$(DRUNTIME_BASE) -defaultlib=$(DRUNTIME_BASE)
# make the file very old so it builds and runs again if it fails
@touch -t 197001230123 $@
# run unittest in its own directory
$(QUIET)$(RUN) $(OBJDIR)/test_runner$(DOTEXE) $(call moduleName,$*)
# succeeded, render the file new again
@touch $@
endif
$(OBJDIR)/emptymain.d :
@$(MKDIR) -p $(OBJDIR)
ifeq (cmd.exe,$(findstring $(SHELL),cmd.exe))
@echo void main(){} >$@
else
@echo 'void main(){}' >$@
endif
detab:
detab $(MANIFEST)
tolf $(MANIFEST)
zip: druntime.zip
druntime.zip: $(MANIFEST) $(DOCS) $(IMPORTS)
rm -rf $@
zip $@ $^
install: target
mkdir -p $(INSTALL_DIR)/html
cp -r doc/* $(INSTALL_DIR)/html/
mkdir -p $(INSTALL_DIR)/import
cp -r import/* $(INSTALL_DIR)/import/
mkdir -p $(INSTALL_DIR)/lib
cp -r lib/* $(INSTALL_DIR)/lib/
cp LICENSE $(INSTALL_DIR)/druntime-LICENSE.txt
clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS))
rm -rf obj lib $(IMPDIR) $(DOCDIR) druntime.zip
test/%/.clean: test/%/Makefile
$(MAKE) -C test/$* clean