pkg-generic.mk 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. ################################################################################
  2. # Generic package infrastructure
  3. #
  4. # This file implements an infrastructure that eases development of
  5. # package .mk files. It should be used for packages that do not rely
  6. # on a well-known build system for which Buildroot has a dedicated
  7. # infrastructure (so far, Buildroot has special support for
  8. # autotools-based and CMake-based packages).
  9. #
  10. # See the Buildroot documentation for details on the usage of this
  11. # infrastructure
  12. #
  13. # In terms of implementation, this generic infrastructure requires the
  14. # .mk file to specify:
  15. #
  16. # 1. Metadata information about the package: name, version,
  17. # download URL, etc.
  18. #
  19. # 2. Description of the commands to be executed to configure, build
  20. # and install the package
  21. ################################################################################
  22. ################################################################################
  23. # Helper functions to catch start/end of each step
  24. ################################################################################
  25. # Those two functions are called by each step below.
  26. # They are responsible for calling all hooks defined in
  27. # $(GLOBAL_INSTRUMENTATION_HOOKS) and pass each of them
  28. # three arguments:
  29. # $1: either 'start' or 'end'
  30. # $2: the name of the step
  31. # $3: the name of the package
  32. # Start step
  33. # $1: step name
  34. define step_start
  35. $(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),start,$(1),$($(PKG)_NAME))$(sep))
  36. endef
  37. # End step
  38. # $1: step name
  39. define step_end
  40. $(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),end,$(1),$($(PKG)_NAME))$(sep))
  41. endef
  42. #######################################
  43. # Actual steps hooks
  44. # Time steps
  45. define step_time
  46. printf "%s:%-5.5s:%-20.20s: %s\n" \
  47. "$$(date +%s.%N)" "$(1)" "$(2)" "$(3)" \
  48. >>"$(BUILD_DIR)/build-time.log"
  49. endef
  50. GLOBAL_INSTRUMENTATION_HOOKS += step_time
  51. # Hooks to collect statistics about installed files
  52. # The suffix is typically empty for the target variant, for legacy backward
  53. # compatibility.
  54. # $(1): package name
  55. # $(2): base directory to search in
  56. # $(3): suffix of file (optional)
  57. define step_pkg_size_inner
  58. @touch $(BUILD_DIR)/.files-list$(3).stat
  59. @touch $(BUILD_DIR)/packages-file-list$(3).txt
  60. $(SED) '/^$(1),/d' $(BUILD_DIR)/packages-file-list$(3).txt
  61. cd $(2); \
  62. LC_ALL=C find . \( -type f -o -type l \) -printf '%T@:%i:%#m:%y:%s,%p\n' \
  63. | LC_ALL=C sort > $(BUILD_DIR)/.files-list$(3).new
  64. LC_ALL=C comm -13 \
  65. $(BUILD_DIR)/.files-list$(3).stat \
  66. $(BUILD_DIR)/.files-list$(3).new \
  67. > $($(PKG)_BUILDDIR)/.files-list$(3).txt
  68. sed -r -e 's/^[^,]+/$(1)/' \
  69. $($(PKG)_BUILDDIR)/.files-list$(3).txt \
  70. >> $(BUILD_DIR)/packages-file-list$(3).txt
  71. mv $(BUILD_DIR)/.files-list$(3).new \
  72. $(BUILD_DIR)/.files-list$(3).stat
  73. endef
  74. define step_pkg_size
  75. $(if $(filter install-target,$(2)),\
  76. $(if $(filter end,$(1)),$(call step_pkg_size_inner,$(3),$(TARGET_DIR))))
  77. $(if $(filter install-staging,$(2)),\
  78. $(if $(filter end,$(1)),$(call step_pkg_size_inner,$(3),$(STAGING_DIR),-staging)))
  79. $(if $(filter install-host,$(2)),\
  80. $(if $(filter end,$(1)),$(call step_pkg_size_inner,$(3),$(HOST_DIR),-host)))
  81. endef
  82. GLOBAL_INSTRUMENTATION_HOOKS += step_pkg_size
  83. # Relies on step_pkg_size, so must be after
  84. define check_bin_arch
  85. $(if $(filter end-install-target,$(1)-$(2)),\
  86. support/scripts/check-bin-arch -p $(3) \
  87. -l $(BUILD_DIR)/packages-file-list.txt \
  88. $(foreach i,$($(PKG)_BIN_ARCH_EXCLUDE),-i "$(i)") \
  89. -r $(TARGET_READELF) \
  90. -a $(BR2_READELF_ARCH_NAME))
  91. endef
  92. GLOBAL_INSTRUMENTATION_HOOKS += check_bin_arch
  93. # This hook checks that host packages that need libraries that we build
  94. # have a proper DT_RPATH or DT_RUNPATH tag
  95. define check_host_rpath
  96. $(if $(filter install-host,$(2)),\
  97. $(if $(filter end,$(1)),support/scripts/check-host-rpath $(3) $(HOST_DIR) $(PER_PACKAGE_DIR)))
  98. endef
  99. GLOBAL_INSTRUMENTATION_HOOKS += check_host_rpath
  100. define step_check_build_dir_one
  101. if [ -d $(2) ]; then \
  102. printf "%s: installs files in %s\n" $(1) $(2) >&2; \
  103. exit 1; \
  104. fi
  105. endef
  106. define step_check_build_dir
  107. $(if $(filter install-staging,$(2)),\
  108. $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(STAGING_DIR)/$(O))))
  109. $(if $(filter install-target,$(2)),\
  110. $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))
  111. endef
  112. GLOBAL_INSTRUMENTATION_HOOKS += step_check_build_dir
  113. # User-supplied script
  114. ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
  115. define step_user
  116. @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
  117. $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
  118. endef
  119. GLOBAL_INSTRUMENTATION_HOOKS += step_user
  120. endif
  121. ################################################################################
  122. # Implicit targets -- produce a stamp file for each step of a package build
  123. ################################################################################
  124. # Retrieve the archive
  125. $(BUILD_DIR)/%/.stamp_downloaded:
  126. @$(call step_start,download)
  127. $(call prepare-per-package-directory,$($(PKG)_FINAL_DOWNLOAD_DEPENDENCIES))
  128. $(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
  129. # Only show the download message if it isn't already downloaded
  130. $(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
  131. if test ! -e $($(PKG)_DL_DIR)/`basename $$p` ; then \
  132. $(call MESSAGE,"Downloading") ; \
  133. break ; \
  134. fi ; \
  135. done
  136. $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p),$(PKG))$(sep))
  137. $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
  138. $(Q)mkdir -p $(@D)
  139. @$(call step_end,download)
  140. $(Q)touch $@
  141. # Retrieve actual source archive, e.g. for prebuilt external toolchains
  142. $(BUILD_DIR)/%/.stamp_actual_downloaded:
  143. @$(call step_start,actual-download)
  144. $(call DOWNLOAD,$($(PKG)_ACTUAL_SOURCE_SITE)/$($(PKG)_ACTUAL_SOURCE_TARBALL),$(PKG))
  145. $(Q)mkdir -p $(@D)
  146. @$(call step_end,actual-download)
  147. $(Q)touch $@
  148. # Unpack the archive
  149. $(BUILD_DIR)/%/.stamp_extracted:
  150. @$(call step_start,extract)
  151. @$(call MESSAGE,"Extracting")
  152. $(call prepare-per-package-directory,$($(PKG)_FINAL_EXTRACT_DEPENDENCIES))
  153. $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
  154. $(Q)mkdir -p $(@D)
  155. $($(PKG)_EXTRACT_CMDS)
  156. # some packages have messed up permissions inside
  157. $(Q)chmod -R +rw $(@D)
  158. $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
  159. @$(call step_end,extract)
  160. $(Q)touch $@
  161. # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
  162. # used.
  163. $(BUILD_DIR)/%/.stamp_rsynced:
  164. @$(call step_start,rsync)
  165. @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
  166. @mkdir -p $(@D)
  167. $(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
  168. @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
  169. rsync -au --chmod=u=rwX,go=rX $($(PKG)_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS) $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
  170. $(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
  171. @$(call step_end,rsync)
  172. $(Q)touch $@
  173. # Patch
  174. #
  175. # The RAWNAME variable is the lowercased package name, which allows to
  176. # find the package directory (typically package/<pkgname>) and the
  177. # prefix of the patches
  178. #
  179. # For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
  180. $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS = $(PKGDIR)
  181. $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
  182. $(BUILD_DIR)/%/.stamp_patched:
  183. @$(call step_start,patch)
  184. @$(call MESSAGE,"Patching")
  185. $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
  186. $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $($(PKG)_DL_DIR) $(notdir $(p))$(sep))
  187. $(Q)( \
  188. for D in $(PATCH_BASE_DIRS); do \
  189. if test -d $${D}; then \
  190. if test -d $${D}/$($(PKG)_VERSION); then \
  191. $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
  192. else \
  193. $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
  194. fi; \
  195. fi; \
  196. done; \
  197. )
  198. $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
  199. @$(call step_end,patch)
  200. $(Q)touch $@
  201. # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
  202. $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
  203. $(if $(wildcard $(dir)),,\
  204. $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
  205. # Configure
  206. $(BUILD_DIR)/%/.stamp_configured:
  207. @$(call step_start,configure)
  208. @$(call MESSAGE,"Configuring")
  209. $(call prepare-per-package-directory,$($(PKG)_FINAL_DEPENDENCIES))
  210. $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
  211. $($(PKG)_CONFIGURE_CMDS)
  212. $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
  213. @$(call step_end,configure)
  214. $(Q)touch $@
  215. # Build
  216. $(BUILD_DIR)/%/.stamp_built::
  217. @$(call step_start,build)
  218. @$(call MESSAGE,"Building")
  219. $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
  220. +$($(PKG)_BUILD_CMDS)
  221. $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
  222. @$(call step_end,build)
  223. $(Q)touch $@
  224. # Install to host dir
  225. $(BUILD_DIR)/%/.stamp_host_installed:
  226. @$(call step_start,install-host)
  227. @$(call MESSAGE,"Installing to host directory")
  228. @mkdir -p $(HOST_DIR)
  229. $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
  230. +$($(PKG)_INSTALL_CMDS)
  231. $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
  232. @$(call step_end,install-host)
  233. $(Q)touch $@
  234. # Install to staging dir
  235. #
  236. # Some packages install libtool .la files alongside any installed
  237. # libraries. These .la files sometimes refer to paths relative to the
  238. # sysroot, which libtool will interpret as absolute paths to host
  239. # libraries instead of the target libraries. Since this is not what we
  240. # want, these paths are fixed by prefixing them with $(STAGING_DIR).
  241. # As we configure with --prefix=/usr, this fix needs to be applied to
  242. # any path that starts with /usr.
  243. #
  244. # To protect against the case that the output or staging directories or
  245. # the pre-installed external toolchain themselves are under /usr, we first
  246. # substitute away any occurrences of these directories with @BASE_DIR@,
  247. # @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
  248. #
  249. # Note that STAGING_DIR can be outside BASE_DIR when the user sets
  250. # BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
  251. # can be under @BASE_DIR@ when it's a downloaded toolchain, and can be
  252. # empty when we use an internal toolchain.
  253. #
  254. $(BUILD_DIR)/%/.stamp_staging_installed:
  255. @$(call step_start,install-staging)
  256. @$(call MESSAGE,"Installing to staging directory")
  257. @mkdir -p $(STAGING_DIR)
  258. $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
  259. +$($(PKG)_INSTALL_STAGING_CMDS)
  260. $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
  261. $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
  262. $(call MESSAGE,"Fixing package configuration files") ;\
  263. $(SED) "s,$(HOST_DIR),@HOST_DIR@,g" \
  264. -e "s,$(BASE_DIR),@BASE_DIR@,g" \
  265. -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
  266. -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
  267. -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
  268. -e 's,@STAGING_DIR@,$$(dirname $$(readlink -e $$0))/../..,g' \
  269. -e 's,@HOST_DIR@,$$(dirname $$(readlink -e $$0))/../../../..,g' \
  270. -e "s,@BASE_DIR@,$(BASE_DIR),g" \
  271. $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
  272. fi
  273. @$(call MESSAGE,"Fixing libtool files")
  274. for la in $$(find $(STAGING_DIR)/usr/lib* -name "*.la"); do \
  275. cp -a "$${la}" "$${la}.fixed" && \
  276. $(SED) "s:$(BASE_DIR):@BASE_DIR@:g" \
  277. -e "s:$(STAGING_DIR):@STAGING_DIR@:g" \
  278. $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
  279. -e "s:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
  280. -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
  281. $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
  282. -e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
  283. -e "s:@STAGING_DIR@:$(STAGING_DIR):g" \
  284. -e "s:@BASE_DIR@:$(BASE_DIR):g" \
  285. "$${la}.fixed" && \
  286. if cmp -s "$${la}" "$${la}.fixed"; then \
  287. rm -f "$${la}.fixed"; \
  288. else \
  289. mv "$${la}.fixed" "$${la}"; \
  290. fi || exit 1; \
  291. done
  292. @$(call step_end,install-staging)
  293. $(Q)touch $@
  294. # Install to images dir
  295. $(BUILD_DIR)/%/.stamp_images_installed:
  296. @$(call step_start,install-image)
  297. @mkdir -p $(BINARIES_DIR)
  298. $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
  299. @$(call MESSAGE,"Installing to images directory")
  300. +$($(PKG)_INSTALL_IMAGES_CMDS)
  301. $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
  302. @$(call step_end,install-image)
  303. $(Q)touch $@
  304. # Install to target dir
  305. $(BUILD_DIR)/%/.stamp_target_installed:
  306. @$(call step_start,install-target)
  307. @$(call MESSAGE,"Installing to target")
  308. @mkdir -p $(TARGET_DIR)
  309. $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
  310. +$($(PKG)_INSTALL_TARGET_CMDS)
  311. $(if $(BR2_INIT_SYSTEMD),\
  312. $($(PKG)_INSTALL_INIT_SYSTEMD))
  313. $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
  314. $($(PKG)_INSTALL_INIT_SYSV))
  315. $(if $(BR2_INIT_OPENRC), \
  316. $(or $($(PKG)_INSTALL_INIT_OPENRC), \
  317. $($(PKG)_INSTALL_INIT_SYSV)))
  318. $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
  319. $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
  320. $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
  321. fi
  322. @$(call step_end,install-target)
  323. $(Q)touch $@
  324. # Remove package sources
  325. $(BUILD_DIR)/%/.stamp_dircleaned:
  326. $(if $(BR2_PER_PACKAGE_DIRECTORIES),rm -Rf $(PER_PACKAGE_DIR)/$(NAME))
  327. rm -Rf $(@D)
  328. ################################################################################
  329. # virt-provides-single -- check that provider-pkg is the declared provider for
  330. # the virtual package virt-pkg
  331. #
  332. # argument 1 is the lower-case name of the virtual package
  333. # argument 2 is the upper-case name of the virtual package
  334. # argument 3 is the lower-case name of the provider
  335. #
  336. # example:
  337. # $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
  338. ################################################################################
  339. define virt-provides-single
  340. ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
  341. $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
  342. are selected as providers for virtual package "$(1)". Only one provider can\
  343. be selected at a time. Please fix your configuration)
  344. endif
  345. endef
  346. define pkg-graph-depends
  347. @$$(INSTALL) -d $$(GRAPHS_DIR)
  348. @cd "$$(CONFIG_DIR)"; \
  349. $$(TOPDIR)/support/scripts/graph-depends $$(BR2_GRAPH_DEPS_OPTS) \
  350. -p $(1) $(2) -o $$(GRAPHS_DIR)/$$(@).dot
  351. dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) \
  352. -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT) \
  353. $$(GRAPHS_DIR)/$$(@).dot
  354. endef
  355. ################################################################################
  356. # inner-generic-package -- generates the make targets needed to build a
  357. # generic package
  358. #
  359. # argument 1 is the lowercase package name
  360. # argument 2 is the uppercase package name, including a HOST_ prefix
  361. # for host packages
  362. # argument 3 is the uppercase package name, without the HOST_ prefix
  363. # for host packages
  364. # argument 4 is the type (target or host)
  365. #
  366. # Note about variable and function references: inside all blocks that are
  367. # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
  368. # specific rules apply with respect to variable and function references.
  369. # - Numbered variables (parameters to the block) can be referenced with a single
  370. # dollar sign: $(1), $(2), $(3), etc.
  371. # - pkgdir and pkgname should be referenced with a single dollar sign too. These
  372. # functions rely on 'the most recently parsed makefile' which is supposed to
  373. # be the package .mk file. If we defer the evaluation of these functions using
  374. # double dollar signs, then they may be evaluated too late, when other
  375. # makefiles have already been parsed. One specific case is when $$(pkgdir) is
  376. # assigned to a variable using deferred evaluation with '=' and this variable
  377. # is used in a target rule outside the eval'ed inner block. In this case, the
  378. # pkgdir will be that of the last makefile parsed by buildroot, which is not
  379. # the expected value. This mechanism is for example used for the TARGET_PATCH
  380. # rule.
  381. # - All other variables should be referenced with a double dollar sign:
  382. # $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
  383. # referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
  384. # etc. This rule ensures that these variables and functions are only expanded
  385. # during the $(eval) step, and not earlier. Otherwise, unintuitive and
  386. # undesired behavior occurs with respect to these variables and functions.
  387. #
  388. ################################################################################
  389. define inner-generic-package
  390. # When doing a package, we're definitely not doing a rootfs, but we
  391. # may inherit it via the dependency chain, so we reset it.
  392. $(1): ROOTFS=
  393. # Ensure the package is only declared once, i.e. do not accept that a
  394. # package be re-defined by a br2-external tree
  395. ifneq ($(call strip,$(filter $(1),$(PACKAGES_ALL))),)
  396. $$(error Package '$(1)' defined a second time in '$(pkgdir)'; \
  397. previous definition was in '$$($(2)_PKGDIR)')
  398. endif
  399. PACKAGES_ALL += $(1)
  400. # Define default values for various package-related variables, if not
  401. # already defined. For some variables (version, source, site and
  402. # subdir), if they are undefined, we try to see if a variable without
  403. # the HOST_ prefix is defined. If so, we use such a variable, so that
  404. # this information has only to be specified once, for both the
  405. # target and host packages of a given .mk file.
  406. $(2)_TYPE = $(4)
  407. $(2)_NAME = $(1)
  408. $(2)_RAWNAME = $$(patsubst host-%,%,$(1))
  409. $(2)_PKGDIR = $(pkgdir)
  410. # Keep the package version that may contain forward slashes in the _DL_VERSION
  411. # variable, then replace all forward slashes ('/') by underscores ('_') to
  412. # sanitize the package version that is used in paths, directory and file names.
  413. # Forward slashes may appear in the package's version when pointing to a
  414. # version control system branch or tag, for example remotes/origin/1_10_stable.
  415. # Similar for spaces and colons (:) that may appear in date-based revisions for
  416. # CVS.
  417. ifndef $(2)_VERSION
  418. ifdef $(3)_DL_VERSION
  419. $(2)_DL_VERSION := $$($(3)_DL_VERSION)
  420. else ifdef $(3)_VERSION
  421. $(2)_DL_VERSION := $$($(3)_VERSION)
  422. endif
  423. else
  424. $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
  425. endif
  426. $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
  427. $(2)_HASH_FILE = \
  428. $$(strip \
  429. $$(if $$(wildcard $$($(2)_PKGDIR)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash),\
  430. $$($(2)_PKGDIR)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash,\
  431. $$($(2)_PKGDIR)/$$($(2)_RAWNAME).hash))
  432. ifdef $(3)_OVERRIDE_SRCDIR
  433. $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
  434. endif
  435. $(2)_BASENAME = $$(if $$($(2)_VERSION),$(1)-$$($(2)_VERSION),$(1))
  436. $(2)_BASENAME_RAW = $$(if $$($(2)_VERSION),$$($(2)_RAWNAME)-$$($(2)_VERSION),$$($(2)_RAWNAME))
  437. $(2)_DL_SUBDIR ?= $$($(2)_RAWNAME)
  438. $(2)_DL_DIR = $$(DL_DIR)/$$($(2)_DL_SUBDIR)
  439. $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASENAME)
  440. ifndef $(2)_SUBDIR
  441. ifdef $(3)_SUBDIR
  442. $(2)_SUBDIR = $$($(3)_SUBDIR)
  443. else
  444. $(2)_SUBDIR ?=
  445. endif
  446. endif
  447. ifndef $(2)_STRIP_COMPONENTS
  448. ifdef $(3)_STRIP_COMPONENTS
  449. $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
  450. else
  451. $(2)_STRIP_COMPONENTS ?= 1
  452. endif
  453. endif
  454. $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
  455. $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
  456. ifneq ($$($(2)_OVERRIDE_SRCDIR),)
  457. $(2)_VERSION = custom
  458. endif
  459. ifndef $(2)_SOURCE
  460. ifdef $(3)_SOURCE
  461. $(2)_SOURCE = $$($(3)_SOURCE)
  462. else ifdef $(2)_VERSION
  463. $(2)_SOURCE ?= $$($(2)_BASENAME_RAW).tar.gz
  464. endif
  465. endif
  466. # If FOO_ACTUAL_SOURCE_TARBALL is explicitly defined, it means FOO_SOURCE is
  467. # indeed a binary (e.g. external toolchain) and FOO_ACTUAL_SOURCE_TARBALL/_SITE
  468. # point to the actual sources tarball. Use the actual sources for legal-info.
  469. # For most packages the FOO_SITE/FOO_SOURCE pair points to real source code,
  470. # so these are the defaults for FOO_ACTUAL_*.
  471. $(2)_ACTUAL_SOURCE_TARBALL ?= $$($(2)_SOURCE)
  472. $(2)_ACTUAL_SOURCE_SITE ?= $$(call qstrip,$$($(2)_SITE))
  473. ifndef $(2)_PATCH
  474. ifdef $(3)_PATCH
  475. $(2)_PATCH = $$($(3)_PATCH)
  476. endif
  477. endif
  478. $(2)_ALL_DOWNLOADS = \
  479. $$(if $$($(2)_SOURCE),$$($(2)_SITE_METHOD)+$$($(2)_SITE)/$$($(2)_SOURCE)) \
  480. $$(foreach p,$$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
  481. $$(if $$(findstring ://,$$(p)),$$(p),\
  482. $$($(2)_SITE)/$$(p)))
  483. ifndef $(2)_SITE
  484. ifdef $(3)_SITE
  485. $(2)_SITE = $$($(3)_SITE)
  486. endif
  487. endif
  488. ifndef $(2)_SITE_METHOD
  489. ifdef $(3)_SITE_METHOD
  490. $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
  491. else
  492. # Try automatic detection using the scheme part of the URI
  493. $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
  494. endif
  495. endif
  496. ifneq ($$(filter bzr cvs hg svn,$$($(2)_SITE_METHOD)),)
  497. BR_NO_CHECK_HASH_FOR += $$($(2)_SOURCE)
  498. endif
  499. # Do not accept to download git submodule if not using the git method
  500. ifneq ($$($(2)_GIT_SUBMODULES),)
  501. ifneq ($$($(2)_SITE_METHOD),git)
  502. $$(error $(2) declares having git sub-modules, but does not use the \
  503. 'git' method (uses '$$($(2)_SITE_METHOD)' instead))
  504. endif
  505. endif
  506. ifeq ($$($(2)_SITE_METHOD),local)
  507. ifeq ($$($(2)_OVERRIDE_SRCDIR),)
  508. $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
  509. endif
  510. ifeq ($$($(2)_OVERRIDE_SRCDIR),)
  511. $$(error $(1) has local site method, but `$(2)_SITE` is not defined)
  512. endif
  513. endif
  514. ifndef $(2)_LICENSE
  515. ifdef $(3)_LICENSE
  516. $(2)_LICENSE = $$($(3)_LICENSE)
  517. endif
  518. endif
  519. $(2)_LICENSE ?= unknown
  520. ifndef $(2)_LICENSE_FILES
  521. ifdef $(3)_LICENSE_FILES
  522. $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
  523. endif
  524. endif
  525. ifndef $(2)_REDISTRIBUTE
  526. ifdef $(3)_REDISTRIBUTE
  527. $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
  528. endif
  529. endif
  530. $(2)_REDISTRIBUTE ?= YES
  531. $(2)_REDIST_SOURCES_DIR = $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))/$$($(2)_BASENAME_RAW)
  532. # When a target package is a toolchain dependency set this variable to
  533. # 'NO' so the 'toolchain' dependency is not added to prevent a circular
  534. # dependency.
  535. # Similarly for the skeleton.
  536. $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
  537. $(2)_ADD_SKELETON_DEPENDENCY ?= YES
  538. ifeq ($(4),target)
  539. ifeq ($$($(2)_ADD_SKELETON_DEPENDENCY),YES)
  540. $(2)_DEPENDENCIES += skeleton
  541. endif
  542. ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
  543. $(2)_DEPENDENCIES += toolchain
  544. endif
  545. endif
  546. ifneq ($(1),host-skeleton)
  547. $(2)_DEPENDENCIES += host-skeleton
  548. endif
  549. ifneq ($$(filter cvs git svn,$$($(2)_SITE_METHOD)),)
  550. $(2)_DOWNLOAD_DEPENDENCIES += \
  551. $(BR2_GZIP_HOST_DEPENDENCY) \
  552. $(BR2_TAR_HOST_DEPENDENCY)
  553. endif
  554. ifeq ($$(filter host-tar host-skeleton host-fakedate,$(1)),)
  555. $(2)_EXTRACT_DEPENDENCIES += $$(BR2_TAR_HOST_DEPENDENCY)
  556. endif
  557. ifeq ($$(filter host-tar host-skeleton host-xz host-lzip host-fakedate,$(1)),)
  558. ifneq ($$(filter .xz .lzma,$$(suffix $$($(2)_SOURCE))),)
  559. $(2)_EXTRACT_DEPENDENCIES += $$(BR2_XZCAT_HOST_DEPENDENCY)
  560. endif
  561. endif
  562. ifeq ($$(filter host-tar host-skeleton host-xz host-lzip host-fakedate,$(1)),)
  563. ifneq ($$(filter .lz,$$(suffix $$($(2)_SOURCE))),)
  564. $(2)_EXTRACT_DEPENDENCIES += $$(BR2_LZIP_HOST_DEPENDENCY)
  565. endif
  566. endif
  567. ifeq ($$(BR2_CCACHE),y)
  568. ifeq ($$(filter host-tar host-skeleton host-xz host-lzip host-fakedate host-ccache,$(1)),)
  569. $(2)_DEPENDENCIES += host-ccache
  570. endif
  571. endif
  572. ifeq ($$(BR2_REPRODUCIBLE),y)
  573. ifeq ($$(filter host-skeleton host-fakedate,$(1)),)
  574. $(2)_DEPENDENCIES += host-fakedate
  575. endif
  576. endif
  577. # Eliminate duplicates in dependencies
  578. $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
  579. $(2)_FINAL_DOWNLOAD_DEPENDENCIES = $$(sort $$($(2)_DOWNLOAD_DEPENDENCIES))
  580. $(2)_FINAL_EXTRACT_DEPENDENCIES = $$(sort $$($(2)_EXTRACT_DEPENDENCIES))
  581. $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
  582. $(2)_FINAL_ALL_DEPENDENCIES = \
  583. $$(sort \
  584. $$($(2)_FINAL_DEPENDENCIES) \
  585. $$($(2)_FINAL_DOWNLOAD_DEPENDENCIES) \
  586. $$($(2)_FINAL_EXTRACT_DEPENDENCIES) \
  587. $$($(2)_FINAL_PATCH_DEPENDENCIES))
  588. $(2)_FINAL_RECURSIVE_DEPENDENCIES = $$(sort \
  589. $$(if $$(filter undefined,$$(origin $(2)_FINAL_RECURSIVE_DEPENDENCIES__X)), \
  590. $$(eval $(2)_FINAL_RECURSIVE_DEPENDENCIES__X := \
  591. $$(foreach p, \
  592. $$($(2)_FINAL_ALL_DEPENDENCIES), \
  593. $$(p) \
  594. $$($$(call UPPERCASE,$$(p))_FINAL_RECURSIVE_DEPENDENCIES) \
  595. ) \
  596. ) \
  597. ) \
  598. $$($(2)_FINAL_RECURSIVE_DEPENDENCIES__X))
  599. $(2)_FINAL_RECURSIVE_RDEPENDENCIES = $$(sort \
  600. $$(if $$(filter undefined,$$(origin $(2)_FINAL_RECURSIVE_RDEPENDENCIES__X)), \
  601. $$(eval $(2)_FINAL_RECURSIVE_RDEPENDENCIES__X := \
  602. $$(foreach p, \
  603. $$($(2)_RDEPENDENCIES), \
  604. $$(p) \
  605. $$($$(call UPPERCASE,$$(p))_FINAL_RECURSIVE_RDEPENDENCIES) \
  606. ) \
  607. ) \
  608. ) \
  609. $$($(2)_FINAL_RECURSIVE_RDEPENDENCIES__X))
  610. $(2)_INSTALL_STAGING ?= NO
  611. $(2)_INSTALL_IMAGES ?= NO
  612. $(2)_INSTALL_TARGET ?= YES
  613. # define sub-target stamps
  614. $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
  615. $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
  616. $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
  617. $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
  618. $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
  619. $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
  620. $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
  621. $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
  622. $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
  623. $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
  624. $(2)_TARGET_ACTUAL_SOURCE = $$($(2)_DIR)/.stamp_actual_downloaded
  625. $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
  626. # default extract command
  627. $(2)_EXTRACT_CMDS ?= \
  628. $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$($(2)_DL_DIR)/$$($(2)_SOURCE) | \
  629. $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
  630. -C $$($(2)_DIR) \
  631. $$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
  632. $$(TAR_OPTIONS) -)
  633. # pre/post-steps hooks
  634. $(2)_PRE_DOWNLOAD_HOOKS ?=
  635. $(2)_POST_DOWNLOAD_HOOKS ?=
  636. $(2)_PRE_EXTRACT_HOOKS ?=
  637. $(2)_POST_EXTRACT_HOOKS ?=
  638. $(2)_PRE_RSYNC_HOOKS ?=
  639. $(2)_POST_RSYNC_HOOKS ?=
  640. $(2)_PRE_PATCH_HOOKS ?=
  641. $(2)_POST_PATCH_HOOKS ?=
  642. $(2)_PRE_CONFIGURE_HOOKS ?=
  643. $(2)_POST_CONFIGURE_HOOKS ?=
  644. $(2)_PRE_BUILD_HOOKS ?=
  645. $(2)_POST_BUILD_HOOKS ?=
  646. $(2)_PRE_INSTALL_HOOKS ?=
  647. $(2)_POST_INSTALL_HOOKS ?=
  648. $(2)_PRE_INSTALL_STAGING_HOOKS ?=
  649. $(2)_POST_INSTALL_STAGING_HOOKS ?=
  650. $(2)_PRE_INSTALL_TARGET_HOOKS ?=
  651. $(2)_POST_INSTALL_TARGET_HOOKS ?=
  652. $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
  653. $(2)_POST_INSTALL_IMAGES_HOOKS ?=
  654. $(2)_PRE_LEGAL_INFO_HOOKS ?=
  655. $(2)_POST_LEGAL_INFO_HOOKS ?=
  656. $(2)_TARGET_FINALIZE_HOOKS ?=
  657. $(2)_ROOTFS_PRE_CMD_HOOKS ?=
  658. ifeq ($$($(2)_TYPE),target)
  659. ifneq ($$(HOST_$(2)_KCONFIG_VAR),)
  660. $$(error "Package $(1) defines host variant before target variant!")
  661. endif
  662. endif
  663. # human-friendly targets and target sequencing
  664. $(1): $(1)-install
  665. ifeq ($$($(2)_TYPE),host)
  666. $(1)-install: $(1)-install-host
  667. else
  668. $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
  669. endif
  670. ifeq ($$($(2)_INSTALL_TARGET),YES)
  671. $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
  672. $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
  673. else
  674. $(1)-install-target:
  675. endif
  676. ifeq ($$($(2)_INSTALL_STAGING),YES)
  677. $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
  678. $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
  679. # Some packages use install-staging stuff for install-target
  680. $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
  681. else
  682. $(1)-install-staging:
  683. endif
  684. ifeq ($$($(2)_INSTALL_IMAGES),YES)
  685. $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
  686. $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
  687. else
  688. $(1)-install-images:
  689. endif
  690. $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
  691. $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
  692. $(1)-build: $$($(2)_TARGET_BUILD)
  693. $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
  694. # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
  695. # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
  696. # therefore the other steps as well) to be re-executed with every
  697. # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
  698. # dependency by using |.
  699. $(1)-configure: $$($(2)_TARGET_CONFIGURE)
  700. $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
  701. $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | prepare
  702. $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
  703. ifeq ($$($(2)_OVERRIDE_SRCDIR),)
  704. # In the normal case (no package override), the sequence of steps is
  705. # source, by downloading
  706. # depends
  707. # extract
  708. # patch
  709. # configure
  710. $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
  711. $(1)-patch: $$($(2)_TARGET_PATCH)
  712. $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
  713. # Order-only dependency
  714. $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
  715. $(1)-extract: $$($(2)_TARGET_EXTRACT)
  716. $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
  717. $$($(2)_TARGET_EXTRACT): | $$($(2)_FINAL_EXTRACT_DEPENDENCIES)
  718. $(1)-depends: $$($(2)_FINAL_ALL_DEPENDENCIES)
  719. $(1)-source: $$($(2)_TARGET_SOURCE)
  720. $$($(2)_TARGET_SOURCE): | $$($(2)_FINAL_DOWNLOAD_DEPENDENCIES)
  721. $(1)-all-source: $(1)-legal-source
  722. $(1)-legal-info: $(1)-legal-source
  723. $(1)-legal-source: $(1)-source
  724. # Only download the actual source if it differs from the 'main' archive
  725. ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),)
  726. ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
  727. $(1)-legal-source: $$($(2)_TARGET_ACTUAL_SOURCE)
  728. endif # actual sources != sources
  729. endif # actual sources != ""
  730. $(1)-external-deps:
  731. @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
  732. echo `basename $$$$p` ; \
  733. done
  734. else
  735. # In the package override case, the sequence of steps
  736. # source, by rsyncing
  737. # depends
  738. # configure
  739. # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
  740. # can remove the stamp file without triggering the configure step.
  741. $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
  742. $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
  743. $(1)-patch: $(1)-rsync
  744. $(1)-extract: $(1)-rsync
  745. $(1)-rsync: $$($(2)_TARGET_RSYNC)
  746. $(1)-source:
  747. $(1)-legal-source:
  748. $(1)-external-deps:
  749. @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
  750. endif
  751. $(1)-show-version:
  752. @echo $$($(2)_VERSION)
  753. $(1)-show-depends:
  754. @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
  755. $(1)-show-recursive-depends:
  756. @echo $$($(2)_FINAL_RECURSIVE_DEPENDENCIES)
  757. $(1)-show-rdepends:
  758. @echo $$($(2)_RDEPENDENCIES)
  759. $(1)-show-recursive-rdepends:
  760. @echo $$($(2)_FINAL_RECURSIVE_RDEPENDENCIES)
  761. $(1)-show-build-order: $$(patsubst %,%-show-build-order,$$($(2)_FINAL_ALL_DEPENDENCIES))
  762. @:
  763. $$(info $(1))
  764. $(1)-show-info:
  765. @:
  766. $$(info $$(call clean-json,{ $$(call json-info,$(2)) }))
  767. $(1)-graph-depends: graph-depends-requirements
  768. $(call pkg-graph-depends,$(1),--direct)
  769. $(1)-graph-rdepends: graph-depends-requirements
  770. $(call pkg-graph-depends,$(1),--reverse)
  771. $(1)-all-source: $(1)-source
  772. $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
  773. $(1)-all-external-deps: $(1)-external-deps
  774. $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
  775. $(1)-all-legal-info: $(1)-legal-info
  776. $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
  777. $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
  778. $(1)-clean-for-reinstall:
  779. ifneq ($$($(2)_OVERRIDE_SRCDIR),)
  780. rm -f $$($(2)_TARGET_RSYNC)
  781. endif
  782. rm -f $$($(2)_TARGET_INSTALL_STAGING)
  783. rm -f $$($(2)_TARGET_INSTALL_TARGET)
  784. rm -f $$($(2)_TARGET_INSTALL_IMAGES)
  785. rm -f $$($(2)_TARGET_INSTALL_HOST)
  786. $(1)-reinstall: $(1)-clean-for-reinstall $(1)
  787. $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
  788. rm -f $$($(2)_TARGET_BUILD)
  789. $(1)-rebuild: $(1)-clean-for-rebuild $(1)
  790. $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
  791. rm -f $$($(2)_TARGET_CONFIGURE)
  792. $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
  793. # define the PKG variable for all targets, containing the
  794. # uppercase package variable prefix
  795. $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
  796. $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
  797. $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
  798. $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
  799. $$($(2)_TARGET_BUILD): PKG=$(2)
  800. $$($(2)_TARGET_CONFIGURE): PKG=$(2)
  801. $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
  802. $$($(2)_TARGET_RSYNC): PKG=$(2)
  803. $$($(2)_TARGET_PATCH): PKG=$(2)
  804. $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
  805. $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
  806. $$($(2)_TARGET_EXTRACT): PKG=$(2)
  807. $$($(2)_TARGET_SOURCE): PKG=$(2)
  808. $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
  809. $$($(2)_TARGET_ACTUAL_SOURCE): PKG=$(2)
  810. $$($(2)_TARGET_ACTUAL_SOURCE): PKGDIR=$(pkgdir)
  811. $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
  812. $$($(2)_TARGET_DIRCLEAN): NAME=$(1)
  813. # Compute the name of the Kconfig option that correspond to the
  814. # package being enabled. We handle three cases: the special Linux
  815. # kernel case, the bootloaders case, and the normal packages case.
  816. ifeq ($(1),linux)
  817. $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
  818. else ifneq ($$(filter boot/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/boot/%),$(pkgdir)),)
  819. $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
  820. else ifneq ($$(filter toolchain/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/toolchain/%),$(pkgdir)),)
  821. $(2)_KCONFIG_VAR = BR2_$(2)
  822. else
  823. $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
  824. endif
  825. # legal-info: declare dependencies and set values used later for the manifest
  826. ifneq ($$($(2)_LICENSE_FILES),)
  827. $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
  828. endif
  829. # We need to extract and patch a package to be able to retrieve its
  830. # license files (if any) and the list of patches applied to it (if
  831. # any).
  832. $(1)-legal-info: $(1)-patch
  833. # We only save the sources of packages we want to redistribute, that are
  834. # non-overriden (local or true override).
  835. ifeq ($$($(2)_REDISTRIBUTE),YES)
  836. ifeq ($$($(2)_OVERRIDE_SRCDIR),)
  837. # Packages that have a tarball need it downloaded beforehand
  838. $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
  839. endif
  840. endif
  841. # legal-info: produce legally relevant info.
  842. $(1)-legal-info: PKG=$(2)
  843. $(1)-legal-info:
  844. @$$(call MESSAGE,"Collecting legal info")
  845. # Packages without a source are assumed to be part of Buildroot, skip them.
  846. $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
  847. ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
  848. # Save license files if defined
  849. # We save the license files for any kind of package: normal, local,
  850. # overridden, or non-redistributable alike.
  851. # The reason to save license files even for no-redistribute packages
  852. # is that the license still applies to the files distributed as part
  853. # of the rootfs, even if the sources are not themselves redistributed.
  854. ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
  855. $(Q)$$(call legal-warning-pkg,$$($(2)_BASENAME_RAW),cannot save license ($(2)_LICENSE_FILES not defined))
  856. else
  857. $(Q)$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$($(2)_BASENAME_RAW),$$($(2)_HASH_FILE),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
  858. endif # license files
  859. ifeq ($$($(2)_SITE_METHOD),local)
  860. # Packages without a tarball: don't save and warn
  861. @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
  862. else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
  863. @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
  864. else
  865. # Other packages
  866. ifeq ($$($(2)_REDISTRIBUTE),YES)
  867. # Save the source tarball and any extra downloads, but not
  868. # patches, as they are handled specially afterwards.
  869. $$(foreach e,$$($(2)_ACTUAL_SOURCE_TARBALL) $$(notdir $$($(2)_EXTRA_DOWNLOADS)),\
  870. $$(Q)support/scripts/hardlink-or-copy \
  871. $$($(2)_DL_DIR)/$$(e) \
  872. $$($(2)_REDIST_SOURCES_DIR)$$(sep))
  873. # Save patches and generate the series file
  874. $$(Q)while read f; do \
  875. support/scripts/hardlink-or-copy \
  876. $$$${f} \
  877. $$($(2)_REDIST_SOURCES_DIR) || exit 1; \
  878. printf "%s\n" "$$$${f##*/}" >>$$($(2)_REDIST_SOURCES_DIR)/series || exit 1; \
  879. done <$$($(2)_DIR)/.applied_patches_list
  880. endif # redistribute
  881. endif # other packages
  882. @$$(call legal-manifest,$$(call UPPERCASE,$(4)),$$($(2)_RAWNAME),$$($(2)_VERSION),$$(subst $$(space)$$(comma),$$(comma),$$($(2)_LICENSE)),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call legal-deps,$(1)))
  883. endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
  884. $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
  885. # add package to the general list of targets if requested by the buildroot
  886. # configuration
  887. ifeq ($$($$($(2)_KCONFIG_VAR)),y)
  888. # Ensure the calling package is the declared provider for all the virtual
  889. # packages it claims to be an implementation of.
  890. ifneq ($$($(2)_PROVIDES),)
  891. $$(foreach pkg,$$($(2)_PROVIDES),\
  892. $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
  893. endif
  894. # Register package as a reverse-dependencies of all its dependencies
  895. $$(eval $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),\
  896. $$(call UPPERCASE,$$(p))_RDEPENDENCIES += $(1)$$(sep)))
  897. # Ensure unified variable name conventions between all packages Some
  898. # of the variables are used by more than one infrastructure; so,
  899. # rather than duplicating the checks in each infrastructure, we check
  900. # all variables here in pkg-generic, even though pkg-generic should
  901. # have no knowledge of infra-specific variables.
  902. $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
  903. $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
  904. $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
  905. $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
  906. $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
  907. $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
  908. $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
  909. $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
  910. $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
  911. $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
  912. PACKAGES += $(1)
  913. ifneq ($$($(2)_PERMISSIONS),)
  914. PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
  915. endif
  916. ifneq ($$($(2)_DEVICES),)
  917. PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
  918. endif
  919. ifneq ($$($(2)_USERS),)
  920. PACKAGES_USERS += $$($(2)_USERS)$$(sep)
  921. endif
  922. TARGET_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)
  923. ROOTFS_PRE_CMD_HOOKS += $$($(2)_ROOTFS_PRE_CMD_HOOKS)
  924. ifeq ($$($(2)_SITE_METHOD),svn)
  925. DL_TOOLS_DEPENDENCIES += svn
  926. else ifeq ($$($(2)_SITE_METHOD),git)
  927. DL_TOOLS_DEPENDENCIES += git
  928. else ifeq ($$($(2)_SITE_METHOD),bzr)
  929. DL_TOOLS_DEPENDENCIES += bzr
  930. else ifeq ($$($(2)_SITE_METHOD),scp)
  931. DL_TOOLS_DEPENDENCIES += scp ssh
  932. else ifeq ($$($(2)_SITE_METHOD),hg)
  933. DL_TOOLS_DEPENDENCIES += hg
  934. else ifeq ($$($(2)_SITE_METHOD),cvs)
  935. DL_TOOLS_DEPENDENCIES += cvs
  936. endif # SITE_METHOD
  937. DL_TOOLS_DEPENDENCIES += $$(call extractor-dependency,$$($(2)_SOURCE))
  938. # Ensure all virtual targets are PHONY. Listed alphabetically.
  939. .PHONY: $(1) \
  940. $(1)-all-external-deps \
  941. $(1)-all-legal-info \
  942. $(1)-all-source \
  943. $(1)-build \
  944. $(1)-clean-for-rebuild \
  945. $(1)-clean-for-reconfigure \
  946. $(1)-clean-for-reinstall \
  947. $(1)-configure \
  948. $(1)-depends \
  949. $(1)-dirclean \
  950. $(1)-external-deps \
  951. $(1)-extract \
  952. $(1)-graph-depends \
  953. $(1)-graph-rdepends \
  954. $(1)-install \
  955. $(1)-install-host \
  956. $(1)-install-images \
  957. $(1)-install-staging \
  958. $(1)-install-target \
  959. $(1)-legal-info \
  960. $(1)-legal-source \
  961. $(1)-patch \
  962. $(1)-rebuild \
  963. $(1)-reconfigure \
  964. $(1)-reinstall \
  965. $(1)-rsync \
  966. $(1)-show-depends \
  967. $(1)-show-info \
  968. $(1)-show-version \
  969. $(1)-source
  970. ifneq ($$($(2)_SOURCE),)
  971. ifeq ($$($(2)_SITE),)
  972. $$(error $(2)_SITE cannot be empty when $(2)_SOURCE is not)
  973. endif
  974. endif
  975. ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
  976. $$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
  977. endif
  978. ifneq ($$($(2)_HELP_CMDS),)
  979. HELP_PACKAGES += $(2)
  980. endif
  981. endif # $(2)_KCONFIG_VAR
  982. endef # inner-generic-package
  983. ################################################################################
  984. # generic-package -- the target generator macro for generic packages
  985. ################################################################################
  986. # In the case of target packages, keep the package name "pkg"
  987. generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  988. # In the case of host packages, turn the package name "pkg" into "host-pkg"
  989. host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
  990. # :mode=makefile: