7 HOSTMAKE := $(shell which $(HOSTMAKE) || type -p $(HOSTMAKE) || echo make)
9 # If BR2_JLEVEL is 0, scale the maximum concurrency with the number of
10 # CPUs. An additional job is used in order to keep processors busy
11 # while waiting on I/O.
12 # If the number of processors is not available, assume one.
13 ifeq ($(BR2_JLEVEL),0)
14 PARALLEL_JOBS := $(shell echo \
15 $$((1 + `getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`)))
17 PARALLEL_JOBS := $(BR2_JLEVEL)
20 MAKE1 := $(HOSTMAKE) -j1
21 override MAKE = $(HOSTMAKE) \
22 $(if $(findstring j,$(filter-out --%,$(MAKEFLAGS))),,-j$(PARALLEL_JOBS))
24 ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y)
25 TARGET_VENDOR = $(call qstrip,$(BR2_TOOLCHAIN_BUILDROOT_VENDOR))
27 TARGET_VENDOR = buildroot
31 ifeq ($(TARGET_VENDOR),)
32 $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR is not allowed to be empty)
34 ifeq ($(TARGET_VENDOR),unknown)
35 $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
36 It might be confused with the native toolchain)
39 # Compute GNU_TARGET_NAME
40 GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI)
42 # FLAT binary format needs uclinux
43 ifeq ($(BR2_BINFMT_FLAT),y)
49 ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
51 else ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
57 # The ABI suffix is a bit special on ARM, as it needs to be
58 # -uclibcgnueabi for uClibc EABI, and -gnueabi for glibc EABI.
59 # This means that the LIBC and ABI aren't strictly orthogonal,
60 # which explains why we need the test on LIBC below.
61 ifeq ($(BR2_arm)$(BR2_armeb),y)
68 ifeq ($(BR2_ARM_EABIHF),y)
73 # For FSL PowerPC there's SPE
74 ifeq ($(BR2_powerpc_SPE),y)
76 # MPC8540s are e500v1 with single precision FP
77 ifeq ($(BR2_powerpc_8540),y)
78 TARGET_ABI += -mabi=spe -mfloat-gprs=single -Wa,-me500
80 ifeq ($(BR2_powerpc_8548),y)
81 TARGET_ABI += -mabi=spe -mfloat-gprs=double -Wa,-me500x2
83 ifeq ($(BR2_powerpc_e500mc),y)
84 TARGET_ABI += -mabi=spe -mfloat-gprs=double -Wa,-me500mc
88 # Use longcalls option for Xtensa globally.
89 # The 'longcalls' option allows calls across a greater range of addresses,
90 # and is required for some packages. While this option can degrade both
91 # code size and performance, the linker can usually optimize away the
92 # overhead when a call ends up within a certain range.
94 # Use auto-litpools for Xtensa globally.
95 # Collecting literals into separate section can be advantageous if that
96 # section is placed into DTCM at link time. This is applicable for code
97 # running on bare metal, but makes no sense under linux, where userspace
98 # is isolated from the physical memory details. OTOH placing literals into
99 # separate section breaks build of huge source files, because l32r
100 # instruction can only access literals in 256 KBytes range.
102 ifeq ($(BR2_xtensa),y)
103 TARGET_ABI += -mlongcalls -mauto-litpools
106 ifeq ($(BR2_arc)$(BR2_ARC_ATOMIC_EXT),yy)
107 TARGET_ABI += -matomic
110 STAGING_SUBDIR = usr/$(GNU_TARGET_NAME)/sysroot
111 STAGING_DIR = $(HOST_DIR)/$(STAGING_SUBDIR)
113 ifeq ($(BR2_OPTIMIZE_0),y)
114 TARGET_OPTIMIZATION = -O0
116 ifeq ($(BR2_OPTIMIZE_1),y)
117 TARGET_OPTIMIZATION = -O1
119 ifeq ($(BR2_OPTIMIZE_2),y)
120 TARGET_OPTIMIZATION = -O2
122 ifeq ($(BR2_OPTIMIZE_3),y)
123 TARGET_OPTIMIZATION = -O3
125 ifeq ($(BR2_OPTIMIZE_G),y)
126 TARGET_OPTIMIZATION = -Og
128 ifeq ($(BR2_OPTIMIZE_S),y)
129 TARGET_OPTIMIZATION = -Os
131 ifeq ($(BR2_DEBUG_1),y)
132 TARGET_DEBUGGING = -g1
134 ifeq ($(BR2_DEBUG_2),y)
135 TARGET_DEBUGGING = -g2
137 ifeq ($(BR2_DEBUG_3),y)
138 TARGET_DEBUGGING = -g3
141 TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
142 TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
143 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
144 TARGET_FCFLAGS = $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
145 TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
147 ifeq ($(BR2_BINFMT_FLAT),y)
148 TARGET_CFLAGS += $(if $($(PKG)_FLAT_STACKSIZE),-Wl$(comma)-elf2flt=-s$($(PKG)_FLAT_STACKSIZE),\
150 TARGET_CXXFLAGS += $(if $($(PKG)_FLAT_STACKSIZE),-Wl$(comma)-elf2flt=-s$($(PKG)_FLAT_STACKSIZE),\
152 TARGET_FCFLAGS += $(if $($(PKG)_FLAT_STACKSIZE),-Wl$(comma)-elf2flt=-s$($(PKG)_FLAT_STACKSIZE),\
154 TARGET_LDFLAGS += $(if $($(PKG)_FLAT_STACKSIZE),-Wl$(comma)-elf2flt=-s$($(PKG)_FLAT_STACKSIZE),-Wl$(comma)-elf2flt)
157 ifeq ($(BR2_BINFMT_FLAT_SHARED),y)
158 TARGET_LDFLAGS += -mid-shared-library -mshared-library-id=0
159 TARGET_CFLAGS += -mid-shared-library -mshared-library-id=0
160 TARGET_FCFLAGS += -mid-shared-library -mshared-library-id=0
161 TARGET_CXXFLAGS += -mid-shared-library -mshared-library-id=0
163 ifeq ($(BR2_BINFMT_FLAT_SEP_DATA),y)
164 TARGET_LDFLAGS += -msep-data
165 TARGET_CFLAGS += -msep-data
166 TARGET_FCFLAGS += -msep-data
167 TARGET_CXXFLAGS += -msep-data
170 ifeq ($(BR2_SSP_REGULAR),y)
171 TARGET_CFLAGS += -fstack-protector
172 TARGET_CXXFLAGS += -fstack-protector
173 TARGET_FCFLAGS += -fstack-protector
174 else ifeq ($(BR2_SSP_STRONG),y)
175 TARGET_CFLAGS += -fstack-protector-strong
176 TARGET_CXXFLAGS += -fstack-protector-strong
177 TARGET_FCFLAGS += -fstack-protector-strong
178 else ifeq ($(BR2_SSP_ALL),y)
179 TARGET_CFLAGS += -fstack-protector-all
180 TARGET_CXXFLAGS += -fstack-protector-all
181 TARGET_FCFLAGS += -fstack-protector-all
184 ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y)
185 TARGET_CROSS = $(HOST_DIR)/usr/bin/$(GNU_TARGET_NAME)-
187 TARGET_CROSS = $(HOST_DIR)/usr/bin/$(TOOLCHAIN_EXTERNAL_PREFIX)-
190 # Define TARGET_xx variables for all common binutils/gcc
191 TARGET_AR = $(TARGET_CROSS)ar
192 TARGET_AS = $(TARGET_CROSS)as
193 TARGET_CC = $(TARGET_CROSS)gcc
194 TARGET_CPP = $(TARGET_CROSS)cpp
195 TARGET_CXX = $(TARGET_CROSS)g++
196 TARGET_FC = $(TARGET_CROSS)gfortran
197 TARGET_LD = $(TARGET_CROSS)ld
198 TARGET_NM = $(TARGET_CROSS)nm
199 TARGET_RANLIB = $(TARGET_CROSS)ranlib
200 TARGET_READELF = $(TARGET_CROSS)readelf
201 TARGET_OBJCOPY = $(TARGET_CROSS)objcopy
202 TARGET_OBJDUMP = $(TARGET_CROSS)objdump
204 ifeq ($(BR2_STRIP_strip),y)
205 STRIP_STRIP_DEBUG := --strip-debug
206 TARGET_STRIP = $(TARGET_CROSS)strip
207 STRIPCMD = $(TARGET_CROSS)strip --remove-section=.comment --remove-section=.note
209 ifeq ($(BR2_STRIP_none),y)
210 TARGET_STRIP = /bin/true
211 STRIPCMD = $(TARGET_STRIP)
213 INSTALL := $(shell which install || type -p install)
214 FLEX := $(shell which flex || type -p flex)
215 BISON := $(shell which bison || type -p bison)
216 UNZIP := $(shell which unzip || type -p unzip) -q
218 APPLY_PATCHES = PATH=$(HOST_DIR)/usr/bin:$$PATH support/scripts/apply-patches.sh $(if $(QUIET),-s)
220 HOST_CPPFLAGS = -I$(HOST_DIR)/usr/include
222 HOST_CFLAGS += $(HOST_CPPFLAGS)
223 HOST_CXXFLAGS += $(HOST_CFLAGS)
224 HOST_LDFLAGS += -L$(HOST_DIR)/lib -L$(HOST_DIR)/usr/lib -Wl,-rpath,$(HOST_DIR)/usr/lib
226 # The macros below are taken from linux 4.11 and adapted slightly.
227 # Copy more when needed.
230 # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
231 # Exit code chooses option. "$$TMP" is can be used as temporary file and
232 # is automatically cleaned up.
233 try-run = $(shell set -e; \
234 TMP="$$(tempfile)"; \
235 if ($(1)) >/dev/null 2>&1; \
242 # Usage: HOST_FOO_CFLAGS += $(call host-cc-option,-no-pie,)
243 host-cc-option = $(call try-run,\
244 $(HOSTCC) $(HOST_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
247 # host-intltool should be executed with the system perl, so we save
248 # the path to the system perl, before a host-perl built by Buildroot
249 # might get installed into $(HOST_DIR)/usr/bin and therefore appears
250 # in our PATH. This system perl will be used as INTLTOOL_PERL.
251 export PERL=$(shell which perl)
253 # host-intltool needs libxml-parser-perl, which Buildroot installs in
254 # $(HOST_DIR)/usr/lib/perl, so we must make sure that the system perl
255 # finds this perl module by exporting the proper value for PERL5LIB.
256 export PERL5LIB=$(HOST_DIR)/usr/lib/perl
258 TARGET_MAKE_ENV = PATH=$(BR_PATH)
260 TARGET_CONFIGURE_OPTS = \
268 CPP="$(TARGET_CPP)" \
269 CXX="$(TARGET_CXX)" \
272 RANLIB="$(TARGET_RANLIB)" \
273 READELF="$(TARGET_READELF)" \
274 STRIP="$(TARGET_STRIP)" \
275 OBJCOPY="$(TARGET_OBJCOPY)" \
276 OBJDUMP="$(TARGET_OBJDUMP)" \
277 AR_FOR_BUILD="$(HOSTAR)" \
278 AS_FOR_BUILD="$(HOSTAS)" \
279 CC_FOR_BUILD="$(HOSTCC)" \
280 GCC_FOR_BUILD="$(HOSTCC)" \
281 CXX_FOR_BUILD="$(HOSTCXX)" \
282 LD_FOR_BUILD="$(HOSTLD)" \
283 CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)" \
284 CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
285 CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
286 LDFLAGS_FOR_BUILD="$(HOST_LDFLAGS)" \
287 FCFLAGS_FOR_BUILD="$(HOST_FCFLAGS)" \
288 DEFAULT_ASSEMBLER="$(TARGET_AS)" \
289 DEFAULT_LINKER="$(TARGET_LD)" \
290 CPPFLAGS="$(TARGET_CPPFLAGS)" \
291 CFLAGS="$(TARGET_CFLAGS)" \
292 CXXFLAGS="$(TARGET_CXXFLAGS)" \
293 LDFLAGS="$(TARGET_LDFLAGS)" \
294 FCFLAGS="$(TARGET_FCFLAGS)" \
295 FFLAGS="$(TARGET_FCFLAGS)" \
296 PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
297 STAGING_DIR="$(STAGING_DIR)" \
298 INTLTOOL_PERL=$(PERL)
303 PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
304 PKG_CONFIG_SYSROOT_DIR="/" \
305 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
306 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
307 PKG_CONFIG_LIBDIR="$(HOST_DIR)/usr/lib/pkgconfig:$(HOST_DIR)/usr/share/pkgconfig"
309 HOST_CONFIGURE_OPTS = \
319 OBJCOPY="$(HOSTOBJCOPY)" \
320 RANLIB="$(HOSTRANLIB)" \
321 CPPFLAGS="$(HOST_CPPFLAGS)" \
322 CFLAGS="$(HOST_CFLAGS)" \
323 CXXFLAGS="$(HOST_CXXFLAGS)" \
324 LDFLAGS="$(HOST_LDFLAGS)" \
325 INTLTOOL_PERL=$(PERL)
327 # This is extra environment we can not export ourselves (eg. because some
328 # packages use that variable internally, eg. uboot), so we have to
329 # explicitly pass it to user-supplied external hooks (eg. post-build,
333 BR2_DL_DIR=$(BR2_DL_DIR) \
334 BUILD_DIR=$(BUILD_DIR)
336 ################################################################################
337 # settings we need to pass to configure
339 # does unaligned access trap?
340 BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=yes
342 BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no
344 ifeq ($(BR2_x86_64),y)
345 BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no
348 BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no
350 ifeq ($(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le),y)
351 BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no
354 ifeq ($(BR2_ENDIAN),"BIG")
355 BR2_AC_CV_C_BIGENDIAN = ac_cv_c_bigendian=yes
357 BR2_AC_CV_C_BIGENDIAN = ac_cv_c_bigendian=no
360 # AM_GNU_GETTEXT misdetects musl gettext support.
361 # musl currently implements api level 1 and 2 (basic + ngettext)
362 # http://www.openwall.com/lists/musl/2015/04/16/3
363 ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
364 BR2_GT_CV_FUNC_GNUGETTEXT_LIBC = \
365 gt_cv_func_gnugettext1_libc=yes \
366 gt_cv_func_gnugettext2_libc=yes
369 TARGET_CONFIGURE_ARGS = \
370 $(BR2_AC_CV_TRAP_CHECK) \
371 ac_cv_func_mmap_fixed_mapped=yes \
372 ac_cv_func_memcmp_working=yes \
373 ac_cv_have_decl_malloc=yes \
374 gl_cv_func_malloc_0_nonnull=yes \
375 ac_cv_func_malloc_0_nonnull=yes \
376 ac_cv_func_calloc_0_nonnull=yes \
377 ac_cv_func_realloc_0_nonnull=yes \
378 lt_cv_sys_lib_search_path_spec="" \
379 $(BR2_AC_CV_C_BIGENDIAN) \
380 $(BR2_GT_CV_FUNC_GNUGETTEXT_LIBC)
382 ################################################################################
384 ifeq ($(BR2_ENABLE_LOCALE),y)
387 DISABLE_NLS :=--disable-nls
390 ifneq ($(BR2_INSTALL_LIBSTDCPP),y)
391 TARGET_CONFIGURE_OPTS += CXX=false
394 ifeq ($(BR2_STATIC_LIBS),y)
395 SHARED_STATIC_LIBS_OPTS = --enable-static --disable-shared
396 TARGET_CFLAGS += -static
397 TARGET_CXXFLAGS += -static
398 TARGET_FCFLAGS += -static
399 TARGET_LDFLAGS += -static
400 else ifeq ($(BR2_SHARED_LIBS),y)
401 SHARED_STATIC_LIBS_OPTS = --disable-static --enable-shared
402 else ifeq ($(BR2_SHARED_STATIC_LIBS),y)
403 SHARED_STATIC_LIBS_OPTS = --enable-static --enable-shared
406 ifeq ($(BR2_COMPILER_PARANOID_UNSAFE_PATH),y)
407 export BR_COMPILER_PARANOID_UNSAFE_PATH=enabled
410 include package/pkg-download.mk
411 include package/pkg-autotools.mk
412 include package/pkg-cmake.mk
413 include package/pkg-luarocks.mk
414 include package/pkg-perl.mk
415 include package/pkg-python.mk
416 include package/pkg-virtual.mk
417 include package/pkg-generic.mk
418 include package/pkg-kconfig.mk
419 include package/pkg-rebar.mk
420 include package/pkg-kernel-module.mk
421 include package/pkg-waf.mk