1ifndef MAKE 2MAKE := make 3endif 4ifndef HOSTMAKE 5HOSTMAKE = $(MAKE) 6endif 7HOSTMAKE := $(shell which $(HOSTMAKE) || type -p $(HOSTMAKE) || echo make) 8 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. 13ifeq ($(BR2_JLEVEL),0) 14PARALLEL_JOBS := $(shell echo \ 15 $$((1 + `getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`))) 16else 17PARALLEL_JOBS := $(BR2_JLEVEL) 18endif 19 20# Only build one job at a time, *and* to not randomise goals and 21# prerequisites ordering in make 4.4+ 22MAKE1 := $(HOSTMAKE) -j1 $(if $(findstring --shuffle,$(MAKEFLAGS)),--shuffle=none) 23override MAKE = $(HOSTMAKE) \ 24 $(if $(findstring j,$(filter-out --%,$(MAKEFLAGS))),,-j$(PARALLEL_JOBS)) 25 26ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y) 27TARGET_VENDOR = $(call qstrip,$(BR2_TOOLCHAIN_BUILDROOT_VENDOR)) 28else 29TARGET_VENDOR = buildroot 30endif 31 32# Sanity checks 33ifeq ($(TARGET_VENDOR),) 34$(error BR2_TOOLCHAIN_BUILDROOT_VENDOR is not allowed to be empty) 35endif 36ifeq ($(TARGET_VENDOR),unknown) 37$(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ 38 It might be confused with the native toolchain) 39endif 40 41# Compute GNU_TARGET_NAME 42GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI) 43 44# FLAT binary format needs uclinux, except RISC-V which needs the 45# regular linux name. 46ifeq ($(BR2_BINFMT_FLAT):$(BR2_riscv),y:) 47TARGET_OS = uclinux 48else 49TARGET_OS = linux 50endif 51 52ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y) 53LIBC = uclibc 54else ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y) 55LIBC = musl 56else ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),y) 57LIBC = gnu 58else ifeq ($(BR_BUILDING),y) 59# This happens if there is a bug in Buildroot that allows an 60# architecture configuration that isn't supported by any library. 61$(error No C library enabled, this is not possible.) 62endif 63 64# The ABI suffix is a bit special on ARM, as it needs to be 65# -uclibcgnueabi for uClibc EABI, and -gnueabi for glibc EABI. 66# This means that the LIBC and ABI aren't strictly orthogonal, 67# which explains why we need the test on LIBC below. 68ifeq ($(BR2_arm)$(BR2_armeb),y) 69ifeq ($(LIBC),uclibc) 70ABI = gnueabi 71else 72ABI = eabi 73endif 74 75ifeq ($(BR2_ARM_EABIHF),y) 76ABI := $(ABI)hf 77endif 78endif 79 80# For FSL PowerPC there's SPE 81ifeq ($(BR2_POWERPC_CPU_HAS_SPE),y) 82ABI = spe 83# MPC8540s are e500v1 with single precision FP 84ifeq ($(BR2_powerpc_8540),y) 85TARGET_ABI += -mabi=spe -mfloat-gprs=single -Wa,-me500 86endif 87ifeq ($(BR2_powerpc_8548),y) 88TARGET_ABI += -mabi=spe -mfloat-gprs=double -Wa,-me500x2 89endif 90ifeq ($(BR2_powerpc_e500mc),y) 91TARGET_ABI += -mabi=spe -mfloat-gprs=double -Wa,-me500mc 92endif 93endif 94 95# Use longcalls option for Xtensa globally. 96# The 'longcalls' option allows calls across a greater range of addresses, 97# and is required for some packages. While this option can degrade both 98# code size and performance, the linker can usually optimize away the 99# overhead when a call ends up within a certain range. 100# 101# Use auto-litpools for Xtensa globally. 102# Collecting literals into separate section can be advantageous if that 103# section is placed into DTCM at link time. This is applicable for code 104# running on bare metal, but makes no sense under linux, where userspace 105# is isolated from the physical memory details. OTOH placing literals into 106# separate section breaks build of huge source files, because l32r 107# instruction can only access literals in 256 KBytes range. 108# 109ifeq ($(BR2_xtensa),y) 110TARGET_ABI += -mlongcalls -mauto-litpools 111endif 112 113STAGING_SUBDIR = $(GNU_TARGET_NAME)/sysroot 114STAGING_DIR = $(HOST_DIR)/$(STAGING_SUBDIR) 115 116ifeq ($(BR2_OPTIMIZE_0),y) 117TARGET_OPTIMIZATION = -O0 118endif 119ifeq ($(BR2_OPTIMIZE_1),y) 120TARGET_OPTIMIZATION = -O1 121endif 122ifeq ($(BR2_OPTIMIZE_2),y) 123TARGET_OPTIMIZATION = -O2 124endif 125ifeq ($(BR2_OPTIMIZE_3),y) 126TARGET_OPTIMIZATION = -O3 127endif 128ifeq ($(BR2_OPTIMIZE_G),y) 129TARGET_OPTIMIZATION = -Og 130endif 131ifeq ($(BR2_OPTIMIZE_S),y) 132TARGET_OPTIMIZATION = -Os 133endif 134ifeq ($(BR2_OPTIMIZE_FAST),y) 135TARGET_OPTIMIZATION = -Ofast 136endif 137ifeq ($(BR2_ENABLE_DEBUG),) 138TARGET_DEBUGGING = -g0 139endif 140ifeq ($(BR2_DEBUG_1),y) 141TARGET_DEBUGGING = -g1 142endif 143ifeq ($(BR2_DEBUG_2),y) 144TARGET_DEBUGGING = -g2 145endif 146ifeq ($(BR2_DEBUG_3),y) 147TARGET_DEBUGGING = -g3 148endif 149 150TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS)) 151 152# By design, _FORTIFY_SOURCE requires gcc optimization to be enabled. 153# Therefore, we need to pass _FORTIFY_SOURCE and the optimization level 154# through the same mechanism, i.e currently through CFLAGS. Passing 155# _FORTIFY_SOURCE through the wrapper and the optimization level 156# through CFLAGS would not work, because CFLAGS are sometimes 157# ignored/overridden by packages, but the flags passed by the wrapper 158# are enforced: this would cause _FORTIFY_SOURCE to be used without any 159# optimization level, leading to a build / configure failure. So we keep 160# passing _FORTIFY_SOURCE and the optimization level both through CFLAGS. 161ifeq ($(BR2_FORTIFY_SOURCE_1),y) 162TARGET_HARDENED += -D_FORTIFY_SOURCE=1 163else ifeq ($(BR2_FORTIFY_SOURCE_2),y) 164TARGET_HARDENED += -D_FORTIFY_SOURCE=2 165else ifeq ($(BR2_FORTIFY_SOURCE_3),y) 166TARGET_HARDENED += -D_FORTIFY_SOURCE=3 167endif 168 169TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 170ifeq ($(BR2_TIME_BITS_64),y) 171TARGET_CPPFLAGS += -D_TIME_BITS=64 172endif 173TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) $(TARGET_HARDENED) 174TARGET_CXXFLAGS = $(TARGET_CFLAGS) 175TARGET_FCFLAGS = $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) 176 177# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79509 178ifeq ($(BR2_m68k_cf),y) 179TARGET_CFLAGS += -fno-dwarf2-cfi-asm 180TARGET_CXXFLAGS += -fno-dwarf2-cfi-asm 181endif 182 183ifeq ($(BR2_BINFMT_FLAT),y) 184ifeq ($(BR2_riscv),y) 185TARGET_CFLAGS += -fPIC 186endif 187ELF2FLT_FLAGS = $(if $($(PKG)_FLAT_STACKSIZE),\ 188 -Wl$(comma)-elf2flt="-r -s$($(PKG)_FLAT_STACKSIZE)",\ 189 -Wl$(comma)-elf2flt=-r) 190TARGET_CFLAGS += $(ELF2FLT_FLAGS) 191TARGET_CXXFLAGS += $(ELF2FLT_FLAGS) 192TARGET_FCFLAGS += $(ELF2FLT_FLAGS) 193TARGET_LDFLAGS += $(ELF2FLT_FLAGS) 194endif 195 196ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y) 197TARGET_CROSS = $(HOST_DIR)/bin/$(GNU_TARGET_NAME)- 198else 199TARGET_CROSS = $(HOST_DIR)/bin/$(TOOLCHAIN_EXTERNAL_PREFIX)- 200endif 201 202# gcc-4.7 and later ships with wrappers that will automatically pass 203# arguments to the binutils tools. Those are paths to necessary linker 204# plugins. 205ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_7),y) 206TARGET_GCC_WRAPPERS_PREFIX = gcc- 207endif 208 209# Define TARGET_xx variables for all common binutils/gcc 210TARGET_AR = $(TARGET_CROSS)$(TARGET_GCC_WRAPPERS_PREFIX)ar 211TARGET_AS = $(TARGET_CROSS)as 212TARGET_CC = $(TARGET_CROSS)gcc 213TARGET_CPP = $(TARGET_CROSS)cpp 214TARGET_CXX = $(TARGET_CROSS)g++ 215TARGET_FC = $(TARGET_CROSS)gfortran 216TARGET_LD = $(TARGET_CROSS)ld 217TARGET_NM = $(TARGET_CROSS)$(TARGET_GCC_WRAPPERS_PREFIX)nm 218TARGET_RANLIB = $(TARGET_CROSS)$(TARGET_GCC_WRAPPERS_PREFIX)ranlib 219TARGET_READELF = $(TARGET_CROSS)readelf 220TARGET_OBJCOPY = $(TARGET_CROSS)objcopy 221TARGET_OBJDUMP = $(TARGET_CROSS)objdump 222 223ifeq ($(BR2_STRIP_strip),y) 224STRIP_STRIP_DEBUG := --strip-debug 225TARGET_STRIP = $(TARGET_CROSS)strip 226STRIPCMD = $(TARGET_CROSS)strip --remove-section=.comment --remove-section=.note 227else 228TARGET_STRIP = /bin/true 229STRIPCMD = $(TARGET_STRIP) 230endif 231INSTALL := $(shell which install || type -p install) 232UNZIP := $(shell which unzip || type -p unzip) -q 233 234APPLY_PATCHES = TAR="$(TAR)" PATH=$(HOST_DIR)/bin:$$PATH support/scripts/apply-patches.sh $(if $(QUIET),-s) 235 236HOST_CPPFLAGS = -I$(HOST_DIR)/include 237HOST_CFLAGS ?= -O2 238HOST_CFLAGS += $(HOST_CPPFLAGS) 239HOST_CXXFLAGS += $(HOST_CFLAGS) 240HOST_LDFLAGS += -L$(HOST_DIR)/lib -Wl,-rpath,$(HOST_DIR)/lib 241 242# host-intltool should be executed with the system perl, so we save 243# the path to the system perl, before a host-perl built by Buildroot 244# might get installed into $(HOST_DIR)/bin and therefore appears 245# in our PATH. This system perl will be used as INTLTOOL_PERL. 246export PERL=$(shell which perl) 247 248# host-intltool needs libxml-parser-perl, which Buildroot installs in 249# $(HOST_DIR)/lib/perl, so we must make sure that the system perl 250# finds this perl module by exporting the proper value for PERL5LIB. 251export PERL5LIB=$(HOST_DIR)/lib/perl 252 253TARGET_MAKE_ENV = \ 254 GIT_DIR=. \ 255 PATH=$(BR_PATH) 256 257TARGET_CONFIGURE_OPTS = \ 258 $(TARGET_MAKE_ENV) \ 259 AR="$(TARGET_AR)" \ 260 AS="$(TARGET_AS)" \ 261 LD="$(TARGET_LD)" \ 262 NM="$(TARGET_NM)" \ 263 CC="$(TARGET_CC)" \ 264 GCC="$(TARGET_CC)" \ 265 CPP="$(TARGET_CPP)" \ 266 CXX="$(TARGET_CXX)" \ 267 FC="$(TARGET_FC)" \ 268 F77="$(TARGET_FC)" \ 269 RANLIB="$(TARGET_RANLIB)" \ 270 READELF="$(TARGET_READELF)" \ 271 STRIP="$(TARGET_STRIP)" \ 272 OBJCOPY="$(TARGET_OBJCOPY)" \ 273 OBJDUMP="$(TARGET_OBJDUMP)" \ 274 AR_FOR_BUILD="$(HOSTAR)" \ 275 AS_FOR_BUILD="$(HOSTAS)" \ 276 CC_FOR_BUILD="$(HOSTCC)" \ 277 GCC_FOR_BUILD="$(HOSTCC)" \ 278 CXX_FOR_BUILD="$(HOSTCXX)" \ 279 LD_FOR_BUILD="$(HOSTLD)" \ 280 CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)" \ 281 CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \ 282 CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \ 283 LDFLAGS_FOR_BUILD="$(HOST_LDFLAGS)" \ 284 FCFLAGS_FOR_BUILD="$(HOST_FCFLAGS)" \ 285 DEFAULT_ASSEMBLER="$(TARGET_AS)" \ 286 DEFAULT_LINKER="$(TARGET_LD)" \ 287 CPPFLAGS="$(TARGET_CPPFLAGS)" \ 288 CFLAGS="$(TARGET_CFLAGS)" \ 289 CXXFLAGS="$(TARGET_CXXFLAGS)" \ 290 LDFLAGS="$(TARGET_LDFLAGS)" \ 291 FCFLAGS="$(TARGET_FCFLAGS)" \ 292 FFLAGS="$(TARGET_FCFLAGS)" \ 293 PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \ 294 STAGING_DIR="$(STAGING_DIR)" \ 295 INTLTOOL_PERL=$(PERL) 296 297 298HOST_MAKE_ENV = \ 299 GIT_DIR=. \ 300 PATH=$(BR_PATH) \ 301 PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \ 302 PKG_CONFIG_SYSROOT_DIR="/" \ 303 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \ 304 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \ 305 PKG_CONFIG_LIBDIR="$(HOST_DIR)/lib/pkgconfig:$(HOST_DIR)/share/pkgconfig" 306 307HOST_CONFIGURE_OPTS = \ 308 $(HOST_MAKE_ENV) \ 309 AR="$(HOSTAR)" \ 310 AS="$(HOSTAS)" \ 311 LD="$(HOSTLD)" \ 312 NM="$(HOSTNM)" \ 313 CC="$(HOSTCC)" \ 314 GCC="$(HOSTCC)" \ 315 CXX="$(HOSTCXX)" \ 316 CPP="$(HOSTCPP)" \ 317 OBJCOPY="$(HOSTOBJCOPY)" \ 318 RANLIB="$(HOSTRANLIB)" \ 319 CPPFLAGS="$(HOST_CPPFLAGS)" \ 320 CFLAGS="$(HOST_CFLAGS)" \ 321 CXXFLAGS="$(HOST_CXXFLAGS)" \ 322 LDFLAGS="$(HOST_LDFLAGS)" \ 323 INTLTOOL_PERL=$(PERL) 324 325# This is extra environment we can not export ourselves (eg. because some 326# packages use that variable internally, eg. uboot), so we have to 327# explicitly pass it to user-supplied external hooks (eg. post-build, 328# post-images) 329EXTRA_ENV = \ 330 PATH=$(BR_PATH) \ 331 BR2_DL_DIR=$(BR2_DL_DIR) \ 332 BUILD_DIR=$(BUILD_DIR) \ 333 CONFIG_DIR=$(CONFIG_DIR) \ 334 O=$(CANONICAL_O) 335 336################################################################################ 337# settings we need to pass to configure 338 339# does unaligned access trap? 340BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=yes 341ifeq ($(BR2_i386),y) 342BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no 343endif 344ifeq ($(BR2_x86_64),y) 345BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no 346endif 347ifeq ($(BR2_m68k),y) 348BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no 349endif 350ifeq ($(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le),y) 351BR2_AC_CV_TRAP_CHECK = ac_cv_lbl_unaligned_fail=no 352endif 353 354ifeq ($(BR2_ENDIAN),"BIG") 355BR2_AC_CV_C_BIGENDIAN = ac_cv_c_bigendian=yes 356else 357BR2_AC_CV_C_BIGENDIAN = ac_cv_c_bigendian=no 358endif 359 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# 364# These autoconf variables should only be pre-seeded when the minimal 365# gettext implementation of musl is used. When the full blown 366# implementation provided by gettext libintl is used, auto-detection 367# works fine, and pre-seeding those values is actually wrong. 368ifeq ($(BR2_TOOLCHAIN_USES_MUSL):$(BR2_PACKAGE_GETTEXT_PROVIDES_LIBINTL),y:) 369BR2_GT_CV_FUNC_GNUGETTEXT_LIBC = \ 370 gt_cv_func_gnugettext1_libc=yes \ 371 gt_cv_func_gnugettext2_libc=yes 372endif 373 374TARGET_CONFIGURE_ARGS = \ 375 $(BR2_AC_CV_TRAP_CHECK) \ 376 ac_cv_func_mmap_fixed_mapped=yes \ 377 ac_cv_func_memcmp_working=yes \ 378 ac_cv_have_decl_malloc=yes \ 379 gl_cv_func_malloc_0_nonnull=yes \ 380 ac_cv_func_malloc_0_nonnull=yes \ 381 ac_cv_func_calloc_0_nonnull=yes \ 382 ac_cv_func_realloc_0_nonnull=yes \ 383 lt_cv_sys_lib_search_path_spec="" \ 384 $(BR2_AC_CV_C_BIGENDIAN) \ 385 $(BR2_GT_CV_FUNC_GNUGETTEXT_LIBC) 386 387################################################################################ 388 389ifeq ($(BR2_SYSTEM_ENABLE_NLS),y) 390NLS_OPTS = --enable-nls 391TARGET_NLS_DEPENDENCIES = host-gettext 392ifeq ($(BR2_PACKAGE_GETTEXT_PROVIDES_LIBINTL),y) 393TARGET_NLS_DEPENDENCIES += gettext 394TARGET_NLS_LIBS += -lintl 395endif 396else 397NLS_OPTS = --disable-nls 398endif 399 400# We need anything that is invalid. Traditionally, we'd have used 'false' (and 401# we did so in the past). However, that breaks libtool for packages that have 402# optional C++ support (e.g. gnutls), because libtool will *require* a *valid* 403# C++ preprocessor as long as CXX is not 'no'. 404# Now, whether we use 'no' or 'false' for CXX as the same side effect: it is an 405# invalid C++ compiler, and thus will cause detection of C++ to fail (which is 406# expected and what we want), while at the same time taming libtool into 407# silence. 408ifneq ($(BR2_INSTALL_LIBSTDCPP),y) 409TARGET_CONFIGURE_OPTS += CXX=no 410endif 411 412ifeq ($(BR2_STATIC_LIBS),y) 413SHARED_STATIC_LIBS_OPTS = --enable-static --disable-shared 414TARGET_CFLAGS += -static 415TARGET_CXXFLAGS += -static 416TARGET_FCFLAGS += -static 417TARGET_LDFLAGS += -static 418else ifeq ($(BR2_SHARED_LIBS),y) 419SHARED_STATIC_LIBS_OPTS = --disable-static --enable-shared 420else ifeq ($(BR2_SHARED_STATIC_LIBS),y) 421SHARED_STATIC_LIBS_OPTS = --enable-static --enable-shared 422endif 423 424# Used by our binutils patches. 425export BR_COMPILER_PARANOID_UNSAFE_PATH=enabled 426 427include package/pkg-download.mk 428include package/pkg-autotools.mk 429include package/pkg-cmake.mk 430include package/pkg-luarocks.mk 431include package/pkg-perl.mk 432include package/pkg-python.mk 433include package/pkg-virtual.mk 434include package/pkg-generic.mk 435include package/pkg-kconfig.mk 436include package/pkg-rebar.mk 437include package/pkg-kernel-module.mk 438include package/pkg-waf.mk 439include package/pkg-golang.mk 440include package/pkg-meson.mk 441include package/pkg-qmake.mk 442include package/pkg-cargo.mk 443