toolchain/gcc: use STAGING_DIR_HOST instead of hardcoding default
[openwrt/openwrt.git] / toolchain / gcc / final / Makefile
1 GCC_VARIANT:=final
2
3 include ../common.mk
4
5 GCC_CONFIGURE += \
6 --with-headers=$(TOOLCHAIN_DIR)/include \
7 --enable-languages=$(TARGET_LANGUAGES) \
8 --enable-shared \
9 --enable-threads \
10 --with-slibdir=$(TOOLCHAIN_DIR)/lib \
11 --enable-lto \
12 --with-libelf=$(STAGING_DIR_HOST)
13
14 ifndef CONFIG_USE_GLIBC
15 GCC_CONFIGURE += --disable-libsanitizer
16 endif
17
18 ifdef CONFIG_USE_MUSL
19 GCC_MAKE += gcc_cv_libc_provides_ssp=yes
20 endif
21
22 ifneq ($(CONFIG_SJLJ_EXCEPTIONS),)
23 GCC_CONFIGURE += \
24 --enable-sjlj-exceptions
25 endif
26
27 define CleanupToolchain
28 $(INSTALL_DIR) $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)
29 # Important! Required for limits.h to be fixed.
30 rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
31 ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
32 rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
33 ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
34 $(if $(CONFIG_ARCH_64BIT),ln -sf ../lib64 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib64)
35 endef
36
37 define Host/Configure
38 $(CleanupToolchain)
39 mkdir -p $(GCC_BUILD_DIR)
40 (cd $(GCC_BUILD_DIR) && rm -f config.cache; \
41 $(GCC_CONFIGURE) \
42 );
43 endef
44
45 ifeq ($(CONFIG_USE_GLIBC)$(CONFIG_INSTALL_GCCGO),yy)
46 define FixGogccCrt
47 # link crtX.o for gotools
48 mkdir -p $(GCC_BUILD_DIR)/gotools
49 $(foreach crt, i 1 n, ln -sf ../../glibc-dev/lib/crt$(crt).o $(GCC_BUILD_DIR)/gotools/ ; )
50 endef
51 endif
52
53 define Host/Compile
54 $(FixGogccCrt)
55 +$(GCC_MAKE) $(HOST_JOBS) -C $(GCC_BUILD_DIR) all
56 endef
57
58 define SetupExtraArch
59 for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
60 [ -e $$$$app ] || continue; \
61 old_base=$$$$(basename $$$$app); \
62 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
63 sed -e "s/@CC_BASE@/$$$$old_base/" \
64 -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
65 ../files/alternate-arch-cc.in > \
66 $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
67 chmod a+x $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
68 done
69 endef
70
71 define Host/Install
72 $(CleanupToolchain)
73 +$(GCC_MAKE) $(HOST_JOBS) -C $(GCC_BUILD_DIR) install
74 # Set up the symlinks to enable lying about target name.
75 set -e; \
76 (cd $(TOOLCHAIN_DIR); \
77 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
78 cd bin; \
79 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
80 ln -sf $$$${app} \
81 $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
82 done; \
83 );
84 $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
85 $(RM) $(TOOLCHAIN_DIR)/lib/libiberty.a
86 $(SCRIPT_DIR)/patch-specs.sh "$(TOOLCHAIN_DIR)"
87 endef
88
89 $(eval $(call HostBuild))
90