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.
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.
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
17 HOST_
$(1) = $(subst i686
,i386
,$(word 1,$(subst -, ,$(1))))
19 $(foreach t
,$(CFG_TARGET
),$(eval
$(call DEF_HOST_VAR
,$(t
))))
20 $(foreach t
,$(CFG_TARGET
),$(info cfg
: host for
$(t
) is
$(HOST_
$(t
))))
24 OSTYPE_
$(1) = $(subst $(firstword $(subst -, ,$(1)))-,,$(1))
26 $(foreach t
,$(CFG_TARGET
),$(eval
$(call DEF_OSTYPE_VAR
,$(t
))))
27 $(foreach t
,$(CFG_TARGET
),$(info cfg
: os for
$(t
) is
$(OSTYPE_
$(t
))))
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.
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
*))
38 ifdef CFG_DISABLE_OPTIMIZE_CXX
39 $(info cfg
: disabling C
++ optimization
(CFG_DISABLE_OPTIMIZE_CXX
))
40 CFG_GCCISH_CFLAGS
+= -O0
42 CFG_GCCISH_CFLAGS
+= -O2
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/
48 CFG_VALGRIND
+= --error-exitcode
=100 \
51 --soname-synonyms
=somalloc
=NONE \
52 --suppressions
=$(CFG_SRC_DIR
)src
/etc
/x86.supp \
54 ifdef CFG_ENABLE_HELGRIND
55 CFG_VALGRIND
+= --tool
=helgrind
57 CFG_VALGRIND
+= --tool
=memcheck \
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
67 ifneq (,$(filter $(OSTYPE_
$(1)),darwin freebsd
))
68 ifeq (HOST_
$(1),x86_64
)
69 GOOD_VALGRIND_
$(1) = 1
73 $(foreach t
,$(CFG_TARGET
),$(eval
$(call DEF_GOOD_VALGRIND
,$(t
))))
74 $(foreach t
,$(CFG_TARGET
),$(info cfg
: good valgrind for
$(t
) is
$(GOOD_VALGRIND_
$(t
))))
76 ifneq ($(findstring linux
,$(CFG_OSTYPE
)),)
78 ifneq ($(CFG_PERF_WITH_LOGFD
),)
79 CFG_PERF_TOOL
:= $(CFG_PERF
) stat
-r
3 --log-fd
2
81 CFG_PERF_TOOL
:= $(CFG_PERF
) stat
-r
3
86 $(CFG_VALGRIND
) --tool
=cachegrind
--cache-sim
=yes
--branch-sim
=yes
88 CFG_PERF_TOOL
:= /usr
/bin
/time
--verbose
97 ifeq ($(origin $(1)),undefined
)
98 $$(info cfg
: using
$(1)=$(CFG_
$(1)) (CFG_
$(1)))
101 ifeq ($(origin $(1)),default
)
102 $$(info cfg
: using
$(1)=$(CFG_
$(1)) (CFG_
$(1)))
108 $(foreach cvar
,CC CXX CPP CFLAGS CXXFLAGS CPPFLAGS
, \
109 $(eval
$(call SET_FROM_CFG
,$(cvar
))))
111 CFG_RLIB_GLOB
=lib
$(1)-*.rlib
113 include $(wildcard $(CFG_SRC_DIR
)mk
/cfg
/*.mk
)
115 define ADD_INSTALLED_OBJECTS
116 INSTALLED_OBJECTS_
$(1) += $$(call CFG_STATIC_LIB_NAME_
$(1),morestack
) \
117 $$(call CFG_STATIC_LIB_NAME_
$(1),compiler-rt
)
120 $(foreach target
,$(CFG_TARGET
), \
121 $(eval
$(call ADD_INSTALLED_OBJECTS
,$(target
))))
125 LINK_
$(1) := $$(CC_
$(1))
129 $(foreach target
,$(CFG_TARGET
), \
130 $(eval
$(call DEFINE_LINKER
,$(target
))))
132 # The -Qunused-arguments sidesteps spurious warnings from clang
134 ifeq ($$(CFG_USING_CLANG
),1)
135 ifneq ($(findstring clang
,$$(shell $(CC_
$(1)) -v
)),)
136 CFG_GCCISH_CFLAGS_
$(1) += -Qunused-arguments
137 CFG_GCCISH_CXXFLAGS_
$(1) += -Qunused-arguments
142 $(foreach target
,$(CFG_TARGET
), \
143 $(eval
$(call FILTER_FLAGS
,$(target
))))
145 # Configure various macros to pass gcc or cl.exe style arguments
147 CFG_CC_INCLUDE_
$(1)=-I
$$(1)
148 ifeq ($$(findstring msvc
,$(1)),msvc
)
149 CFG_CC_OUTPUT_
$(1)=-Fo
:$$(1)
150 CFG_CREATE_ARCHIVE_
$(1)=$$(AR_
$(1)) -OUT
:$$(1)
152 CFG_CC_OUTPUT_
$(1)=-o
$$(1)
153 CFG_CREATE_ARCHIVE_
$(1)=$$(AR_
$(1)) crus
$$(1)
157 $(foreach target
,$(CFG_TARGET
), \
158 $(eval
$(call CC_MACROS
,$(target
))))
161 ifeq ($(CFG_CCACHE_CPP2
),1)
166 ifdef CFG_CCACHE_BASEDIR
167 CCACHE_BASEDIR
=$(CFG_CCACHE_BASEDIR
)
168 export CCACHE_BASEDIR
171 FIND_COMPILER
= $(word 1,$(1:ccache
=))
173 define CFG_MAKE_TOOLCHAIN
174 # Prepend the tools with their prefix if cross compiling
175 ifneq ($(CFG_BUILD
),$(1))
176 ifneq ($$(findstring msvc
,$(1)),msvc
)
177 CC_
$(1)=$(CROSS_PREFIX_
$(1))$(CC_
$(1))
178 CXX_
$(1)=$(CROSS_PREFIX_
$(1))$(CXX_
$(1))
179 CPP_
$(1)=$(CROSS_PREFIX_
$(1))$(CPP_
$(1))
180 AR_
$(1)=$(CROSS_PREFIX_
$(1))$(AR_
$(1))
181 LINK_
$(1)=$(CROSS_PREFIX_
$(1))$(LINK_
$(1))
182 RUSTC_CROSS_FLAGS_
$(1)=-C linker
=$$(call FIND_COMPILER
,$$(LINK_
$(1))) \
183 -C
ar=$$(call FIND_COMPILER
,$$(AR_
$(1))) $(RUSTC_CROSS_FLAGS_
$(1))
185 RUSTC_FLAGS_
$(1)=$$(RUSTC_CROSS_FLAGS_
$(1)) $(RUSTC_FLAGS_
$(1))
189 CFG_COMPILE_C_
$(1) = $$(CC_
$(1)) \
190 $$(CFG_GCCISH_CFLAGS
) \
191 $$(CFG_GCCISH_CFLAGS_
$(1)) \
192 -c
$$(call CFG_CC_OUTPUT_
$(1),$$(1)) $$(2)
193 CFG_LINK_C_
$(1) = $$(CC_
$(1)) \
194 $$(CFG_GCCISH_LINK_FLAGS
) -o
$$(1) \
195 $$(CFG_GCCISH_LINK_FLAGS_
$(1)) \
196 $$(CFG_GCCISH_DEF_FLAG_
$(1))$$(3) $$(2) \
197 $$(call CFG_INSTALL_NAME_
$(1),$$(4))
198 CFG_COMPILE_CXX_
$(1) = $$(CXX_
$(1)) \
199 $$(CFG_GCCISH_CFLAGS
) \
200 $$(CFG_GCCISH_CXXFLAGS
) \
201 $$(CFG_GCCISH_CFLAGS_
$(1)) \
202 $$(CFG_GCCISH_CXXFLAGS_
$(1)) \
203 -c
$$(call CFG_CC_OUTPUT_
$(1),$$(1)) $$(2)
204 CFG_LINK_CXX_
$(1) = $$(CXX_
$(1)) \
205 $$(CFG_GCCISH_LINK_FLAGS
) -o
$$(1) \
206 $$(CFG_GCCISH_LINK_FLAGS_
$(1)) \
207 $$(CFG_GCCISH_DEF_FLAG_
$(1))$$(3) $$(2) \
208 $$(call CFG_INSTALL_NAME_
$(1),$$(4))
210 ifeq ($$(findstring $(HOST_
$(1)),arm aarch64 mips mipsel powerpc
),)
212 # On Bitrig, we need the relocation model to be PIC for everything
213 ifeq (,$(filter $(OSTYPE_
$(1)),bitrig
))
214 LLVM_MC_RELOCATION_MODEL
="pic"
216 LLVM_MC_RELOCATION_MODEL
="default"
219 # We're using llvm-mc as our assembler because it supports
220 # .cfi pseudo-ops on mac
221 CFG_ASSEMBLE_
$(1)=$$(CPP_
$(1)) -E
$$(2) | \
222 $$(LLVM_MC_
$$(CFG_BUILD
)) \
224 -relocation-model
=$$(LLVM_MC_RELOCATION_MODEL
) \
230 # For the ARM, AARCH64, MIPS and POWER crosses, use the toolchain assembler
231 # FIXME: We should be able to use the LLVM assembler
232 CFG_ASSEMBLE_
$(1)=$$(CC_
$(1)) $$(CFG_GCCISH_CFLAGS_
$(1)) \
239 $(foreach target
,$(CFG_TARGET
), \
240 $(eval
$(call CFG_MAKE_TOOLCHAIN
,$(target
))))