xref: /OK3568_Linux_fs/buildroot/toolchain/toolchain-wrapper.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1################################################################################
2#
3# definition of the toolchain wrapper build commands
4#
5################################################################################
6
7# We use --hash-style=both to increase the compatibility of the generated
8# binary with older platforms, except for MIPS, where the only acceptable
9# hash style is 'sysv'
10ifeq ($(findstring mips,$(HOSTARCH)),mips)
11TOOLCHAIN_WRAPPER_HASH_STYLE = sysv
12else
13TOOLCHAIN_WRAPPER_HASH_STYLE = both
14endif
15
16TOOLCHAIN_WRAPPER_ARGS = $($(PKG)_TOOLCHAIN_WRAPPER_ARGS)
17TOOLCHAIN_WRAPPER_ARGS += -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
18
19TOOLCHAIN_WRAPPER_OPTS = \
20	$(ARCH_TOOLCHAIN_WRAPPER_OPTS) \
21	$(call qstrip,$(BR2_SSP_OPTION)) \
22	$(call qstrip,$(BR2_TARGET_OPTIMIZATION))
23
24ifeq ($(BR2_REPRODUCIBLE),y)
25TOOLCHAIN_WRAPPER_OPTS += -Wl,--build-id=none
26ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
27TOOLCHAIN_WRAPPER_OPTS += -ffile-prefix-map=$(BASE_DIR)=buildroot
28else
29TOOLCHAIN_WRAPPER_OPTS += -D__FILE__=\"\" -D__BASE_FILE__=\"\" -Wno-builtin-macro-redefined
30endif
31ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_7),)
32TOOLCHAIN_WRAPPER_OPTS += -DBR_NEED_SOURCE_DATE_EPOCH
33endif
34endif
35
36# Disable -ftree-loop-distribute-patterns on microblaze to
37# workaround a compiler bug with gcc 10 and -O2, -Os or -O3.
38# https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=5879ab5fafedc8f6f9bfe95a4cf8501b0df90edd
39# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97208
40ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_10)$(BR2_microblaze),yy)
41TOOLCHAIN_WRAPPER_OPTS += -fno-tree-loop-distribute-patterns
42endif
43
44# We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each flag is a
45# separate argument when used in execv() by the toolchain wrapper.
46TOOLCHAIN_WRAPPER_ARGS += \
47	-DBR_ADDITIONAL_CFLAGS='$(foreach f,$(TOOLCHAIN_WRAPPER_OPTS),"$(f)"$(comma))'
48
49ifeq ($(BR2_CCACHE),y)
50TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE
51endif
52
53ifeq ($(BR2_x86_x1000),y)
54TOOLCHAIN_WRAPPER_ARGS += -DBR_OMIT_LOCK_PREFIX
55endif
56
57# Avoid FPU bug on XBurst CPUs
58ifeq ($(BR2_mips_xburst),y)
59# Before gcc 4.6, -mno-fused-madd was needed, after -ffp-contract is
60# needed
61ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_6),y)
62TOOLCHAIN_WRAPPER_ARGS += -DBR_FP_CONTRACT_OFF
63else
64TOOLCHAIN_WRAPPER_ARGS += -DBR_NO_FUSED_MADD
65endif
66endif
67
68ifeq ($(BR2_CCACHE_USE_BASEDIR),y)
69TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_BASEDIR='"$(BASE_DIR)"'
70endif
71
72ifeq ($(BR2_PIC_PIE),y)
73TOOLCHAIN_WRAPPER_ARGS += -DBR2_PIC_PIE
74endif
75
76ifeq ($(BR2_RELRO_PARTIAL),y)
77TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_PARTIAL
78else ifeq ($(BR2_RELRO_FULL),y)
79TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_FULL
80endif
81
82define TOOLCHAIN_WRAPPER_BUILD
83	$(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
84		-s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
85		toolchain/toolchain-wrapper.c \
86		-o $(@D)/toolchain-wrapper
87endef
88
89define TOOLCHAIN_WRAPPER_INSTALL
90	$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper \
91		$(HOST_DIR)/bin/toolchain-wrapper
92endef
93