2
1

Makefile 45 KB

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