1# Makefile for buildroot 2# 3# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> 4# Copyright (C) 2006-2014 by the Buildroot developers <buildroot@uclibc.org> 5# Copyright (C) 2014-2020 by the Buildroot developers <buildroot@buildroot.org> 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20# 21 22#-------------------------------------------------------------- 23# Just run 'make menuconfig', configure stuff, then run 'make'. 24# You shouldn't need to mess with anything beyond this point... 25#-------------------------------------------------------------- 26 27# Delete default rules. We don't use them. This saves a bit of time. 28.SUFFIXES: 29 30# we want bash as shell 31SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ 32 else if [ -x /bin/bash ]; then echo /bin/bash; \ 33 else echo sh; fi; fi) 34 35O_LATEST := $(CURDIR)/output/latest 36DEFCONFIG = $(firstword $(filter %_defconfig,$(MAKECMDGOALS))) 37 38# Set O variable if not already done on the command line; 39# or avoid confusing packages that can use the O=<dir> syntax for out-of-tree 40# build by preventing it from being forwarded to sub-make calls. 41ifneq ("$(origin O)", "command line") 42ifneq ($(DEFCONFIG),) 43# Set O=output/<board> for defconfig 44O := $(patsubst %_defconfig,$(CURDIR)/output/%,$(DEFCONFIG)) 45else 46# Prefer BUILDROOT_OUTPUT_DIR env and $(CURDIR)/output/latest symlink 47O := $(BUILDROOT_OUTPUT_DIR) 48O := $(if $(O),$(O),$(realpath $(CURDIR)/output/latest)) 49endif 50# Fallback to $(CURDIR)/output 51O := $(if $(O),$(O),$(CURDIR)/output) 52endif 53 54ifneq ($(BUILDROOT_OUTPUT_DIR),) 55ifneq ($(BUILDROOT_OUTPUT_DIR),$(O)) 56$(warning "BUILDROOT_OUTPUT_DIR environment unmatched with output dir!") 57$(warning "BUILDROOT_OUTPUT_DIR: $(BUILDROOT_OUTPUT_DIR)") 58$(warning "Output dir: $(O)") 59$(error "Please unset it: unset BUILDROOT_OUTPUT_DIR") 60endif 61endif 62 63ifneq ($(DEFCONFIG),) 64$(shell rm -rf $(O_LATEST); mkdir -p $(CURDIR)/output) 65$(shell ln -rsf $(O) $(O_LATEST)) 66endif 67 68# Check if the current Buildroot execution meets all the pre-requisites. 69# If they are not met, Buildroot will actually do its job in a sub-make meeting 70# its pre-requisites, which are: 71# 1- Permissive enough umask: 72# Wrong or too restrictive umask will prevent Buildroot and packages from 73# creating files and directories. 74# 2- Absolute canonical CWD (i.e. $(CURDIR)): 75# Otherwise, some packages will use CWD as-is, others will compute its 76# absolute canonical path. This makes harder tracking and fixing host 77# machine path leaks. 78# 3- Absolute canonical output location (i.e. $(O)): 79# For the same reason as the one for CWD. 80 81# Remove the trailing '/.' from $(O) as it can be added by the makefile wrapper 82# installed in the $(O) directory. 83# Also remove the trailing '/' the user can set when on the command line. 84override O := $(patsubst %/,%,$(patsubst %.,%,$(O))) 85# Make sure $(O) actually exists before calling realpath on it; this is to 86# avoid empty CANONICAL_O in case on non-existing entry. 87CANONICAL_O := $(shell mkdir -p $(O) >/dev/null 2>&1)$(realpath $(O)) 88 89# gcc fails to build when the srcdir contains a '@' 90ifneq ($(findstring @,$(CANONICAL_O)),) 91$(error The build directory can not contain a '@') 92endif 93 94CANONICAL_CURDIR = $(realpath $(CURDIR)) 95 96REQ_UMASK = 0022 97 98# Make sure O= is passed (with its absolute canonical path) everywhere the 99# toplevel makefile is called back. 100EXTRAMAKEARGS := O=$(CANONICAL_O) 101 102# Check Buildroot execution pre-requisites here. 103ifneq ($(shell umask):$(CURDIR):$(O),$(REQ_UMASK):$(CANONICAL_CURDIR):$(CANONICAL_O)) 104.PHONY: _all $(MAKECMDGOALS) 105 106$(MAKECMDGOALS): _all 107 @: 108 109_all: 110 @umask $(REQ_UMASK) && \ 111 $(MAKE) -C $(CANONICAL_CURDIR) --no-print-directory \ 112 $(MAKECMDGOALS) $(EXTRAMAKEARGS) 113 114else # umask / $(CURDIR) / $(O) 115 116# This is our default rule, so must come first 117all: 118.PHONY: all 119 120# Set and export the version string 121export BR2_VERSION := 2021.11 122# Actual time the release is cut (for reproducible builds) 123BR2_VERSION_EPOCH = 1638734000 124 125# Save running make version since it's clobbered by the make package 126RUNNING_MAKE_VERSION := $(MAKE_VERSION) 127 128# Check for minimal make version (note: this check will break at make 10.x) 129MIN_MAKE_VERSION = 3.81 130ifneq ($(firstword $(sort $(RUNNING_MAKE_VERSION) $(MIN_MAKE_VERSION))),$(MIN_MAKE_VERSION)) 131$(error You have make '$(RUNNING_MAKE_VERSION)' installed. GNU make >= $(MIN_MAKE_VERSION) is required) 132endif 133 134# absolute path 135TOPDIR := $(CURDIR) 136CONFIG_CONFIG_IN = Config.in 137CONFIG = support/kconfig 138DATE := $(shell date +%Y%m%d) 139 140# Compute the full local version string so packages can use it as-is 141# Need to export it, so it can be got from environment in children (eg. mconf) 142 143BR2_LOCALVERSION := $(shell $(TOPDIR)/support/scripts/setlocalversion) 144ifeq ($(BR2_LOCALVERSION),) 145export BR2_VERSION_FULL := $(BR2_VERSION) 146else 147export BR2_VERSION_FULL := $(BR2_LOCALVERSION) 148endif 149 150# List of targets and target patterns for which .config doesn't need to be read in 151noconfig_targets := menuconfig nconfig gconfig xconfig config oldconfig randconfig \ 152 defconfig %_defconfig allyesconfig allnoconfig alldefconfig syncconfig release \ 153 randpackageconfig allyespackageconfig allnopackageconfig \ 154 print-version olddefconfig distclean manual manual-% check-package check-flake8 155 156# Some global targets do not trigger a build, but are used to collect 157# metadata, or do various checks. When such targets are triggered, 158# some packages should not do their configuration sanity 159# checks. Provide them a BR_BUILDING variable set to 'y' when we're 160# actually building and they should do their sanity checks. 161# 162# We're building in two situations: when MAKECMDGOALS is empty 163# (default target is to build), or when MAKECMDGOALS contains 164# something else than one of the nobuild_targets. 165nobuild_targets := source %-source \ 166 legal-info %-legal-info external-deps _external-deps \ 167 clean distclean help show-targets graph-depends \ 168 %-graph-depends %-show-depends %-show-version \ 169 graph-build graph-size list-defconfigs \ 170 savedefconfig update-defconfig printvars 171ifeq ($(MAKECMDGOALS),) 172BR_BUILDING = y 173else ifneq ($(filter-out $(nobuild_targets),$(MAKECMDGOALS)),) 174BR_BUILDING = y 175endif 176 177# We call make recursively to build packages. The command-line overrides that 178# are passed to Buildroot don't apply to those package build systems. In 179# particular, we don't want to pass down the O=<dir> option for out-of-tree 180# builds, because the value specified on the command line will not be correct 181# for packages. 182MAKEOVERRIDES := 183 184# Include some helper macros and variables 185include support/misc/utils.mk 186 187# Set variables related to in-tree or out-of-tree build. 188# Here, both $(O) and $(CURDIR) are absolute canonical paths. 189ifeq ($(O),$(CURDIR)/output) 190CONFIG_DIR := $(CURDIR) 191NEED_WRAPPER = 192else 193CONFIG_DIR := $(O) 194NEED_WRAPPER = y 195endif 196 197# bash prints the name of the directory on 'cd <dir>' if CDPATH is 198# set, so unset it here to not cause problems. Notice that the export 199# line doesn't affect the environment of $(shell ..) calls. 200export CDPATH := 201 202BASE_DIR := $(CANONICAL_O) 203$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist)) 204 205 206# Handling of BR2_EXTERNAL. 207# 208# The value of BR2_EXTERNAL is stored in .br-external in the output directory. 209# The location of the external.mk makefile fragments is computed in that file. 210# On subsequent invocations of make, this file is read in. BR2_EXTERNAL can 211# still be overridden on the command line, therefore the file is re-created 212# every time make is run. 213 214BR2_EXTERNAL_FILE = $(BASE_DIR)/.br2-external.mk 215-include $(BR2_EXTERNAL_FILE) 216$(shell support/scripts/br2-external -d '$(BASE_DIR)' $(BR2_EXTERNAL)) 217BR2_EXTERNAL_ERROR = 218include $(BR2_EXTERNAL_FILE) 219ifneq ($(BR2_EXTERNAL_ERROR),) 220$(error $(BR2_EXTERNAL_ERROR)) 221endif 222 223# Workaround bug in make-4.3: https://savannah.gnu.org/bugs/?57676 224$(BASE_DIR)/.br2-external.mk:; 225 226# To make sure that the environment variable overrides the .config option, 227# set this before including .config. 228ifneq ($(BR2_DL_DIR),) 229DL_DIR := $(BR2_DL_DIR) 230endif 231ifneq ($(BR2_CCACHE_DIR),) 232BR_CACHE_DIR := $(BR2_CCACHE_DIR) 233endif 234 235# Need that early, before we scan packages 236# Avoids doing the $(or...) everytime 237BR_GRAPH_OUT := $(or $(BR2_GRAPH_OUT),pdf) 238 239BUILD_DIR := $(BASE_DIR)/build 240BINARIES_DIR := $(BASE_DIR)/images 241BASE_TARGET_DIR := $(BASE_DIR)/target 242PER_PACKAGE_DIR := $(BASE_DIR)/per-package 243# initial definition so that 'make clean' works for most users, even without 244# .config. HOST_DIR will be overwritten later when .config is included. 245HOST_DIR := $(BASE_DIR)/host 246GRAPHS_DIR := $(BASE_DIR)/graphs 247 248LEGAL_INFO_DIR = $(BASE_DIR)/legal-info 249REDIST_SOURCES_DIR_TARGET = $(LEGAL_INFO_DIR)/sources 250REDIST_SOURCES_DIR_HOST = $(LEGAL_INFO_DIR)/host-sources 251LICENSE_FILES_DIR_TARGET = $(LEGAL_INFO_DIR)/licenses 252LICENSE_FILES_DIR_HOST = $(LEGAL_INFO_DIR)/host-licenses 253LEGAL_MANIFEST_CSV_TARGET = $(LEGAL_INFO_DIR)/manifest.csv 254LEGAL_MANIFEST_CSV_HOST = $(LEGAL_INFO_DIR)/host-manifest.csv 255LEGAL_WARNINGS = $(LEGAL_INFO_DIR)/.warnings 256LEGAL_REPORT = $(LEGAL_INFO_DIR)/README 257 258CPE_UPDATES_DIR = $(BASE_DIR)/cpe-updates 259 260BR2_CONFIG = $(CONFIG_DIR)/.config 261 262# Pull in the user's configuration file 263ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),) 264-include $(BR2_CONFIG) 265endif 266 267ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),) 268# Disable top-level parallel build if per-package directories is not 269# used. Indeed, per-package directories is necessary to guarantee 270# determinism and reproducibility with top-level parallel build. 271.NOTPARALLEL: 272endif 273 274# timezone and locale may affect build output 275ifeq ($(BR2_REPRODUCIBLE),y) 276export TZ = UTC 277export LANG = C 278export LC_ALL = C 279endif 280 281# To put more focus on warnings, be less verbose as default 282# Use 'make V=1' to see the full commands 283ifeq ("$(origin V)", "command line") 284 KBUILD_VERBOSE = $(V) 285endif 286ifndef KBUILD_VERBOSE 287 KBUILD_VERBOSE = 0 288endif 289 290ifeq ($(KBUILD_VERBOSE),1) 291 Q = 292ifndef VERBOSE 293 VERBOSE = 1 294endif 295export VERBOSE 296else 297 Q = @ 298endif 299 300# kconfig uses CONFIG_SHELL 301CONFIG_SHELL := $(SHELL) 302 303export SHELL CONFIG_SHELL Q KBUILD_VERBOSE 304 305CUSTOM_KERNEL := $(CURDIR)/../kernel 306CUSTOM_KERNEL_VERSION := $(shell if [ -f "$(CUSTOM_KERNEL)/Makefile" ]; then grep -A 1 "^VERSION = " "$(CUSTOM_KERNEL)/Makefile" | cut -d' ' -f 3 | paste -sd'.'; fi) 307 308ifndef HOSTAR 309HOSTAR := ar 310endif 311ifndef HOSTAS 312HOSTAS := as 313endif 314ifndef HOSTCC 315HOSTCC := gcc 316HOSTCC := $(shell which $(HOSTCC) || type -p $(HOSTCC) || echo gcc) 317endif 318HOSTCC_NOCCACHE := $(HOSTCC) 319ifndef HOSTCXX 320HOSTCXX := g++ 321HOSTCXX := $(shell which $(HOSTCXX) || type -p $(HOSTCXX) || echo g++) 322endif 323HOSTCXX_NOCCACHE := $(HOSTCXX) 324ifndef HOSTCPP 325HOSTCPP := cpp 326endif 327ifndef HOSTLD 328HOSTLD := ld 329endif 330ifndef HOSTLN 331HOSTLN := ln 332endif 333ifndef HOSTNM 334HOSTNM := nm 335endif 336ifndef HOSTOBJCOPY 337HOSTOBJCOPY := objcopy 338endif 339ifndef HOSTRANLIB 340HOSTRANLIB := ranlib 341endif 342HOSTAR := $(shell which $(HOSTAR) || type -p $(HOSTAR) || echo ar) 343HOSTAS := $(shell which $(HOSTAS) || type -p $(HOSTAS) || echo as) 344HOSTCPP := $(shell which $(HOSTCPP) || type -p $(HOSTCPP) || echo cpp) 345HOSTLD := $(shell which $(HOSTLD) || type -p $(HOSTLD) || echo ld) 346HOSTLN := $(shell which $(HOSTLN) || type -p $(HOSTLN) || echo ln) 347HOSTNM := $(shell which $(HOSTNM) || type -p $(HOSTNM) || echo nm) 348HOSTOBJCOPY := $(shell which $(HOSTOBJCOPY) || type -p $(HOSTOBJCOPY) || echo objcopy) 349HOSTRANLIB := $(shell which $(HOSTRANLIB) || type -p $(HOSTRANLIB) || echo ranlib) 350SED := $(shell which sed || type -p sed) -i -e 351 352export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTLD 353export HOSTCC_NOCCACHE HOSTCXX_NOCCACHE 354 355# Determine the userland we are running on. 356# 357# Note that, despite its name, we are not interested in the actual 358# architecture name. This is mostly used to determine whether some 359# of the binary tools (e.g. pre-built external toolchains) can run 360# on the current host. So we need to know if the userland we're 361# running on can actually run those toolchains. 362# 363# For example, a 64-bit prebuilt toolchain will not run on a 64-bit 364# kernel if the userland is 32-bit (e.g. in a chroot for example). 365# 366# So, we extract the first part of the tuple the host gcc was 367# configured to generate code for; we assume this is our userland. 368# 369export HOSTARCH := $(shell LC_ALL=C $(HOSTCC_NOCCACHE) -v 2>&1 | \ 370 sed -e '/^Target: \([^-]*\).*/!d' \ 371 -e 's//\1/' \ 372 -e 's/i.86/x86/' \ 373 -e 's/sun4u/sparc64/' \ 374 -e 's/arm.*/arm/' \ 375 -e 's/sa110/arm/' \ 376 -e 's/ppc64/powerpc64/' \ 377 -e 's/ppc/powerpc/' \ 378 -e 's/macppc/powerpc/' \ 379 -e 's/sh.*/sh/' ) 380 381# When adding a new host gcc version in Config.in, 382# update the HOSTCC_MAX_VERSION variable: 383HOSTCC_MAX_VERSION := 9 384 385HOSTCC_VERSION := $(shell V=$$($(HOSTCC_NOCCACHE) --version | \ 386 sed -n -r 's/^.* ([0-9]*)\.([0-9]*)\.([0-9]*)[ ]*.*/\1 \2/p'); \ 387 [ "$${V%% *}" -le $(HOSTCC_MAX_VERSION) ] || V=$(HOSTCC_MAX_VERSION); \ 388 printf "%s" "$${V}") 389 390# For gcc >= 5.x, we only need the major version. 391ifneq ($(firstword $(HOSTCC_VERSION)),4) 392HOSTCC_VERSION := $(firstword $(HOSTCC_VERSION)) 393endif 394 395ifeq ($(BR2_NEEDS_HOST_UTF8_LOCALE),y) 396# First, we try to use the user's configured locale (as that's the 397# language they'd expect messages to be displayed), then we favour 398# a non language-specific locale like C.UTF-8 if one is available, 399# so we sort with the C locale to get it at the top. 400# This is guaranteed to not be empty, because of the check in 401# support/dependencies/dependencies.sh 402HOST_UTF8_LOCALE := $(shell \ 403 ( echo $${LC_ALL:-$${LC_MESSAGES:-$${LANG}}}; \ 404 locale -a 2>/dev/null | LC_ALL=C sort \ 405 ) \ 406 | grep -i -E 'utf-?8$$' \ 407 | head -n 1) 408HOST_UTF8_LOCALE_ENV := LC_ALL=$(HOST_UTF8_LOCALE) 409endif 410 411# Make sure pkg-config doesn't look outside the buildroot tree 412HOST_PKG_CONFIG_PATH := $(PKG_CONFIG_PATH) 413unexport PKG_CONFIG_PATH 414unexport PKG_CONFIG_SYSROOT_DIR 415unexport PKG_CONFIG_LIBDIR 416 417# Having DESTDIR set in the environment confuses the installation 418# steps of some packages. 419unexport DESTDIR 420 421# Causes breakage with packages that needs host-ruby 422unexport RUBYOPT 423 424include package/pkg-utils.mk 425include package/doc-asciidoc.mk 426 427ifeq ($(BR2_HAVE_DOT_CONFIG),y) 428 429################################################################################ 430# 431# Hide troublesome environment variables from sub processes 432# 433################################################################################ 434unexport CROSS_COMPILE 435unexport ARCH 436unexport CC 437unexport LD 438unexport AR 439unexport CXX 440unexport CPP 441unexport RANLIB 442unexport CFLAGS 443unexport CXXFLAGS 444unexport UNZIP 445unexport GREP_OPTIONS 446unexport TAR_OPTIONS 447unexport CONFIG_SITE 448unexport QMAKESPEC 449unexport TERMINFO 450unexport MACHINE 451unexport O 452unexport GCC_COLORS 453unexport PLATFORM 454unexport OS 455 456GNU_HOST_NAME := $(shell support/gnuconfig/config.guess) 457 458PACKAGES := 459PACKAGES_ALL := 460 461# silent mode requested? 462QUIET := $(if $(findstring s,$(filter-out --%,$(MAKEFLAGS))),-q) 463 464# Strip off the annoying quoting 465ARCH := $(call qstrip,$(BR2_ARCH)) 466NORMALIZED_ARCH := $(call qstrip,$(BR2_NORMALIZED_ARCH)) 467KERNEL_ARCH := $(call qstrip,$(BR2_NORMALIZED_ARCH)) 468 469ZCAT := $(call qstrip,$(BR2_ZCAT)) 470BZCAT := $(call qstrip,$(BR2_BZCAT)) 471XZCAT := $(call qstrip,$(BR2_XZCAT)) 472LZCAT := $(call qstrip,$(BR2_LZCAT)) 473TAR_OPTIONS = $(call qstrip,$(BR2_TAR_OPTIONS)) -xf 474 475ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),y) 476HOST_DIR = $(if $(PKG),$(PER_PACKAGE_DIR)/$($(PKG)_NAME)/host,$(call qstrip,$(BR2_HOST_DIR))) 477TARGET_DIR = $(if $(ROOTFS),$(ROOTFS_$(ROOTFS)_TARGET_DIR),$(if $(PKG),$(PER_PACKAGE_DIR)/$($(PKG)_NAME)/target,$(BASE_TARGET_DIR))) 478else 479HOST_DIR := $(call qstrip,$(BR2_HOST_DIR)) 480TARGET_DIR = $(if $(ROOTFS),$(ROOTFS_$(ROOTFS)_TARGET_DIR),$(BASE_TARGET_DIR))$(if $($(PKG)_OEM_INSTALL),/oem) 481 482ifeq ($(BR2_PACKAGE_OEM),y) 483$(eval $(foreach pkg,$(call qstrip,$(BR2_PACKAGE_OEM_PACKAGES)), \ 484 $(eval $(call UPPERCASE,$(pkg))_OEM_INSTALL := y)$(sep) \ 485 $(eval OEM_DEPENDENCIES += $(pkg))$(sep))) 486endif 487endif 488 489ifneq ($(HOST_DIR),$(BASE_DIR)/host) 490HOST_DIR_SYMLINK = $(BASE_DIR)/host 491$(HOST_DIR_SYMLINK): | $(BASE_DIR) 492 ln -snf $(HOST_DIR) $(HOST_DIR_SYMLINK) 493endif 494 495STAGING_DIR_SYMLINK = $(BASE_DIR)/staging 496$(STAGING_DIR_SYMLINK): | $(BASE_DIR) 497 ln -snf $(STAGING_DIR) $(STAGING_DIR_SYMLINK) 498 499# Quotes are needed for spaces and all in the original PATH content. 500BR_PATH = "$(HOST_DIR)/bin:$(HOST_DIR)/sbin:$(PATH)" 501 502# Location of a file giving a big fat warning that output/target 503# should not be used as the root filesystem. 504TARGET_DIR_WARNING_FILE = $(TARGET_DIR)/THIS_IS_NOT_YOUR_ROOT_FILESYSTEM 505 506ifeq ($(BR2_CCACHE),y) 507CCACHE = $(HOST_DIR)/bin/ccache 508BR_CACHE_DIR ?= $(call qstrip,$(BR2_CCACHE_DIR)) 509export BR_CACHE_DIR 510HOSTCC = $(CCACHE) $(HOSTCC_NOCCACHE) 511HOSTCXX = $(CCACHE) $(HOSTCXX_NOCCACHE) 512else 513export BR_NO_CCACHE 514endif 515 516# Scripts in support/ or post-build scripts may need to reference 517# these locations, so export them so it is easier to use 518export BR2_CONFIG 519export BR2_REPRODUCIBLE 520export TARGET_DIR 521export STAGING_DIR 522export HOST_DIR 523export BINARIES_DIR 524export BASE_DIR 525 526################################################################################ 527# 528# You should probably leave this stuff alone unless you know 529# what you are doing. 530# 531################################################################################ 532 533all: world 534 535# Include legacy before the other things, because package .mk files 536# may rely on it. 537include Makefile.legacy 538 539include system/system.mk 540include package/Makefile.in 541# arch/arch.mk must be after package/Makefile.in because it may need to 542# complement variables defined therein, like BR_NO_CHECK_HASH_FOR. 543include arch/arch.mk 544include support/dependencies/dependencies.mk 545 546include $(sort $(wildcard toolchain/*.mk)) 547include $(sort $(wildcard toolchain/*/*.mk)) 548 549ifeq ($(BR2_REPRODUCIBLE),y) 550# If SOURCE_DATE_EPOCH has not been set then use the commit date, or the last 551# release date if the source tree is not within a Git repository. 552# See: https://reproducible-builds.org/specs/source-date-epoch/ 553BR2_VERSION_GIT_EPOCH := $(shell $(GIT) log -1 --format=%at 2> /dev/null) 554export SOURCE_DATE_EPOCH ?= $(or $(BR2_VERSION_GIT_EPOCH),$(BR2_VERSION_EPOCH)) 555endif 556 557# Include the package override file if one has been provided in the 558# configuration. 559PACKAGE_OVERRIDE_FILE = $(call qstrip,$(BR2_PACKAGE_OVERRIDE_FILE)) 560ifneq ($(PACKAGE_OVERRIDE_FILE),) 561-include $(PACKAGE_OVERRIDE_FILE) 562endif 563 564include $(sort $(wildcard package/*/*.mk)) 565 566include boot/common.mk 567include linux/linux.mk 568include fs/common.mk 569 570# If using a br2-external tree, the BR2_EXTERNAL_$(NAME)_PATH variables 571# are also present in the .config file. Since .config is included after 572# we defined them in the Makefile, the values for those variables are 573# quoted. We just include the generated Makefile fragment .br2-external.mk 574# a third time, which will set those variables to the un-quoted values. 575include $(BR2_EXTERNAL_FILE) 576 577# Nothing to include if no BR2_EXTERNAL tree in use 578include $(BR2_EXTERNAL_MKS) 579 580# Now we are sure we have all the packages scanned and defined. We now 581# check for each package in the list of enabled packages, that all its 582# dependencies are indeed enabled. 583# 584# Only trigger the check for default builds. If the user forces building 585# a package, even if not enabled in the configuration, we want to accept 586# it. However; we also want to be able to force checking the dependencies 587# if the user so desires. Forcing a dependency check is useful in the case 588# of test-pkg, as we want to make sure during testing, that a package has 589# all the dependencies selected in the config file. 590# 591ifeq ($(MAKECMDGOALS),) 592BR_FORCE_CHECK_DEPENDENCIES = YES 593endif 594 595ifeq ($(BR_FORCE_CHECK_DEPENDENCIES),YES) 596 597define CHECK_ONE_DEPENDENCY 598ifneq ($(2)|$(BR2_LINUX_KERNEL),LINUX|) 599ifeq ($$($(2)_TYPE),target) 600ifeq ($$($(2)_IS_VIRTUAL),) 601ifneq ($$($$($(2)_KCONFIG_VAR)),y) 602$$(error $$($(2)_NAME) is in the dependency chain of $$($(1)_NAME) that \ 603has added it to its _DEPENDENCIES variable without selecting it or \ 604depending on it from Config.in) 605endif 606endif 607endif 608endif 609endef 610 611$(foreach pkg,$(call UPPERCASE,$(PACKAGES)),\ 612 $(foreach dep,$(call UPPERCASE,$($(pkg)_FINAL_ALL_DEPENDENCIES)),\ 613 $(eval $(call CHECK_ONE_DEPENDENCY,$(pkg),$(dep))$(sep)))) 614 615endif 616 617$(BUILD_DIR)/buildroot-config/auto.conf: $(BR2_CONFIG) 618 $(MAKE1) $(EXTRAMAKEARGS) HOSTCC="$(HOSTCC_NOCCACHE)" HOSTCXX="$(HOSTCXX_NOCCACHE)" syncconfig 619 620.PHONY: prepare 621prepare: $(BUILD_DIR)/buildroot-config/auto.conf 622 623.PHONY: world 624world: target-post-image 625 626.PHONY: prepare-sdk 627prepare-sdk: world 628 @$(call MESSAGE,"Rendering the SDK relocatable") 629 PER_PACKAGE_DIR=$(PER_PACKAGE_DIR) $(TOPDIR)/support/scripts/fix-rpath host 630 PER_PACKAGE_DIR=$(PER_PACKAGE_DIR) $(TOPDIR)/support/scripts/fix-rpath staging 631 $(INSTALL) -m 755 $(TOPDIR)/support/misc/relocate-sdk.sh $(HOST_DIR)/relocate-sdk.sh 632 mkdir -p $(HOST_DIR)/share/buildroot 633 echo $(HOST_DIR) > $(HOST_DIR)/share/buildroot/sdk-location 634 635 636.PHONY: reinstall 637clean-for-reinstall: $(patsubst %,%-clean-for-reinstall,$(PACKAGES)) 638 rm -rf $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) 639 find $(BUILD_DIR) -name ".stamp_*_installed" -delete 640 641reinstall: clean-for-reinstall all 642 643BR2_SDK_PREFIX ?= $(GNU_TARGET_NAME)_sdk-buildroot 644.PHONY: sdk 645sdk: prepare-sdk $(BR2_TAR_HOST_DEPENDENCY) 646 @$(call MESSAGE,"Generating SDK tarball") 647 $(if $(BR2_SDK_PREFIX),,$(error BR2_SDK_PREFIX can not be empty)) 648 $(Q)mkdir -p $(BINARIES_DIR) 649 $(TAR) czf "$(BINARIES_DIR)/$(BR2_SDK_PREFIX).tar.gz" \ 650 --owner=0 --group=0 --numeric-owner \ 651 --transform='s#^$(patsubst /%,%,$(HOST_DIR))#$(BR2_SDK_PREFIX)#' \ 652 -C / $(patsubst /%,%,$(HOST_DIR)) 653 654RSYNC_VCS_EXCLUSIONS = \ 655 --exclude .svn --exclude .git --exclude .hg --exclude .bzr \ 656 --exclude CVS 657 658# When stripping, obey to BR2_STRIP_EXCLUDE_DIRS and 659# BR2_STRIP_EXCLUDE_FILES 660STRIP_FIND_COMMON_CMD = \ 661 find $(TARGET_DIR) \ 662 $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS)), \ 663 \( $(call finddirclauses,$(TARGET_DIR),$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) \) \ 664 -prune -o \ 665 ) \ 666 $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)), \ 667 -not \( $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) ) 668 669# Regular stripping for everything, except libpthread, ld-*.so and 670# kernel modules: 671# - libpthread.so: a non-stripped libpthread shared library is needed for 672# proper debugging of pthread programs using gdb. 673# - ld.so: a non-stripped dynamic linker library is needed for valgrind 674# - kernel modules (*.ko): do not function properly when stripped like normal 675# applications and libraries. Normally kernel modules are already excluded 676# by the executable permission check, so the explicit exclusion is only 677# done for kernel modules with incorrect permissions. 678STRIP_FIND_CMD = \ 679 $(STRIP_FIND_COMMON_CMD) \ 680 -type f \( -perm /111 -o -name '*.so*' \) \ 681 -not \( $(call findfileclauses,libpthread*.so* ld-*.so* *.ko) \) \ 682 -print0 683 684# Special stripping (only debugging symbols) for libpthread and ld-*.so. 685STRIP_FIND_SPECIAL_LIBS_CMD = \ 686 $(STRIP_FIND_COMMON_CMD) \ 687 \( -name 'ld-*.so*' -o -name 'libpthread*.so*' \) \ 688 -print0 689 690ifeq ($(BR2_ECLIPSE_REGISTER),y) 691define TOOLCHAIN_ECLIPSE_REGISTER 692 ./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \ 693 $(notdir $(TARGET_CROSS)) $(BR2_ARCH) 694endef 695TARGET_FINALIZE_HOOKS += TOOLCHAIN_ECLIPSE_REGISTER 696endif 697 698# Generate locale data. 699ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),y) 700GLIBC_GENERATE_LOCALES = $(call qstrip,$(BR2_GENERATE_LOCALE)) 701ifneq ($(GLIBC_GENERATE_LOCALES),) 702PACKAGES += host-localedef 703 704define GENERATE_GLIBC_LOCALES 705 $(MAKE) -f support/misc/gen-glibc-locales.mk \ 706 ENDIAN=$(call LOWERCASE,$(BR2_ENDIAN)) \ 707 LOCALES="$(GLIBC_GENERATE_LOCALES)" \ 708 Q=$(Q) 709endef 710TARGET_FINALIZE_HOOKS += GENERATE_GLIBC_LOCALES 711endif 712endif 713 714ifeq ($(BR2_ENABLE_LOCALE_PURGE),y) 715LOCALE_WHITELIST = $(BUILD_DIR)/locales.nopurge 716LOCALE_NOPURGE = $(call qstrip,$(BR2_ENABLE_LOCALE_WHITELIST)) 717 718# This piece of junk does the following: 719# First collect the whitelist in a file. 720# Then go over all the locale dirs and for each subdir, check if it exists 721# in the whitelist file. If it doesn't, kill it. 722# Finally, specifically for X11, regenerate locale.dir from the whitelist. 723define PURGE_LOCALES 724 printf '%s\n' $(LOCALE_NOPURGE) locale-archive > $(LOCALE_WHITELIST) 725 726 for dir in $(addprefix $(TARGET_DIR),/usr/share/locale /usr/share/X11/locale /usr/lib/locale); \ 727 do \ 728 if [ ! -d $$dir ]; then continue; fi; \ 729 for langdir in $$dir/*; \ 730 do \ 731 if [ -e "$${langdir}" ]; \ 732 then \ 733 grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \ 734 fi \ 735 done; \ 736 done 737 if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \ 738 then \ 739 for lang in $(LOCALE_NOPURGE); \ 740 do \ 741 if [ -f $(TARGET_DIR)/usr/share/X11/locale/$$lang/XLC_LOCALE ]; \ 742 then \ 743 echo "$$lang/XLC_LOCALE: $$lang"; \ 744 fi \ 745 done > $(TARGET_DIR)/usr/share/X11/locale/locale.dir; \ 746 fi 747endef 748TARGET_FINALIZE_HOOKS += PURGE_LOCALES 749endif 750 751$(TARGETS_ROOTFS): target-finalize 752 753# Avoid the rootfs name leaking down the dependency chain 754target-finalize: ROOTFS= 755 756TARGET_DIR_FILES_LISTS = $(sort $(wildcard $(BUILD_DIR)/*/.files-list.txt)) 757HOST_DIR_FILES_LISTS = $(sort $(wildcard $(BUILD_DIR)/*/.files-list-host.txt)) 758STAGING_DIR_FILES_LISTS = $(sort $(wildcard $(BUILD_DIR)/*/.files-list-staging.txt)) 759 760.PHONY: host-finalize 761host-finalize: $(PACKAGES) $(HOST_DIR) $(HOST_DIR_SYMLINK) 762 @$(call MESSAGE,"Finalizing host directory") 763 $(call per-package-rsync,$(sort $(PACKAGES)),host,$(HOST_DIR)) 764 765.PHONY: staging-finalize 766staging-finalize: $(STAGING_DIR_SYMLINK) 767 768.PHONY: target-finalize 769target-finalize: $(PACKAGES) $(TARGET_DIR) host-finalize 770 @$(call MESSAGE,"Finalizing target directory") 771 $(call per-package-rsync,$(sort $(PACKAGES)),target,$(TARGET_DIR)) 772 $(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep)) 773 rm -rf $(TARGET_DIR)/usr/share/aclocal \ 774 $(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake \ 775 $(TARGET_DIR)/usr/doc 776 find $(TARGET_DIR)/usr/{lib,share}/ -name '*.cmake' -print0 | xargs -0 rm -f 777 find $(TARGET_DIR)/lib/ $(TARGET_DIR)/usr/lib/ $(TARGET_DIR)/usr/libexec/ \ 778 \( -name '*.la' -o -name '*.prl' \) -print0 | xargs -0 rm -f 779ifneq ($(BR2_PACKAGE_GCC_TARGET),y) 780 rm -rf $(TARGET_DIR)/usr/include \ 781 $(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig 782 find $(TARGET_DIR)/lib/ $(TARGET_DIR)/usr/lib/ $(TARGET_DIR)/usr/libexec/ \ 783 -name '*.a' -print0 | xargs -0 rm -f 784endif 785ifneq ($(BR2_PACKAGE_GDB),y) 786 rm -rf $(TARGET_DIR)/usr/share/gdb 787endif 788ifneq ($(BR2_PACKAGE_BASH),y) 789 rm -rf $(TARGET_DIR)/usr/share/bash-completion 790 rm -rf $(TARGET_DIR)/etc/bash_completion.d 791endif 792ifneq ($(BR2_PACKAGE_ZSH),y) 793 rm -rf $(TARGET_DIR)/usr/share/zsh 794endif 795 rm -rf $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/man 796 rm -rf $(TARGET_DIR)/usr/info $(TARGET_DIR)/usr/share/info 797 rm -rf $(TARGET_DIR)/usr/doc $(TARGET_DIR)/usr/share/doc 798 rm -rf $(TARGET_DIR)/usr/share/gtk-doc 799 rmdir $(TARGET_DIR)/usr/share 2>/dev/null || true 800ifneq ($(BR2_ENABLE_DEBUG):$(BR2_STRIP_strip),y:) 801 rm -rf $(TARGET_DIR)/lib/debug $(TARGET_DIR)/usr/lib/debug 802endif 803 $(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 2>/dev/null || true 804 $(STRIP_FIND_SPECIAL_LIBS_CMD) | xargs -0 -r $(STRIPCMD) $(STRIP_STRIP_DEBUG) 2>/dev/null || true 805 806ifneq ($(BR2_TOOLCHAIN_USES_GLIBC),y) 807 test -f $(TARGET_DIR)/etc/ld.so.conf && \ 808 { echo "ERROR: we shouldn't have a /etc/ld.so.conf file"; exit 1; } || true 809 test -d $(TARGET_DIR)/etc/ld.so.conf.d && \ 810 { echo "ERROR: we shouldn't have a /etc/ld.so.conf.d directory"; exit 1; } || true 811endif 812 813 mkdir -p $(TARGET_DIR)/etc 814 ( \ 815 echo "NAME=Buildroot"; \ 816 echo "VERSION=$(BR2_VERSION_FULL)"; \ 817 echo "ID=buildroot"; \ 818 echo "VERSION_ID=$(BR2_VERSION)"; \ 819 echo "PRETTY_NAME=\"Buildroot $(BR2_VERSION)\"" \ 820 ) > $(TARGET_DIR)/usr/lib/os-release 821 ln -sf ../usr/lib/os-release $(TARGET_DIR)/etc 822 823 @$(call MESSAGE,"Sanitizing RPATH in target tree") 824 PER_PACKAGE_DIR=$(PER_PACKAGE_DIR) $(TOPDIR)/support/scripts/fix-rpath target 825 826# For a merged /usr, ensure that /lib, /bin and /sbin and their /usr 827# counterparts are appropriately setup as symlinks ones to the others. 828ifeq ($(BR2_ROOTFS_MERGED_USR),y) 829 830 $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ 831 @$(call MESSAGE,"Sanity check in overlay $(d)")$(sep) \ 832 $(Q)not_merged_dirs="$$(support/scripts/check-merged-usr.sh $(d))"; \ 833 test -n "$$not_merged_dirs" && { \ 834 echo "ERROR: The overlay in $(d) is not" \ 835 "using a merged /usr for the following directories:" \ 836 $$not_merged_dirs; \ 837 exit 1; \ 838 } || true$(sep)) 839 840endif # merged /usr 841 842 $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ 843 @$(call MESSAGE,"Copying overlay $(d)")$(sep) \ 844 $(Q)$(call SYSTEM_RSYNC,$(d),$(TARGET_DIR))$(sep)) 845 846 $(Q)$(if $(TARGET_DIR_FILES_LISTS), \ 847 cat $(TARGET_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list.txt 848 $(Q)$(if $(HOST_DIR_FILES_LISTS), \ 849 cat $(HOST_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list-host.txt 850 $(Q)$(if $(STAGING_DIR_FILES_LISTS), \ 851 cat $(STAGING_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list-staging.txt 852 853 $(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_BUILD_SCRIPT)), \ 854 @$(call MESSAGE,"Executing post-build script $(s)")$(sep) \ 855 $(Q)$(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep)) 856 857 touch $(TARGET_DIR)/usr 858 859.PHONY: target-post-image 860target-post-image: $(TARGETS_ROOTFS) target-finalize staging-finalize 861 @rm -f $(ROOTFS_COMMON_TAR) 862 $(Q)mkdir -p $(BINARIES_DIR) 863 @$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT)), \ 864 $(call MESSAGE,"Executing post-image script $(s)"); \ 865 $(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep)) 866 867.PHONY: source 868source: $(foreach p,$(PACKAGES),$(p)-all-source) 869 870.PHONY: _external-deps external-deps 871_external-deps: $(foreach p,$(PACKAGES),$(p)-all-external-deps) 872external-deps: 873 @$(MAKE1) -Bs $(EXTRAMAKEARGS) _external-deps | sort -u 874 875.PHONY: legal-info-clean 876legal-info-clean: 877 @rm -fr $(LEGAL_INFO_DIR) 878 879.PHONY: legal-info-prepare 880legal-info-prepare: $(LEGAL_INFO_DIR) 881 @$(call MESSAGE,"Buildroot $(BR2_VERSION_FULL) Collecting legal info") 882 @$(call legal-license-file,buildroot,buildroot,support/legal-info/buildroot.hash,COPYING,COPYING,HOST) 883 @$(call legal-manifest,TARGET,PACKAGE,VERSION,LICENSE,LICENSE FILES,SOURCE ARCHIVE,SOURCE SITE,DEPENDENCIES WITH LICENSES) 884 @$(call legal-manifest,HOST,PACKAGE,VERSION,LICENSE,LICENSE FILES,SOURCE ARCHIVE,SOURCE SITE,DEPENDENCIES WITH LICENSES) 885 @$(call legal-manifest,HOST,buildroot,$(BR2_VERSION_FULL),GPL-2.0+,COPYING,not saved,not saved) 886 @$(call legal-warning,the Buildroot source code has not been saved) 887 @cp $(BR2_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config 888 889.PHONY: legal-info 890legal-info: legal-info-clean legal-info-prepare $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ 891 $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) 892 @cat support/legal-info/README.header >>$(LEGAL_REPORT) 893 @if [ -r $(LEGAL_WARNINGS) ]; then \ 894 cat support/legal-info/README.warnings-header \ 895 $(LEGAL_WARNINGS) >>$(LEGAL_REPORT); \ 896 cat $(LEGAL_WARNINGS); fi 897 @rm -f $(LEGAL_WARNINGS) 898 @(cd $(LEGAL_INFO_DIR); \ 899 find * -type f -exec sha256sum {} + | LC_ALL=C sort -k2 \ 900 >.legal-info.sha256; \ 901 mv .legal-info.sha256 legal-info.sha256) 902 @echo "Legal info produced in $(LEGAL_INFO_DIR)" 903 904.PHONY: show-targets 905show-targets: 906 @echo $(sort $(PACKAGES)) $(sort $(TARGETS_ROOTFS)) 907 908.PHONY: show-build-order 909show-build-order: $(patsubst %,%-show-build-order,$(PACKAGES)) 910 911.PHONY: graph-build 912graph-build: $(O)/build/build-time.log 913 @install -d $(GRAPHS_DIR) 914 $(foreach o,name build duration,./support/scripts/graph-build-time \ 915 --type=histogram --order=$(o) --input=$(<) \ 916 --output=$(GRAPHS_DIR)/build.hist-$(o).$(BR_GRAPH_OUT) \ 917 $(if $(BR2_GRAPH_ALT),--alternate-colors)$(sep)) 918 $(foreach t,packages steps,./support/scripts/graph-build-time \ 919 --type=pie-$(t) --input=$(<) \ 920 --output=$(GRAPHS_DIR)/build.pie-$(t).$(BR_GRAPH_OUT) \ 921 $(if $(BR2_GRAPH_ALT),--alternate-colors)$(sep)) 922 923.PHONY: graph-depends-requirements 924graph-depends-requirements: 925 @dot -? >/dev/null 2>&1 || \ 926 { echo "ERROR: The 'dot' program from Graphviz is needed for graph-depends" >&2; exit 1; } 927 928.PHONY: graph-depends 929graph-depends: graph-depends-requirements 930 @$(INSTALL) -d $(GRAPHS_DIR) 931 @cd "$(CONFIG_DIR)"; \ 932 $(TOPDIR)/support/scripts/graph-depends $(BR2_GRAPH_DEPS_OPTS) \ 933 --direct -o $(GRAPHS_DIR)/$(@).dot 934 dot $(BR2_GRAPH_DOT_OPTS) -T$(BR_GRAPH_OUT) \ 935 -o $(GRAPHS_DIR)/$(@).$(BR_GRAPH_OUT) \ 936 $(GRAPHS_DIR)/$(@).dot 937 938.PHONY: graph-size 939graph-size: 940 $(Q)mkdir -p $(GRAPHS_DIR) 941 $(Q)$(TOPDIR)/support/scripts/size-stats --builddir $(BASE_DIR) \ 942 --graph $(GRAPHS_DIR)/graph-size.$(BR_GRAPH_OUT) \ 943 --file-size-csv $(GRAPHS_DIR)/file-size-stats.csv \ 944 --package-size-csv $(GRAPHS_DIR)/package-size-stats.csv \ 945 $(BR2_GRAPH_SIZE_OPTS) 946 947.PHONY: check-dependencies 948check-dependencies: 949 @cd "$(CONFIG_DIR)"; \ 950 $(TOPDIR)/support/scripts/graph-depends -C 951 952.PHONY: show-info 953show-info: 954 @: 955 $(info $(call clean-json, \ 956 { $(foreach p, \ 957 $(sort $(foreach i,$(PACKAGES) $(TARGETS_ROOTFS), \ 958 $(i) \ 959 $($(call UPPERCASE,$(i))_FINAL_RECURSIVE_DEPENDENCIES) \ 960 ) \ 961 ), \ 962 $(call json-info,$(call UPPERCASE,$(p)))$(comma) \ 963 ) } \ 964 ) \ 965 ) 966 967.PHONY: pkg-stats 968pkg-stats: 969 @cd "$(CONFIG_DIR)" ; \ 970 $(TOPDIR)/support/scripts/pkg-stats -c \ 971 --json $(O)/pkg-stats.json \ 972 --html $(O)/pkg-stats.html \ 973 --nvd-path $(DL_DIR)/buildroot-nvd 974 975.PHONY: missing-cpe 976missing-cpe: 977 $(Q)mkdir -p $(CPE_UPDATES_DIR) 978 $(Q)cd "$(CONFIG_DIR)" ; \ 979 $(TOPDIR)/support/scripts/gen-missing-cpe \ 980 --nvd-path $(DL_DIR)/buildroot-nvd \ 981 --output $(CPE_UPDATES_DIR) 982 983else # ifeq ($(BR2_HAVE_DOT_CONFIG),y) 984 985# Some subdirectories are also package names. To avoid that "make linux" 986# on an unconfigured tree produces "Nothing to be done", add an explicit 987# rule for it. 988# Also for 'all' we error out and ask the user to configure first. 989.PHONY: linux toolchain 990linux toolchain all: outputmakefile 991 $(error Please configure Buildroot first (e.g. "make menuconfig")) 992 @exit 1 993 994endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y) 995 996# configuration 997# --------------------------------------------------------------------------- 998 999HOSTCFLAGS = $(CFLAGS_FOR_BUILD) 1000export HOSTCFLAGS 1001 1002$(BUILD_DIR)/buildroot-config/%onf: 1003 mkdir -p $(@D)/lxdialog 1004 PKG_CONFIG_PATH="$(HOST_PKG_CONFIG_PATH)" $(MAKE) CC="$(HOSTCC_NOCCACHE)" HOSTCC="$(HOSTCC_NOCCACHE)" \ 1005 obj=$(@D) -C $(CONFIG) -f Makefile.br $(@F) 1006 1007DEFCONFIG = $(call qstrip,$(BR2_DEFCONFIG)) 1008 1009# We don't want to fully expand BR2_DEFCONFIG here, so Kconfig will 1010# recognize that if it's still at its default $(CONFIG_DIR)/defconfig 1011COMMON_CONFIG_ENV = \ 1012 BR2_DEFCONFIG='$(call qstrip,$(value BR2_DEFCONFIG))' \ 1013 KCONFIG_AUTOCONFIG=$(BUILD_DIR)/buildroot-config/auto.conf \ 1014 KCONFIG_AUTOHEADER=$(BUILD_DIR)/buildroot-config/autoconf.h \ 1015 KCONFIG_TRISTATE=$(BUILD_DIR)/buildroot-config/tristate.config \ 1016 BR2_CONFIG=$(BR2_CONFIG) \ 1017 HOST_GCC_VERSION="$(HOSTCC_VERSION)" \ 1018 BASE_DIR=$(BASE_DIR) \ 1019 SKIP_LEGACY= \ 1020 CUSTOM_KERNEL_VERSION="$(CUSTOM_KERNEL_VERSION)" 1021 1022xconfig: $(BUILD_DIR)/buildroot-config/qconf outputmakefile 1023 @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN) 1024 1025gconfig: $(BUILD_DIR)/buildroot-config/gconf outputmakefile 1026 @$(COMMON_CONFIG_ENV) srctree=$(TOPDIR) $< $(CONFIG_CONFIG_IN) 1027 1028menuconfig: $(BUILD_DIR)/buildroot-config/mconf outputmakefile 1029 @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN) 1030 1031nconfig: $(BUILD_DIR)/buildroot-config/nconf outputmakefile 1032 @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN) 1033 1034config: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1035 @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN) 1036 1037# For the config targets that automatically select options, we pass 1038# SKIP_LEGACY=y to disable the legacy options. However, in that case 1039# no values are set for the legacy options so a subsequent oldconfig 1040# will query them. Therefore, run an additional olddefconfig. 1041 1042randconfig allyesconfig alldefconfig allnoconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1043 @$(COMMON_CONFIG_ENV) SKIP_LEGACY=y $< --$@ $(CONFIG_CONFIG_IN) 1044 @$(COMMON_CONFIG_ENV) $< --olddefconfig $(CONFIG_CONFIG_IN) >/dev/null 1045 1046randpackageconfig allyespackageconfig allnopackageconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1047 @grep -v BR2_PACKAGE_ $(BR2_CONFIG) > $(CONFIG_DIR)/.config.nopkg 1048 @$(COMMON_CONFIG_ENV) SKIP_LEGACY=y \ 1049 KCONFIG_ALLCONFIG=$(CONFIG_DIR)/.config.nopkg \ 1050 $< --$(subst package,,$@) $(CONFIG_CONFIG_IN) 1051 @rm -f $(CONFIG_DIR)/.config.nopkg 1052 @$(COMMON_CONFIG_ENV) $< --olddefconfig $(CONFIG_CONFIG_IN) >/dev/null 1053 1054oldconfig syncconfig olddefconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1055 @$(COMMON_CONFIG_ENV) $< --$@ $(CONFIG_CONFIG_IN) 1056 1057defconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1058 @$(COMMON_CONFIG_ENV) $< --defconfig$(if $(DEFCONFIG),=$(DEFCONFIG)) $(CONFIG_CONFIG_IN) 1059 1060define percent_defconfig 1061# Override the BR2_DEFCONFIG from COMMON_CONFIG_ENV with the new defconfig 1062rockchip_%_defconfig: $(BUILD_DIR)/buildroot-config/conf $(1)/configs/rockchip_%_defconfig outputmakefile 1063 $(TOPDIR)/build/parse_defconfig.sh $(1)/configs/$$@ \ 1064 $(BASE_DIR)/.config.in 1065 $$(COMMON_CONFIG_ENV) BR2_DEFCONFIG=$(1)/configs/$$@ \ 1066 $$< --defconfig=$(BASE_DIR)/.config.in $$(CONFIG_CONFIG_IN) 1067 1068%_defconfig: $(BUILD_DIR)/buildroot-config/conf $(1)/configs/%_defconfig outputmakefile 1069 $(TOPDIR)/build/parse_defconfig.sh $(1)/configs/$$@ \ 1070 $(BASE_DIR)/.config.in 1071 $$(COMMON_CONFIG_ENV) BR2_DEFCONFIG=$(1)/configs/$$@ \ 1072 $$< --defconfig=$(BASE_DIR)/.config.in $$(CONFIG_CONFIG_IN) 1073endef 1074$(eval $(foreach d,$(call reverse,$(TOPDIR) $(BR2_EXTERNAL_DIRS)),$(call percent_defconfig,$(d))$(sep))) 1075 1076update-defconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1077 $(TOPDIR)/build/update_defconfig.sh \ 1078 $(if $(DEFCONFIG),$(DEFCONFIG),$(CONFIG_DIR)/defconfig) 1079 1080savedefconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile 1081 @$(COMMON_CONFIG_ENV) $< \ 1082 --savedefconfig=$(if $(DEFCONFIG),$(DEFCONFIG),$(CONFIG_DIR)/defconfig) \ 1083 $(CONFIG_CONFIG_IN) 1084 @$(SED) '/^BR2_DEFCONFIG=/d' $(if $(DEFCONFIG),$(DEFCONFIG),$(CONFIG_DIR)/defconfig) 1085 1086.PHONY: defconfig savedefconfig update-defconfig 1087 1088################################################################################ 1089# 1090# Cleanup and misc junk 1091# 1092################################################################################ 1093 1094# staging and target directories do NOT list these as 1095# dependencies anywhere else 1096$(BUILD_DIR) $(BASE_TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) $(PER_PACKAGE_DIR): 1097 @mkdir -p $@ 1098 1099# outputmakefile generates a Makefile in the output directory, if using a 1100# separate output directory. This allows convenient use of make in the 1101# output directory. 1102.PHONY: outputmakefile 1103outputmakefile: 1104ifeq ($(NEED_WRAPPER),y) 1105 $(Q)$(TOPDIR)/support/scripts/mkmakefile $(TOPDIR) $(O) 1106endif 1107 1108# printvars prints all the variables currently defined in our 1109# Makefiles. Alternatively, if a non-empty VARS variable is passed, 1110# only the variables matching the make pattern passed in VARS are 1111# displayed. 1112.PHONY: printvars 1113printvars: 1114 @: 1115 $(foreach V, \ 1116 $(sort $(filter $(VARS),$(.VARIABLES))), \ 1117 $(if $(filter-out environment% default automatic, \ 1118 $(origin $V)), \ 1119 $(if $(QUOTED_VARS),\ 1120 $(info $V='$(subst ','\'',$(if $(RAW_VARS),$(value $V),$($V)))'), \ 1121 $(info $V=$(if $(RAW_VARS),$(value $V),$($V)))))) 1122# ')))) # Syntax colouring... 1123 1124.PHONY: clean 1125clean: 1126 rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \ 1127 $(BUILD_DIR) $(BASE_DIR)/staging \ 1128 $(LEGAL_INFO_DIR) $(GRAPHS_DIR) $(PER_PACKAGE_DIR) $(CPE_UPDATES_DIR) \ 1129 $(O)/pkg-stats.* 1130 1131.PHONY: distclean 1132distclean: clean 1133ifeq ($(O),$(CURDIR)/output) 1134 rm -rf $(O) 1135endif 1136 rm -rf $(TOPDIR)/dl $(BR2_CONFIG) $(CONFIG_DIR)/.config.old $(CONFIG_DIR)/..config.tmp \ 1137 $(CONFIG_DIR)/.auto.deps $(BASE_DIR)/.br2-external.* 1138 1139.PHONY: help 1140help: 1141 @echo 'Cleaning:' 1142 @echo ' clean - delete all files created by build' 1143 @echo ' distclean - delete all non-source files (including .config)' 1144 @echo 1145 @echo 'Build:' 1146 @echo ' all - make world' 1147 @echo ' toolchain - build toolchain' 1148 @echo ' sdk - build relocatable SDK' 1149 @echo ' reinstall - reinstall all' 1150 @echo 1151 @echo 'Configuration:' 1152 @echo ' menuconfig - interactive curses-based configurator' 1153 @echo ' nconfig - interactive ncurses-based configurator' 1154 @echo ' xconfig - interactive Qt-based configurator' 1155 @echo ' gconfig - interactive GTK-based configurator' 1156 @echo ' oldconfig - resolve any unresolved symbols in .config' 1157 @echo ' syncconfig - Same as oldconfig, but quietly, additionally update deps' 1158 @echo ' olddefconfig - Same as syncconfig but sets new symbols to their default value' 1159 @echo ' randconfig - New config with random answer to all options' 1160 @echo ' defconfig - New config with default answer to all options;' 1161 @echo ' BR2_DEFCONFIG, if set on the command line, is used as input' 1162 @echo ' savedefconfig - Save current config to BR2_DEFCONFIG (minimal config)' 1163 @echo ' update-defconfig - Same as savedefconfig, but with fragments' 1164 @echo ' allyesconfig - New config where all options are accepted with yes' 1165 @echo ' allnoconfig - New config where all options are answered with no' 1166 @echo ' alldefconfig - New config where all options are set to default' 1167 @echo ' randpackageconfig - New config with random answer to package options' 1168 @echo ' allyespackageconfig - New config where pkg options are accepted with yes' 1169 @echo ' allnopackageconfig - New config where package options are answered with no' 1170 @echo 1171 @echo 'Package-specific:' 1172 @echo ' <pkg> - Build and install <pkg> and all its dependencies' 1173 @echo ' <pkg>-source - Only download the source files for <pkg>' 1174 @echo ' <pkg>-extract - Extract <pkg> sources' 1175 @echo ' <pkg>-patch - Apply patches to <pkg>' 1176 @echo ' <pkg>-depends - Build <pkg>'\''s dependencies' 1177 @echo ' <pkg>-configure - Build <pkg> up to the configure step' 1178 @echo ' <pkg>-build - Build <pkg> up to the build step' 1179 @echo ' <pkg>-show-info - generate info about <pkg>, as a JSON blurb' 1180 @echo ' <pkg>-show-depends - List packages on which <pkg> depends' 1181 @echo ' <pkg>-show-rdepends - List packages which have <pkg> as a dependency' 1182 @echo ' <pkg>-show-recursive-depends' 1183 @echo ' - Recursively list packages on which <pkg> depends' 1184 @echo ' <pkg>-show-recursive-rdepends' 1185 @echo ' - Recursively list packages which have <pkg> as a dependency' 1186 @echo ' <pkg>-graph-depends - Generate a graph of <pkg>'\''s dependencies' 1187 @echo ' <pkg>-graph-rdepends - Generate a graph of <pkg>'\''s reverse dependencies' 1188 @echo ' <pkg>-dirclean - Remove <pkg> build directory' 1189 @echo ' <pkg>-reconfigure - Restart the build from the configure step' 1190 @echo ' <pkg>-rebuild - Restart the build from the build step' 1191 @echo ' <pkg>-reinstall - Restart the build from the install step' 1192 $(foreach p,$(HELP_PACKAGES), \ 1193 @echo $(sep) \ 1194 @echo '$($(p)_NAME):' $(sep) \ 1195 $($(p)_HELP_CMDS)$(sep)) 1196 @echo 1197 @echo 'Documentation:' 1198 @echo ' manual - build manual in all formats' 1199 @echo ' manual-html - build manual in HTML' 1200 @echo ' manual-split-html - build manual in split HTML' 1201 @echo ' manual-pdf - build manual in PDF' 1202 @echo ' manual-text - build manual in text' 1203 @echo ' manual-epub - build manual in ePub' 1204 @echo ' graph-build - generate graphs of the build times' 1205 @echo ' graph-depends - generate graph of the dependency tree' 1206 @echo ' graph-size - generate stats of the filesystem size' 1207 @echo ' list-defconfigs - list all defconfigs (pre-configured minimal systems)' 1208 @echo 1209 @echo 'Miscellaneous:' 1210 @echo ' source - download all sources needed for offline-build' 1211 @echo ' external-deps - list external packages used' 1212 @echo ' legal-info - generate info about license compliance' 1213 @echo ' show-info - generate info about packages, as a JSON blurb' 1214 @echo ' pkg-stats - generate info about packages as JSON and HTML' 1215 @echo ' missing-cpe - generate XML snippets for missing CPE identifiers' 1216 @echo ' printvars - dump internal variables selected with VARS=...' 1217 @echo 1218 @echo ' make V=0|1 - 0 => quiet build (default), 1 => verbose build' 1219 @echo ' make O=dir - Locate all output files in "dir", including .config' 1220 @echo 1221 @echo 'For further details, see README, generate the Buildroot manual, or consult' 1222 @echo 'it on-line at http://buildroot.org/docs.html' 1223 @echo 1224 1225# List the defconfig files 1226# $(1): base directory 1227# $(2): br2-external name, empty for bundled 1228define list-defconfigs 1229 @first=true; \ 1230 for defconfig in $(1)/configs/*_defconfig; do \ 1231 [ -f "$${defconfig}" ] || continue; \ 1232 if $${first}; then \ 1233 if [ "$(2)" ]; then \ 1234 printf 'External configs in "$(call qstrip,$(2))":\n'; \ 1235 else \ 1236 printf "Built-in configs:\n"; \ 1237 fi; \ 1238 first=false; \ 1239 fi; \ 1240 defconfig="$${defconfig##*/}"; \ 1241 printf " %-35s - Build for %s\n" "$${defconfig}" "$${defconfig%_defconfig}"; \ 1242 done; \ 1243 $${first} || printf "\n" 1244endef 1245 1246# We iterate over BR2_EXTERNAL_NAMES rather than BR2_EXTERNAL_DIRS, 1247# because we want to display the name of the br2-external tree. 1248.PHONY: list-defconfigs 1249list-defconfigs: 1250 $(call list-defconfigs,$(TOPDIR)) 1251 $(foreach name,$(BR2_EXTERNAL_NAMES),\ 1252 $(call list-defconfigs,$(BR2_EXTERNAL_$(name)_PATH),\ 1253 $(BR2_EXTERNAL_$(name)_DESC))$(sep)) 1254 1255release: OUT = buildroot-$(BR2_VERSION) 1256 1257# Create release tarballs. We need to fiddle a bit to add the generated 1258# documentation to the git output 1259release: 1260 git archive --format=tar --prefix=$(OUT)/ HEAD > $(OUT).tar 1261 $(MAKE) O=$(OUT) manual-html manual-text manual-pdf 1262 $(MAKE) O=$(OUT) distclean 1263 tar rf $(OUT).tar $(OUT) 1264 gzip -9 -c < $(OUT).tar > $(OUT).tar.gz 1265 xz -9 -c < $(OUT).tar > $(OUT).tar.xz 1266 rm -rf $(OUT) $(OUT).tar 1267 1268print-version: 1269 @echo $(BR2_VERSION_FULL) 1270 1271check-flake8: 1272 $(Q)git ls-tree -r --name-only HEAD \ 1273 | xargs file \ 1274 | grep 'Python script' \ 1275 | cut -d':' -f1 \ 1276 | xargs -- python3 -m flake8 --statistics 1277 1278check-package: 1279 find $(TOPDIR) -type f \( -name '*.mk' -o -name '*.hash' -o -name 'Config.*' \) \ 1280 -exec ./utils/check-package {} + 1281 1282include docs/manual/manual.mk 1283-include $(foreach dir,$(BR2_EXTERNAL_DIRS),$(sort $(wildcard $(dir)/docs/*/*.mk))) 1284 1285.PHONY: $(noconfig_targets) 1286 1287endif #umask / $(CURDIR) / $(O) 1288