Makefile 46 KB

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