Makefile 45 KB

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