"Fossies" - the Fresh Open Source Software Archive

Member "buildroot-2021.05/Makefile" (6 Jun 2021, 45908 Bytes) of package /linux/privat/buildroot-2021.05.tar.bz2:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes reports for "Makefile": 2021.05-rc3_vs_2021.05 or 2021.02.2_vs_2021.05.

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