pkg-generic.mk 39 KB

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