pkg-generic.mk 43 KB

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