-
-
Notifications
You must be signed in to change notification settings - Fork 724
Expand file tree
/
Copy pathMakefile
More file actions
185 lines (149 loc) · 6.27 KB
/
Copy pathMakefile
File metadata and controls
185 lines (149 loc) · 6.27 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
# This makefile is designed to be run by gnu make.
# - Windows: you may download a prebuilt zipped .exe from https://github.com/dlang/dmd/releases/download/nightly/gnumake-4.4-win64.zip.
# You also need a Git for Windows installation, for bash and common GNU tools like cp,mkdir,mv,rm,touch,which.
# - FreeBSD: the default make program on FreeBSD is not gnu make; to install gnu make:
# pkg install gmake
# and then run as gmake rather than make.
#
# Examples:
# - Build compiler (unoptimized) and druntime:
# make -j$(nproc)
# - Build compiler (optimized) and druntime using an LDC host compiler:
# make -j$(nproc) HOST_DMD=ldmd2 ENABLE_RELEASE=1 [ENABLE_LTO=1]
# - Build heavily (LTO+PGO) optimized compiler, incl. druntime and Phobos as side-effects:
# make -j$(nproc) HOST_DMD=path/to/ldmd2 dmd-pgo
# - Build and run druntime tests:
# make -j$(nproc) druntime-test
# - Run compiler tests (involving a Phobos build):
# make -j$(nproc) dmd-test
#
# See compiler/src/build.d for variables affecting the compiler build.
# Use HOST_DFLAGS (not DFLAGS) for extra flags (for the host compiler) to be used for the compiler build.
include compiler/src/osmodel.mak
INSTALL_DIR=$(shell pwd)/../install
ECTAGS_LANGS = Make,C,C++,D,Sh
ECTAGS_FILES = compiler/dmd/*.[chd] compiler/dmd/backend/*.[chd] compiler/dmd/root/*.[chd]
EXE:=$(if $(findstring windows,$(OS)),.exe,)
ifeq (,$(HOST_DMD))
ifneq (,$(HOST_DC))
$(warning The HOST_DC variable is deprecated, please use HOST_DMD instead.)
HOST_DMD:=$(HOST_DC)
else ifneq (,$(DMD))
HOST_DMD:=$(DMD)
else ifneq (,$(shell which dmd 2>/dev/null))
HOST_DMD:=dmd$(EXE)
else ifneq (,$(shell which ldmd2 2>/dev/null))
HOST_DMD:=ldmd2$(EXE)
else ifneq (,$(shell which gdmd 2>/dev/null))
HOST_DMD:=gdmd$(EXE)
else
$(error Couldn't find a D host compiler. Please set variable HOST_DMD to the path to a dmd/ldmd2/gdmd executable)
endif
$(info Using D host compiler: $(HOST_DMD))
endif
export HOST_DMD
GENERATED:=generated
BUILD_EXE:=$(GENERATED)/build$(EXE)
RUN_EXE:=$(GENERATED)/run$(EXE)
# forward any HOST_DFLAGS as DFLAGS for the build tool
ifeq (,$(HOST_DFLAGS))
BUILD_CMD:=$(BUILD_EXE)
else
BUILD_CMD:=$(BUILD_EXE) DFLAGS='$(HOST_DFLAGS)'
endif
.PHONY: all clean test html install \
dmd dmd-unittest dmd-test druntime druntime-test \
phobos dmd-pgo \
auto-tester-build auto-tester-test buildkite-test \
toolchain-info check-clean-git style
all: dmd druntime
$(BUILD_EXE): compiler/src/build.d
$(HOST_DMD) -of$@ -g $<
$(RUN_EXE): compiler/test/run.d
$(HOST_DMD) -of$@ -g -i -Icompiler/test -release $<
auto-tester-build:
echo "Auto-Tester has been disabled"
auto-tester-test:
echo "Auto-Tester has been disabled"
buildkite-test: test
toolchain-info: $(BUILD_EXE)
$(BUILD_CMD) $@
clean:
rm -rf $(GENERATED)
cd compiler/test && rm -rf test_results *.lst trace.log trace.def
$(RM) tags
$(QUIET)$(MAKE) -C druntime clean
dmd: $(BUILD_EXE)
$(BUILD_CMD) $@
dmd-unittest: $(BUILD_EXE)
$(BUILD_CMD) unittest
dmd-test: dmd-unittest dmd druntime phobos $(RUN_EXE)
$(RUN_EXE) --environment
druntime: dmd
$(QUIET)$(MAKE) -C druntime
druntime-test: dmd
$(QUIET)$(MAKE) -C druntime unittest
test: dmd-test druntime-test
../phobos:
git clone --depth=1 https://github.com/dlang/phobos $@
phobos: ../phobos druntime
$(MAKE) -C ../phobos
html: $(BUILD_EXE)
$(BUILD_CMD) $@
# Creates Exuberant Ctags tags file
tags: Makefile $(ECTAGS_FILES)
ctags --sort=yes --links=no --excmd=number --languages=$(ECTAGS_LANGS) \
--langmap='C++:+.c,C++:+.h' --extra=+f --file-scope=yes --fields=afikmsSt --totals=yes Makefile $(ECTAGS_FILES)
ifneq (,$(findstring Darwin_64_32, $(PWD)))
install:
echo "Darwin_64_32_disabled"
else
install: $(BUILD_EXE)
$(BUILD_CMD) man
$(BUILD_CMD) install INSTALL_DIR='$(if $(findstring $(OS),windows),$(shell cygpath -w '$(INSTALL_DIR)'),$(INSTALL_DIR))'
mkdir -p '$(INSTALL_DIR)'/man
cp -r $(GENERATED)/docs/man/* '$(INSTALL_DIR)'/man/
$(QUIET)$(MAKE) -C druntime install INSTALL_DIR='$(INSTALL_DIR)'
endif
# Checks that all files have been committed and no temporary, untracked files exist.
# See: https://github.com/dlang/dmd/pull/7483
check-clean-git:
@if [ -n "$$(git status --porcelain)" ] ; then \
echo "ERROR: Found the following residual temporary files."; \
echo 'ERROR: Temporary files should be stored in `test_results` or explicitly removed.'; \
git status -s ; \
exit 1; \
fi
style: $(BUILD_EXE)
$(BUILD_CMD) $@
# PGO+LTO'd compiler
ifeq (,$(findstring ldmd2,$(notdir $(HOST_DMD))))
dmd-pgo:
@echo "Error: dmd-pgo currently requires an ldmd2 host compiler, not $(notdir $(HOST_DMD)). Please set HOST_DMD appropriately, or activate an LDC compiler."
@exit 1
else # ldmd2
LDC_PROFDATA:=$(dir $(shell which $(if $(findstring $(OS),windows),$(shell cygpath --unix $(HOST_DMD)),$(HOST_DMD))))ldc-profdata$(EXE)
ifeq (,$(wildcard $(LDC_PROFDATA)))
# if the ldc-profdata tool isn't found in the same dir as ldmd2, fall back to PATH
LDC_PROFDATA:=ldc-profdata
endif
dmd-pgo: $(BUILD_EXE) $(RUN_EXE) ../phobos
@echo "PGO step 1/4: Building instrumented compiler"
$(BUILD_EXE) ENABLE_RELEASE=1 DFLAGS='-fprofile-generate=$(abspath $(GENERATED))/%p.profraw $(HOST_DFLAGS)' dmd --force
@echo "PGO step 2/4: Gathering profiles by compiling druntime & phobos and running 'compilable' test suite"
$(MAKE) -C ../phobos
$(RUN_EXE) compilable
@echo "PGO step 3/4: Merging profiles"
# using a response file with list of generated *.profraw files, to avoid cmdline-length problems with many files
cd $(GENERATED) && find . -maxdepth 1 -name '*.profraw' > profraw_list.rsp
cd $(GENERATED) && $(LDC_PROFDATA) merge --output=merged.profdata --input-files=profraw_list.rsp
cd $(GENERATED) && xargs $(RM) < profraw_list.rsp && $(RM) profraw_list.rsp
@echo "PGO step 4/4: Building PGO+LTO'd compiler"
$(BUILD_EXE) ENABLE_RELEASE=1 ENABLE_LTO=1 DFLAGS='-fprofile-use=$(abspath $(GENERATED))/merged.profdata $(HOST_DFLAGS)' dmd --force
$(RM) $(GENERATED)/merged.profdata
endif # ldmd2
.DELETE_ON_ERROR: # GNU Make directive (delete output files on error)
# Dont run targets in parallel because this makefile is just a thin wrapper
# for build.d and multiple invocations might stomp on each other.
# (build.d employs it's own parallelization)
.NOTPARALLEL: