]> git.lizzy.rs Git - rust.git/blob - mk/platform.mk
rollup merge of #21151: brson/beta
[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) = $(subst i686,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                   --soname-synonyms=somalloc=NONE \
50                   --quiet \
51                   --suppressions=$(CFG_SRC_DIR)src/etc/x86.supp \
52                   $(OS_SUPP)
53   ifdef CFG_ENABLE_HELGRIND
54     CFG_VALGRIND += --tool=helgrind
55   else
56     CFG_VALGRIND += --tool=memcheck \
57                     --leak-check=full
58   endif
59 endif
60
61 # If we actually want to run Valgrind on a given platform, set this variable
62 define DEF_GOOD_VALGRIND
63   ifeq ($(OSTYPE_$(1)),unknown-linux-gnu)
64     GOOD_VALGRIND_$(1) = 1
65   endif
66   ifneq (,$(filter $(OSTYPE_$(1)),darwin freebsd))
67     ifeq (HOST_$(1),x86_64)
68       GOOD_VALGRIND_$(1) = 1
69     endif
70   endif
71 endef
72 $(foreach t,$(CFG_TARGET),$(eval $(call DEF_GOOD_VALGRIND,$(t))))
73 $(foreach t,$(CFG_TARGET),$(info cfg: good valgrind for $(t) is $(GOOD_VALGRIND_$(t))))
74
75 ifneq ($(findstring linux,$(CFG_OSTYPE)),)
76   ifdef CFG_PERF
77     ifneq ($(CFG_PERF_WITH_LOGFD),)
78         CFG_PERF_TOOL := $(CFG_PERF) stat -r 3 --log-fd 2
79     else
80         CFG_PERF_TOOL := $(CFG_PERF) stat -r 3
81     endif
82   else
83     ifdef CFG_VALGRIND
84       CFG_PERF_TOOL := \
85         $(CFG_VALGRIND) --tool=cachegrind --cache-sim=yes --branch-sim=yes
86     else
87       CFG_PERF_TOOL := /usr/bin/time --verbose
88     endif
89   endif
90 endif
91
92 # These flags will cause the compiler to produce a .d file
93 # next to the .o file that lists header deps.
94 CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d)
95
96 AR := ar
97
98 define SET_FROM_CFG
99   ifdef CFG_$(1)
100     ifeq ($(origin $(1)),undefined)
101       $$(info cfg: using $(1)=$(CFG_$(1)) (CFG_$(1)))
102       $(1)=$(CFG_$(1))
103     endif
104     ifeq ($(origin $(1)),default)
105       $$(info cfg: using $(1)=$(CFG_$(1)) (CFG_$(1)))
106       $(1)=$(CFG_$(1))
107     endif
108   endif
109 endef
110
111 $(foreach cvar,CC CXX CPP CFLAGS CXXFLAGS CPPFLAGS, \
112   $(eval $(call SET_FROM_CFG,$(cvar))))
113
114 CFG_RLIB_GLOB=lib$(1)-*.rlib
115
116 include $(wildcard $(CFG_SRC_DIR)mk/cfg/*.mk)
117
118 # The -Qunused-arguments sidesteps spurious warnings from clang
119 define FILTER_FLAGS
120   ifeq ($$(CFG_USING_CLANG),1)
121     ifneq ($(findstring clang,$$(shell $(CC_$(1)) -v)),)
122       CFG_GCCISH_CFLAGS_$(1) += -Qunused-arguments
123       CFG_GCCISH_CXXFLAGS_$(1) += -Qunused-arguments
124     endif
125   endif
126 endef
127
128 $(foreach target,$(CFG_TARGET), \
129   $(eval $(call FILTER_FLAGS,$(target))))
130
131
132 ifeq ($(CFG_CCACHE_CPP2),1)
133   CCACHE_CPP2=1
134   export CCACHE_CPP
135 endif
136
137 ifdef CFG_CCACHE_BASEDIR
138   CCACHE_BASEDIR=$(CFG_CCACHE_BASEDIR)
139   export CCACHE_BASEDIR
140 endif
141
142 FIND_COMPILER = $(word 1,$(1:ccache=))
143
144 define CFG_MAKE_TOOLCHAIN
145   # Prepend the tools with their prefix if cross compiling
146   ifneq ($(CFG_BUILD),$(1))
147         CC_$(1)=$(CROSS_PREFIX_$(1))$(CC_$(1))
148         CXX_$(1)=$(CROSS_PREFIX_$(1))$(CXX_$(1))
149         CPP_$(1)=$(CROSS_PREFIX_$(1))$(CPP_$(1))
150         AR_$(1)=$(CROSS_PREFIX_$(1))$(AR_$(1))
151         RUSTC_CROSS_FLAGS_$(1)=-C linker=$$(call FIND_COMPILER,$$(CC_$(1))) \
152             -C ar=$$(call FIND_COMPILER,$$(AR_$(1))) $(RUSTC_CROSS_FLAGS_$(1))
153
154         RUSTC_FLAGS_$(1)=$$(RUSTC_CROSS_FLAGS_$(1)) $(RUSTC_FLAGS_$(1))
155   endif
156
157   CFG_COMPILE_C_$(1) = $$(CC_$(1)) \
158         $$(CFG_GCCISH_CFLAGS) \
159         $$(CFG_GCCISH_CFLAGS_$(1)) \
160         $$(CFG_DEPEND_FLAGS) \
161         -c -o $$(1) $$(2)
162   CFG_LINK_C_$(1) = $$(CC_$(1)) \
163         $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
164         $$(CFG_GCCISH_LINK_FLAGS_$(1)) \
165         $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \
166         $$(call CFG_INSTALL_NAME_$(1),$$(4))
167   CFG_COMPILE_CXX_$(1) = $$(CXX_$(1)) \
168         $$(CFG_GCCISH_CFLAGS) \
169         $$(CFG_GCCISH_CXXFLAGS) \
170         $$(CFG_GCCISH_CFLAGS_$(1)) \
171         $$(CFG_GCCISH_CXXFLAGS_$(1)) \
172         $$(CFG_DEPEND_FLAGS) \
173         -c -o $$(1) $$(2)
174   CFG_LINK_CXX_$(1) = $$(CXX_$(1)) \
175         $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
176         $$(CFG_GCCISH_LINK_FLAGS_$(1)) \
177         $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \
178         $$(call CFG_INSTALL_NAME_$(1),$$(4))
179
180   ifeq ($$(findstring $(HOST_$(1)),arm aarch64 mips mipsel powerpc),)
181
182   # We're using llvm-mc as our assembler because it supports
183   # .cfi pseudo-ops on mac
184   CFG_ASSEMBLE_$(1)=$$(CPP_$(1)) -E $$(CFG_DEPEND_FLAGS) $$(2) | \
185                     $$(LLVM_MC_$$(CFG_BUILD)) \
186                     -assemble \
187                     -filetype=obj \
188                     -triple=$(1) \
189                     -o=$$(1)
190   else
191
192   # For the ARM, AARCH64, MIPS and POWER crosses, use the toolchain assembler
193   # FIXME: We should be able to use the LLVM assembler
194   CFG_ASSEMBLE_$(1)=$$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
195                     $$(CFG_DEPEND_FLAGS) $$(2) -c -o $$(1)
196
197   endif
198
199 endef
200
201 $(foreach target,$(CFG_TARGET), \
202   $(eval $(call CFG_MAKE_TOOLCHAIN,$(target))))