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