]> git.lizzy.rs Git - rust.git/blob - mk/rt.mk
Rollup merge of #34828 - seanmonstar:into-opton, r=alexcrichton
[rust.git] / mk / rt.mk
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.
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 # Native libraries built as part of the rust build process
13 #
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.
18 #
19 # This section should need minimal modification to add new libraries. The
20 # relevant variables are:
21 #
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 ################################################################################
38 NATIVE_LIBS := hoedown miniz rust_test_helpers
39
40 # $(1) is the target triple
41 define NATIVE_LIBRARIES
42
43 NATIVE_DEPS_hoedown_$(1) := hoedown/src/autolink.c \
44                         hoedown/src/buffer.c \
45                         hoedown/src/document.c \
46                         hoedown/src/escape.c \
47                         hoedown/src/html.c \
48                         hoedown/src/html_blocks.c \
49                         hoedown/src/html_smartypants.c \
50                         hoedown/src/stack.c \
51                         hoedown/src/version.c
52 NATIVE_DEPS_miniz_$(1) = miniz.c
53 NATIVE_DEPS_rust_test_helpers_$(1) := rust_test_helpers.c
54
55 ################################################################################
56 # You shouldn't find it that necessary to edit anything below this line.
57 ################################################################################
58
59 # While we're defining the native libraries for each target, we define some
60 # common rules used to build files for various targets.
61
62 RT_OUTPUT_DIR_$(1) := $(1)/rt
63
64 $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.c $$(MKFILE_DEPS)
65         @mkdir -p $$(@D)
66         @$$(call E, compile: $$@)
67         $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
68                 $$(call CFG_CC_INCLUDE_$(1),$$(S)src/rt/hoedown/src) \
69                 $$(call CFG_CC_INCLUDE_$(1),$$(S)src/rt) \
70                  $$(RUNTIME_CFLAGS_$(1))) $$<
71
72 $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.S $$(MKFILE_DEPS) \
73             $$(LLVM_CONFIG_$$(CFG_BUILD))
74         @mkdir -p $$(@D)
75         @$$(call E, compile: $$@)
76         $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
77
78 # On MSVC targets the compiler's default include path (e.g. where to find system
79 # headers) is specified by the INCLUDE environment variable. This may not be set
80 # so the ./configure script scraped the relevant values and this is the location
81 # that we put them into cl.exe's environment.
82 ifeq ($$(findstring msvc,$(1)),msvc)
83 $$(RT_OUTPUT_DIR_$(1))/%.o: \
84         export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
85 $(1)/rustllvm/%.o: \
86         export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
87 endif
88 endef
89
90 $(foreach target,$(CFG_TARGET),$(eval $(call NATIVE_LIBRARIES,$(target))))
91
92 # A macro for devining how to build third party libraries listed above (based
93 # on their dependencies).
94 #
95 # $(1) is the target
96 # $(2) is the lib name
97 define THIRD_PARTY_LIB
98
99 OBJS_$(2)_$(1) := $$(NATIVE_DEPS_$(2)_$(1):%=$$(RT_OUTPUT_DIR_$(1))/%)
100 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.c=.o)
101 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.cpp=.o)
102 OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.S=.o)
103 NATIVE_$(2)_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),$(2))
104 $$(RT_OUTPUT_DIR_$(1))/$$(NATIVE_$(2)_$(1)): $$(OBJS_$(2)_$(1))
105         @$$(call E, link: $$@)
106         $$(Q)$$(call CFG_CREATE_ARCHIVE_$(1),$$@) $$^
107
108 endef
109
110 $(foreach target,$(CFG_TARGET), \
111  $(eval $(call RUNTIME_RULES,$(target))))
112 $(foreach lib,$(NATIVE_LIBS), \
113  $(foreach target,$(CFG_TARGET), \
114   $(eval $(call THIRD_PARTY_LIB,$(target),$(lib)))))
115
116
117 ################################################################################
118 # Building third-party targets with external build systems
119 #
120 # This location is meant for dependencies which have external build systems. It
121 # is still assumed that the output of each of these steps is a static library
122 # in the correct location.
123 ################################################################################
124
125 define DEF_THIRD_PARTY_TARGETS
126
127 # $(1) is the target triple
128
129 ifeq ($$(CFG_WINDOWSY_$(1)),1)
130   # A bit of history here, this used to be --enable-lazy-lock added in #14006
131   # which was filed with jemalloc in jemalloc/jemalloc#83 which was also
132   # reported to MinGW: http://sourceforge.net/p/mingw-w64/bugs/395/
133   #
134   # When updating jemalloc to 4.0, however, it was found that binaries would
135   # exit with the status code STATUS_RESOURCE_NOT_OWNED indicating that a thread
136   # was unlocking a mutex it never locked. Disabling this "lazy lock" option
137   # seems to fix the issue, but it was enabled by default for MinGW targets in
138   # 13473c7 for jemalloc.
139   #
140   # As a result of all that, force disabling lazy lock on Windows, and after
141   # reading some code it at least *appears* that the initialization of mutexes
142   # is otherwise ok in jemalloc, so shouldn't cause problems hopefully...
143   #
144   # tl;dr: make windows behave like other platforms by disabling lazy locking,
145   #        but requires passing an option due to a historical default with
146   #        jemalloc.
147   JEMALLOC_ARGS_$(1) := --disable-lazy-lock
148 else ifeq ($(OSTYPE_$(1)), apple-ios)
149   JEMALLOC_ARGS_$(1) := --disable-tls
150 else ifeq ($(findstring android, $(OSTYPE_$(1))), android)
151   # We force android to have prefixed symbols because apparently replacement of
152   # the libc allocator doesn't quite work. When this was tested (unprefixed
153   # symbols), it was found that the `realpath` function in libc would allocate
154   # with libc malloc (not jemalloc malloc), and then the standard library would
155   # free with jemalloc free, causing a segfault.
156   #
157   # If the test suite passes, however, without symbol prefixes then we should be
158   # good to go!
159   JEMALLOC_ARGS_$(1) := --disable-tls --with-jemalloc-prefix=je_
160 else ifeq ($(findstring dragonfly, $(OSTYPE_$(1))), dragonfly)
161   JEMALLOC_ARGS_$(1) := --with-jemalloc-prefix=je_
162 endif
163
164 ifdef CFG_ENABLE_DEBUG_JEMALLOC
165   JEMALLOC_ARGS_$(1) += --enable-debug --enable-fill
166 endif
167
168 ################################################################################
169 # jemalloc
170 ################################################################################
171
172 ifdef CFG_ENABLE_FAST_MAKE
173 JEMALLOC_DEPS := $(S)/.gitmodules
174 else
175 JEMALLOC_DEPS := $(wildcard \
176                    $(S)src/jemalloc/* \
177                    $(S)src/jemalloc/*/* \
178                    $(S)src/jemalloc/*/*/* \
179                    $(S)src/jemalloc/*/*/*/*)
180 endif
181
182 # See #17183 for details, this file is touched during the build process so we
183 # don't want to consider it as a dependency.
184 JEMALLOC_DEPS := $(filter-out $(S)src/jemalloc/VERSION,$(JEMALLOC_DEPS))
185
186 JEMALLOC_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),jemalloc)
187 ifeq ($$(CFG_WINDOWSY_$(1)),1)
188   JEMALLOC_REAL_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),jemalloc_s)
189 else
190   JEMALLOC_REAL_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),jemalloc_pic)
191 endif
192 JEMALLOC_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(JEMALLOC_NAME_$(1))
193 JEMALLOC_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/jemalloc
194 JEMALLOC_LOCAL_$(1) := $$(JEMALLOC_BUILD_DIR_$(1))/lib/$$(JEMALLOC_REAL_NAME_$(1))
195
196 $$(JEMALLOC_LOCAL_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS)
197         @$$(call E, make: jemalloc)
198         cd "$$(JEMALLOC_BUILD_DIR_$(1))"; "$(S)src/jemalloc/configure" \
199                 $$(JEMALLOC_ARGS_$(1)) $(CFG_JEMALLOC_FLAGS) \
200                 --build=$$(CFG_GNU_TRIPLE_$(CFG_BUILD)) --host=$$(CFG_GNU_TRIPLE_$(1)) \
201                 CC="$$(CC_$(1)) $$(CFG_JEMALLOC_CFLAGS_$(1))" \
202                 AR="$$(AR_$(1))" \
203                 RANLIB="$$(AR_$(1)) s" \
204                 CPPFLAGS="-I $(S)src/rt/" \
205                 EXTRA_CFLAGS="-g1 -ffunction-sections -fdata-sections"
206         $$(Q)$$(MAKE) -C "$$(JEMALLOC_BUILD_DIR_$(1))" build_lib_static
207
208 ifeq ($(1),$$(CFG_BUILD))
209 ifneq ($$(CFG_JEMALLOC_ROOT),)
210 $$(JEMALLOC_LIB_$(1)): $$(CFG_JEMALLOC_ROOT)/libjemalloc_pic.a
211         @$$(call E, copy: jemalloc)
212         $$(Q)cp $$< $$@
213 else
214 $$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_LOCAL_$(1))
215         $$(Q)cp $$< $$@
216 endif
217 else
218 $$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_LOCAL_$(1))
219         $$(Q)cp $$< $$@
220 endif
221
222 ################################################################################
223 # compiler-rt
224 ################################################################################
225
226 # Everything below is a manual compilation of compiler-rt, disregarding its
227 # build system. See comments in `src/bootstrap/native.rs` for more information.
228
229 COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
230 COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
231 COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
232
233 # GENERIC_SOURCES in CMakeLists.txt
234 COMPRT_OBJS_$(1) := \
235   absvdi2.o \
236   absvsi2.o \
237   adddf3.o \
238   addsf3.o \
239   addvdi3.o \
240   addvsi3.o \
241   apple_versioning.o \
242   ashldi3.o \
243   ashrdi3.o \
244   clear_cache.o \
245   clzdi2.o \
246   clzsi2.o \
247   cmpdi2.o \
248   comparedf2.o \
249   comparesf2.o \
250   ctzdi2.o \
251   ctzsi2.o \
252   divdc3.o \
253   divdf3.o \
254   divdi3.o \
255   divmoddi4.o \
256   divmodsi4.o \
257   divsc3.o \
258   divsf3.o \
259   divsi3.o \
260   divxc3.o \
261   extendsfdf2.o \
262   extendhfsf2.o \
263   ffsdi2.o \
264   fixdfdi.o \
265   fixdfsi.o \
266   fixsfdi.o \
267   fixsfsi.o \
268   fixunsdfdi.o \
269   fixunsdfsi.o \
270   fixunssfdi.o \
271   fixunssfsi.o \
272   fixunsxfdi.o \
273   fixunsxfsi.o \
274   fixxfdi.o \
275   floatdidf.o \
276   floatdisf.o \
277   floatdixf.o \
278   floatsidf.o \
279   floatsisf.o \
280   floatundidf.o \
281   floatundisf.o \
282   floatundixf.o \
283   floatunsidf.o \
284   floatunsisf.o \
285   int_util.o \
286   lshrdi3.o \
287   moddi3.o \
288   modsi3.o \
289   muldc3.o \
290   muldf3.o \
291   muldi3.o \
292   mulodi4.o \
293   mulosi4.o \
294   muloti4.o \
295   mulsc3.o \
296   mulsf3.o \
297   mulvdi3.o \
298   mulvsi3.o \
299   mulxc3.o \
300   negdf2.o \
301   negdi2.o \
302   negsf2.o \
303   negvdi2.o \
304   negvsi2.o \
305   paritydi2.o \
306   paritysi2.o \
307   popcountdi2.o \
308   popcountsi2.o \
309   powidf2.o \
310   powisf2.o \
311   powixf2.o \
312   subdf3.o \
313   subsf3.o \
314   subvdi3.o \
315   subvsi3.o \
316   truncdfhf2.o \
317   truncdfsf2.o \
318   truncsfhf2.o \
319   ucmpdi2.o \
320   udivdi3.o \
321   udivmoddi4.o \
322   udivmodsi4.o \
323   udivsi3.o \
324   umoddi3.o \
325   umodsi3.o
326
327 ifeq ($$(findstring ios,$(1)),)
328 COMPRT_OBJS_$(1) += \
329   absvti2.o \
330   addtf3.o \
331   addvti3.o \
332   ashlti3.o \
333   ashrti3.o \
334   clzti2.o \
335   cmpti2.o \
336   ctzti2.o \
337   divtf3.o \
338   divti3.o \
339   ffsti2.o \
340   fixdfti.o \
341   fixsfti.o \
342   fixunsdfti.o \
343   fixunssfti.o \
344   fixunsxfti.o \
345   fixxfti.o \
346   floattidf.o \
347   floattisf.o \
348   floattixf.o \
349   floatuntidf.o \
350   floatuntisf.o \
351   floatuntixf.o \
352   lshrti3.o \
353   modti3.o \
354   multf3.o \
355   multi3.o \
356   mulvti3.o \
357   negti2.o \
358   negvti2.o \
359   parityti2.o \
360   popcountti2.o \
361   powitf2.o \
362   subtf3.o \
363   subvti3.o \
364   trampoline_setup.o \
365   ucmpti2.o \
366   udivmodti4.o \
367   udivti3.o \
368   umodti3.o
369 endif
370
371 ifeq ($$(findstring apple,$(1)),apple)
372 COMPRT_OBJS_$(1) +=  \
373             atomic_flag_clear.o \
374             atomic_flag_clear_explicit.o \
375             atomic_flag_test_and_set.o \
376             atomic_flag_test_and_set_explicit.o \
377             atomic_signal_fence.o \
378             atomic_thread_fence.o
379 endif
380
381
382 ifeq ($$(findstring windows,$(1)),)
383 COMPRT_OBJS_$(1) += emutls.o
384 endif
385
386 ifeq ($$(findstring msvc,$(1)),)
387 COMPRT_OBJS_$(1) += gcc_personality_v0.o
388 COMPRT_OBJS_$(1) += emutls.o
389
390 ifeq ($$(findstring x86_64,$(1)),x86_64)
391 COMPRT_OBJS_$(1) += \
392       x86_64/chkstk.o \
393       x86_64/chkstk2.o \
394       x86_64/floatdidf.o \
395       x86_64/floatdisf.o \
396       x86_64/floatdixf.o \
397       x86_64/floatundidf.o \
398       x86_64/floatundisf.o \
399       x86_64/floatundixf.o
400 endif
401
402 ifeq ($$(findstring i686,$$(patsubts i%86,i686,$(1))),i686)
403 COMPRT_OBJS_$(1) += \
404       i386/ashldi3.o \
405       i386/ashrdi3.o \
406       i386/chkstk.o \
407       i386/chkstk2.o \
408       i386/divdi3.o \
409       i386/floatdidf.o \
410       i386/floatdisf.o \
411       i386/floatdixf.o \
412       i386/floatundidf.o \
413       i386/floatundisf.o \
414       i386/floatundixf.o \
415       i386/lshrdi3.o \
416       i386/moddi3.o \
417       i386/muldi3.o \
418       i386/udivdi3.o \
419       i386/umoddi3.o
420 endif
421
422 else
423
424 ifeq ($$(findstring x86_64,$(1)),x86_64)
425 COMPRT_OBJS_$(1) += \
426       x86_64/floatdidf.o \
427       x86_64/floatdisf.o \
428       x86_64/floatdixf.o
429 endif
430
431 endif
432
433 # Generic ARM sources, nothing compiles on iOS though
434 ifeq ($$(findstring arm,$(1)),arm)
435 ifeq ($$(findstring ios,$(1)),)
436 COMPRT_OBJS_$(1) += \
437   arm/aeabi_cdcmp.o \
438   arm/aeabi_cdcmpeq_check_nan.o \
439   arm/aeabi_cfcmp.o \
440   arm/aeabi_cfcmpeq_check_nan.o \
441   arm/aeabi_dcmp.o \
442   arm/aeabi_div0.o \
443   arm/aeabi_drsub.o \
444   arm/aeabi_fcmp.o \
445   arm/aeabi_frsub.o \
446   arm/aeabi_idivmod.o \
447   arm/aeabi_ldivmod.o \
448   arm/aeabi_memcmp.o \
449   arm/aeabi_memcpy.o \
450   arm/aeabi_memmove.o \
451   arm/aeabi_memset.o \
452   arm/aeabi_uidivmod.o \
453   arm/aeabi_uldivmod.o \
454   arm/bswapdi2.o \
455   arm/bswapsi2.o \
456   arm/clzdi2.o \
457   arm/clzsi2.o \
458   arm/comparesf2.o \
459   arm/divmodsi4.o \
460   arm/divsi3.o \
461   arm/modsi3.o \
462   arm/switch16.o \
463   arm/switch32.o \
464   arm/switch8.o \
465   arm/switchu8.o \
466   arm/sync_synchronize.o \
467   arm/udivmodsi4.o \
468   arm/udivsi3.o \
469   arm/umodsi3.o
470 endif
471 endif
472
473 # Thumb sources
474 ifeq ($$(findstring armv7,$(1)),armv7)
475 COMPRT_OBJS_$(1) += \
476   arm/sync_fetch_and_add_4.o \
477   arm/sync_fetch_and_add_8.o \
478   arm/sync_fetch_and_and_4.o \
479   arm/sync_fetch_and_and_8.o \
480   arm/sync_fetch_and_max_4.o \
481   arm/sync_fetch_and_max_8.o \
482   arm/sync_fetch_and_min_4.o \
483   arm/sync_fetch_and_min_8.o \
484   arm/sync_fetch_and_nand_4.o \
485   arm/sync_fetch_and_nand_8.o \
486   arm/sync_fetch_and_or_4.o \
487   arm/sync_fetch_and_or_8.o \
488   arm/sync_fetch_and_sub_4.o \
489   arm/sync_fetch_and_sub_8.o \
490   arm/sync_fetch_and_umax_4.o \
491   arm/sync_fetch_and_umax_8.o \
492   arm/sync_fetch_and_umin_4.o \
493   arm/sync_fetch_and_umin_8.o \
494   arm/sync_fetch_and_xor_4.o \
495   arm/sync_fetch_and_xor_8.o
496 endif
497
498 # VFP sources
499 ifeq ($$(findstring eabihf,$(1)),eabihf)
500 COMPRT_OBJS_$(1) += \
501   arm/adddf3vfp.o \
502   arm/addsf3vfp.o \
503   arm/divdf3vfp.o \
504   arm/divsf3vfp.o \
505   arm/eqdf2vfp.o \
506   arm/eqsf2vfp.o \
507   arm/extendsfdf2vfp.o \
508   arm/fixdfsivfp.o \
509   arm/fixsfsivfp.o \
510   arm/fixunsdfsivfp.o \
511   arm/fixunssfsivfp.o \
512   arm/floatsidfvfp.o \
513   arm/floatsisfvfp.o \
514   arm/floatunssidfvfp.o \
515   arm/floatunssisfvfp.o \
516   arm/gedf2vfp.o \
517   arm/gesf2vfp.o \
518   arm/gtdf2vfp.o \
519   arm/gtsf2vfp.o \
520   arm/ledf2vfp.o \
521   arm/lesf2vfp.o \
522   arm/ltdf2vfp.o \
523   arm/ltsf2vfp.o \
524   arm/muldf3vfp.o \
525   arm/mulsf3vfp.o \
526   arm/negdf2vfp.o \
527   arm/negsf2vfp.o \
528   arm/nedf2vfp.o \
529   arm/nesf2vfp.o \
530   arm/restore_vfp_d8_d15_regs.o \
531   arm/save_vfp_d8_d15_regs.o \
532   arm/subdf3vfp.o \
533   arm/subsf3vfp.o \
534   arm/truncdfsf2vfp.o \
535   arm/unorddf2vfp.o \
536   arm/unordsf2vfp.o
537 endif
538
539 ifeq ($$(findstring aarch64,$(1)),aarch64)
540 COMPRT_OBJS_$(1) += \
541   comparetf2.o \
542   extenddftf2.o \
543   extendsftf2.o \
544   fixtfdi.o \
545   fixtfsi.o \
546   fixtfti.o \
547   fixunstfdi.o \
548   fixunstfsi.o \
549   fixunstfti.o \
550   floatditf.o \
551   floatsitf.o \
552   floatunditf.o \
553   floatunsitf.o \
554   multc3.o \
555   trunctfdf2.o \
556   trunctfsf2.o
557 endif
558
559 ifeq ($$(findstring msvc,$(1)),msvc)
560 $$(COMPRT_BUILD_DIR_$(1))/%.o: CFLAGS += -Zl -D__func__=__FUNCTION__
561 else
562 $$(COMPRT_BUILD_DIR_$(1))/%.o: CFLAGS += -fno-builtin -fvisibility=hidden \
563         -fomit-frame-pointer -ffreestanding
564 endif
565
566 COMPRT_OBJS_$(1) := $$(COMPRT_OBJS_$(1):%=$$(COMPRT_BUILD_DIR_$(1))/%)
567
568 $$(COMPRT_BUILD_DIR_$(1))/%.o: $(S)src/compiler-rt/lib/builtins/%.c
569         @mkdir -p $$(@D)
570         @$$(call E, compile: $$@)
571         $$(Q)$$(call CFG_COMPILE_C_$(1),$$@,$$<)
572
573 $$(COMPRT_BUILD_DIR_$(1))/%.o: $(S)src/compiler-rt/lib/builtins/%.S \
574             $$(LLVM_CONFIG_$$(CFG_BUILD))
575         @mkdir -p $$(@D)
576         @$$(call E, compile: $$@)
577         $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
578
579 ifeq ($$(findstring msvc,$(1)),msvc)
580 $$(COMPRT_BUILD_DIR_$(1))/%.o: \
581         export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
582 endif
583
584 ifeq ($$(findstring emscripten,$(1)),emscripten)
585 # FIXME: emscripten doesn't use compiler-rt and can't build it without
586 # further hacks
587 COMPRT_OBJS_$(1) :=
588 endif
589
590 $$(COMPRT_LIB_$(1)): $$(COMPRT_OBJS_$(1))
591         @$$(call E, link: $$@)
592         $$(Q)$$(call CFG_CREATE_ARCHIVE_$(1),$$@) $$^
593
594 ################################################################################
595 # libbacktrace
596 #
597 # We use libbacktrace on linux to get symbols in backtraces, but only on linux.
598 # Elsewhere we use other system utilities, so this library is only built on
599 # linux.
600 ################################################################################
601
602 BACKTRACE_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),backtrace)
603 BACKTRACE_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(BACKTRACE_NAME_$(1))
604 BACKTRACE_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/libbacktrace
605
606 # We don't use this on platforms that aren't linux-based (with the exception of
607 # msys2/mingw builds on windows, which use it to read the dwarf debug
608 # information) so just make the file available, the compilation of libstd won't
609 # actually build it.
610 ifeq ($$(findstring darwin,$$(OSTYPE_$(1))),darwin)
611 # See comment above
612 $$(BACKTRACE_LIB_$(1)):
613         touch $$@
614
615 else ifeq ($$(findstring ios,$$(OSTYPE_$(1))),ios)
616 # See comment above
617 $$(BACKTRACE_LIB_$(1)):
618         touch $$@
619 else ifeq ($$(findstring msvc,$(1)),msvc)
620 # See comment above
621 $$(BACKTRACE_LIB_$(1)):
622         touch $$@
623 else ifeq ($$(findstring emscripten,$(1)),emscripten)
624 # FIXME: libbacktrace doesn't understand the emscripten triple
625 $$(BACKTRACE_LIB_$(1)):
626         touch $$@
627 else
628
629 ifdef CFG_ENABLE_FAST_MAKE
630 BACKTRACE_DEPS := $(S)/.gitmodules
631 else
632 BACKTRACE_DEPS := $(wildcard $(S)src/libbacktrace/*)
633 endif
634
635 # We need to export CFLAGS because otherwise it doesn't pick up cross compile
636 # builds. If libbacktrace doesn't realize this, it will attempt to read 64-bit
637 # elf headers when compiled for a 32-bit system, yielding blank backtraces.
638 #
639 # This also removes the -Werror flag specifically to prevent errors during
640 # configuration.
641 #
642 # Down below you'll also see echos into the config.h generated by the
643 # ./configure script. This is done to force libbacktrace to *not* use the
644 # atomic/sync functionality because it pulls in unnecessary dependencies and we
645 # never use it anyway.
646 #
647 # We also use `env PWD=` to clear the PWD environment variable, and then
648 # execute the command in a new shell. This is necessary to workaround a
649 # buildbot/msys2 bug: the shell is launched with PWD set to a windows-style path,
650 # which results in all further uses of `pwd` also printing a windows-style path,
651 # which breaks libbacktrace's configure script. Clearing PWD within the same
652 # shell is not sufficient.
653
654 $$(BACKTRACE_BUILD_DIR_$(1))/Makefile: $$(BACKTRACE_DEPS) $$(MKFILE_DEPS)
655         @$$(call E, configure: libbacktrace for $(1))
656         $$(Q)rm -rf $$(BACKTRACE_BUILD_DIR_$(1))
657         $$(Q)mkdir -p $$(BACKTRACE_BUILD_DIR_$(1))
658         $$(Q)(cd $$(BACKTRACE_BUILD_DIR_$(1)) && env \
659               PWD= \
660               CC="$$(CC_$(1))" \
661               AR="$$(AR_$(1))" \
662               RANLIB="$$(AR_$(1)) s" \
663               CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1)) -Wno-error -fno-stack-protector" \
664               $(S)src/libbacktrace/configure --build=$(CFG_GNU_TRIPLE_$(CFG_BUILD)) --host=$(CFG_GNU_TRIPLE_$(1)))
665         $$(Q)echo '#undef HAVE_ATOMIC_FUNCTIONS' >> \
666               $$(BACKTRACE_BUILD_DIR_$(1))/config.h
667         $$(Q)echo '#undef HAVE_SYNC_FUNCTIONS' >> \
668               $$(BACKTRACE_BUILD_DIR_$(1))/config.h
669
670 $$(BACKTRACE_LIB_$(1)): $$(BACKTRACE_BUILD_DIR_$(1))/Makefile $$(MKFILE_DEPS)
671         @$$(call E, make: libbacktrace)
672         $$(Q)$$(MAKE) -C $$(BACKTRACE_BUILD_DIR_$(1)) \
673                 INCDIR=$(S)src/libbacktrace
674         $$(Q)cp $$(BACKTRACE_BUILD_DIR_$(1))/.libs/libbacktrace.a $$@
675
676 endif
677
678 ################################################################################
679 # libc/libunwind for musl
680 #
681 # When we're building a musl-like target we're going to link libc/libunwind
682 # statically into the standard library and liblibc, so we need to make sure
683 # they're in a location that we can find
684 ################################################################################
685
686 ifeq ($$(findstring musl,$(1)),musl)
687 $$(RT_OUTPUT_DIR_$(1))/%: $$(CFG_MUSL_ROOT)/lib/%
688         cp $$^ $$@
689 else
690 # Ask gcc where it is
691 $$(RT_OUTPUT_DIR_$(1))/%:
692         cp $$(shell $$(CC_$(1)) -print-file-name=$$(@F)) $$@
693 endif
694
695 endef
696
697 # Instantiate template for all stages/targets
698 $(foreach target,$(CFG_TARGET), \
699      $(eval $(call DEF_THIRD_PARTY_TARGETS,$(target))))