pkg-generic.mk 29 KB

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