pkg-generic.mk 23 KB

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