]> git.proxmox.com Git - rustc.git/blame - mk/rt.mk
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / mk / rt.mk
CommitLineData
1a4d82fc
JJ
1# Copyright 2014 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.
223e47cc 4#
1a4d82fc
JJ
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# Native libraries built as part of the rust build process
223e47cc 13#
1a4d82fc
JJ
14# This portion of the rust build system is meant to keep track of native
15# dependencies and how to build them. It is currently required that all native
16# dependencies are built as static libraries, as slinging around dynamic
17# libraries isn't exactly the most fun thing to do.
223e47cc 18#
1a4d82fc
JJ
19# This section should need minimal modification to add new libraries. The
20# relevant variables are:
223e47cc 21#
1a4d82fc
JJ
22# NATIVE_LIBS
23# This is a list of all native libraries which are built as part of the
24# build process. It will build all libraries into RT_OUTPUT_DIR with the
25# appropriate name of static library as dictated by the target platform
26#
27# NATIVE_DEPS_<lib>
28# This is a list of files relative to the src/rt directory which are
29# needed to build the native library. Each file will be compiled to an
30# object file, and then all the object files will be assembled into an
31# archive (static library). The list contains files of any extension
32#
33# If adding a new library, you should update the NATIVE_LIBS list, and then list
34# the required files below it. The list of required files is a list of files
35# that's per-target so you're allowed to conditionally add files based on the
36# target.
37################################################################################
38NATIVE_LIBS := rust_builtin hoedown morestack miniz \
39 rustrt_native rust_test_helpers
223e47cc 40
970d7e83 41# $(1) is the target triple
1a4d82fc
JJ
42define NATIVE_LIBRARIES
43
44NATIVE_DEPS_hoedown_$(1) := hoedown/src/autolink.c \
45 hoedown/src/buffer.c \
46 hoedown/src/document.c \
47 hoedown/src/escape.c \
48 hoedown/src/html.c \
49 hoedown/src/html_blocks.c \
50 hoedown/src/html_smartypants.c \
51 hoedown/src/stack.c \
52 hoedown/src/version.c
53NATIVE_DEPS_miniz_$(1) = miniz.c
54NATIVE_DEPS_rust_builtin_$(1) := rust_builtin.c \
55 rust_android_dummy.c
c1a9b12d 56NATIVE_DEPS_rustrt_native_$(1) := arch/$$(HOST_$(1))/record_sp.S
1a4d82fc
JJ
57NATIVE_DEPS_rust_test_helpers_$(1) := rust_test_helpers.c
58NATIVE_DEPS_morestack_$(1) := arch/$$(HOST_$(1))/morestack.S
59
60
61################################################################################
62# You shouldn't find it that necessary to edit anything below this line.
63################################################################################
64
65# While we're defining the native libraries for each target, we define some
66# common rules used to build files for various targets.
67
68RT_OUTPUT_DIR_$(1) := $(1)/rt
69
1a4d82fc
JJ
70$$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.c $$(MKFILE_DEPS)
71 @mkdir -p $$(@D)
72 @$$(call E, compile: $$@)
73 $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
62682a34
SL
74 $$(call CFG_CC_INCLUDE_$(1),$$(S)src/rt/hoedown/src) \
75 $$(call CFG_CC_INCLUDE_$(1),$$(S)src/rt) \
1a4d82fc
JJ
76 $$(RUNTIME_CFLAGS_$(1))) $$<
77
78$$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.S $$(MKFILE_DEPS) \
79 $$(LLVM_CONFIG_$$(CFG_BUILD))
80 @mkdir -p $$(@D)
81 @$$(call E, compile: $$@)
82 $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
c1a9b12d
SL
83
84# On MSVC targets the compiler's default include path (e.g. where to find system
85# headers) is specified by the INCLUDE environment variable. This may not be set
86# so the ./configure script scraped the relevant values and this is the location
87# that we put them into cl.exe's environment.
88ifeq ($$(findstring msvc,$(1)),msvc)
89$$(RT_OUTPUT_DIR_$(1))/%.o: \
90 export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
91$(1)/rustllvm/%.o: \
92 export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
93endif
1a4d82fc 94endef
970d7e83 95
1a4d82fc 96$(foreach target,$(CFG_TARGET),$(eval $(call NATIVE_LIBRARIES,$(target))))
223e47cc 97
1a4d82fc
JJ
98# A macro for devining how to build third party libraries listed above (based
99# on their dependencies).
100#
101# $(1) is the target
102# $(2) is the lib name
103define THIRD_PARTY_LIB
104
105OBJS_$(2)_$(1) := $$(NATIVE_DEPS_$(2)_$(1):%=$$(RT_OUTPUT_DIR_$(1))/%)
106OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.c=.o)
107OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.cpp=.o)
1a4d82fc
JJ
108OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.S=.o)
109NATIVE_$(2)_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),$(2))
110$$(RT_OUTPUT_DIR_$(1))/$$(NATIVE_$(2)_$(1)): $$(OBJS_$(2)_$(1))
111 @$$(call E, link: $$@)
62682a34 112 $$(Q)$$(call CFG_CREATE_ARCHIVE_$(1),$$@) $$^
d9579d0f 113
1a4d82fc 114endef
223e47cc 115
1a4d82fc
JJ
116$(foreach target,$(CFG_TARGET), \
117 $(eval $(call RUNTIME_RULES,$(target))))
118$(foreach lib,$(NATIVE_LIBS), \
119 $(foreach target,$(CFG_TARGET), \
120 $(eval $(call THIRD_PARTY_LIB,$(target),$(lib)))))
223e47cc 121
223e47cc 122
1a4d82fc
JJ
123################################################################################
124# Building third-party targets with external build systems
125#
126# This location is meant for dependencies which have external build systems. It
127# is still assumed that the output of each of these steps is a static library
128# in the correct location.
129################################################################################
223e47cc 130
1a4d82fc 131define DEF_THIRD_PARTY_TARGETS
223e47cc 132
1a4d82fc 133# $(1) is the target triple
223e47cc 134
1a4d82fc
JJ
135ifeq ($$(CFG_WINDOWSY_$(1)), 1)
136 # This isn't necessarily a desired option, but it's harmless and works around
137 # what appears to be a mingw-w64 bug.
138 #
139 # https://sourceforge.net/p/mingw-w64/bugs/395/
140 JEMALLOC_ARGS_$(1) := --enable-lazy-lock
141else ifeq ($(OSTYPE_$(1)), apple-ios)
142 JEMALLOC_ARGS_$(1) := --disable-tls
85aaf69f 143else ifeq ($(findstring android, $(OSTYPE_$(1))), android)
1a4d82fc
JJ
144 JEMALLOC_ARGS_$(1) := --disable-tls
145endif
223e47cc 146
9346a6ac
AL
147ifdef CFG_ENABLE_DEBUG_JEMALLOC
148 JEMALLOC_ARGS_$(1) += --enable-debug --enable-fill
149endif
150
1a4d82fc
JJ
151################################################################################
152# jemalloc
153################################################################################
223e47cc
LB
154
155ifdef CFG_ENABLE_FAST_MAKE
1a4d82fc 156JEMALLOC_DEPS := $(S)/.gitmodules
223e47cc 157else
1a4d82fc
JJ
158JEMALLOC_DEPS := $(wildcard \
159 $(S)src/jemalloc/* \
160 $(S)src/jemalloc/*/* \
161 $(S)src/jemalloc/*/*/* \
162 $(S)src/jemalloc/*/*/*/*)
223e47cc
LB
163endif
164
1a4d82fc
JJ
165# See #17183 for details, this file is touched during the build process so we
166# don't want to consider it as a dependency.
167JEMALLOC_DEPS := $(filter-out $(S)src/jemalloc/VERSION,$(JEMALLOC_DEPS))
168
169JEMALLOC_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),jemalloc)
170ifeq ($$(CFG_WINDOWSY_$(1)),1)
171 JEMALLOC_REAL_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),jemalloc_s)
223e47cc 172else
1a4d82fc
JJ
173 JEMALLOC_REAL_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),jemalloc_pic)
174endif
175JEMALLOC_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(JEMALLOC_NAME_$(1))
176JEMALLOC_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/jemalloc
177JEMALLOC_LOCAL_$(1) := $$(JEMALLOC_BUILD_DIR_$(1))/lib/$$(JEMALLOC_REAL_NAME_$(1))
178
179$$(JEMALLOC_LOCAL_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS)
180 @$$(call E, make: jemalloc)
181 cd "$$(JEMALLOC_BUILD_DIR_$(1))"; "$(S)src/jemalloc/configure" \
182 $$(JEMALLOC_ARGS_$(1)) --with-jemalloc-prefix=je_ $(CFG_JEMALLOC_FLAGS) \
183 --build=$$(CFG_GNU_TRIPLE_$(CFG_BUILD)) --host=$$(CFG_GNU_TRIPLE_$(1)) \
184 CC="$$(CC_$(1)) $$(CFG_JEMALLOC_CFLAGS_$(1))" \
970d7e83 185 AR="$$(AR_$(1))" \
1a4d82fc
JJ
186 RANLIB="$$(AR_$(1)) s" \
187 CPPFLAGS="-I $(S)src/rt/" \
188 EXTRA_CFLAGS="-g1 -ffunction-sections -fdata-sections"
189 $$(Q)$$(MAKE) -C "$$(JEMALLOC_BUILD_DIR_$(1))" build_lib_static
190
191ifeq ($$(CFG_DISABLE_JEMALLOC),)
192RUSTFLAGS_alloc := --cfg jemalloc
193ifeq ($(1),$$(CFG_BUILD))
194ifneq ($$(CFG_JEMALLOC_ROOT),)
195$$(JEMALLOC_LIB_$(1)): $$(CFG_JEMALLOC_ROOT)/libjemalloc_pic.a
196 @$$(call E, copy: jemalloc)
197 $$(Q)cp $$< $$@
198else
199$$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_LOCAL_$(1))
200 $$(Q)cp $$< $$@
223e47cc 201endif
970d7e83 202else
1a4d82fc
JJ
203$$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_LOCAL_$(1))
204 $$(Q)cp $$< $$@
205endif
206else
207$$(JEMALLOC_LIB_$(1)): $$(MKFILE_DEPS)
208 $$(Q)touch $$@
970d7e83
LB
209endif
210
1a4d82fc
JJ
211################################################################################
212# compiler-rt
213################################################################################
223e47cc 214
1a4d82fc
JJ
215ifdef CFG_ENABLE_FAST_MAKE
216COMPRT_DEPS := $(S)/.gitmodules
217else
218COMPRT_DEPS := $(wildcard \
219 $(S)src/compiler-rt/* \
220 $(S)src/compiler-rt/*/* \
221 $(S)src/compiler-rt/*/*/* \
222 $(S)src/compiler-rt/*/*/*/*)
223endif
223e47cc 224
62682a34 225COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
1a4d82fc
JJ
226COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
227COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
223e47cc 228
62682a34
SL
229# Note that on MSVC-targeting builds we hardwire CC/AR to gcc/ar even though
230# we're targeting MSVC. This is because although compiler-rt has a CMake build
231# config I can't actually figure out how to use it, so I'm not sure how to use
232# cl.exe to build the objects. Additionally, the compiler-rt library when built
233# with gcc has the same ABI as cl.exe, so they're largely compatible
234COMPRT_CC_$(1) := $$(CC_$(1))
235COMPRT_AR_$(1) := $$(AR_$(1))
236COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1))
237ifeq ($$(findstring msvc,$(1)),msvc)
238COMPRT_CC_$(1) := gcc
239COMPRT_AR_$(1) := ar
c1a9b12d
SL
240ifeq ($$(findstring i686,$(1)),i686)
241COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m32
242else
62682a34
SL
243COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m64
244endif
c1a9b12d 245endif
62682a34 246
1a4d82fc
JJ
247$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
248 @$$(call E, make: compiler-rt)
249 $$(Q)$$(MAKE) -C "$(S)src/compiler-rt" \
250 ProjSrcRoot="$(S)src/compiler-rt" \
251 ProjObjRoot="$$(abspath $$(COMPRT_BUILD_DIR_$(1)))" \
62682a34
SL
252 CC='$$(COMPRT_CC_$(1))' \
253 AR='$$(COMPRT_AR_$(1))' \
254 RANLIB='$$(COMPRT_AR_$(1)) s' \
255 CFLAGS="$$(COMPRT_CFLAGS_$(1))" \
1a4d82fc
JJ
256 TargetTriple=$(1) \
257 triple-builtins
62682a34 258 $$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@
1a4d82fc
JJ
259
260################################################################################
261# libbacktrace
262#
263# We use libbacktrace on linux to get symbols in backtraces, but only on linux.
264# Elsewhere we use other system utilities, so this library is only built on
265# linux.
266################################################################################
267
268BACKTRACE_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),backtrace)
269BACKTRACE_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(BACKTRACE_NAME_$(1))
270BACKTRACE_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/libbacktrace
271
272# We don't use this on platforms that aren't linux-based, so just make the file
273# available, the compilation of libstd won't actually build it.
274ifeq ($$(findstring darwin,$$(OSTYPE_$(1))),darwin)
275# See comment above
276$$(BACKTRACE_LIB_$(1)):
277 touch $$@
223e47cc 278
1a4d82fc
JJ
279else
280ifeq ($$(findstring ios,$$(OSTYPE_$(1))),ios)
281# See comment above
282$$(BACKTRACE_LIB_$(1)):
283 touch $$@
284else
223e47cc 285
1a4d82fc
JJ
286ifeq ($$(CFG_WINDOWSY_$(1)),1)
287# See comment above
288$$(BACKTRACE_LIB_$(1)):
289 touch $$@
290else
223e47cc 291
1a4d82fc
JJ
292ifdef CFG_ENABLE_FAST_MAKE
293BACKTRACE_DEPS := $(S)/.gitmodules
294else
295BACKTRACE_DEPS := $(wildcard $(S)src/libbacktrace/*)
296endif
297
298# We need to export CFLAGS because otherwise it doesn't pick up cross compile
299# builds. If libbacktrace doesn't realize this, it will attempt to read 64-bit
300# elf headers when compiled for a 32-bit system, yielding blank backtraces.
301#
302# This also removes the -Werror flag specifically to prevent errors during
303# configuration.
304#
305# Down below you'll also see echos into the config.h generated by the
306# ./configure script. This is done to force libbacktrace to *not* use the
307# atomic/sync functionality because it pulls in unnecessary dependencies and we
308# never use it anyway.
309$$(BACKTRACE_BUILD_DIR_$(1))/Makefile: $$(BACKTRACE_DEPS) $$(MKFILE_DEPS)
310 @$$(call E, configure: libbacktrace for $(1))
311 $$(Q)rm -rf $$(BACKTRACE_BUILD_DIR_$(1))
312 $$(Q)mkdir -p $$(BACKTRACE_BUILD_DIR_$(1))
313 $$(Q)(cd $$(BACKTRACE_BUILD_DIR_$(1)) && \
314 CC="$$(CC_$(1))" \
315 AR="$$(AR_$(1))" \
316 RANLIB="$$(AR_$(1)) s" \
317 CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1):-Werror=) -fno-stack-protector" \
318 $(S)src/libbacktrace/configure --target=$(1) --host=$(CFG_BUILD))
319 $$(Q)echo '#undef HAVE_ATOMIC_FUNCTIONS' >> \
320 $$(BACKTRACE_BUILD_DIR_$(1))/config.h
321 $$(Q)echo '#undef HAVE_SYNC_FUNCTIONS' >> \
322 $$(BACKTRACE_BUILD_DIR_$(1))/config.h
323
324$$(BACKTRACE_LIB_$(1)): $$(BACKTRACE_BUILD_DIR_$(1))/Makefile $$(MKFILE_DEPS)
325 @$$(call E, make: libbacktrace)
326 $$(Q)$$(MAKE) -C $$(BACKTRACE_BUILD_DIR_$(1)) \
327 INCDIR=$(S)src/libbacktrace
328 $$(Q)cp $$(BACKTRACE_BUILD_DIR_$(1))/.libs/libbacktrace.a $$@
329
330endif # endif for windowsy
331endif # endif for ios
332endif # endif for darwin
223e47cc 333
d9579d0f
AL
334################################################################################
335# libc/libunwind for musl
336#
337# When we're building a musl-like target we're going to link libc/libunwind
338# statically into the standard library and liblibc, so we need to make sure
339# they're in a location that we can find
340################################################################################
341
342ifeq ($$(findstring musl,$(1)),musl)
343$$(RT_OUTPUT_DIR_$(1))/%: $$(CFG_MUSL_ROOT)/lib/%
344 cp $$^ $$@
345endif
346
223e47cc
LB
347endef
348
1a4d82fc
JJ
349# Instantiate template for all stages/targets
350$(foreach target,$(CFG_TARGET), \
351 $(eval $(call DEF_THIRD_PARTY_TARGETS,$(target))))