]> git.lizzy.rs Git - rust.git/blob - mk/platform.mk
Rollup merge of #34972 - oli-obk:cant_cast_str_to_const_ptr, r=eddyb
[rust.git] / mk / platform.mk
1 # Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
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
14 # would create a variable HOST_i686-darwin-macos with the value
15 # i386.
16 define DEF_HOST_VAR
17   HOST_$(1) = $(patsubst i%86,i386,$(word 1,$(subst -, ,$(1))))
18 endef
19 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_HOST_VAR,$(t))))
20 $(foreach t,$(CFG_TARGET),$(info cfg: host for $(t) is $(HOST_$(t))))
21
22 # Ditto for OSTYPE
23 define DEF_OSTYPE_VAR
24   OSTYPE_$(1) = $(subst $(firstword $(subst -, ,$(1)))-,,$(1))
25 endef
26 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_OSTYPE_VAR,$(t))))
27 $(foreach t,$(CFG_TARGET),$(info cfg: os for $(t) is $(OSTYPE_$(t))))
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
35 OS_SUPP = $(patsubst %,--suppressions=%, \
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
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/
47 ifdef CFG_VALGRIND
48   CFG_VALGRIND += --error-exitcode=100 \
49                   --fair-sched=try \
50                   --quiet \
51                   --soname-synonyms=somalloc=NONE \
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
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
67   ifneq (,$(filter $(OSTYPE_$(1)),apple-darwin freebsd))
68     ifeq ($(HOST_$(1)),x86_64)
69       GOOD_VALGRIND_$(1) = 1
70     endif
71   endif
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
77 endef
78 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_GOOD_VALGRIND,$(t))))
79
80 AR := ar
81
82 define SET_FROM_CFG
83   ifdef CFG_$(1)
84     ifeq ($(origin $(1)),undefined)
85       $$(info cfg: using $(1)=$(CFG_$(1)) (CFG_$(1)))
86       $(1)=$(CFG_$(1))
87     endif
88     ifeq ($(origin $(1)),default)
89       $$(info cfg: using $(1)=$(CFG_$(1)) (CFG_$(1)))
90       $(1)=$(CFG_$(1))
91     endif
92   endif
93 endef
94
95 $(foreach cvar,CC CXX CPP CFLAGS CXXFLAGS CPPFLAGS, \
96   $(eval $(call SET_FROM_CFG,$(cvar))))
97
98 CFG_RLIB_GLOB=lib$(1)-*.rlib
99
100 include $(wildcard $(CFG_SRC_DIR)mk/cfg/*.mk)
101
102 define ADD_INSTALLED_OBJECTS
103   INSTALLED_OBJECTS_$(1) += $$(CFG_INSTALLED_OBJECTS_$(1))
104   REQUIRED_OBJECTS_$(1) += $$(CFG_THIRD_PARTY_OBJECTS_$(1))
105   INSTALLED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
106   REQUIRED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
107 endef
108
109 $(foreach target,$(CFG_TARGET), \
110   $(eval $(call ADD_INSTALLED_OBJECTS,$(target))))
111
112 define DEFINE_LINKER
113   ifndef LINK_$(1)
114     LINK_$(1) := $$(CC_$(1))
115   endif
116 endef
117
118 $(foreach target,$(CFG_TARGET), \
119   $(eval $(call DEFINE_LINKER,$(target))))
120
121 define ADD_JEMALLOC_DEP
122   ifndef CFG_DISABLE_JEMALLOC_$(1)
123     ifndef CFG_DISABLE_JEMALLOC
124       RUST_DEPS_std_T_$(1) += alloc_jemalloc
125       TARGET_CRATES_$(1) += alloc_jemalloc
126     endif
127   endif
128 endef
129
130 $(foreach target,$(CFG_TARGET), \
131   $(eval $(call ADD_JEMALLOC_DEP,$(target))))
132
133 # The -Qunused-arguments sidesteps spurious warnings from clang
134 define FILTER_FLAGS
135   ifeq ($$(CFG_USING_CLANG),1)
136     ifneq ($(findstring clang,$$(shell $(CC_$(1)) -v)),)
137       CFG_GCCISH_CFLAGS_$(1) += -Qunused-arguments
138       CFG_GCCISH_CXXFLAGS_$(1) += -Qunused-arguments
139     endif
140   endif
141 endef
142
143 $(foreach target,$(CFG_TARGET), \
144   $(eval $(call FILTER_FLAGS,$(target))))
145
146 # Configure various macros to pass gcc or cl.exe style arguments
147 define CC_MACROS
148   CFG_CC_INCLUDE_$(1)=-I $$(1)
149   ifeq ($$(findstring msvc,$(1)),msvc)
150     CFG_CC_OUTPUT_$(1)=-Fo:$$(1)
151     CFG_CREATE_ARCHIVE_$(1)='$$(AR_$(1))' -OUT:$$(1)
152   else
153     CFG_CC_OUTPUT_$(1)=-o $$(1)
154     CFG_CREATE_ARCHIVE_$(1)=$$(AR_$(1)) crus $$(1)
155   endif
156 endef
157
158 $(foreach target,$(CFG_TARGET), \
159   $(eval $(call CC_MACROS,$(target))))
160
161
162 ifeq ($(CFG_CCACHE_CPP2),1)
163   CCACHE_CPP2=1
164   export CCACHE_CPP
165 endif
166
167 ifdef CFG_CCACHE_BASEDIR
168   CCACHE_BASEDIR=$(CFG_CCACHE_BASEDIR)
169   export CCACHE_BASEDIR
170 endif
171
172 FIND_COMPILER = $(strip $(1:ccache=))
173
174 define CFG_MAKE_TOOLCHAIN
175   # Prepend the tools with their prefix if cross compiling
176   ifneq ($(CFG_BUILD),$(1))
177     ifneq ($$(findstring msvc,$(1)),msvc)
178        CC_$(1)=$(CROSS_PREFIX_$(1))$(CC_$(1))
179        CXX_$(1)=$(CROSS_PREFIX_$(1))$(CXX_$(1))
180        CPP_$(1)=$(CROSS_PREFIX_$(1))$(CPP_$(1))
181        AR_$(1)=$(CROSS_PREFIX_$(1))$(AR_$(1))
182        LINK_$(1)=$(CROSS_PREFIX_$(1))$(LINK_$(1))
183        RUSTC_CROSS_FLAGS_$(1)=-C linker=$$(call FIND_COMPILER,$$(LINK_$(1))) \
184            -C ar=$$(call FIND_COMPILER,$$(AR_$(1))) $(RUSTC_CROSS_FLAGS_$(1))
185
186        RUSTC_FLAGS_$(1)=$$(RUSTC_CROSS_FLAGS_$(1)) $(RUSTC_FLAGS_$(1))
187     endif
188   endif
189
190   CFG_COMPILE_C_$(1) = '$$(call FIND_COMPILER,$$(CC_$(1)))' \
191         $$(CFLAGS) \
192         $$(CFG_GCCISH_CFLAGS) \
193         $$(CFG_GCCISH_CFLAGS_$(1)) \
194         -c $$(call CFG_CC_OUTPUT_$(1),$$(1)) $$(2)
195   CFG_LINK_C_$(1) = $$(CC_$(1)) \
196         $$(LDFLAGS) \
197         $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
198         $$(CFG_GCCISH_LINK_FLAGS_$(1)) \
199         $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \
200         $$(call CFG_INSTALL_NAME_$(1),$$(4))
201   CFG_COMPILE_CXX_$(1) = '$$(call FIND_COMPILER,$$(CXX_$(1)))' \
202         $$(CXXFLAGS) \
203         $$(CFG_GCCISH_CFLAGS) \
204         $$(CFG_GCCISH_CXXFLAGS) \
205         $$(CFG_GCCISH_CFLAGS_$(1)) \
206         $$(CFG_GCCISH_CXXFLAGS_$(1)) \
207         -c $$(call CFG_CC_OUTPUT_$(1),$$(1)) $$(2)
208   CFG_LINK_CXX_$(1) = $$(CXX_$(1)) \
209         $$(LDFLAGS) \
210         $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
211         $$(CFG_GCCISH_LINK_FLAGS_$(1)) \
212         $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \
213         $$(call CFG_INSTALL_NAME_$(1),$$(4))
214
215   ifeq ($$(findstring $(HOST_$(1)),arm aarch64 mips mipsel powerpc),)
216
217   # On Bitrig, we need the relocation model to be PIC for everything
218   ifeq (,$(filter $(OSTYPE_$(1)),bitrig))
219     LLVM_MC_RELOCATION_MODEL="pic"
220   else
221     LLVM_MC_RELOCATION_MODEL="default"
222   endif
223
224   # We're using llvm-mc as our assembler because it supports
225   # .cfi pseudo-ops on mac
226   CFG_ASSEMBLE_$(1)=$$(CPP_$(1)) -E $$(2) | \
227                     $$(LLVM_MC_$$(CFG_BUILD)) \
228                     -assemble \
229                     -relocation-model=$$(LLVM_MC_RELOCATION_MODEL) \
230                     -filetype=obj \
231                     -triple=$(1) \
232                     -o=$$(1)
233   else
234
235   # For the ARM, AARCH64, MIPS and POWER crosses, use the toolchain assembler
236   # FIXME: We should be able to use the LLVM assembler
237   CFG_ASSEMBLE_$(1)=$$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
238                    $$(2) -c -o $$(1)
239
240   endif
241
242 endef
243
244 $(foreach target,$(CFG_TARGET), \
245   $(eval $(call CFG_MAKE_TOOLCHAIN,$(target))))