xref: /OK3568_Linux_fs/buildroot/toolchain/toolchain-external/pkg-toolchain-external.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun################################################################################
2*4882a593Smuzhiyun# External toolchain package infrastructure
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# This package infrastructure implements the support for external
5*4882a593Smuzhiyun# toolchains, i.e toolchains that are available pre-built, ready to
6*4882a593Smuzhiyun# use. Such toolchain may either be readily available on the Web
7*4882a593Smuzhiyun# (Linaro, Sourcery CodeBench, from processor vendors) or may be built
8*4882a593Smuzhiyun# with tools like Crosstool-NG or Buildroot itself. So far, we have
9*4882a593Smuzhiyun# tested this with:
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun#  * Toolchains generated by Crosstool-NG
12*4882a593Smuzhiyun#  * Toolchains generated by Buildroot
13*4882a593Smuzhiyun#  * Toolchains provided by Linaro for the ARM and AArch64
14*4882a593Smuzhiyun#    architectures
15*4882a593Smuzhiyun#  * Sourcery CodeBench toolchains (from Mentor Graphics) for the ARM,
16*4882a593Smuzhiyun#    MIPS, PowerPC, x86_64 and NIOS 2 architectures. For the MIPS
17*4882a593Smuzhiyun#    toolchain, the -muclibc variant isn't supported yet, only the
18*4882a593Smuzhiyun#    default glibc-based variant is.
19*4882a593Smuzhiyun#  * Synopsys DesignWare toolchains for ARC cores
20*4882a593Smuzhiyun#
21*4882a593Smuzhiyun# The basic principle is the following
22*4882a593Smuzhiyun#
23*4882a593Smuzhiyun#  1. If the toolchain is not pre-installed, download and extract it
24*4882a593Smuzhiyun#  in $(TOOLCHAIN_EXTERNAL_INSTALL_DIR). Otherwise,
25*4882a593Smuzhiyun#  $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) points to were the toolchain has
26*4882a593Smuzhiyun#  already been installed by the user.
27*4882a593Smuzhiyun#
28*4882a593Smuzhiyun#  2. For all external toolchains, perform some checks on the
29*4882a593Smuzhiyun#  conformity between the toolchain configuration described in the
30*4882a593Smuzhiyun#  Buildroot menuconfig system, and the real configuration of the
31*4882a593Smuzhiyun#  external toolchain. This is for example important to make sure that
32*4882a593Smuzhiyun#  the Buildroot configuration system knows whether the toolchain
33*4882a593Smuzhiyun#  supports RPC, IPv6, locales, large files, etc. Unfortunately, these
34*4882a593Smuzhiyun#  things cannot be detected automatically, since the value of these
35*4882a593Smuzhiyun#  options (such as BR2_TOOLCHAIN_HAS_NATIVE_RPC) are needed at
36*4882a593Smuzhiyun#  configuration time because these options are used as dependencies
37*4882a593Smuzhiyun#  for other options. And at configuration time, we are not able to
38*4882a593Smuzhiyun#  retrieve the external toolchain configuration.
39*4882a593Smuzhiyun#
40*4882a593Smuzhiyun#  3. Copy the libraries needed at runtime to the target directory,
41*4882a593Smuzhiyun#  $(TARGET_DIR). Obviously, things such as the C library, the dynamic
42*4882a593Smuzhiyun#  loader and a few other utility libraries are needed if dynamic
43*4882a593Smuzhiyun#  applications are to be executed on the target system.
44*4882a593Smuzhiyun#
45*4882a593Smuzhiyun#  4. Copy the libraries and headers to the staging directory. This
46*4882a593Smuzhiyun#  will allow all further calls to gcc to be made using --sysroot
47*4882a593Smuzhiyun#  $(STAGING_DIR), which greatly simplifies the compilation of the
48*4882a593Smuzhiyun#  packages when using external toolchains. So in the end, only the
49*4882a593Smuzhiyun#  cross-compiler binaries remains external, all libraries and headers
50*4882a593Smuzhiyun#  are imported into the Buildroot tree.
51*4882a593Smuzhiyun#
52*4882a593Smuzhiyun#  5. Build a toolchain wrapper which executes the external toolchain
53*4882a593Smuzhiyun#  with a number of arguments (sysroot/march/mtune/..) hardcoded,
54*4882a593Smuzhiyun#  so we're sure the correct configuration is always used and the
55*4882a593Smuzhiyun#  toolchain behaves similar to an internal toolchain.
56*4882a593Smuzhiyun#  This toolchain wrapper and symlinks are installed into
57*4882a593Smuzhiyun#  $(HOST_DIR)/bin like for the internal toolchains, and the rest
58*4882a593Smuzhiyun#  of Buildroot is handled identical for the 2 toolchain types.
59*4882a593Smuzhiyun################################################################################
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun#
62*4882a593Smuzhiyun# Definitions of where the toolchain can be found
63*4882a593Smuzhiyun#
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_PREFIX = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
66*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR = $(HOST_DIR)/opt/ext-toolchain
67*4882a593Smuzhiyun
68*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
69*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_INSTALL_DIR = $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
70*4882a593Smuzhiyunelse
71*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_INSTALL_DIR = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
72*4882a593Smuzhiyunendif
73*4882a593Smuzhiyun
74*4882a593Smuzhiyunifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),)
75*4882a593Smuzhiyunifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),)
76*4882a593Smuzhiyun# if no path set, figure it out from path
77*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_BIN := $(dir $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
78*4882a593Smuzhiyunendif
79*4882a593Smuzhiyunelse
80*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_REL_BIN_PATH = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_REL_BIN_PATH))
81*4882a593Smuzhiyunifeq ($(TOOLCHAIN_EXTERNAL_REL_BIN_PATH),)
82*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_REL_BIN_PATH = bin
83*4882a593Smuzhiyunendif
84*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_BIN = $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/$(TOOLCHAIN_EXTERNAL_REL_BIN_PATH)
85*4882a593Smuzhiyunendif
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun# If this is a buildroot toolchain, it already has a wrapper which we want to
88*4882a593Smuzhiyun# bypass. Since this is only evaluated after it has been extracted, we can use
89*4882a593Smuzhiyun# $(wildcard ...) here.
90*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_SUFFIX = \
91*4882a593Smuzhiyun	$(if $(wildcard $(TOOLCHAIN_EXTERNAL_BIN)/*.br_real),.br_real)
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CROSS = $(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
94*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CC = $(TOOLCHAIN_EXTERNAL_CROSS)gcc$(TOOLCHAIN_EXTERNAL_SUFFIX)
95*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CXX = $(TOOLCHAIN_EXTERNAL_CROSS)g++$(TOOLCHAIN_EXTERNAL_SUFFIX)
96*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_GDC = $(TOOLCHAIN_EXTERNAL_CROSS)gdc$(TOOLCHAIN_EXTERNAL_SUFFIX)
97*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_FC = $(TOOLCHAIN_EXTERNAL_CROSS)gfortran$(TOOLCHAIN_EXTERNAL_SUFFIX)
98*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun# Normal handling of downloaded toolchain tarball extraction.
101*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
102*4882a593Smuzhiyun# As a regular package, the toolchain gets extracted in $(@D), but
103*4882a593Smuzhiyun# since it's actually a fairly special package, we need it to be moved
104*4882a593Smuzhiyun# into TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR.
105*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_MOVE
106*4882a593Smuzhiyun	rm -rf $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
107*4882a593Smuzhiyun	mkdir -p $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
108*4882a593Smuzhiyun	mv $(@D)/* $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)/
109*4882a593Smuzhiyunendef
110*4882a593Smuzhiyunendif
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun#
113*4882a593Smuzhiyun# Definitions of the list of libraries that should be copied to the target.
114*4882a593Smuzhiyun#
115*4882a593Smuzhiyun
116*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += ld*.so.* libgcc_s.so.* libatomic.so.*
117*4882a593Smuzhiyun
118*4882a593Smuzhiyunifneq ($(BR2_SSP_NONE),y)
119*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libssp.so.*
120*4882a593Smuzhiyunendif
121*4882a593Smuzhiyun
122*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
123*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libc.so.* libcrypt.so.* libdl.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
124*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
125*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libpthread.so.*
126*4882a593Smuzhiyunifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
127*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libthread_db.so.*
128*4882a593Smuzhiyunendif # gdbserver
129*4882a593Smuzhiyunendif # ! no threads
130*4882a593Smuzhiyunendif
131*4882a593Smuzhiyun
132*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
133*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.* libmvec.so.* libanl.so.*
134*4882a593Smuzhiyunendif
135*4882a593Smuzhiyun
136*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
137*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libc.so
138*4882a593Smuzhiyunendif
139*4882a593Smuzhiyun
140*4882a593Smuzhiyunifeq ($(BR2_INSTALL_LIBSTDCPP),y)
141*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libstdc++.so.*
142*4882a593Smuzhiyunendif
143*4882a593Smuzhiyun
144*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_HAS_FORTRAN),y)
145*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libgfortran.so.*
146*4882a593Smuzhiyun# fortran needs quadmath on x86 and x86_64
147*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_HAS_LIBQUADMATH),y)
148*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libquadmath.so*
149*4882a593Smuzhiyunendif
150*4882a593Smuzhiyunendif
151*4882a593Smuzhiyun
152*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_HAS_OPENMP),y)
153*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libgomp.so.*
154*4882a593Smuzhiyunendif
155*4882a593Smuzhiyun
156*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_HAS_DLANG),y)
157*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += libgdruntime.so* libgphobos.so*
158*4882a593Smuzhiyunendif
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_LIBS += $(addsuffix .so*,$(call qstrip,$(BR2_TOOLCHAIN_EXTRA_LIBS)))
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun#
164*4882a593Smuzhiyun# Definition of the CFLAGS to use with the external toolchain, as well as the
165*4882a593Smuzhiyun# common toolchain wrapper build arguments
166*4882a593Smuzhiyun#
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun# march/mtune/floating point mode needs to be passed to the external toolchain
169*4882a593Smuzhiyun# to select the right multilib variant
170*4882a593Smuzhiyunifeq ($(BR2_x86_64),y)
171*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -m64
172*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_64
173*4882a593Smuzhiyunendif
174*4882a593Smuzhiyunifneq ($(GCC_TARGET_ARCH),)
175*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -march=$(GCC_TARGET_ARCH)
176*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARCH='"$(GCC_TARGET_ARCH)"'
177*4882a593Smuzhiyunendif
178*4882a593Smuzhiyunifneq ($(GCC_TARGET_CPU),)
179*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(GCC_TARGET_CPU)
180*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_CPU='"$(GCC_TARGET_CPU)"'
181*4882a593Smuzhiyunendif
182*4882a593Smuzhiyunifneq ($(GCC_TARGET_ABI),)
183*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(GCC_TARGET_ABI)
184*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(GCC_TARGET_ABI)"'
185*4882a593Smuzhiyunendif
186*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
187*4882a593Smuzhiyunifneq ($(GCC_TARGET_NAN),)
188*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -mnan=$(GCC_TARGET_NAN)
189*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_NAN='"$(GCC_TARGET_NAN)"'
190*4882a593Smuzhiyunendif
191*4882a593Smuzhiyunendif
192*4882a593Smuzhiyunifneq ($(GCC_TARGET_FP32_MODE),)
193*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -mfp$(GCC_TARGET_FP32_MODE)
194*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FP32_MODE='"$(GCC_TARGET_FP32_MODE)"'
195*4882a593Smuzhiyunendif
196*4882a593Smuzhiyunifneq ($(GCC_TARGET_FPU),)
197*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(GCC_TARGET_FPU)
198*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(GCC_TARGET_FPU)"'
199*4882a593Smuzhiyunendif
200*4882a593Smuzhiyunifneq ($(GCC_TARGET_FLOAT_ABI),)
201*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(GCC_TARGET_FLOAT_ABI)
202*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(GCC_TARGET_FLOAT_ABI)"'
203*4882a593Smuzhiyunendif
204*4882a593Smuzhiyunifneq ($(GCC_TARGET_MODE),)
205*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -m$(GCC_TARGET_MODE)
206*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(GCC_TARGET_MODE)"'
207*4882a593Smuzhiyunendif
208*4882a593Smuzhiyunifeq ($(BR2_BINFMT_FLAT),y)
209*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
210*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_BINFMT_FLAT
211*4882a593Smuzhiyunendif
212*4882a593Smuzhiyunifeq ($(BR2_mipsel)$(BR2_mips64el),y)
213*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
214*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -EL
215*4882a593Smuzhiyunendif
216*4882a593Smuzhiyunifeq ($(BR2_mips)$(BR2_mips64),y)
217*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
218*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -EB
219*4882a593Smuzhiyunendif
220*4882a593Smuzhiyunifeq ($(BR2_arceb),y)
221*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
222*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -EB
223*4882a593Smuzhiyunendif
224*4882a593Smuzhiyun
225*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
226*4882a593Smuzhiyun
227*4882a593Smuzhiyunifeq ($(BR2_SOFT_FLOAT),y)
228*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
229*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
230*4882a593Smuzhiyunendif
231*4882a593Smuzhiyun
232*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
233*4882a593Smuzhiyun	-DBR_CROSS_PATH_SUFFIX='"$(TOOLCHAIN_EXTERNAL_SUFFIX)"'
234*4882a593Smuzhiyun
235*4882a593Smuzhiyunifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
236*4882a593Smuzhiyun# TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
237*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
238*4882a593Smuzhiyun	-DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
239*4882a593Smuzhiyunelse
240*4882a593Smuzhiyun# TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
241*4882a593SmuzhiyunTOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
242*4882a593Smuzhiyun	-DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
243*4882a593Smuzhiyunendif
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun#
247*4882a593Smuzhiyun# The following functions creates the symbolic links needed to get the
248*4882a593Smuzhiyun# cross-compilation tools visible in $(HOST_DIR)/bin. Some of
249*4882a593Smuzhiyun# links are done directly to the corresponding tool in the external
250*4882a593Smuzhiyun# toolchain installation directory, while some other links are done to
251*4882a593Smuzhiyun# the toolchain wrapper (preprocessor, C, C++ and Fortran compiler)
252*4882a593Smuzhiyun#
253*4882a593Smuzhiyun# We skip gdb symlink when we are building our own gdb to prevent two
254*4882a593Smuzhiyun# gdb's in $(HOST_DIR)/bin.
255*4882a593Smuzhiyun#
256*4882a593Smuzhiyun# The LTO support in gcc creates wrappers for ar, ranlib and nm which load
257*4882a593Smuzhiyun# the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
258*4882a593Smuzhiyun# *-gcc-nm and should be used instead of the real programs when -flto is
259*4882a593Smuzhiyun# used. However, we should not add the toolchain wrapper for them, and they
260*4882a593Smuzhiyun# match the *cc-* pattern. Therefore, an additional case is added for *-ar,
261*4882a593Smuzhiyun# *-ranlib and *-nm.
262*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
263*4882a593Smuzhiyun	$(Q)cd $(HOST_DIR)/bin; \
264*4882a593Smuzhiyun	for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
265*4882a593Smuzhiyun		base=$${i##*/}; \
266*4882a593Smuzhiyun		case "$$base" in \
267*4882a593Smuzhiyun		*-ar|*-ranlib|*-nm) \
268*4882a593Smuzhiyun			ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
269*4882a593Smuzhiyun			;; \
270*4882a593Smuzhiyun		*cc|*cc-*|*++|*++-*|*cpp|*-gfortran|*-gdc) \
271*4882a593Smuzhiyun			ln -sf toolchain-wrapper $$base; \
272*4882a593Smuzhiyun			;; \
273*4882a593Smuzhiyun		*gdb|*gdbtui) \
274*4882a593Smuzhiyun			if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
275*4882a593Smuzhiyun				ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
276*4882a593Smuzhiyun			fi \
277*4882a593Smuzhiyun			;; \
278*4882a593Smuzhiyun		*) \
279*4882a593Smuzhiyun			ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
280*4882a593Smuzhiyun			;; \
281*4882a593Smuzhiyun		esac; \
282*4882a593Smuzhiyun	done
283*4882a593Smuzhiyunendef
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun# Various utility functions used by the external toolchain package
287*4882a593Smuzhiyun# infrastructure. Those functions are mainly responsible for:
288*4882a593Smuzhiyun#
289*4882a593Smuzhiyun#   - installation the toolchain libraries to $(TARGET_DIR)
290*4882a593Smuzhiyun#   - copying the toolchain sysroot to $(STAGING_DIR)
291*4882a593Smuzhiyun#   - installing a gdbinit file
292*4882a593Smuzhiyun#
293*4882a593Smuzhiyun# Details about sysroot directory selection.
294*4882a593Smuzhiyun#
295*4882a593Smuzhiyun# To find the sysroot directory, we use the trick of looking for the
296*4882a593Smuzhiyun# 'libc.a' file with the -print-file-name gcc option, and then
297*4882a593Smuzhiyun# mangling the path to find the base directory of the sysroot.
298*4882a593Smuzhiyun#
299*4882a593Smuzhiyun# Note that we do not use the -print-sysroot option, because it is
300*4882a593Smuzhiyun# only available since gcc 4.4.x, and we only recently dropped support
301*4882a593Smuzhiyun# for 4.2.x and 4.3.x.
302*4882a593Smuzhiyun#
303*4882a593Smuzhiyun# When doing this, we don't pass any option to gcc that could select a
304*4882a593Smuzhiyun# multilib variant (such as -march) as we want the "main" sysroot,
305*4882a593Smuzhiyun# which contains all variants of the C library in the case of multilib
306*4882a593Smuzhiyun# toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
307*4882a593Smuzhiyun# path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
308*4882a593Smuzhiyun# since what we want to find is the location of the original toolchain
309*4882a593Smuzhiyun# sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
310*4882a593Smuzhiyun#
311*4882a593Smuzhiyun# Then, multilib toolchains are a little bit more complicated, since
312*4882a593Smuzhiyun# they in fact have multiple sysroots, one for each variant supported
313*4882a593Smuzhiyun# by the toolchain. So we need to find the particular sysroot we're
314*4882a593Smuzhiyun# interested in.
315*4882a593Smuzhiyun#
316*4882a593Smuzhiyun# To do so, we ask the compiler where its sysroot is by passing all
317*4882a593Smuzhiyun# flags (including -march and al.), except the --sysroot flag since we
318*4882a593Smuzhiyun# want to the compiler to tell us where its original sysroot
319*4882a593Smuzhiyun# is. ARCH_SUBDIR will contain the subdirectory, in the main
320*4882a593Smuzhiyun# SYSROOT_DIR, that corresponds to the selected architecture
321*4882a593Smuzhiyun# variant. ARCH_SYSROOT_DIR will contain the full path to this
322*4882a593Smuzhiyun# location.
323*4882a593Smuzhiyun#
324*4882a593Smuzhiyun# One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
325*4882a593Smuzhiyun# fact is that in multilib toolchains, the header files are often only
326*4882a593Smuzhiyun# present in the main sysroot, and only the libraries are available in
327*4882a593Smuzhiyun# each variant-specific sysroot directory.
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun# toolchain_find_sysroot returns the sysroot location for the given
331*4882a593Smuzhiyun# compiler + flags. We need to handle cases where libc.a is in:
332*4882a593Smuzhiyun#
333*4882a593Smuzhiyun#  - lib/
334*4882a593Smuzhiyun#  - usr/lib/
335*4882a593Smuzhiyun#  - lib32/
336*4882a593Smuzhiyun#  - lib64/
337*4882a593Smuzhiyun#  - lib32-fp/ (Cavium toolchain)
338*4882a593Smuzhiyun#  - lib64-fp/ (Cavium toolchain)
339*4882a593Smuzhiyun#  - usr/lib/<tuple>/ (Linaro toolchain)
340*4882a593Smuzhiyun#
341*4882a593Smuzhiyun# And variations on these.
342*4882a593Smuzhiyundefine toolchain_find_sysroot
343*4882a593Smuzhiyun$$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:/(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a:/:')
344*4882a593Smuzhiyunendef
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun# Returns the lib subdirectory for the given compiler + flags (i.e
347*4882a593Smuzhiyun# typically lib32 or lib64 for some toolchains)
348*4882a593Smuzhiyundefine toolchain_find_libdir
349*4882a593Smuzhiyun$$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?(/[^/]*)?)/libc.a:\2:')
350*4882a593Smuzhiyunendef
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun# Returns the location of the libc.a file for the given compiler + flags
353*4882a593Smuzhiyundefine toolchain_find_libc_a
354*4882a593Smuzhiyun$$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
355*4882a593Smuzhiyunendef
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun# Integration of the toolchain into Buildroot: find the main sysroot
358*4882a593Smuzhiyun# and the variant-specific sysroot, then copy the needed libraries to
359*4882a593Smuzhiyun# the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
360*4882a593Smuzhiyun# to $(STAGING_DIR).
361*4882a593Smuzhiyun#
362*4882a593Smuzhiyun# Variables are defined as follows:
363*4882a593Smuzhiyun#
364*4882a593Smuzhiyun# SYSROOT_DIR:          the main sysroot directory, deduced from the location of
365*4882a593Smuzhiyun#                       the libc.a file in the default multilib variant, by
366*4882a593Smuzhiyun#                       removing the usr/lib[32|64]/libc.a part of the path.
367*4882a593Smuzhiyun#                       Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
368*4882a593Smuzhiyun#
369*4882a593Smuzhiyun# ARCH_SYSROOT_DIR:     the sysroot of the selected multilib variant,
370*4882a593Smuzhiyun#                       deduced from the location of the libc.a file in the
371*4882a593Smuzhiyun#                       selected multilib variant (taking into account the
372*4882a593Smuzhiyun#                       CFLAGS), by removing usr/lib[32|64]/libc.a at the end
373*4882a593Smuzhiyun#                       of the path.
374*4882a593Smuzhiyun#                       Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
375*4882a593Smuzhiyun#
376*4882a593Smuzhiyun# ARCH_LIB_DIR:         'lib', 'lib32' or 'lib64' depending on where libraries
377*4882a593Smuzhiyun#                       are stored. Deduced from the location of the libc.a file
378*4882a593Smuzhiyun#                       in the selected multilib variant, by looking at
379*4882a593Smuzhiyun#                       usr/lib??/libc.a.
380*4882a593Smuzhiyun#                       Ex: lib
381*4882a593Smuzhiyun#
382*4882a593Smuzhiyun# ARCH_SUBDIR:          the relative location of the sysroot of the selected
383*4882a593Smuzhiyun#                       multilib variant compared to the main sysroot.
384*4882a593Smuzhiyun#                       Ex: mips16/soft-float/el
385*4882a593Smuzhiyun#
386*4882a593Smuzhiyun# SUPPORT_LIB_DIR:      some toolchains, such as recent Linaro toolchains,
387*4882a593Smuzhiyun#                       store GCC support libraries (libstdc++,
388*4882a593Smuzhiyun#                       libgcc_s, etc.) outside of the sysroot. In
389*4882a593Smuzhiyun#                       this case, SUPPORT_LIB_DIR is set to a
390*4882a593Smuzhiyun#                       non-empty value, and points to the directory
391*4882a593Smuzhiyun#                       where these support libraries are
392*4882a593Smuzhiyun#                       available. Those libraries will be copied to
393*4882a593Smuzhiyun#                       our sysroot, and the directory will also be
394*4882a593Smuzhiyun#                       considered when searching libraries for copy
395*4882a593Smuzhiyun#                       to the target filesystem.
396*4882a593Smuzhiyun#
397*4882a593Smuzhiyun# Please be very careful to check the major toolchain sources:
398*4882a593Smuzhiyun# Buildroot, Crosstool-NG, CodeSourcery and Linaro
399*4882a593Smuzhiyun# before doing any modification on the below logic.
400*4882a593Smuzhiyun
401*4882a593Smuzhiyunifeq ($(BR2_STATIC_LIBS),)
402*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
403*4882a593Smuzhiyun	$(Q)$(call MESSAGE,"Copying external toolchain libraries to target...")
404*4882a593Smuzhiyun	$(Q)for libpattern in $(TOOLCHAIN_EXTERNAL_LIBS); do \
405*4882a593Smuzhiyun		$(call copy_toolchain_lib_root,$$libpattern); \
406*4882a593Smuzhiyun	done
407*4882a593Smuzhiyunendef
408*4882a593Smuzhiyunendif
409*4882a593Smuzhiyun
410*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),y)
411*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
412*4882a593Smuzhiyun	$(Q)$(call MESSAGE,"Copying gdbserver")
413*4882a593Smuzhiyun	$(Q)ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
414*4882a593Smuzhiyun	ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
415*4882a593Smuzhiyun	gdbserver_found=0 ; \
416*4882a593Smuzhiyun	for d in $${ARCH_SYSROOT_DIR}/usr \
417*4882a593Smuzhiyun		 $${ARCH_SYSROOT_DIR}/../debug-root/usr \
418*4882a593Smuzhiyun		 $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \
419*4882a593Smuzhiyun		 $(TOOLCHAIN_EXTERNAL_INSTALL_DIR); do \
420*4882a593Smuzhiyun		if test -f $${d}/bin/gdbserver ; then \
421*4882a593Smuzhiyun			install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
422*4882a593Smuzhiyun			gdbserver_found=1 ; \
423*4882a593Smuzhiyun			break ; \
424*4882a593Smuzhiyun		fi ; \
425*4882a593Smuzhiyun	done ; \
426*4882a593Smuzhiyun	if [ $${gdbserver_found} -eq 0 ] ; then \
427*4882a593Smuzhiyun		echo "Could not find gdbserver in external toolchain" ; \
428*4882a593Smuzhiyun		exit 1 ; \
429*4882a593Smuzhiyun	fi
430*4882a593Smuzhiyunendef
431*4882a593Smuzhiyunendif
432*4882a593Smuzhiyun
433*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
434*4882a593Smuzhiyun	$(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
435*4882a593Smuzhiyun	ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
436*4882a593Smuzhiyun	ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
437*4882a593Smuzhiyun	SUPPORT_LIB_DIR="" ; \
438*4882a593Smuzhiyun	if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
439*4882a593Smuzhiyun		LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
440*4882a593Smuzhiyun		if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
441*4882a593Smuzhiyun			SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
442*4882a593Smuzhiyun		fi ; \
443*4882a593Smuzhiyun	fi ; \
444*4882a593Smuzhiyun	if [ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
445*4882a593Smuzhiyun		ARCH_SUBDIR="" ; \
446*4882a593Smuzhiyun	elif [ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
447*4882a593Smuzhiyun		SYSROOT_DIR_DIRNAME=`dirname $${SYSROOT_DIR}`/ ; \
448*4882a593Smuzhiyun		ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
449*4882a593Smuzhiyun	else \
450*4882a593Smuzhiyun		ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
451*4882a593Smuzhiyun	fi ; \
452*4882a593Smuzhiyun	$(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
453*4882a593Smuzhiyun	$(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
454*4882a593Smuzhiyunendef
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun# Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
457*4882a593Smuzhiyun# Note: the skeleton package additionally creates lib32->lib or lib64->lib
458*4882a593Smuzhiyun# (as appropriate)
459*4882a593Smuzhiyun#
460*4882a593Smuzhiyun# $1: destination directory (TARGET_DIR / STAGING_DIR)
461*4882a593Smuzhiyuncreate_lib_symlinks = \
462*4882a593Smuzhiyun	$(Q)DESTDIR="$(strip $1)" ; \
463*4882a593Smuzhiyun	ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
464*4882a593Smuzhiyun	if [ ! -e "$${DESTDIR}/$${ARCH_LIB_DIR}" -a ! -e "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
465*4882a593Smuzhiyun		relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
466*4882a593Smuzhiyun		ln -snf $${relpath}lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
467*4882a593Smuzhiyun		ln -snf $${relpath}lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
468*4882a593Smuzhiyun	fi
469*4882a593Smuzhiyun
470*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
471*4882a593Smuzhiyun	$(call create_lib_symlinks,$(STAGING_DIR))
472*4882a593Smuzhiyunendef
473*4882a593Smuzhiyun
474*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
475*4882a593Smuzhiyun	$(call create_lib_symlinks,$(TARGET_DIR))
476*4882a593Smuzhiyunendef
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun#
479*4882a593Smuzhiyun# Generate gdbinit file for use with Buildroot
480*4882a593Smuzhiyun#
481*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
482*4882a593Smuzhiyun	$(Q)if test -f $(TARGET_CROSS)gdb ; then \
483*4882a593Smuzhiyun		$(call MESSAGE,"Installing gdbinit"); \
484*4882a593Smuzhiyun		$(gen_gdbinit_file); \
485*4882a593Smuzhiyun	fi
486*4882a593Smuzhiyunendef
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun# GCC installs a libstdcxx-...so-gdb.py file that gdb will load automatically,
489*4882a593Smuzhiyun# but it contains hardcoded paths referring to the location where the (external)
490*4882a593Smuzhiyun# toolchain was built. Fix up these paths so that the pretty printers can be
491*4882a593Smuzhiyun# loaded automatically.
492*4882a593Smuzhiyun# By default, the pretty printers are installed in
493*4882a593Smuzhiyun# $(datadir)/gcc-$(gcc_version)/python but this could have been overwritten with
494*4882a593Smuzhiyun# the gcc configure option: --with-python-dir. We thus have to search the
495*4882a593Smuzhiyun# correct path first.
496*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER
497*4882a593Smuzhiyun	$(Q)loadfiles=$$(find $(STAGING_DIR) -name 'libstdc++.so*-gdb.py' 2>/dev/null); \
498*4882a593Smuzhiyun	pythondir=$$(find $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR) -path '*/libstdcxx/__init__.py' 2>/dev/null | sed 's%/libstdcxx/__init__.py%%' | head -n1); \
499*4882a593Smuzhiyun	if [ -n "$$loadfiles" ] && [ -n "$$pythondir" ]; then \
500*4882a593Smuzhiyun		echo "Fixing up hardcoded paths in GDB pretty-printer auto-load file(s) for libstdcxx: $$loadfiles"; \
501*4882a593Smuzhiyun		sed -ri \
502*4882a593Smuzhiyun			-e 's%^libdir\s*=.*%libdir = "$(STAGING_DIR)/lib"%' \
503*4882a593Smuzhiyun			-e "s%^pythondir\s*=.*%pythondir = '$$pythondir'%" \
504*4882a593Smuzhiyun			$$loadfiles; \
505*4882a593Smuzhiyun	fi
506*4882a593Smuzhiyunendef
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun# uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
509*4882a593Smuzhiyun# patched specifically for uClibc-ng, so it continues to generate
510*4882a593Smuzhiyun# binaries that expect the dynamic loader to be named ld-uClibc.so.0,
511*4882a593Smuzhiyun# like with the original uClibc. Therefore, we create an additional
512*4882a593Smuzhiyun# symbolic link to make uClibc-ng systems work properly.
513*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
514*4882a593Smuzhiyun	$(Q)if test -e $(TARGET_DIR)/lib/ld-uClibc.so.1; then \
515*4882a593Smuzhiyun		ln -sf ld-uClibc.so.1 $(TARGET_DIR)/lib/ld-uClibc.so.0 ; \
516*4882a593Smuzhiyun	fi
517*4882a593Smuzhiyun	$(Q)if test -e $(TARGET_DIR)/lib/ld64-uClibc.so.1; then \
518*4882a593Smuzhiyun		ln -sf ld64-uClibc.so.1 $(TARGET_DIR)/lib/ld64-uClibc.so.0 ; \
519*4882a593Smuzhiyun	fi
520*4882a593Smuzhiyunendef
521*4882a593Smuzhiyun
522*4882a593Smuzhiyundefine TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD
523*4882a593Smuzhiyun	$(Q)if test -f $(STAGING_DIR)/usr/bin/ldd ; then \
524*4882a593Smuzhiyun		$(INSTALL) -D $(STAGING_DIR)/usr/bin/ldd $(TARGET_DIR)/usr/bin/ldd ; \
525*4882a593Smuzhiyun		$(SED) 's:.*/bin/bash:#!/bin/sh:' $(TARGET_DIR)/usr/bin/ldd ; \
526*4882a593Smuzhiyun	fi
527*4882a593Smuzhiyunendef
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun################################################################################
530*4882a593Smuzhiyun# inner-toolchain-external-package -- defines the generic installation rules
531*4882a593Smuzhiyun# for external toolchain packages
532*4882a593Smuzhiyun#
533*4882a593Smuzhiyun#  argument 1 is the lowercase package name
534*4882a593Smuzhiyun#  argument 2 is the uppercase package name, including a HOST_ prefix
535*4882a593Smuzhiyun#             for host packages
536*4882a593Smuzhiyun#  argument 3 is the uppercase package name, without the HOST_ prefix
537*4882a593Smuzhiyun#             for host packages
538*4882a593Smuzhiyun#  argument 4 is the type (target or host)
539*4882a593Smuzhiyun################################################################################
540*4882a593Smuzhiyundefine inner-toolchain-external-package
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun$(2)_INSTALL_STAGING = YES
543*4882a593Smuzhiyun$(2)_ADD_TOOLCHAIN_DEPENDENCY = NO
544*4882a593Smuzhiyun
545*4882a593Smuzhiyun# In fact, we don't need to download the toolchain, since it is already
546*4882a593Smuzhiyun# available on the system, so force the site and source to be empty so
547*4882a593Smuzhiyun# that nothing will be downloaded/extracted.
548*4882a593Smuzhiyunifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
549*4882a593Smuzhiyun$(2)_SITE =
550*4882a593Smuzhiyun$(2)_SOURCE =
551*4882a593Smuzhiyunendif
552*4882a593Smuzhiyun
553*4882a593Smuzhiyunifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
554*4882a593Smuzhiyun$(2)_EXCLUDES = usr/lib/locale/*
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun$(2)_POST_EXTRACT_HOOKS += \
557*4882a593Smuzhiyun	TOOLCHAIN_EXTERNAL_MOVE
558*4882a593Smuzhiyunendif
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun# Checks for an already installed toolchain: check the toolchain
561*4882a593Smuzhiyun# location, check that it is usable, and then verify that it
562*4882a593Smuzhiyun# matches the configuration provided in Buildroot: ABI, C++ support,
563*4882a593Smuzhiyun# kernel headers version, type of C library and all C library features.
564*4882a593Smuzhiyundefine $(2)_CONFIGURE_CMDS
565*4882a593Smuzhiyun	$$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
566*4882a593Smuzhiyun	$$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC))
567*4882a593Smuzhiyun	$$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
568*4882a593Smuzhiyun	$$(call check_kernel_headers_version,\
569*4882a593Smuzhiyun		$$(BUILD_DIR),\
570*4882a593Smuzhiyun		$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
571*4882a593Smuzhiyun		$$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
572*4882a593Smuzhiyun		$$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
573*4882a593Smuzhiyun	$$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
574*4882a593Smuzhiyun		$$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
575*4882a593Smuzhiyun	if test "$$(BR2_arm)" = "y" ; then \
576*4882a593Smuzhiyun		$$(call check_arm_abi,\
577*4882a593Smuzhiyun			"$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
578*4882a593Smuzhiyun	fi ; \
579*4882a593Smuzhiyun	if test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
580*4882a593Smuzhiyun		$$(call check_cplusplus,$$(TOOLCHAIN_EXTERNAL_CXX)) ; \
581*4882a593Smuzhiyun	fi ; \
582*4882a593Smuzhiyun	if test "$$(BR2_TOOLCHAIN_HAS_DLANG)" = "y" ; then \
583*4882a593Smuzhiyun		$$(call check_dlang,$$(TOOLCHAIN_EXTERNAL_GDC)) ; \
584*4882a593Smuzhiyun	fi ; \
585*4882a593Smuzhiyun	if test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
586*4882a593Smuzhiyun		$$(call check_fortran,$$(TOOLCHAIN_EXTERNAL_FC)) ; \
587*4882a593Smuzhiyun	fi ; \
588*4882a593Smuzhiyun	if test "$$(BR2_TOOLCHAIN_HAS_OPENMP)" = "y" ; then \
589*4882a593Smuzhiyun		$$(call check_openmp,$$(TOOLCHAIN_EXTERNAL_CC)) ; \
590*4882a593Smuzhiyun	fi ; \
591*4882a593Smuzhiyun	if test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
592*4882a593Smuzhiyun		$$(call check_uclibc,$$$${SYSROOT_DIR}) ; \
593*4882a593Smuzhiyun	elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
594*4882a593Smuzhiyun		$$(call check_musl,\
595*4882a593Smuzhiyun			"$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
596*4882a593Smuzhiyun	else \
597*4882a593Smuzhiyun		$$(call check_glibc,$$$${SYSROOT_DIR}) ; \
598*4882a593Smuzhiyun	fi
599*4882a593Smuzhiyun	$$(Q)$$(call check_toolchain_ssp,$$(TOOLCHAIN_EXTERNAL_CC),$(BR2_SSP_OPTION))
600*4882a593Smuzhiyunendef
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun$(2)_TOOLCHAIN_WRAPPER_ARGS += $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS)
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun$(2)_BUILD_CMDS = $$(TOOLCHAIN_WRAPPER_BUILD)
605*4882a593Smuzhiyun
606*4882a593Smuzhiyundefine $(2)_INSTALL_STAGING_CMDS
607*4882a593Smuzhiyun	$$(TOOLCHAIN_WRAPPER_INSTALL)
608*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK)
609*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
610*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
611*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
612*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER)
613*4882a593Smuzhiyunendef
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun# Even though we're installing things in both the staging, the host
616*4882a593Smuzhiyun# and the target directory, we do everything within the
617*4882a593Smuzhiyun# install-staging step, arbitrarily.
618*4882a593Smuzhiyundefine $(2)_INSTALL_TARGET_CMDS
619*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK)
620*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
621*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER)
622*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO)
623*4882a593Smuzhiyun	$$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD)
624*4882a593Smuzhiyunendef
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun# Call the generic package infrastructure to generate the necessary
627*4882a593Smuzhiyun# make targets
628*4882a593Smuzhiyun$(call inner-generic-package,$(1),$(2),$(3),$(4))
629*4882a593Smuzhiyun
630*4882a593Smuzhiyunendef
631*4882a593Smuzhiyun
632*4882a593Smuzhiyuntoolchain-external-package = $(call inner-toolchain-external-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
633