Makefile 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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.02-git
  80. # Actual time the release is cut (for reproducible builds)
  81. BR2_VERSION_EPOCH = 1638734000
  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. GNU_HOST_NAME := $(shell support/gnuconfig/config.guess)
  372. PACKAGES :=
  373. PACKAGES_ALL :=
  374. # silent mode requested?
  375. QUIET := $(if $(findstring s,$(filter-out --%,$(MAKEFLAGS))),-q)
  376. # Strip off the annoying quoting
  377. ARCH := $(call qstrip,$(BR2_ARCH))
  378. NORMALIZED_ARCH := $(call qstrip,$(BR2_NORMALIZED_ARCH))
  379. KERNEL_ARCH := $(call qstrip,$(BR2_NORMALIZED_ARCH))
  380. ZCAT := $(call qstrip,$(BR2_ZCAT))
  381. BZCAT := $(call qstrip,$(BR2_BZCAT))
  382. XZCAT := $(call qstrip,$(BR2_XZCAT))
  383. LZCAT := $(call qstrip,$(BR2_LZCAT))
  384. TAR_OPTIONS = $(call qstrip,$(BR2_TAR_OPTIONS)) -xf
  385. ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),y)
  386. HOST_DIR = $(if $(PKG),$(PER_PACKAGE_DIR)/$($(PKG)_NAME)/host,$(call qstrip,$(BR2_HOST_DIR)))
  387. TARGET_DIR = $(if $(ROOTFS),$(ROOTFS_$(ROOTFS)_TARGET_DIR),$(if $(PKG),$(PER_PACKAGE_DIR)/$($(PKG)_NAME)/target,$(BASE_TARGET_DIR)))
  388. else
  389. HOST_DIR := $(call qstrip,$(BR2_HOST_DIR))
  390. TARGET_DIR = $(if $(ROOTFS),$(ROOTFS_$(ROOTFS)_TARGET_DIR),$(BASE_TARGET_DIR))
  391. endif
  392. ifneq ($(HOST_DIR),$(BASE_DIR)/host)
  393. HOST_DIR_SYMLINK = $(BASE_DIR)/host
  394. $(HOST_DIR_SYMLINK): | $(BASE_DIR)
  395. ln -snf $(HOST_DIR) $(HOST_DIR_SYMLINK)
  396. endif
  397. STAGING_DIR_SYMLINK = $(BASE_DIR)/staging
  398. $(STAGING_DIR_SYMLINK): | $(BASE_DIR)
  399. ln -snf $(STAGING_DIR) $(STAGING_DIR_SYMLINK)
  400. # Quotes are needed for spaces and all in the original PATH content.
  401. BR_PATH = "$(HOST_DIR)/bin:$(HOST_DIR)/sbin:$(PATH)"
  402. # Location of a file giving a big fat warning that output/target
  403. # should not be used as the root filesystem.
  404. TARGET_DIR_WARNING_FILE = $(TARGET_DIR)/THIS_IS_NOT_YOUR_ROOT_FILESYSTEM
  405. ifeq ($(BR2_CCACHE),y)
  406. CCACHE = $(HOST_DIR)/bin/ccache
  407. BR_CACHE_DIR ?= $(call qstrip,$(BR2_CCACHE_DIR))
  408. export BR_CACHE_DIR
  409. HOSTCC = $(CCACHE) $(HOSTCC_NOCCACHE)
  410. HOSTCXX = $(CCACHE) $(HOSTCXX_NOCCACHE)
  411. else
  412. export BR_NO_CCACHE
  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. ifeq ($$($(2)_IS_VIRTUAL),)
  484. ifneq ($$($$($(2)_KCONFIG_VAR)),y)
  485. $$(error $$($(2)_NAME) is in the dependency chain of $$($(1)_NAME) that \
  486. has added it to its _DEPENDENCIES variable without selecting it or \
  487. depending on it from Config.in)
  488. endif
  489. endif
  490. endif
  491. endef
  492. $(foreach pkg,$(call UPPERCASE,$(PACKAGES)),\
  493. $(foreach dep,$(call UPPERCASE,$($(pkg)_FINAL_ALL_DEPENDENCIES)),\
  494. $(eval $(call CHECK_ONE_DEPENDENCY,$(pkg),$(dep))$(sep))))
  495. endif
  496. $(BUILD_DIR)/buildroot-config/auto.conf: $(BR2_CONFIG)
  497. $(MAKE1) $(EXTRAMAKEARGS) HOSTCC="$(HOSTCC_NOCCACHE)" HOSTCXX="$(HOSTCXX_NOCCACHE)" syncconfig
  498. .PHONY: prepare
  499. prepare: $(BUILD_DIR)/buildroot-config/auto.conf
  500. @$(foreach s, $(call qstrip,$(BR2_ROOTFS_PRE_BUILD_SCRIPT)), \
  501. $(call MESSAGE,"Executing pre-build script $(s)"); \
  502. $(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
  503. .PHONY: world
  504. world: target-post-image
  505. .PHONY: prepare-sdk
  506. prepare-sdk: world
  507. @$(call MESSAGE,"Rendering the SDK relocatable")
  508. PER_PACKAGE_DIR=$(PER_PACKAGE_DIR) $(TOPDIR)/support/scripts/fix-rpath host
  509. PER_PACKAGE_DIR=$(PER_PACKAGE_DIR) $(TOPDIR)/support/scripts/fix-rpath staging
  510. $(INSTALL) -m 755 $(TOPDIR)/support/misc/relocate-sdk.sh $(HOST_DIR)/relocate-sdk.sh
  511. mkdir -p $(HOST_DIR)/share/buildroot
  512. echo $(HOST_DIR) > $(HOST_DIR)/share/buildroot/sdk-location
  513. BR2_SDK_PREFIX ?= $(GNU_TARGET_NAME)_sdk-buildroot
  514. .PHONY: sdk
  515. sdk: prepare-sdk $(BR2_TAR_HOST_DEPENDENCY)
  516. @$(call MESSAGE,"Generating SDK tarball")
  517. $(if $(BR2_SDK_PREFIX),,$(error BR2_SDK_PREFIX can not be empty))
  518. $(Q)mkdir -p $(BINARIES_DIR)
  519. $(TAR) czf "$(BINARIES_DIR)/$(BR2_SDK_PREFIX).tar.gz" \
  520. --owner=0 --group=0 --numeric-owner \
  521. --transform='s#^$(patsubst /%,%,$(HOST_DIR))#$(BR2_SDK_PREFIX)#' \
  522. -C / $(patsubst /%,%,$(HOST_DIR))
  523. RSYNC_VCS_EXCLUSIONS = \
  524. --exclude .svn --exclude .git --exclude .hg --exclude .bzr \
  525. --exclude CVS
  526. # When stripping, obey to BR2_STRIP_EXCLUDE_DIRS and
  527. # BR2_STRIP_EXCLUDE_FILES
  528. STRIP_FIND_COMMON_CMD = \
  529. find $(TARGET_DIR) \
  530. $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS)), \
  531. \( $(call finddirclauses,$(TARGET_DIR),$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) \) \
  532. -prune -o \
  533. ) \
  534. $(if $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES)), \
  535. -not \( $(call findfileclauses,$(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) )
  536. # Regular stripping for everything, except libpthread, ld-*.so and
  537. # kernel modules:
  538. # - libpthread.so: a non-stripped libpthread shared library is needed for
  539. # proper debugging of pthread programs using gdb.
  540. # - ld.so: a non-stripped dynamic linker library is needed for valgrind
  541. # - kernel modules (*.ko): do not function properly when stripped like normal
  542. # applications and libraries. Normally kernel modules are already excluded
  543. # by the executable permission check, so the explicit exclusion is only
  544. # done for kernel modules with incorrect permissions.
  545. STRIP_FIND_CMD = \
  546. $(STRIP_FIND_COMMON_CMD) \
  547. -type f \( -perm /111 -o -name '*.so*' \) \
  548. -not \( $(call findfileclauses,libpthread*.so* ld-*.so* *.ko) \) \
  549. -print0
  550. # Special stripping (only debugging symbols) for libpthread and ld-*.so.
  551. STRIP_FIND_SPECIAL_LIBS_CMD = \
  552. $(STRIP_FIND_COMMON_CMD) \
  553. \( -name 'ld-*.so*' -o -name 'libpthread*.so*' \) \
  554. -print0
  555. ifeq ($(BR2_ECLIPSE_REGISTER),y)
  556. define TOOLCHAIN_ECLIPSE_REGISTER
  557. ./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \
  558. $(notdir $(TARGET_CROSS)) $(BR2_ARCH)
  559. endef
  560. TARGET_FINALIZE_HOOKS += TOOLCHAIN_ECLIPSE_REGISTER
  561. endif
  562. # Generate locale data.
  563. ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),y)
  564. GLIBC_GENERATE_LOCALES = $(call qstrip,$(BR2_GENERATE_LOCALE))
  565. ifneq ($(GLIBC_GENERATE_LOCALES),)
  566. PACKAGES += host-localedef
  567. define GENERATE_GLIBC_LOCALES
  568. $(MAKE) -f support/misc/gen-glibc-locales.mk \
  569. ENDIAN=$(call LOWERCASE,$(BR2_ENDIAN)) \
  570. LOCALES="$(GLIBC_GENERATE_LOCALES)" \
  571. Q=$(Q)
  572. endef
  573. TARGET_FINALIZE_HOOKS += GENERATE_GLIBC_LOCALES
  574. endif
  575. endif
  576. ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
  577. LOCALE_WHITELIST = $(BUILD_DIR)/locales.nopurge
  578. LOCALE_NOPURGE = $(call qstrip,$(BR2_ENABLE_LOCALE_WHITELIST))
  579. # This piece of junk does the following:
  580. # First collect the whitelist in a file.
  581. # Then go over all the locale dirs and for each subdir, check if it exists
  582. # in the whitelist file. If it doesn't, kill it.
  583. # Finally, specifically for X11, regenerate locale.dir from the whitelist.
  584. define PURGE_LOCALES
  585. printf '%s\n' $(LOCALE_NOPURGE) locale-archive > $(LOCALE_WHITELIST)
  586. for dir in $(addprefix $(TARGET_DIR),/usr/share/locale /usr/share/X11/locale /usr/lib/locale); \
  587. do \
  588. if [ ! -d $$dir ]; then continue; fi; \
  589. for langdir in $$dir/*; \
  590. do \
  591. if [ -e "$${langdir}" ]; \
  592. then \
  593. grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
  594. fi \
  595. done; \
  596. done
  597. if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
  598. then \
  599. for lang in $(LOCALE_NOPURGE); \
  600. do \
  601. if [ -f $(TARGET_DIR)/usr/share/X11/locale/$$lang/XLC_LOCALE ]; \
  602. then \
  603. echo "$$lang/XLC_LOCALE: $$lang"; \
  604. fi \
  605. done > $(TARGET_DIR)/usr/share/X11/locale/locale.dir; \
  606. fi
  607. endef
  608. TARGET_FINALIZE_HOOKS += PURGE_LOCALES
  609. endif
  610. $(TARGETS_ROOTFS): target-finalize
  611. # Avoid the rootfs name leaking down the dependency chain
  612. target-finalize: ROOTFS=
  613. TARGET_DIR_FILES_LISTS = $(sort $(wildcard $(BUILD_DIR)/*/.files-list.txt))
  614. HOST_DIR_FILES_LISTS = $(sort $(wildcard $(BUILD_DIR)/*/.files-list-host.txt))
  615. STAGING_DIR_FILES_LISTS = $(sort $(wildcard $(BUILD_DIR)/*/.files-list-staging.txt))
  616. .PHONY: host-finalize
  617. host-finalize: $(PACKAGES) $(HOST_DIR) $(HOST_DIR_SYMLINK)
  618. @$(call MESSAGE,"Finalizing host directory")
  619. $(call per-package-rsync,$(sort $(PACKAGES)),host,$(HOST_DIR))
  620. .PHONY: staging-finalize
  621. staging-finalize: $(STAGING_DIR_SYMLINK)
  622. .PHONY: target-finalize
  623. target-finalize: $(PACKAGES) $(TARGET_DIR) host-finalize
  624. @$(call MESSAGE,"Finalizing target directory")
  625. $(call per-package-rsync,$(sort $(PACKAGES)),target,$(TARGET_DIR))
  626. $(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep))
  627. rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/share/aclocal \
  628. $(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig \
  629. $(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake \
  630. $(TARGET_DIR)/usr/doc
  631. find $(TARGET_DIR)/usr/{lib,share}/ -name '*.cmake' -print0 | xargs -0 rm -f
  632. find $(TARGET_DIR)/lib/ $(TARGET_DIR)/usr/lib/ $(TARGET_DIR)/usr/libexec/ \
  633. \( -name '*.a' -o -name '*.la' -o -name '*.prl' \) -print0 | xargs -0 rm -f
  634. ifneq ($(BR2_PACKAGE_GDB),y)
  635. rm -rf $(TARGET_DIR)/usr/share/gdb
  636. endif
  637. ifneq ($(BR2_PACKAGE_BASH),y)
  638. rm -rf $(TARGET_DIR)/usr/share/bash-completion
  639. rm -rf $(TARGET_DIR)/etc/bash_completion.d
  640. endif
  641. ifneq ($(BR2_PACKAGE_ZSH),y)
  642. rm -rf $(TARGET_DIR)/usr/share/zsh
  643. endif
  644. rm -rf $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/man
  645. rm -rf $(TARGET_DIR)/usr/info $(TARGET_DIR)/usr/share/info
  646. rm -rf $(TARGET_DIR)/usr/doc $(TARGET_DIR)/usr/share/doc
  647. rm -rf $(TARGET_DIR)/usr/share/gtk-doc
  648. rmdir $(TARGET_DIR)/usr/share 2>/dev/null || true
  649. ifneq ($(BR2_ENABLE_DEBUG):$(BR2_STRIP_strip),y:)
  650. rm -rf $(TARGET_DIR)/lib/debug $(TARGET_DIR)/usr/lib/debug
  651. endif
  652. $(STRIP_FIND_CMD) | xargs -0 $(STRIPCMD) 2>/dev/null || true
  653. $(STRIP_FIND_SPECIAL_LIBS_CMD) | xargs -0 -r $(STRIPCMD) $(STRIP_STRIP_DEBUG) 2>/dev/null || true
  654. test -f $(TARGET_DIR)/etc/ld.so.conf && \
  655. { echo "ERROR: we shouldn't have a /etc/ld.so.conf file"; exit 1; } || true
  656. test -d $(TARGET_DIR)/etc/ld.so.conf.d && \
  657. { echo "ERROR: we shouldn't have a /etc/ld.so.conf.d directory"; exit 1; } || true
  658. mkdir -p $(TARGET_DIR)/etc
  659. ( \
  660. echo "NAME=Buildroot"; \
  661. echo "VERSION=$(BR2_VERSION_FULL)"; \
  662. echo "ID=buildroot"; \
  663. echo "VERSION_ID=$(BR2_VERSION)"; \
  664. echo "PRETTY_NAME=\"Buildroot $(BR2_VERSION)\"" \
  665. ) > $(TARGET_DIR)/usr/lib/os-release
  666. ln -sf ../usr/lib/os-release $(TARGET_DIR)/etc
  667. @$(call MESSAGE,"Sanitizing RPATH in target tree")
  668. PER_PACKAGE_DIR=$(PER_PACKAGE_DIR) $(TOPDIR)/support/scripts/fix-rpath target
  669. # For a merged /usr, ensure that /lib, /bin and /sbin and their /usr
  670. # counterparts are appropriately setup as symlinks ones to the others.
  671. ifeq ($(BR2_ROOTFS_MERGED_USR),y)
  672. $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \
  673. @$(call MESSAGE,"Sanity check in overlay $(d)")$(sep) \
  674. $(Q)not_merged_dirs="$$(support/scripts/check-merged-usr.sh $(d))"; \
  675. test -n "$$not_merged_dirs" && { \
  676. echo "ERROR: The overlay in $(d) is not" \
  677. "using a merged /usr for the following directories:" \
  678. $$not_merged_dirs; \
  679. exit 1; \
  680. } || true$(sep))
  681. endif # merged /usr
  682. $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \
  683. @$(call MESSAGE,"Copying overlay $(d)")$(sep) \
  684. $(Q)$(call SYSTEM_RSYNC,$(d),$(TARGET_DIR))$(sep))
  685. $(Q)$(if $(TARGET_DIR_FILES_LISTS), \
  686. cat $(TARGET_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list.txt
  687. $(Q)$(if $(HOST_DIR_FILES_LISTS), \
  688. cat $(HOST_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list-host.txt
  689. $(Q)$(if $(STAGING_DIR_FILES_LISTS), \
  690. cat $(STAGING_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list-staging.txt
  691. $(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_BUILD_SCRIPT)), \
  692. @$(call MESSAGE,"Executing post-build script $(s)")$(sep) \
  693. $(Q)$(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
  694. touch $(TARGET_DIR)/usr
  695. .PHONY: target-post-image
  696. target-post-image: $(TARGETS_ROOTFS) target-finalize staging-finalize
  697. @rm -f $(ROOTFS_COMMON_TAR)
  698. $(Q)mkdir -p $(BINARIES_DIR)
  699. @$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT)), \
  700. $(call MESSAGE,"Executing post-image script $(s)"); \
  701. $(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
  702. .PHONY: source
  703. source: $(foreach p,$(PACKAGES),$(p)-all-source)
  704. .PHONY: _external-deps external-deps
  705. _external-deps: $(foreach p,$(PACKAGES),$(p)-all-external-deps)
  706. external-deps:
  707. @$(MAKE1) -Bs $(EXTRAMAKEARGS) _external-deps | sort -u
  708. .PHONY: legal-info-clean
  709. legal-info-clean:
  710. @rm -fr $(LEGAL_INFO_DIR)
  711. .PHONY: legal-info-prepare
  712. legal-info-prepare: $(LEGAL_INFO_DIR)
  713. @$(call MESSAGE,"Buildroot $(BR2_VERSION_FULL) Collecting legal info")
  714. @$(call legal-license-file,buildroot,buildroot,support/legal-info/buildroot.hash,COPYING,COPYING,HOST)
  715. @$(call legal-manifest,TARGET,PACKAGE,VERSION,LICENSE,LICENSE FILES,SOURCE ARCHIVE,SOURCE SITE,DEPENDENCIES WITH LICENSES)
  716. @$(call legal-manifest,HOST,PACKAGE,VERSION,LICENSE,LICENSE FILES,SOURCE ARCHIVE,SOURCE SITE,DEPENDENCIES WITH LICENSES)
  717. @$(call legal-manifest,HOST,buildroot,$(BR2_VERSION_FULL),GPL-2.0+,COPYING,not saved,not saved)
  718. @$(call legal-warning,the Buildroot source code has not been saved)
  719. @cp $(BR2_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config
  720. .PHONY: legal-info
  721. legal-info: legal-info-clean legal-info-prepare $(foreach p,$(PACKAGES),$(p)-all-legal-info) \
  722. $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST)
  723. @cat support/legal-info/README.header >>$(LEGAL_REPORT)
  724. @if [ -r $(LEGAL_WARNINGS) ]; then \
  725. cat support/legal-info/README.warnings-header \
  726. $(LEGAL_WARNINGS) >>$(LEGAL_REPORT); \
  727. cat $(LEGAL_WARNINGS); fi
  728. @rm -f $(LEGAL_WARNINGS)
  729. @(cd $(LEGAL_INFO_DIR); \
  730. find * -type f -exec sha256sum {} + | LC_ALL=C sort -k2 \
  731. >.legal-info.sha256; \
  732. mv .legal-info.sha256 legal-info.sha256)
  733. @echo "Legal info produced in $(LEGAL_INFO_DIR)"
  734. .PHONY: show-targets
  735. show-targets:
  736. @echo $(sort $(PACKAGES)) $(sort $(TARGETS_ROOTFS))
  737. .PHONY: show-build-order
  738. show-build-order: $(patsubst %,%-show-build-order,$(PACKAGES))
  739. .PHONY: graph-build
  740. graph-build: $(O)/build/build-time.log
  741. @install -d $(GRAPHS_DIR)
  742. $(foreach o,name build duration,./support/scripts/graph-build-time \
  743. --type=histogram --order=$(o) --input=$(<) \
  744. --output=$(GRAPHS_DIR)/build.hist-$(o).$(BR_GRAPH_OUT) \
  745. $(if $(BR2_GRAPH_ALT),--alternate-colors)$(sep))
  746. $(foreach t,packages steps,./support/scripts/graph-build-time \
  747. --type=pie-$(t) --input=$(<) \
  748. --output=$(GRAPHS_DIR)/build.pie-$(t).$(BR_GRAPH_OUT) \
  749. $(if $(BR2_GRAPH_ALT),--alternate-colors)$(sep))
  750. .PHONY: graph-depends-requirements
  751. graph-depends-requirements:
  752. @dot -? >/dev/null 2>&1 || \
  753. { echo "ERROR: The 'dot' program from Graphviz is needed for graph-depends" >&2; exit 1; }
  754. .PHONY: graph-depends
  755. graph-depends: graph-depends-requirements
  756. @$(INSTALL) -d $(GRAPHS_DIR)
  757. @cd "$(CONFIG_DIR)"; \
  758. $(TOPDIR)/support/scripts/graph-depends $(BR2_GRAPH_DEPS_OPTS) \
  759. --direct -o $(GRAPHS_DIR)/$(@).dot
  760. dot $(BR2_GRAPH_DOT_OPTS) -T$(BR_GRAPH_OUT) \
  761. -o $(GRAPHS_DIR)/$(@).$(BR_GRAPH_OUT) \
  762. $(GRAPHS_DIR)/$(@).dot
  763. .PHONY: graph-size
  764. graph-size:
  765. $(Q)mkdir -p $(GRAPHS_DIR)
  766. $(Q)$(TOPDIR)/support/scripts/size-stats --builddir $(BASE_DIR) \
  767. --graph $(GRAPHS_DIR)/graph-size.$(BR_GRAPH_OUT) \
  768. --file-size-csv $(GRAPHS_DIR)/file-size-stats.csv \
  769. --package-size-csv $(GRAPHS_DIR)/package-size-stats.csv \
  770. $(BR2_GRAPH_SIZE_OPTS)
  771. .PHONY: check-dependencies
  772. check-dependencies:
  773. @cd "$(CONFIG_DIR)"; \
  774. $(TOPDIR)/support/scripts/graph-depends -C
  775. .PHONY: show-info
  776. show-info:
  777. @:
  778. $(info $(call clean-json, \
  779. { $(foreach p, \
  780. $(sort $(foreach i,$(PACKAGES) $(TARGETS_ROOTFS), \
  781. $(i) \
  782. $($(call UPPERCASE,$(i))_FINAL_RECURSIVE_DEPENDENCIES) \
  783. ) \
  784. ), \
  785. $(call json-info,$(call UPPERCASE,$(p)))$(comma) \
  786. ) } \
  787. ) \
  788. )
  789. .PHONY: pkg-stats
  790. pkg-stats:
  791. @cd "$(CONFIG_DIR)" ; \
  792. $(TOPDIR)/support/scripts/pkg-stats -c \
  793. --json $(O)/pkg-stats.json \
  794. --html $(O)/pkg-stats.html \
  795. --nvd-path $(DL_DIR)/buildroot-nvd
  796. .PHONY: missing-cpe
  797. missing-cpe:
  798. $(Q)mkdir -p $(CPE_UPDATES_DIR)
  799. $(Q)cd "$(CONFIG_DIR)" ; \
  800. $(TOPDIR)/support/scripts/gen-missing-cpe \
  801. --nvd-path $(DL_DIR)/buildroot-nvd \
  802. --output $(CPE_UPDATES_DIR)
  803. else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
  804. # Some subdirectories are also package names. To avoid that "make linux"
  805. # on an unconfigured tree produces "Nothing to be done", add an explicit
  806. # rule for it.
  807. # Also for 'all' we error out and ask the user to configure first.
  808. .PHONY: linux toolchain
  809. linux toolchain all: outputmakefile
  810. $(error Please configure Buildroot first (e.g. "make menuconfig"))
  811. @exit 1
  812. endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
  813. # configuration
  814. # ---------------------------------------------------------------------------
  815. HOSTCFLAGS = $(CFLAGS_FOR_BUILD)
  816. export HOSTCFLAGS
  817. $(BUILD_DIR)/buildroot-config/%onf:
  818. mkdir -p $(@D)/lxdialog
  819. PKG_CONFIG_PATH="$(HOST_PKG_CONFIG_PATH)" $(MAKE) CC="$(HOSTCC_NOCCACHE)" HOSTCC="$(HOSTCC_NOCCACHE)" \
  820. obj=$(@D) -C $(CONFIG) -f Makefile.br $(@F)
  821. DEFCONFIG = $(call qstrip,$(BR2_DEFCONFIG))
  822. # We don't want to fully expand BR2_DEFCONFIG here, so Kconfig will
  823. # recognize that if it's still at its default $(CONFIG_DIR)/defconfig
  824. COMMON_CONFIG_ENV = \
  825. BR2_DEFCONFIG='$(call qstrip,$(value BR2_DEFCONFIG))' \
  826. KCONFIG_AUTOCONFIG=$(BUILD_DIR)/buildroot-config/auto.conf \
  827. KCONFIG_AUTOHEADER=$(BUILD_DIR)/buildroot-config/autoconf.h \
  828. KCONFIG_TRISTATE=$(BUILD_DIR)/buildroot-config/tristate.config \
  829. BR2_CONFIG=$(BR2_CONFIG) \
  830. HOST_GCC_VERSION="$(HOSTCC_VERSION)" \
  831. BASE_DIR=$(BASE_DIR) \
  832. SKIP_LEGACY=
  833. xconfig: $(BUILD_DIR)/buildroot-config/qconf outputmakefile
  834. @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN)
  835. gconfig: $(BUILD_DIR)/buildroot-config/gconf outputmakefile
  836. @$(COMMON_CONFIG_ENV) srctree=$(TOPDIR) $< $(CONFIG_CONFIG_IN)
  837. menuconfig: $(BUILD_DIR)/buildroot-config/mconf outputmakefile
  838. @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN)
  839. nconfig: $(BUILD_DIR)/buildroot-config/nconf outputmakefile
  840. @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN)
  841. config: $(BUILD_DIR)/buildroot-config/conf outputmakefile
  842. @$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN)
  843. # For the config targets that automatically select options, we pass
  844. # SKIP_LEGACY=y to disable the legacy options. However, in that case
  845. # no values are set for the legacy options so a subsequent oldconfig
  846. # will query them. Therefore, run an additional olddefconfig.
  847. randconfig allyesconfig alldefconfig allnoconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
  848. @$(COMMON_CONFIG_ENV) SKIP_LEGACY=y $< --$@ $(CONFIG_CONFIG_IN)
  849. @$(COMMON_CONFIG_ENV) $< --olddefconfig $(CONFIG_CONFIG_IN) >/dev/null
  850. randpackageconfig allyespackageconfig allnopackageconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
  851. @grep -v BR2_PACKAGE_ $(BR2_CONFIG) > $(CONFIG_DIR)/.config.nopkg
  852. @$(COMMON_CONFIG_ENV) SKIP_LEGACY=y \
  853. KCONFIG_ALLCONFIG=$(CONFIG_DIR)/.config.nopkg \
  854. $< --$(subst package,,$@) $(CONFIG_CONFIG_IN)
  855. @rm -f $(CONFIG_DIR)/.config.nopkg
  856. @$(COMMON_CONFIG_ENV) $< --olddefconfig $(CONFIG_CONFIG_IN) >/dev/null
  857. oldconfig syncconfig olddefconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
  858. @$(COMMON_CONFIG_ENV) $< --$@ $(CONFIG_CONFIG_IN)
  859. defconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
  860. @$(COMMON_CONFIG_ENV) $< --defconfig$(if $(DEFCONFIG),=$(DEFCONFIG)) $(CONFIG_CONFIG_IN)
  861. define percent_defconfig
  862. # Override the BR2_DEFCONFIG from COMMON_CONFIG_ENV with the new defconfig
  863. %_defconfig: $(BUILD_DIR)/buildroot-config/conf $(1)/configs/%_defconfig outputmakefile
  864. @$$(COMMON_CONFIG_ENV) BR2_DEFCONFIG=$(1)/configs/$$@ \
  865. $$< --defconfig=$(1)/configs/$$@ $$(CONFIG_CONFIG_IN)
  866. endef
  867. $(eval $(foreach d,$(call reverse,$(TOPDIR) $(BR2_EXTERNAL_DIRS)),$(call percent_defconfig,$(d))$(sep)))
  868. update-defconfig: savedefconfig
  869. savedefconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
  870. @$(COMMON_CONFIG_ENV) $< \
  871. --savedefconfig=$(if $(DEFCONFIG),$(DEFCONFIG),$(CONFIG_DIR)/defconfig) \
  872. $(CONFIG_CONFIG_IN)
  873. @$(SED) '/^BR2_DEFCONFIG=/d' $(if $(DEFCONFIG),$(DEFCONFIG),$(CONFIG_DIR)/defconfig)
  874. .PHONY: defconfig savedefconfig update-defconfig
  875. ################################################################################
  876. #
  877. # Cleanup and misc junk
  878. #
  879. ################################################################################
  880. # staging and target directories do NOT list these as
  881. # dependencies anywhere else
  882. $(BUILD_DIR) $(BASE_TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) $(PER_PACKAGE_DIR):
  883. @mkdir -p $@
  884. # outputmakefile generates a Makefile in the output directory, if using a
  885. # separate output directory. This allows convenient use of make in the
  886. # output directory.
  887. .PHONY: outputmakefile
  888. outputmakefile:
  889. ifeq ($(NEED_WRAPPER),y)
  890. $(Q)$(TOPDIR)/support/scripts/mkmakefile $(TOPDIR) $(O)
  891. endif
  892. .PHONY: check-make-version
  893. check-make-version:
  894. ifneq ($(filter $(RUNNING_MAKE_VERSION),4.3),)
  895. @echo "Make 4.3 doesn't support 'printvars' and 'show-vars' recipes"
  896. @exit 1
  897. endif
  898. # printvars prints all the variables currently defined in our
  899. # Makefiles. Alternatively, if a non-empty VARS variable is passed,
  900. # only the variables matching the make pattern passed in VARS are
  901. # displayed.
  902. # show-vars does the same, but as a JSON dictionnary.
  903. .PHONY: printvars
  904. printvars: check-make-version
  905. @:
  906. $(foreach V, \
  907. $(sort $(filter $(VARS),$(.VARIABLES))), \
  908. $(if $(filter-out environment% default automatic, \
  909. $(origin $V)), \
  910. $(if $(QUOTED_VARS),\
  911. $(info $V='$(subst ','\'',$(if $(RAW_VARS),$(value $V),$($V)))'), \
  912. $(info $V=$(if $(RAW_VARS),$(value $V),$($V))))))
  913. # ')))) # Syntax colouring...
  914. .PHONY: show-vars
  915. show-vars: VARS?=%
  916. show-vars: check-make-version
  917. @:
  918. $(info $(call clean-json, { \
  919. $(foreach V, \
  920. $(sort $(filter $(VARS),$(.VARIABLES))), \
  921. $(if $(filter-out environment% default automatic, $(origin $V)), \
  922. "$V": { \
  923. "expanded": $(call mk-json-str,$($V))$(comma) \
  924. "raw": $(call mk-json-str,$(value $V)) \
  925. }$(comma) \
  926. ) \
  927. ) \
  928. } ))
  929. .PHONY: clean
  930. clean:
  931. rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
  932. $(BUILD_DIR) $(BASE_DIR)/staging \
  933. $(LEGAL_INFO_DIR) $(GRAPHS_DIR) $(PER_PACKAGE_DIR) $(CPE_UPDATES_DIR) \
  934. $(O)/pkg-stats.*
  935. .PHONY: distclean
  936. distclean: clean
  937. ifeq ($(O),$(CURDIR)/output)
  938. rm -rf $(O)
  939. endif
  940. rm -rf $(TOPDIR)/dl $(BR2_CONFIG) $(CONFIG_DIR)/.config.old $(CONFIG_DIR)/..config.tmp \
  941. $(CONFIG_DIR)/.auto.deps $(BASE_DIR)/.br2-external.*
  942. .PHONY: help
  943. help:
  944. @echo 'Cleaning:'
  945. @echo ' clean - delete all files created by build'
  946. @echo ' distclean - delete all non-source files (including .config)'
  947. @echo
  948. @echo 'Build:'
  949. @echo ' all - make world'
  950. @echo ' toolchain - build toolchain'
  951. @echo ' sdk - build relocatable SDK'
  952. @echo
  953. @echo 'Configuration:'
  954. @echo ' menuconfig - interactive curses-based configurator'
  955. @echo ' nconfig - interactive ncurses-based configurator'
  956. @echo ' xconfig - interactive Qt-based configurator'
  957. @echo ' gconfig - interactive GTK-based configurator'
  958. @echo ' oldconfig - resolve any unresolved symbols in .config'
  959. @echo ' syncconfig - Same as oldconfig, but quietly, additionally update deps'
  960. @echo ' olddefconfig - Same as syncconfig but sets new symbols to their default value'
  961. @echo ' randconfig - New config with random answer to all options'
  962. @echo ' defconfig - New config with default answer to all options;'
  963. @echo ' BR2_DEFCONFIG, if set on the command line, is used as input'
  964. @echo ' savedefconfig - Save current config to BR2_DEFCONFIG (minimal config)'
  965. @echo ' update-defconfig - Same as savedefconfig'
  966. @echo ' allyesconfig - New config where all options are accepted with yes'
  967. @echo ' allnoconfig - New config where all options are answered with no'
  968. @echo ' alldefconfig - New config where all options are set to default'
  969. @echo ' randpackageconfig - New config with random answer to package options'
  970. @echo ' allyespackageconfig - New config where pkg options are accepted with yes'
  971. @echo ' allnopackageconfig - New config where package options are answered with no'
  972. @echo
  973. @echo 'Package-specific:'
  974. @echo ' <pkg> - Build and install <pkg> and all its dependencies'
  975. @echo ' <pkg>-source - Only download the source files for <pkg>'
  976. @echo ' <pkg>-extract - Extract <pkg> sources'
  977. @echo ' <pkg>-patch - Apply patches to <pkg>'
  978. @echo ' <pkg>-depends - Build <pkg>'\''s dependencies'
  979. @echo ' <pkg>-configure - Build <pkg> up to the configure step'
  980. @echo ' <pkg>-build - Build <pkg> up to the build step'
  981. @echo ' <pkg>-show-info - generate info about <pkg>, as a JSON blurb'
  982. @echo ' <pkg>-show-depends - List packages on which <pkg> depends'
  983. @echo ' <pkg>-show-rdepends - List packages which have <pkg> as a dependency'
  984. @echo ' <pkg>-show-recursive-depends'
  985. @echo ' - Recursively list packages on which <pkg> depends'
  986. @echo ' <pkg>-show-recursive-rdepends'
  987. @echo ' - Recursively list packages which have <pkg> as a dependency'
  988. @echo ' <pkg>-graph-depends - Generate a graph of <pkg>'\''s dependencies'
  989. @echo ' <pkg>-graph-rdepends - Generate a graph of <pkg>'\''s reverse dependencies'
  990. @echo ' <pkg>-dirclean - Remove <pkg> build directory'
  991. @echo ' <pkg>-reconfigure - Restart the build from the configure step'
  992. @echo ' <pkg>-rebuild - Restart the build from the build step'
  993. @echo ' <pkg>-reinstall - Restart the build from the install step'
  994. $(foreach p,$(HELP_PACKAGES), \
  995. @echo $(sep) \
  996. @echo '$($(p)_NAME):' $(sep) \
  997. $($(p)_HELP_CMDS)$(sep))
  998. @echo
  999. @echo 'Documentation:'
  1000. @echo ' manual - build manual in all formats'
  1001. @echo ' manual-html - build manual in HTML'
  1002. @echo ' manual-split-html - build manual in split HTML'
  1003. @echo ' manual-pdf - build manual in PDF'
  1004. @echo ' manual-text - build manual in text'
  1005. @echo ' manual-epub - build manual in ePub'
  1006. @echo ' graph-build - generate graphs of the build times'
  1007. @echo ' graph-depends - generate graph of the dependency tree'
  1008. @echo ' graph-size - generate stats of the filesystem size'
  1009. @echo ' list-defconfigs - list all defconfigs (pre-configured minimal systems)'
  1010. @echo
  1011. @echo 'Miscellaneous:'
  1012. @echo ' source - download all sources needed for offline-build'
  1013. @echo ' external-deps - list external packages used'
  1014. @echo ' legal-info - generate info about license compliance'
  1015. @echo ' show-info - generate info about packages, as a JSON blurb'
  1016. @echo ' pkg-stats - generate info about packages as JSON and HTML'
  1017. @echo ' missing-cpe - generate XML snippets for missing CPE identifiers'
  1018. @echo ' printvars - dump internal variables selected with VARS=...'
  1019. @echo ' show-vars - dump all internal variables as a JSON blurb; use VARS=...'
  1020. @echo ' to limit the list to variables names matching that pattern'
  1021. @echo
  1022. @echo ' make V=0|1 - 0 => quiet build (default), 1 => verbose build'
  1023. @echo ' make O=dir - Locate all output files in "dir", including .config'
  1024. @echo
  1025. @echo 'For further details, see README, generate the Buildroot manual, or consult'
  1026. @echo 'it on-line at http://buildroot.org/docs.html'
  1027. @echo
  1028. # List the defconfig files
  1029. # $(1): base directory
  1030. # $(2): br2-external name, empty for bundled
  1031. define list-defconfigs
  1032. @first=true; \
  1033. for defconfig in $(1)/configs/*_defconfig; do \
  1034. [ -f "$${defconfig}" ] || continue; \
  1035. if $${first}; then \
  1036. if [ "$(2)" ]; then \
  1037. printf 'External configs in "$(call qstrip,$(2))":\n'; \
  1038. else \
  1039. printf "Built-in configs:\n"; \
  1040. fi; \
  1041. first=false; \
  1042. fi; \
  1043. defconfig="$${defconfig##*/}"; \
  1044. printf " %-35s - Build for %s\n" "$${defconfig}" "$${defconfig%_defconfig}"; \
  1045. done; \
  1046. $${first} || printf "\n"
  1047. endef
  1048. # We iterate over BR2_EXTERNAL_NAMES rather than BR2_EXTERNAL_DIRS,
  1049. # because we want to display the name of the br2-external tree.
  1050. .PHONY: list-defconfigs
  1051. list-defconfigs:
  1052. $(call list-defconfigs,$(TOPDIR))
  1053. $(foreach name,$(BR2_EXTERNAL_NAMES),\
  1054. $(call list-defconfigs,$(BR2_EXTERNAL_$(name)_PATH),\
  1055. $(BR2_EXTERNAL_$(name)_DESC))$(sep))
  1056. release: OUT = buildroot-$(BR2_VERSION)
  1057. # Create release tarballs. We need to fiddle a bit to add the generated
  1058. # documentation to the git output
  1059. release:
  1060. git archive --format=tar --prefix=$(OUT)/ HEAD > $(OUT).tar
  1061. $(MAKE) O=$(OUT) manual-html manual-text manual-pdf
  1062. $(MAKE) O=$(OUT) distclean
  1063. tar rf $(OUT).tar $(OUT)
  1064. gzip -9 -c < $(OUT).tar > $(OUT).tar.gz
  1065. xz -9 -c < $(OUT).tar > $(OUT).tar.xz
  1066. rm -rf $(OUT) $(OUT).tar
  1067. print-version:
  1068. @echo $(BR2_VERSION_FULL)
  1069. check-flake8:
  1070. $(Q)git ls-tree -r --name-only HEAD \
  1071. | xargs file \
  1072. | grep 'Python script' \
  1073. | cut -d':' -f1 \
  1074. | xargs -- python3 -m flake8 --statistics
  1075. check-package:
  1076. find $(TOPDIR) -type f \( -name '*.mk' -o -name '*.hash' -o -name 'Config.*' -o -name '*.patch' \) \
  1077. -exec ./utils/check-package --exclude=Sob --exclude=HashSpaces {} +
  1078. include docs/manual/manual.mk
  1079. -include $(foreach dir,$(BR2_EXTERNAL_DIRS),$(sort $(wildcard $(dir)/docs/*/*.mk)))
  1080. .PHONY: $(noconfig_targets)
  1081. endif #umask / $(CURDIR) / $(O)