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