]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | # Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
2 | # file at the top-level directory of this distribution and at |
3 | # http://rust-lang.org/COPYRIGHT. | |
4 | # | |
5 | # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | # option. This file may not be copied, modified, or distributed | |
9 | # except according to those terms. | |
10 | ||
11 | ||
12 | # Create variables HOST_<triple> containing the host part | |
13 | # of each target triple. For example, the triple i686-darwin-macos | |
970d7e83 | 14 | # would create a variable HOST_i686-darwin-macos with the value |
223e47cc LB |
15 | # i386. |
16 | define DEF_HOST_VAR | |
92a42be0 | 17 | HOST_$(1) = $(patsubst i%86,i386,$(word 1,$(subst -, ,$(1)))) |
223e47cc | 18 | endef |
1a4d82fc JJ |
19 | $(foreach t,$(CFG_TARGET),$(eval $(call DEF_HOST_VAR,$(t)))) |
20 | $(foreach t,$(CFG_TARGET),$(info cfg: host for $(t) is $(HOST_$(t)))) | |
223e47cc LB |
21 | |
22 | # Ditto for OSTYPE | |
23 | define DEF_OSTYPE_VAR | |
24 | OSTYPE_$(1) = $(subst $(firstword $(subst -, ,$(1)))-,,$(1)) | |
25 | endef | |
1a4d82fc JJ |
26 | $(foreach t,$(CFG_TARGET),$(eval $(call DEF_OSTYPE_VAR,$(t)))) |
27 | $(foreach t,$(CFG_TARGET),$(info cfg: os for $(t) is $(OSTYPE_$(t)))) | |
223e47cc LB |
28 | |
29 | # On Darwin, we need to run dsymutil so the debugging information ends | |
30 | # up in the right place. On other platforms, it automatically gets | |
31 | # embedded into the executable, so use a no-op command. | |
32 | CFG_DSYMUTIL := true | |
33 | ||
34 | # Hack: not sure how to test if a file exists in make other than this | |
1a4d82fc | 35 | OS_SUPP = $(patsubst %,--suppressions=%, \ |
223e47cc LB |
36 | $(wildcard $(CFG_SRC_DIR)src/etc/$(CFG_OSTYPE).supp*)) |
37 | ||
38 | ifdef CFG_DISABLE_OPTIMIZE_CXX | |
39 | $(info cfg: disabling C++ optimization (CFG_DISABLE_OPTIMIZE_CXX)) | |
40 | CFG_GCCISH_CFLAGS += -O0 | |
41 | else | |
42 | CFG_GCCISH_CFLAGS += -O2 | |
43 | endif | |
44 | ||
1a4d82fc JJ |
45 | # The soname thing is for supporting a statically linked jemalloc. |
46 | # see https://blog.mozilla.org/jseward/2012/06/05/valgrind-now-supports-jemalloc-builds-directly/ | |
223e47cc LB |
47 | ifdef CFG_VALGRIND |
48 | CFG_VALGRIND += --error-exitcode=100 \ | |
d9579d0f | 49 | --fair-sched=try \ |
223e47cc | 50 | --quiet \ |
d9579d0f | 51 | --soname-synonyms=somalloc=NONE \ |
223e47cc LB |
52 | --suppressions=$(CFG_SRC_DIR)src/etc/x86.supp \ |
53 | $(OS_SUPP) | |
54 | ifdef CFG_ENABLE_HELGRIND | |
55 | CFG_VALGRIND += --tool=helgrind | |
56 | else | |
57 | CFG_VALGRIND += --tool=memcheck \ | |
58 | --leak-check=full | |
59 | endif | |
60 | endif | |
61 | ||
1a4d82fc JJ |
62 | # If we actually want to run Valgrind on a given platform, set this variable |
63 | define DEF_GOOD_VALGRIND | |
64 | ifeq ($(OSTYPE_$(1)),unknown-linux-gnu) | |
65 | GOOD_VALGRIND_$(1) = 1 | |
66 | endif | |
9cc50fc6 SL |
67 | ifneq (,$(filter $(OSTYPE_$(1)),apple-darwin freebsd)) |
68 | ifeq ($(HOST_$(1)),x86_64) | |
1a4d82fc JJ |
69 | GOOD_VALGRIND_$(1) = 1 |
70 | endif | |
71 | endif | |
9cc50fc6 SL |
72 | ifdef GOOD_VALGRIND_$(t) |
73 | $$(info cfg: have good valgrind for $(t)) | |
74 | else | |
75 | $$(info cfg: no good valgrind for $(t)) | |
76 | endif | |
1a4d82fc JJ |
77 | endef |
78 | $(foreach t,$(CFG_TARGET),$(eval $(call DEF_GOOD_VALGRIND,$(t)))) | |
1a4d82fc | 79 | |
223e47cc LB |
80 | ifneq ($(findstring linux,$(CFG_OSTYPE)),) |
81 | ifdef CFG_PERF | |
82 | ifneq ($(CFG_PERF_WITH_LOGFD),) | |
83 | CFG_PERF_TOOL := $(CFG_PERF) stat -r 3 --log-fd 2 | |
84 | else | |
85 | CFG_PERF_TOOL := $(CFG_PERF) stat -r 3 | |
86 | endif | |
87 | else | |
88 | ifdef CFG_VALGRIND | |
1a4d82fc | 89 | CFG_PERF_TOOL := \ |
223e47cc LB |
90 | $(CFG_VALGRIND) --tool=cachegrind --cache-sim=yes --branch-sim=yes |
91 | else | |
92 | CFG_PERF_TOOL := /usr/bin/time --verbose | |
93 | endif | |
94 | endif | |
95 | endif | |
96 | ||
223e47cc LB |
97 | AR := ar |
98 | ||
1a4d82fc JJ |
99 | define SET_FROM_CFG |
100 | ifdef CFG_$(1) | |
101 | ifeq ($(origin $(1)),undefined) | |
102 | $$(info cfg: using $(1)=$(CFG_$(1)) (CFG_$(1))) | |
103 | $(1)=$(CFG_$(1)) | |
104 | endif | |
105 | ifeq ($(origin $(1)),default) | |
106 | $$(info cfg: using $(1)=$(CFG_$(1)) (CFG_$(1))) | |
107 | $(1)=$(CFG_$(1)) | |
108 | endif | |
970d7e83 | 109 | endif |
1a4d82fc | 110 | endef |
223e47cc | 111 | |
1a4d82fc JJ |
112 | $(foreach cvar,CC CXX CPP CFLAGS CXXFLAGS CPPFLAGS, \ |
113 | $(eval $(call SET_FROM_CFG,$(cvar)))) | |
223e47cc | 114 | |
1a4d82fc | 115 | CFG_RLIB_GLOB=lib$(1)-*.rlib |
970d7e83 | 116 | |
1a4d82fc | 117 | include $(wildcard $(CFG_SRC_DIR)mk/cfg/*.mk) |
970d7e83 | 118 | |
62682a34 | 119 | define ADD_INSTALLED_OBJECTS |
92a42be0 SL |
120 | INSTALLED_OBJECTS_$(1) += $$(CFG_INSTALLED_OBJECTS_$(1)) |
121 | REQUIRED_OBJECTS_$(1) += $$(CFG_THIRD_PARTY_OBJECTS_$(1)) | |
e9174d1e | 122 | INSTALLED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt) |
92a42be0 | 123 | REQUIRED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt) |
62682a34 SL |
124 | endef |
125 | ||
126 | $(foreach target,$(CFG_TARGET), \ | |
127 | $(eval $(call ADD_INSTALLED_OBJECTS,$(target)))) | |
128 | ||
129 | define DEFINE_LINKER | |
130 | ifndef LINK_$(1) | |
131 | LINK_$(1) := $$(CC_$(1)) | |
132 | endif | |
133 | endef | |
134 | ||
135 | $(foreach target,$(CFG_TARGET), \ | |
136 | $(eval $(call DEFINE_LINKER,$(target)))) | |
137 | ||
1a4d82fc JJ |
138 | # The -Qunused-arguments sidesteps spurious warnings from clang |
139 | define FILTER_FLAGS | |
140 | ifeq ($$(CFG_USING_CLANG),1) | |
141 | ifneq ($(findstring clang,$$(shell $(CC_$(1)) -v)),) | |
142 | CFG_GCCISH_CFLAGS_$(1) += -Qunused-arguments | |
143 | CFG_GCCISH_CXXFLAGS_$(1) += -Qunused-arguments | |
144 | endif | |
145 | endif | |
146 | endef | |
223e47cc | 147 | |
1a4d82fc JJ |
148 | $(foreach target,$(CFG_TARGET), \ |
149 | $(eval $(call FILTER_FLAGS,$(target)))) | |
223e47cc | 150 | |
62682a34 SL |
151 | # Configure various macros to pass gcc or cl.exe style arguments |
152 | define CC_MACROS | |
153 | CFG_CC_INCLUDE_$(1)=-I $$(1) | |
154 | ifeq ($$(findstring msvc,$(1)),msvc) | |
155 | CFG_CC_OUTPUT_$(1)=-Fo:$$(1) | |
156 | CFG_CREATE_ARCHIVE_$(1)=$$(AR_$(1)) -OUT:$$(1) | |
157 | else | |
158 | CFG_CC_OUTPUT_$(1)=-o $$(1) | |
159 | CFG_CREATE_ARCHIVE_$(1)=$$(AR_$(1)) crus $$(1) | |
160 | endif | |
161 | endef | |
162 | ||
163 | $(foreach target,$(CFG_TARGET), \ | |
164 | $(eval $(call CC_MACROS,$(target)))) | |
165 | ||
223e47cc | 166 | |
970d7e83 LB |
167 | ifeq ($(CFG_CCACHE_CPP2),1) |
168 | CCACHE_CPP2=1 | |
169 | export CCACHE_CPP | |
170 | endif | |
171 | ||
172 | ifdef CFG_CCACHE_BASEDIR | |
173 | CCACHE_BASEDIR=$(CFG_CCACHE_BASEDIR) | |
174 | export CCACHE_BASEDIR | |
175 | endif | |
223e47cc | 176 | |
1a4d82fc JJ |
177 | FIND_COMPILER = $(word 1,$(1:ccache=)) |
178 | ||
223e47cc | 179 | define CFG_MAKE_TOOLCHAIN |
1a4d82fc JJ |
180 | # Prepend the tools with their prefix if cross compiling |
181 | ifneq ($(CFG_BUILD),$(1)) | |
62682a34 | 182 | ifneq ($$(findstring msvc,$(1)),msvc) |
c34b1796 AL |
183 | CC_$(1)=$(CROSS_PREFIX_$(1))$(CC_$(1)) |
184 | CXX_$(1)=$(CROSS_PREFIX_$(1))$(CXX_$(1)) | |
185 | CPP_$(1)=$(CROSS_PREFIX_$(1))$(CPP_$(1)) | |
186 | AR_$(1)=$(CROSS_PREFIX_$(1))$(AR_$(1)) | |
62682a34 SL |
187 | LINK_$(1)=$(CROSS_PREFIX_$(1))$(LINK_$(1)) |
188 | RUSTC_CROSS_FLAGS_$(1)=-C linker=$$(call FIND_COMPILER,$$(LINK_$(1))) \ | |
c34b1796 AL |
189 | -C ar=$$(call FIND_COMPILER,$$(AR_$(1))) $(RUSTC_CROSS_FLAGS_$(1)) |
190 | ||
191 | RUSTC_FLAGS_$(1)=$$(RUSTC_CROSS_FLAGS_$(1)) $(RUSTC_FLAGS_$(1)) | |
62682a34 | 192 | endif |
1a4d82fc JJ |
193 | endif |
194 | ||
195 | CFG_COMPILE_C_$(1) = $$(CC_$(1)) \ | |
92a42be0 | 196 | $$(CFLAGS) \ |
1a4d82fc | 197 | $$(CFG_GCCISH_CFLAGS) \ |
223e47cc | 198 | $$(CFG_GCCISH_CFLAGS_$(1)) \ |
62682a34 | 199 | -c $$(call CFG_CC_OUTPUT_$(1),$$(1)) $$(2) |
223e47cc | 200 | CFG_LINK_C_$(1) = $$(CC_$(1)) \ |
92a42be0 | 201 | $$(LDFLAGS) \ |
1a4d82fc JJ |
202 | $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \ |
203 | $$(CFG_GCCISH_LINK_FLAGS_$(1)) \ | |
204 | $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \ | |
223e47cc LB |
205 | $$(call CFG_INSTALL_NAME_$(1),$$(4)) |
206 | CFG_COMPILE_CXX_$(1) = $$(CXX_$(1)) \ | |
92a42be0 | 207 | $$(CXXFLAGS) \ |
1a4d82fc JJ |
208 | $$(CFG_GCCISH_CFLAGS) \ |
209 | $$(CFG_GCCISH_CXXFLAGS) \ | |
223e47cc | 210 | $$(CFG_GCCISH_CFLAGS_$(1)) \ |
1a4d82fc | 211 | $$(CFG_GCCISH_CXXFLAGS_$(1)) \ |
62682a34 | 212 | -c $$(call CFG_CC_OUTPUT_$(1),$$(1)) $$(2) |
223e47cc | 213 | CFG_LINK_CXX_$(1) = $$(CXX_$(1)) \ |
92a42be0 | 214 | $$(LDFLAGS) \ |
1a4d82fc JJ |
215 | $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \ |
216 | $$(CFG_GCCISH_LINK_FLAGS_$(1)) \ | |
217 | $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \ | |
223e47cc LB |
218 | $$(call CFG_INSTALL_NAME_$(1),$$(4)) |
219 | ||
85aaf69f | 220 | ifeq ($$(findstring $(HOST_$(1)),arm aarch64 mips mipsel powerpc),) |
223e47cc | 221 | |
c34b1796 AL |
222 | # On Bitrig, we need the relocation model to be PIC for everything |
223 | ifeq (,$(filter $(OSTYPE_$(1)),bitrig)) | |
224 | LLVM_MC_RELOCATION_MODEL="pic" | |
225 | else | |
226 | LLVM_MC_RELOCATION_MODEL="default" | |
227 | endif | |
228 | ||
223e47cc LB |
229 | # We're using llvm-mc as our assembler because it supports |
230 | # .cfi pseudo-ops on mac | |
62682a34 | 231 | CFG_ASSEMBLE_$(1)=$$(CPP_$(1)) -E $$(2) | \ |
1a4d82fc | 232 | $$(LLVM_MC_$$(CFG_BUILD)) \ |
223e47cc | 233 | -assemble \ |
c34b1796 | 234 | -relocation-model=$$(LLVM_MC_RELOCATION_MODEL) \ |
223e47cc LB |
235 | -filetype=obj \ |
236 | -triple=$(1) \ | |
237 | -o=$$(1) | |
238 | else | |
239 | ||
85aaf69f | 240 | # For the ARM, AARCH64, MIPS and POWER crosses, use the toolchain assembler |
1a4d82fc JJ |
241 | # FIXME: We should be able to use the LLVM assembler |
242 | CFG_ASSEMBLE_$(1)=$$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \ | |
62682a34 | 243 | $$(2) -c -o $$(1) |
223e47cc LB |
244 | |
245 | endif | |
246 | ||
247 | endef | |
248 | ||
1a4d82fc | 249 | $(foreach target,$(CFG_TARGET), \ |
223e47cc | 250 | $(eval $(call CFG_MAKE_TOOLCHAIN,$(target)))) |