pkg-generic.mk 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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)" "$(1)" "$(2)" "$(3)" \
  48. >>"$(BUILD_DIR)/build-time.log"
  49. endef
  50. GLOBAL_INSTRUMENTATION_HOOKS += step_time
  51. # User-supplied script
  52. ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
  53. define step_user
  54. @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
  55. $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
  56. endef
  57. GLOBAL_INSTRUMENTATION_HOOKS += step_user
  58. endif
  59. ################################################################################
  60. # Implicit targets -- produce a stamp file for each step of a package build
  61. ################################################################################
  62. # Retrieve the archive
  63. $(BUILD_DIR)/%/.stamp_downloaded:
  64. $(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
  65. # Only show the download message if it isn't already downloaded
  66. $(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
  67. if test ! -e $(DL_DIR)/`basename $$p` ; then \
  68. $(call MESSAGE,"Downloading") ; \
  69. break ; \
  70. fi ; \
  71. done
  72. $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p))$(sep))
  73. $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
  74. $(Q)mkdir -p $(@D)
  75. $(Q)touch $@
  76. # Unpack the archive
  77. $(BUILD_DIR)/%/.stamp_extracted:
  78. @$(call step_start,extract)
  79. @$(call MESSAGE,"Extracting")
  80. $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
  81. $(Q)mkdir -p $(@D)
  82. $($(PKG)_EXTRACT_CMDS)
  83. # some packages have messed up permissions inside
  84. $(Q)chmod -R +rw $(@D)
  85. $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
  86. $(Q)touch $@
  87. @$(call step_end,extract)
  88. # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
  89. # used.
  90. $(BUILD_DIR)/%/.stamp_rsynced:
  91. @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
  92. @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
  93. $(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
  94. rsync -au --chmod=u=rwX,go=rX $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
  95. $(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
  96. $(Q)touch $@
  97. # Patch
  98. #
  99. # The RAWNAME variable is the lowercased package name, which allows to
  100. # find the package directory (typically package/<pkgname>) and the
  101. # prefix of the patches
  102. #
  103. # For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
  104. $(BUILD_DIR)/%/.stamp_patched: NAMEVER = $(RAWNAME)-$($(PKG)_VERSION)
  105. $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS = $(PKGDIR)
  106. $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
  107. $(BUILD_DIR)/%/.stamp_patched:
  108. @$(call step_start,patch)
  109. @$(call MESSAGE,"Patching")
  110. $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
  111. $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $(DL_DIR) $(notdir $(p))$(sep))
  112. $(Q)( \
  113. for D in $(PATCH_BASE_DIRS); do \
  114. if test -d $${D}; then \
  115. if test -d $${D}/$($(PKG)_VERSION); then \
  116. $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
  117. else \
  118. $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
  119. fi; \
  120. fi; \
  121. done; \
  122. )
  123. $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
  124. $(Q)touch $@
  125. @$(call step_end,patch)
  126. # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
  127. $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
  128. $(if $(wildcard $(dir)),,\
  129. $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
  130. # Configure
  131. $(BUILD_DIR)/%/.stamp_configured:
  132. @$(call step_start,configure)
  133. @$(call MESSAGE,"Configuring")
  134. $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
  135. $($(PKG)_CONFIGURE_CMDS)
  136. $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
  137. $(Q)touch $@
  138. @$(call step_end,configure)
  139. # Build
  140. $(BUILD_DIR)/%/.stamp_built::
  141. @$(call step_start,build)
  142. @$(call MESSAGE,"Building")
  143. $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
  144. +$($(PKG)_BUILD_CMDS)
  145. $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
  146. $(Q)touch $@
  147. @$(call step_end,build)
  148. # Install to host dir
  149. $(BUILD_DIR)/%/.stamp_host_installed:
  150. @$(call step_start,install-host)
  151. @$(call MESSAGE,"Installing to host directory")
  152. $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
  153. +$($(PKG)_INSTALL_CMDS)
  154. $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
  155. $(Q)touch $@
  156. @$(call step_end,install-host)
  157. # Install to staging dir
  158. $(BUILD_DIR)/%/.stamp_staging_installed:
  159. @$(call step_start,install-staging)
  160. @$(call MESSAGE,"Installing to staging directory")
  161. $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
  162. +$($(PKG)_INSTALL_STAGING_CMDS)
  163. $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
  164. $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
  165. $(call MESSAGE,"Fixing package configuration files") ;\
  166. $(SED) "s,$(BASE_DIR),@BASE_DIR@,g" \
  167. -e "s,$(STAGING_DIR),@STAGING_DIR@,g" \
  168. -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
  169. -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
  170. -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
  171. -e "s,@STAGING_DIR@,$(STAGING_DIR),g" \
  172. -e "s,@BASE_DIR@,$(BASE_DIR),g" \
  173. $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
  174. fi
  175. $(Q)touch $@
  176. @$(call step_end,install-staging)
  177. # Install to images dir
  178. $(BUILD_DIR)/%/.stamp_images_installed:
  179. @$(call step_start,install-image)
  180. $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
  181. @$(call MESSAGE,"Installing to images directory")
  182. +$($(PKG)_INSTALL_IMAGES_CMDS)
  183. $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
  184. $(Q)touch $@
  185. @$(call step_end,install-image)
  186. # Install to target dir
  187. $(BUILD_DIR)/%/.stamp_target_installed:
  188. @$(call step_start,install-target)
  189. @$(call MESSAGE,"Installing to target")
  190. $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
  191. +$($(PKG)_INSTALL_TARGET_CMDS)
  192. $(if $(BR2_INIT_SYSTEMD),\
  193. $($(PKG)_INSTALL_INIT_SYSTEMD))
  194. $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
  195. $($(PKG)_INSTALL_INIT_SYSV))
  196. $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
  197. $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
  198. $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
  199. fi
  200. $(Q)touch $@
  201. @$(call step_end,install-target)
  202. # Remove package sources
  203. $(BUILD_DIR)/%/.stamp_dircleaned:
  204. rm -Rf $(@D)
  205. ################################################################################
  206. # virt-provides-single -- check that provider-pkg is the declared provider for
  207. # the virtual package virt-pkg
  208. #
  209. # argument 1 is the lower-case name of the virtual package
  210. # argument 2 is the upper-case name of the virtual package
  211. # argument 3 is the lower-case name of the provider
  212. #
  213. # example:
  214. # $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
  215. ################################################################################
  216. define virt-provides-single
  217. ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
  218. $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
  219. are selected as providers for virtual package "$(1)". Only one provider can\
  220. be selected at a time. Please fix your configuration)
  221. endif
  222. endef
  223. ################################################################################
  224. # inner-generic-package -- generates the make targets needed to build a
  225. # generic package
  226. #
  227. # argument 1 is the lowercase package name
  228. # argument 2 is the uppercase package name, including a HOST_ prefix
  229. # for host packages
  230. # argument 3 is the uppercase package name, without the HOST_ prefix
  231. # for host packages
  232. # argument 4 is the type (target or host)
  233. #
  234. # Note about variable and function references: inside all blocks that are
  235. # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
  236. # specific rules apply with respect to variable and function references.
  237. # - Numbered variables (parameters to the block) can be referenced with a single
  238. # dollar sign: $(1), $(2), $(3), etc.
  239. # - pkgdir and pkgname should be referenced with a single dollar sign too. These
  240. # functions rely on 'the most recently parsed makefile' which is supposed to
  241. # be the package .mk file. If we defer the evaluation of these functions using
  242. # double dollar signs, then they may be evaluated too late, when other
  243. # makefiles have already been parsed. One specific case is when $$(pkgdir) is
  244. # assigned to a variable using deferred evaluation with '=' and this variable
  245. # is used in a target rule outside the eval'ed inner block. In this case, the
  246. # pkgdir will be that of the last makefile parsed by buildroot, which is not
  247. # the expected value. This mechanism is for example used for the TARGET_PATCH
  248. # rule.
  249. # - All other variables should be referenced with a double dollar sign:
  250. # $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
  251. # referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
  252. # etc. This rule ensures that these variables and functions are only expanded
  253. # during the $(eval) step, and not earlier. Otherwise, unintuitive and
  254. # undesired behavior occurs with respect to these variables and functions.
  255. #
  256. ################################################################################
  257. define inner-generic-package
  258. # Define default values for various package-related variables, if not
  259. # already defined. For some variables (version, source, site and
  260. # subdir), if they are undefined, we try to see if a variable without
  261. # the HOST_ prefix is defined. If so, we use such a variable, so that
  262. # this information has only to be specified once, for both the
  263. # target and host packages of a given .mk file.
  264. $(2)_TYPE = $(4)
  265. $(2)_NAME = $(1)
  266. $(2)_RAWNAME = $$(patsubst host-%,%,$(1))
  267. # Keep the package version that may contain forward slashes in the _DL_VERSION
  268. # variable, then replace all forward slashes ('/') by underscores ('_') to
  269. # sanitize the package version that is used in paths, directory and file names.
  270. # Forward slashes may appear in the package's version when pointing to a
  271. # version control system branch or tag, for example remotes/origin/1_10_stable.
  272. # Similar for spaces and colons (:) that may appear in date-based revisions for
  273. # CVS.
  274. ifndef $(2)_VERSION
  275. ifdef $(3)_DL_VERSION
  276. $(2)_DL_VERSION := $$($(3)_DL_VERSION)
  277. else ifdef $(3)_VERSION
  278. $(2)_DL_VERSION := $$($(3)_VERSION)
  279. else
  280. $(2)_DL_VERSION = undefined
  281. endif
  282. else
  283. $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
  284. endif
  285. $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
  286. $(2)_BASE_NAME = $(1)-$$($(2)_VERSION)
  287. $(2)_DL_DIR = $$(DL_DIR)/$$($(2)_BASE_NAME)
  288. $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
  289. ifndef $(2)_SUBDIR
  290. ifdef $(3)_SUBDIR
  291. $(2)_SUBDIR = $$($(3)_SUBDIR)
  292. else
  293. $(2)_SUBDIR ?=
  294. endif
  295. endif
  296. ifndef $(2)_STRIP_COMPONENTS
  297. ifdef $(3)_STRIP_COMPONENTS
  298. $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
  299. else
  300. $(2)_STRIP_COMPONENTS ?= 1
  301. endif
  302. endif
  303. $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
  304. $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
  305. ifneq ($$($(2)_OVERRIDE_SRCDIR),)
  306. $(2)_VERSION = custom
  307. endif
  308. ifndef $(2)_SOURCE
  309. ifdef $(3)_SOURCE
  310. $(2)_SOURCE = $$($(3)_SOURCE)
  311. else
  312. $(2)_SOURCE ?= $$($(2)_RAWNAME)-$$($(2)_VERSION).tar.gz
  313. endif
  314. endif
  315. ifndef $(2)_PATCH
  316. ifdef $(3)_PATCH
  317. $(2)_PATCH = $$($(3)_PATCH)
  318. endif
  319. endif
  320. $(2)_ALL_DOWNLOADS = \
  321. $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
  322. $$(if $$(findstring ://,$$(p)),$$(p),\
  323. $$($(2)_SITE:/=)/$$(p)))
  324. ifndef $(2)_SITE
  325. ifdef $(3)_SITE
  326. $(2)_SITE = $$($(3)_SITE)
  327. endif
  328. endif
  329. ifndef $(2)_SITE_METHOD
  330. ifdef $(3)_SITE_METHOD
  331. $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
  332. else
  333. # Try automatic detection using the scheme part of the URI
  334. $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
  335. endif
  336. endif
  337. ifeq ($$($(2)_SITE_METHOD),local)
  338. ifeq ($$($(2)_OVERRIDE_SRCDIR),)
  339. $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
  340. endif
  341. endif
  342. ifndef $(2)_LICENSE
  343. ifdef $(3)_LICENSE
  344. $(2)_LICENSE = $$($(3)_LICENSE)
  345. endif
  346. endif
  347. $(2)_LICENSE ?= unknown
  348. ifndef $(2)_LICENSE_FILES
  349. ifdef $(3)_LICENSE_FILES
  350. $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
  351. endif
  352. endif
  353. ifndef $(2)_REDISTRIBUTE
  354. ifdef $(3)_REDISTRIBUTE
  355. $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
  356. endif
  357. endif
  358. $(2)_REDISTRIBUTE ?= YES
  359. # When a target package is a toolchain dependency set this variable to
  360. # 'NO' so the 'toolchain' dependency is not added to prevent a circular
  361. # dependency
  362. $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
  363. ifeq ($(4),host)
  364. $(2)_DEPENDENCIES ?= $$(filter-out host-skeleton host-toolchain $(1),\
  365. $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
  366. endif
  367. ifeq ($(4),target)
  368. ifneq ($(1),skeleton)
  369. $(2)_DEPENDENCIES += skeleton
  370. endif
  371. ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
  372. $(2)_DEPENDENCIES += toolchain
  373. endif
  374. endif
  375. # Eliminate duplicates in dependencies
  376. $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
  377. $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
  378. $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
  379. $(2)_INSTALL_STAGING ?= NO
  380. $(2)_INSTALL_IMAGES ?= NO
  381. $(2)_INSTALL_TARGET ?= YES
  382. # define sub-target stamps
  383. $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
  384. $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
  385. $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
  386. $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
  387. $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
  388. $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
  389. $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
  390. $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
  391. $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
  392. $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
  393. $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
  394. # default extract command
  395. $(2)_EXTRACT_CMDS ?= \
  396. $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
  397. $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) -C $$($(2)_DIR) $$(TAR_OPTIONS) -)
  398. # pre/post-steps hooks
  399. $(2)_PRE_DOWNLOAD_HOOKS ?=
  400. $(2)_POST_DOWNLOAD_HOOKS ?=
  401. $(2)_PRE_EXTRACT_HOOKS ?=
  402. $(2)_POST_EXTRACT_HOOKS ?=
  403. $(2)_PRE_RSYNC_HOOKS ?=
  404. $(2)_POST_RSYNC_HOOKS ?=
  405. $(2)_PRE_PATCH_HOOKS ?=
  406. $(2)_POST_PATCH_HOOKS ?=
  407. $(2)_PRE_CONFIGURE_HOOKS ?=
  408. $(2)_POST_CONFIGURE_HOOKS ?=
  409. $(2)_PRE_BUILD_HOOKS ?=
  410. $(2)_POST_BUILD_HOOKS ?=
  411. $(2)_PRE_INSTALL_HOOKS ?=
  412. $(2)_POST_INSTALL_HOOKS ?=
  413. $(2)_PRE_INSTALL_STAGING_HOOKS ?=
  414. $(2)_POST_INSTALL_STAGING_HOOKS ?=
  415. $(2)_PRE_INSTALL_TARGET_HOOKS ?=
  416. $(2)_POST_INSTALL_TARGET_HOOKS ?=
  417. $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
  418. $(2)_POST_INSTALL_IMAGES_HOOKS ?=
  419. $(2)_PRE_LEGAL_INFO_HOOKS ?=
  420. $(2)_POST_LEGAL_INFO_HOOKS ?=
  421. # human-friendly targets and target sequencing
  422. $(1): $(1)-install
  423. ifeq ($$($(2)_TYPE),host)
  424. $(1)-install: $(1)-install-host
  425. else
  426. $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
  427. endif
  428. ifeq ($$($(2)_INSTALL_TARGET),YES)
  429. $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
  430. $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
  431. else
  432. $(1)-install-target:
  433. endif
  434. ifeq ($$($(2)_INSTALL_STAGING),YES)
  435. $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
  436. $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
  437. # Some packages use install-staging stuff for install-target
  438. $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
  439. else
  440. $(1)-install-staging:
  441. endif
  442. ifeq ($$($(2)_INSTALL_IMAGES),YES)
  443. $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
  444. $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
  445. else
  446. $(1)-install-images:
  447. endif
  448. $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
  449. $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
  450. $(1)-build: $$($(2)_TARGET_BUILD)
  451. $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
  452. # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
  453. # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
  454. # therefore the other steps as well) to be re-executed with every
  455. # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
  456. # dependency by using |.
  457. $(1)-configure: $$($(2)_TARGET_CONFIGURE)
  458. $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
  459. $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
  460. ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
  461. $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
  462. endif
  463. ifeq ($$($(2)_OVERRIDE_SRCDIR),)
  464. # In the normal case (no package override), the sequence of steps is
  465. # source, by downloading
  466. # depends
  467. # extract
  468. # patch
  469. # configure
  470. $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
  471. $(1)-patch: $$($(2)_TARGET_PATCH)
  472. $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
  473. # Order-only dependency
  474. $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
  475. $(1)-extract: $$($(2)_TARGET_EXTRACT)
  476. $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
  477. $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
  478. $(1)-source: $$($(2)_TARGET_SOURCE)
  479. $(1)-source-check:
  480. $$(foreach p,$$($(2)_ALL_DOWNLOADS),$$(call SOURCE_CHECK,$$(p))$$(sep))
  481. $(1)-external-deps:
  482. @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
  483. echo `basename $$$$p` ; \
  484. done
  485. else
  486. # In the package override case, the sequence of steps
  487. # source, by rsyncing
  488. # depends
  489. # configure
  490. # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
  491. # can remove the stamp file without triggering the configure step.
  492. $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
  493. $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
  494. $(1)-patch: $(1)-rsync
  495. $(1)-extract: $(1)-rsync
  496. $(1)-rsync: $$($(2)_TARGET_RSYNC)
  497. $(1)-source:
  498. $(1)-source-check:
  499. test -d $$($(2)_OVERRIDE_SRCDIR)
  500. $(1)-external-deps:
  501. @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
  502. endif
  503. $(1)-show-version:
  504. @echo $$($(2)_VERSION)
  505. $(1)-show-depends:
  506. @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
  507. $(1)-graph-depends: graph-depends-requirements
  508. @$$(INSTALL) -d $$(GRAPHS_DIR)
  509. @cd "$$(CONFIG_DIR)"; \
  510. $$(TOPDIR)/support/scripts/graph-depends -p $(1) $$(BR2_GRAPH_DEPS_OPTS) \
  511. |tee $$(GRAPHS_DIR)/$$(@).dot \
  512. |dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT)
  513. $(1)-all-source: $(1)-source
  514. $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
  515. $(1)-all-source-check: $(1)-source-check
  516. $(1)-all-source-check: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source-check)
  517. $(1)-all-external-deps: $(1)-external-deps
  518. $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
  519. $(1)-all-legal-info: $(1)-legal-info
  520. $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
  521. $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
  522. $(1)-clean-for-reinstall:
  523. ifneq ($$($(2)_OVERRIDE_SRCDIR),)
  524. rm -f $$($(2)_TARGET_RSYNC)
  525. endif
  526. rm -f $$($(2)_TARGET_INSTALL_STAGING)
  527. rm -f $$($(2)_TARGET_INSTALL_TARGET)
  528. rm -f $$($(2)_TARGET_INSTALL_IMAGES)
  529. rm -f $$($(2)_TARGET_INSTALL_HOST)
  530. $(1)-reinstall: $(1)-clean-for-reinstall $(1)
  531. $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
  532. rm -f $$($(2)_TARGET_BUILD)
  533. $(1)-rebuild: $(1)-clean-for-rebuild $(1)
  534. $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
  535. rm -f $$($(2)_TARGET_CONFIGURE)
  536. $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
  537. # define the PKG variable for all targets, containing the
  538. # uppercase package variable prefix
  539. $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
  540. $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
  541. $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
  542. $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
  543. $$($(2)_TARGET_BUILD): PKG=$(2)
  544. $$($(2)_TARGET_CONFIGURE): PKG=$(2)
  545. $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
  546. $$($(2)_TARGET_RSYNC): PKG=$(2)
  547. $$($(2)_TARGET_PATCH): PKG=$(2)
  548. $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
  549. $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
  550. $$($(2)_TARGET_EXTRACT): PKG=$(2)
  551. $$($(2)_TARGET_SOURCE): PKG=$(2)
  552. $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
  553. $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
  554. # Compute the name of the Kconfig option that correspond to the
  555. # package being enabled. We handle three cases: the special Linux
  556. # kernel case, the bootloaders case, and the normal packages case.
  557. ifeq ($(1),linux)
  558. $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
  559. else ifneq ($$(filter boot/% $(BR2_EXTERNAL)/boot/%,$(pkgdir)),)
  560. $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
  561. else ifneq ($$(filter toolchain/% $(BR2_EXTERNAL)/toolchain/%,$(pkgdir)),)
  562. $(2)_KCONFIG_VAR = BR2_$(2)
  563. else
  564. $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
  565. endif
  566. # legal-info: declare dependencies and set values used later for the manifest
  567. ifneq ($$($(2)_LICENSE_FILES),)
  568. $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
  569. endif
  570. $(2)_MANIFEST_LICENSE_FILES ?= not saved
  571. # If the package declares _LICENSE_FILES, we need to extract it,
  572. # for overriden, local or normal remote packages alike, whether
  573. # we want to redistribute it or not.
  574. ifneq ($$($(2)_LICENSE_FILES),)
  575. $(1)-legal-info: $(1)-patch
  576. endif
  577. # We only save the sources of packages we want to redistribute, that are
  578. # non-local, and non-overriden. So only store, in the manifest, the tarball
  579. # name of those packages.
  580. ifeq ($$($(2)_REDISTRIBUTE),YES)
  581. ifneq ($$($(2)_SITE_METHOD),local)
  582. ifneq ($$($(2)_SITE_METHOD),override)
  583. # Packages that have a tarball need it downloaded beforehand
  584. $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
  585. $(2)_MANIFEST_TARBALL = $$($(2)_SOURCE)
  586. $(2)_MANIFEST_SITE = $$(call qstrip,$$($(2)_SITE))
  587. endif
  588. endif
  589. endif
  590. # legal-info: produce legally relevant info.
  591. $(1)-legal-info:
  592. # Packages without a source are assumed to be part of Buildroot, skip them.
  593. $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
  594. ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
  595. # Save license files if defined
  596. # We save the license files for any kind of package: normal, local,
  597. # overridden, or non-redistributable alike.
  598. # The reason to save license files even for no-redistribute packages
  599. # is that the license still applies to the files distributed as part
  600. # of the rootfs, even if the sources are not themselves redistributed.
  601. ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
  602. @$$(call legal-license-nofiles,$$($(2)_RAWNAME),$$(call UPPERCASE,$(4)))
  603. @$$(call legal-warning-pkg,$$($(2)_RAWNAME),cannot save license ($(2)_LICENSE_FILES not defined))
  604. else
  605. @$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
  606. endif # license files
  607. ifeq ($$($(2)_SITE_METHOD),local)
  608. # Packages without a tarball: don't save and warn
  609. @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
  610. else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
  611. @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
  612. else
  613. # Other packages
  614. ifeq ($$($(2)_REDISTRIBUTE),YES)
  615. # Copy the source tarball (just hardlink if possible)
  616. @cp -l $$(DL_DIR)/$$($(2)_SOURCE) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4))) 2>/dev/null || \
  617. cp $$(DL_DIR)/$$($(2)_SOURCE) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
  618. endif # redistribute
  619. endif # other packages
  620. @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_MANIFEST_TARBALL),$$($(2)_MANIFEST_SITE),$$(call UPPERCASE,$(4)))
  621. endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
  622. $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
  623. # add package to the general list of targets if requested by the buildroot
  624. # configuration
  625. ifeq ($$($$($(2)_KCONFIG_VAR)),y)
  626. # Ensure the calling package is the declared provider for all the virtual
  627. # packages it claims to be an implementation of.
  628. ifneq ($$($(2)_PROVIDES),)
  629. $$(foreach pkg,$$($(2)_PROVIDES),\
  630. $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
  631. endif
  632. # Ensure unified variable name conventions between all packages Some
  633. # of the variables are used by more than one infrastructure; so,
  634. # rather than duplicating the checks in each infrastructure, we check
  635. # all variables here in pkg-generic, even though pkg-generic should
  636. # have no knowledge of infra-specific variables.
  637. $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
  638. $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
  639. $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
  640. $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
  641. $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
  642. $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
  643. $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
  644. $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
  645. $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
  646. $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
  647. PACKAGES += $(1)
  648. ifneq ($$($(2)_PERMISSIONS),)
  649. PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
  650. endif
  651. ifneq ($$($(2)_DEVICES),)
  652. PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
  653. endif
  654. ifneq ($$($(2)_USERS),)
  655. PACKAGES_USERS += $$($(2)_USERS)$$(sep)
  656. endif
  657. ifeq ($$($(2)_SITE_METHOD),svn)
  658. DL_TOOLS_DEPENDENCIES += svn
  659. else ifeq ($$($(2)_SITE_METHOD),git)
  660. DL_TOOLS_DEPENDENCIES += git
  661. else ifeq ($$($(2)_SITE_METHOD),bzr)
  662. DL_TOOLS_DEPENDENCIES += bzr
  663. else ifeq ($$($(2)_SITE_METHOD),scp)
  664. DL_TOOLS_DEPENDENCIES += scp ssh
  665. else ifeq ($$($(2)_SITE_METHOD),hg)
  666. DL_TOOLS_DEPENDENCIES += hg
  667. else ifeq ($$($(2)_SITE_METHOD),cvs)
  668. DL_TOOLS_DEPENDENCIES += cvs
  669. endif # SITE_METHOD
  670. # $(firstword) is used here because the extractor can have arguments, like
  671. # ZCAT="gzip -d -c", and to check for the dependency we only want 'gzip'.
  672. # Do not add xzcat to the list of required dependencies, as it gets built
  673. # automatically if it isn't found.
  674. ifneq ($$(call suitable-extractor,$$($(2)_SOURCE)),$$(XZCAT))
  675. DL_TOOLS_DEPENDENCIES += $$(firstword $$(call suitable-extractor,$$($(2)_SOURCE)))
  676. endif
  677. # Ensure all virtual targets are PHONY. Listed alphabetically.
  678. .PHONY: $(1) \
  679. $(1)-all-external-deps \
  680. $(1)-all-legal-info \
  681. $(1)-all-source \
  682. $(1)-all-source-check \
  683. $(1)-build \
  684. $(1)-clean-for-rebuild \
  685. $(1)-clean-for-reconfigure \
  686. $(1)-clean-for-reinstall \
  687. $(1)-configure \
  688. $(1)-depends \
  689. $(1)-dirclean \
  690. $(1)-external-deps \
  691. $(1)-extract \
  692. $(1)-graph-depends \
  693. $(1)-install \
  694. $(1)-install-host \
  695. $(1)-install-images \
  696. $(1)-install-staging \
  697. $(1)-install-target \
  698. $(1)-legal-info \
  699. $(1)-patch \
  700. $(1)-rebuild \
  701. $(1)-reconfigure \
  702. $(1)-reinstall \
  703. $(1)-rsync \
  704. $(1)-show-depends \
  705. $(1)-show-version \
  706. $(1)-source \
  707. $(1)-source-check
  708. endif # $(2)_KCONFIG_VAR
  709. endef # inner-generic-package
  710. ################################################################################
  711. # generic-package -- the target generator macro for generic packages
  712. ################################################################################
  713. # In the case of target packages, keep the package name "pkg"
  714. generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  715. # In the case of host packages, turn the package name "pkg" into "host-pkg"
  716. host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
  717. # :mode=makefile: