1 ################################################################################
2 # Generic package infrastructure
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).
10 # See the Buildroot documentation for details on the usage of this
13 # In terms of implementation, this generic infrastructure requires the
14 # .mk file to specify:
16 # 1. Metadata information about the package: name, version,
19 # 2. Description of the commands to be executed to configure, build
20 # and install the package
21 ################################################################################
23 ################################################################################
24 # Helper functions to catch start/end of each step
25 ################################################################################
27 # Those two functions are called by each step below.
28 # They are responsible for calling all hooks defined in
29 # $(GLOBAL_INSTRUMENTATION_HOOKS) and pass each of them
31 # $1: either 'start' or 'end'
32 # $2: the name of the step
33 # $3: the name of the package
38 $(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),start,$(1),$($(PKG)_NAME))$(sep))
44 $(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),end,$(1),$($(PKG)_NAME))$(sep))
47 #######################################
52 printf "%s:%-5.5s:%-20.20s: %s\n" \
53 "$$(date +%s)" "$(1)" "$(2)" "$(3)" \
54 >>"$(BUILD_DIR)/build-time.log"
56 GLOBAL_INSTRUMENTATION_HOOKS += step_time
58 # Hooks to collect statistics about installed files
60 # This hook will be called before the target installation of a
61 # package. We store in a file named .br_filelist_before the list of
62 # files currently installed in the target. Note that the MD5 is also
63 # stored, in order to identify if the files are overwritten.
64 define step_pkg_size_start
65 (cd $(TARGET_DIR) ; find . -type f -print0 | xargs -0 md5sum) | sort > \
66 $($(PKG)_DIR)/.br_filelist_before
69 # This hook will be called after the target installation of a
70 # package. We store in a file named .br_filelist_after the list of
71 # files (and their MD5) currently installed in the target. We then do
72 # a diff with the .br_filelist_before to compute the list of files
73 # installed by this package.
74 define step_pkg_size_end
75 (cd $(TARGET_DIR); find . -type f -print0 | xargs -0 md5sum) | sort > \
76 $($(PKG)_DIR)/.br_filelist_after
77 comm -13 $($(PKG)_DIR)/.br_filelist_before $($(PKG)_DIR)/.br_filelist_after | \
78 while read hash file ; do \
79 echo "$(1),$${file}" >> $(BUILD_DIR)/packages-file-list.txt ; \
84 $(if $(filter install-target,$(2)),\
85 $(if $(filter start,$(1)),$(call step_pkg_size_start,$(3))) \
86 $(if $(filter end,$(1)),$(call step_pkg_size_end,$(3))))
88 GLOBAL_INSTRUMENTATION_HOOKS += step_pkg_size
90 # This hook checks that host packages that need libraries that we build
91 # have a proper DT_RPATH or DT_RUNPATH tag
92 define check_host_rpath
93 $(if $(filter install-host,$(2)),\
94 $(if $(filter end,$(1)),support/scripts/check-host-rpath $(3) $(HOST_DIR)))
96 GLOBAL_INSTRUMENTATION_HOOKS += check_host_rpath
98 # User-supplied script
99 ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
101 @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
102 $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
104 GLOBAL_INSTRUMENTATION_HOOKS += step_user
107 ################################################################################
108 # Implicit targets -- produce a stamp file for each step of a package build
109 ################################################################################
111 # Retrieve the archive
112 $(BUILD_DIR)/%/.stamp_downloaded:
113 $(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
114 # Only show the download message if it isn't already downloaded
115 $(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
116 if test ! -e $(DL_DIR)/`basename $$p` ; then \
117 $(call MESSAGE,"Downloading") ; \
121 $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p))$(sep))
122 $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
127 $(BUILD_DIR)/%/.stamp_extracted:
128 @$(call step_start,extract)
129 @$(call MESSAGE,"Extracting")
130 $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
132 $($(PKG)_EXTRACT_CMDS)
133 # some packages have messed up permissions inside
134 $(Q)chmod -R +rw $(@D)
135 $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
136 @$(call step_end,extract)
139 # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
141 $(BUILD_DIR)/%/.stamp_rsynced:
142 @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
143 @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
144 $(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
145 rsync -au --chmod=u=rwX,go=rX $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
146 $(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
151 # The RAWNAME variable is the lowercased package name, which allows to
152 # find the package directory (typically package/<pkgname>) and the
153 # prefix of the patches
155 # For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
156 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS = $(PKGDIR)
157 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
158 $(BUILD_DIR)/%/.stamp_patched:
159 @$(call step_start,patch)
160 @$(call MESSAGE,"Patching")
161 $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
162 $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $(DL_DIR) $(notdir $(p))$(sep))
164 for D in $(PATCH_BASE_DIRS); do \
165 if test -d $${D}; then \
166 if test -d $${D}/$($(PKG)_VERSION); then \
167 $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
169 $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
174 $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
175 @$(call step_end,patch)
178 # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
179 $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
180 $(if $(wildcard $(dir)),,\
181 $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
184 $(BUILD_DIR)/%/.stamp_configured:
185 @$(call step_start,configure)
186 @$(call MESSAGE,"Configuring")
187 $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
188 $($(PKG)_CONFIGURE_CMDS)
189 $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
190 @$(call step_end,configure)
194 $(BUILD_DIR)/%/.stamp_built::
195 @$(call step_start,build)
196 @$(call MESSAGE,"Building")
197 $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
198 +$($(PKG)_BUILD_CMDS)
199 $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
200 @$(call step_end,build)
203 # Install to host dir
204 $(BUILD_DIR)/%/.stamp_host_installed:
205 @$(call step_start,install-host)
206 @$(call MESSAGE,"Installing to host directory")
207 $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
208 +$($(PKG)_INSTALL_CMDS)
209 $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
210 @$(call step_end,install-host)
213 # Install to staging dir
215 # Some packages install libtool .la files alongside any installed
216 # libraries. These .la files sometimes refer to paths relative to the
217 # sysroot, which libtool will interpret as absolute paths to host
218 # libraries instead of the target libraries. Since this is not what we
219 # want, these paths are fixed by prefixing them with $(STAGING_DIR).
220 # As we configure with --prefix=/usr, this fix needs to be applied to
221 # any path that starts with /usr.
223 # To protect against the case that the output or staging directories or
224 # the pre-installed external toolchain themselves are under /usr, we first
225 # substitute away any occurrences of these directories with @BASE_DIR@,
226 # @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
228 # Note that STAGING_DIR can be outside BASE_DIR when the user sets
229 # BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
230 # can be under @BASE_DIR@ when it's a downloaded toolchain, and can be
231 # empty when we use an internal toolchain.
233 $(BUILD_DIR)/%/.stamp_staging_installed:
234 @$(call step_start,install-staging)
235 @$(call MESSAGE,"Installing to staging directory")
236 $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
237 +$($(PKG)_INSTALL_STAGING_CMDS)
238 $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
239 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
240 $(call MESSAGE,"Fixing package configuration files") ;\
241 $(SED) "s,$(BASE_DIR),@BASE_DIR@,g" \
242 -e "s,$(STAGING_DIR),@STAGING_DIR@,g" \
243 -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
244 -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
245 -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
246 -e "s,@STAGING_DIR@,$(STAGING_DIR),g" \
247 -e "s,@BASE_DIR@,$(BASE_DIR),g" \
248 $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
250 @$(call MESSAGE,"Fixing libtool files")
251 $(Q)find $(STAGING_DIR)/usr/lib* -name "*.la" | xargs --no-run-if-empty \
252 $(SED) "s:$(BASE_DIR):@BASE_DIR@:g" \
253 -e "s:$(STAGING_DIR):@STAGING_DIR@:g" \
254 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
255 -e "s:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
256 -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
257 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
258 -e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
259 -e "s:@STAGING_DIR@:$(STAGING_DIR):g" \
260 -e "s:@BASE_DIR@:$(BASE_DIR):g"
261 @$(call step_end,install-staging)
264 # Install to images dir
265 $(BUILD_DIR)/%/.stamp_images_installed:
266 @$(call step_start,install-image)
267 $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
268 @$(call MESSAGE,"Installing to images directory")
269 +$($(PKG)_INSTALL_IMAGES_CMDS)
270 $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
271 @$(call step_end,install-image)
274 # Install to target dir
275 $(BUILD_DIR)/%/.stamp_target_installed:
276 @$(call step_start,install-target)
277 @$(call MESSAGE,"Installing to target")
278 $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
279 +$($(PKG)_INSTALL_TARGET_CMDS)
280 $(if $(BR2_INIT_SYSTEMD),\
281 $($(PKG)_INSTALL_INIT_SYSTEMD))
282 $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
283 $($(PKG)_INSTALL_INIT_SYSV))
284 $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
285 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
286 $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
288 @$(call step_end,install-target)
291 # Remove package sources
292 $(BUILD_DIR)/%/.stamp_dircleaned:
295 ################################################################################
296 # virt-provides-single -- check that provider-pkg is the declared provider for
297 # the virtual package virt-pkg
299 # argument 1 is the lower-case name of the virtual package
300 # argument 2 is the upper-case name of the virtual package
301 # argument 3 is the lower-case name of the provider
304 # $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
305 ################################################################################
306 define virt-provides-single
307 ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
308 $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
309 are selected as providers for virtual package "$(1)". Only one provider can\
310 be selected at a time. Please fix your configuration)
314 ################################################################################
315 # inner-generic-package -- generates the make targets needed to build a
318 # argument 1 is the lowercase package name
319 # argument 2 is the uppercase package name, including a HOST_ prefix
321 # argument 3 is the uppercase package name, without the HOST_ prefix
323 # argument 4 is the type (target or host)
325 # Note about variable and function references: inside all blocks that are
326 # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
327 # specific rules apply with respect to variable and function references.
328 # - Numbered variables (parameters to the block) can be referenced with a single
329 # dollar sign: $(1), $(2), $(3), etc.
330 # - pkgdir and pkgname should be referenced with a single dollar sign too. These
331 # functions rely on 'the most recently parsed makefile' which is supposed to
332 # be the package .mk file. If we defer the evaluation of these functions using
333 # double dollar signs, then they may be evaluated too late, when other
334 # makefiles have already been parsed. One specific case is when $$(pkgdir) is
335 # assigned to a variable using deferred evaluation with '=' and this variable
336 # is used in a target rule outside the eval'ed inner block. In this case, the
337 # pkgdir will be that of the last makefile parsed by buildroot, which is not
338 # the expected value. This mechanism is for example used for the TARGET_PATCH
340 # - All other variables should be referenced with a double dollar sign:
341 # $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
342 # referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
343 # etc. This rule ensures that these variables and functions are only expanded
344 # during the $(eval) step, and not earlier. Otherwise, unintuitive and
345 # undesired behavior occurs with respect to these variables and functions.
347 ################################################################################
349 define inner-generic-package
351 # Ensure the package is only declared once, i.e. do not accept that a
352 # package be re-defined by a br2-external tree
353 ifneq ($(call strip,$(filter $(1),$(PACKAGES_ALL))),)
354 $$(error Package '$(1)' defined a second time in '$(pkgdir)'; \
355 previous definition was in '$$($(2)_PKGDIR)')
359 # Define default values for various package-related variables, if not
360 # already defined. For some variables (version, source, site and
361 # subdir), if they are undefined, we try to see if a variable without
362 # the HOST_ prefix is defined. If so, we use such a variable, so that
363 # this information has only to be specified once, for both the
364 # target and host packages of a given .mk file.
368 $(2)_RAWNAME = $$(patsubst host-%,%,$(1))
369 $(2)_PKGDIR = $(pkgdir)
371 # Keep the package version that may contain forward slashes in the _DL_VERSION
372 # variable, then replace all forward slashes ('/') by underscores ('_') to
373 # sanitize the package version that is used in paths, directory and file names.
374 # Forward slashes may appear in the package's version when pointing to a
375 # version control system branch or tag, for example remotes/origin/1_10_stable.
376 # Similar for spaces and colons (:) that may appear in date-based revisions for
379 ifdef $(3)_DL_VERSION
380 $(2)_DL_VERSION := $$($(3)_DL_VERSION)
381 else ifdef $(3)_VERSION
382 $(2)_DL_VERSION := $$($(3)_VERSION)
384 $(2)_DL_VERSION = undefined
387 $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
389 $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
391 ifdef $(3)_OVERRIDE_SRCDIR
392 $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
395 $(2)_BASE_NAME = $(1)-$$($(2)_VERSION)
396 $(2)_RAW_BASE_NAME = $$($(2)_RAWNAME)-$$($(2)_VERSION)
397 $(2)_DL_DIR = $$(DL_DIR)/$$($(2)_BASE_NAME)
398 $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
402 $(2)_SUBDIR = $$($(3)_SUBDIR)
408 ifndef $(2)_STRIP_COMPONENTS
409 ifdef $(3)_STRIP_COMPONENTS
410 $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
412 $(2)_STRIP_COMPONENTS ?= 1
416 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
417 $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
419 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
420 $(2)_VERSION = custom
425 $(2)_SOURCE = $$($(3)_SOURCE)
427 $(2)_SOURCE ?= $$($(2)_RAW_BASE_NAME).tar.gz
433 $(2)_PATCH = $$($(3)_PATCH)
437 $(2)_ALL_DOWNLOADS = \
438 $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
439 $$(if $$(findstring ://,$$(p)),$$(p),\
440 $$($(2)_SITE)/$$(p)))
444 $(2)_SITE = $$($(3)_SITE)
448 ifndef $(2)_SITE_METHOD
449 ifdef $(3)_SITE_METHOD
450 $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
452 # Try automatic detection using the scheme part of the URI
453 $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
457 ifeq ($$($(2)_SITE_METHOD),local)
458 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
459 $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
465 $(2)_LICENSE = $$($(3)_LICENSE)
469 $(2)_LICENSE ?= unknown
471 ifndef $(2)_LICENSE_FILES
472 ifdef $(3)_LICENSE_FILES
473 $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
477 ifndef $(2)_REDISTRIBUTE
478 ifdef $(3)_REDISTRIBUTE
479 $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
483 $(2)_REDISTRIBUTE ?= YES
485 $(2)_REDIST_SOURCES_DIR = $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))/$$($(2)_RAW_BASE_NAME)
487 # When a target package is a toolchain dependency set this variable to
488 # 'NO' so the 'toolchain' dependency is not added to prevent a circular
490 $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
493 $(2)_DEPENDENCIES ?= $$(filter-out host-skeleton host-toolchain $(1),\
494 $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
497 ifneq ($(1),skeleton)
498 $(2)_DEPENDENCIES += skeleton
500 ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
501 $(2)_DEPENDENCIES += toolchain
505 # Eliminate duplicates in dependencies
506 $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
507 $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
508 $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
510 $(2)_INSTALL_STAGING ?= NO
511 $(2)_INSTALL_IMAGES ?= NO
512 $(2)_INSTALL_TARGET ?= YES
514 # define sub-target stamps
515 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
516 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
517 $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
518 $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
519 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
520 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
521 $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
522 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
523 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
524 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
525 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
527 # default extract command
528 $(2)_EXTRACT_CMDS ?= \
529 $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
530 $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
532 $$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
535 # pre/post-steps hooks
536 $(2)_PRE_DOWNLOAD_HOOKS ?=
537 $(2)_POST_DOWNLOAD_HOOKS ?=
538 $(2)_PRE_EXTRACT_HOOKS ?=
539 $(2)_POST_EXTRACT_HOOKS ?=
540 $(2)_PRE_RSYNC_HOOKS ?=
541 $(2)_POST_RSYNC_HOOKS ?=
542 $(2)_PRE_PATCH_HOOKS ?=
543 $(2)_POST_PATCH_HOOKS ?=
544 $(2)_PRE_CONFIGURE_HOOKS ?=
545 $(2)_POST_CONFIGURE_HOOKS ?=
546 $(2)_PRE_BUILD_HOOKS ?=
547 $(2)_POST_BUILD_HOOKS ?=
548 $(2)_PRE_INSTALL_HOOKS ?=
549 $(2)_POST_INSTALL_HOOKS ?=
550 $(2)_PRE_INSTALL_STAGING_HOOKS ?=
551 $(2)_POST_INSTALL_STAGING_HOOKS ?=
552 $(2)_PRE_INSTALL_TARGET_HOOKS ?=
553 $(2)_POST_INSTALL_TARGET_HOOKS ?=
554 $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
555 $(2)_POST_INSTALL_IMAGES_HOOKS ?=
556 $(2)_PRE_LEGAL_INFO_HOOKS ?=
557 $(2)_POST_LEGAL_INFO_HOOKS ?=
559 # human-friendly targets and target sequencing
562 ifeq ($$($(2)_TYPE),host)
563 $(1)-install: $(1)-install-host
565 $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
568 ifeq ($$($(2)_INSTALL_TARGET),YES)
569 $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
570 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
575 ifeq ($$($(2)_INSTALL_STAGING),YES)
576 $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
577 $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
578 # Some packages use install-staging stuff for install-target
579 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
581 $(1)-install-staging:
584 ifeq ($$($(2)_INSTALL_IMAGES),YES)
585 $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
586 $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
591 $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
592 $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
594 $(1)-build: $$($(2)_TARGET_BUILD)
595 $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
597 # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
598 # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
599 # therefore the other steps as well) to be re-executed with every
600 # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
601 # dependency by using |.
603 $(1)-configure: $$($(2)_TARGET_CONFIGURE)
604 $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
606 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
607 ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
608 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
611 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
612 # In the normal case (no package override), the sequence of steps is
613 # source, by downloading
618 $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
620 $(1)-patch: $$($(2)_TARGET_PATCH)
621 $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
622 # Order-only dependency
623 $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
625 $(1)-extract: $$($(2)_TARGET_EXTRACT)
626 $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
628 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
630 $(1)-source: $$($(2)_TARGET_SOURCE)
633 $$(foreach p,$$($(2)_ALL_DOWNLOADS),$$(call SOURCE_CHECK,$$(p))$$(sep))
636 @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
637 echo `basename $$$$p` ; \
640 # In the package override case, the sequence of steps
641 # source, by rsyncing
645 # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
646 # can remove the stamp file without triggering the configure step.
647 $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
649 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
651 $(1)-patch: $(1)-rsync
652 $(1)-extract: $(1)-rsync
654 $(1)-rsync: $$($(2)_TARGET_RSYNC)
659 test -d $$($(2)_OVERRIDE_SRCDIR)
662 @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
666 @echo $$($(2)_VERSION)
669 @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
671 $(1)-graph-depends: graph-depends-requirements
672 @$$(INSTALL) -d $$(GRAPHS_DIR)
673 @cd "$$(CONFIG_DIR)"; \
674 $$(TOPDIR)/support/scripts/graph-depends $$(BR2_GRAPH_DEPS_OPTS) \
675 -p $(1) -o $$(GRAPHS_DIR)/$$(@).dot
676 dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) \
677 -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT) \
678 $$(GRAPHS_DIR)/$$(@).dot
680 $(1)-all-source: $(1)-source
681 $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
683 $(1)-all-source-check: $(1)-source-check
684 $(1)-all-source-check: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source-check)
686 $(1)-all-external-deps: $(1)-external-deps
687 $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
689 $(1)-all-legal-info: $(1)-legal-info
690 $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
692 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
694 $(1)-clean-for-reinstall:
695 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
696 rm -f $$($(2)_TARGET_RSYNC)
698 rm -f $$($(2)_TARGET_INSTALL_STAGING)
699 rm -f $$($(2)_TARGET_INSTALL_TARGET)
700 rm -f $$($(2)_TARGET_INSTALL_IMAGES)
701 rm -f $$($(2)_TARGET_INSTALL_HOST)
703 $(1)-reinstall: $(1)-clean-for-reinstall $(1)
705 $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
706 rm -f $$($(2)_TARGET_BUILD)
708 $(1)-rebuild: $(1)-clean-for-rebuild $(1)
710 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
711 rm -f $$($(2)_TARGET_CONFIGURE)
713 $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
715 # define the PKG variable for all targets, containing the
716 # uppercase package variable prefix
717 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
718 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
719 $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
720 $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
721 $$($(2)_TARGET_BUILD): PKG=$(2)
722 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
723 $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
724 $$($(2)_TARGET_RSYNC): PKG=$(2)
725 $$($(2)_TARGET_PATCH): PKG=$(2)
726 $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
727 $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
728 $$($(2)_TARGET_EXTRACT): PKG=$(2)
729 $$($(2)_TARGET_SOURCE): PKG=$(2)
730 $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
731 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
733 # Compute the name of the Kconfig option that correspond to the
734 # package being enabled. We handle three cases: the special Linux
735 # kernel case, the bootloaders case, and the normal packages case.
737 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
738 else ifneq ($$(filter boot/% $(BR2_EXTERNAL)/boot/%,$(pkgdir)),)
739 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
740 else ifneq ($$(filter toolchain/% $(BR2_EXTERNAL)/toolchain/%,$(pkgdir)),)
741 $(2)_KCONFIG_VAR = BR2_$(2)
743 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
746 # legal-info: declare dependencies and set values used later for the manifest
747 ifneq ($$($(2)_LICENSE_FILES),)
748 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
750 $(2)_MANIFEST_LICENSE_FILES ?= not saved
752 # If the package declares _LICENSE_FILES, we need to extract it,
753 # for overriden, local or normal remote packages alike, whether
754 # we want to redistribute it or not.
755 ifneq ($$($(2)_LICENSE_FILES),)
756 $(1)-legal-info: $(1)-patch
759 # We only save the sources of packages we want to redistribute, that are
760 # non-overriden (local or true override).
761 ifeq ($$($(2)_REDISTRIBUTE),YES)
762 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
763 # Packages that have a tarball need it downloaded beforehand
764 $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
768 # If FOO_ACTUAL_SOURCE_TARBALL is explicitly defined, it means FOO_SOURCE is
769 # indeed a binary (e.g. external toolchain) and FOO_ACTUAL_SOURCE_TARBALL/_SITE
770 # point to the actual sources tarball. Use the actual sources for legal-info.
771 # For most packages the FOO_SITE/FOO_SOURCE pair points to real source code,
772 # so these are the defaults for FOO_ACTUAL_*.
773 $(2)_ACTUAL_SOURCE_TARBALL ?= $$($(2)_SOURCE)
774 $(2)_ACTUAL_SOURCE_SITE ?= $$(call qstrip,$$($(2)_SITE))
776 # legal-info: produce legally relevant info.
778 # Packages without a source are assumed to be part of Buildroot, skip them.
779 $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
780 ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
782 # Save license files if defined
783 # We save the license files for any kind of package: normal, local,
784 # overridden, or non-redistributable alike.
785 # The reason to save license files even for no-redistribute packages
786 # is that the license still applies to the files distributed as part
787 # of the rootfs, even if the sources are not themselves redistributed.
788 ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
789 @$$(call legal-license-nofiles,$$($(2)_RAWNAME),$$(call UPPERCASE,$(4)))
790 @$$(call legal-warning-pkg,$$($(2)_RAWNAME),cannot save license ($(2)_LICENSE_FILES not defined))
792 @$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
793 endif # license files
795 ifeq ($$($(2)_SITE_METHOD),local)
796 # Packages without a tarball: don't save and warn
797 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
799 else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
800 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
805 ifeq ($$($(2)_REDISTRIBUTE),YES)
806 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
807 $$(call DOWNLOAD,$$($(2)_ACTUAL_SOURCE_SITE)/$$($(2)_ACTUAL_SOURCE_TARBALL))
809 # Save the source tarball
810 $$(Q)support/scripts/hardlink-or-copy \
811 $$(DL_DIR)/$$($(2)_ACTUAL_SOURCE_TARBALL) \
812 $$($(2)_REDIST_SOURCES_DIR)
815 endif # other packages
816 @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call UPPERCASE,$(4)))
817 endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
818 $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
820 # add package to the general list of targets if requested by the buildroot
822 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
824 # Ensure the calling package is the declared provider for all the virtual
825 # packages it claims to be an implementation of.
826 ifneq ($$($(2)_PROVIDES),)
827 $$(foreach pkg,$$($(2)_PROVIDES),\
828 $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
831 # Ensure unified variable name conventions between all packages Some
832 # of the variables are used by more than one infrastructure; so,
833 # rather than duplicating the checks in each infrastructure, we check
834 # all variables here in pkg-generic, even though pkg-generic should
835 # have no knowledge of infra-specific variables.
836 $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
837 $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
838 $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
839 $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
840 $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
841 $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
842 $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
843 $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
844 $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
845 $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
849 ifneq ($$($(2)_PERMISSIONS),)
850 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
852 ifneq ($$($(2)_DEVICES),)
853 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
855 ifneq ($$($(2)_USERS),)
856 PACKAGES_USERS += $$($(2)_USERS)$$(sep)
859 ifeq ($$($(2)_SITE_METHOD),svn)
860 DL_TOOLS_DEPENDENCIES += svn
861 else ifeq ($$($(2)_SITE_METHOD),git)
862 DL_TOOLS_DEPENDENCIES += git
863 else ifeq ($$($(2)_SITE_METHOD),bzr)
864 DL_TOOLS_DEPENDENCIES += bzr
865 else ifeq ($$($(2)_SITE_METHOD),scp)
866 DL_TOOLS_DEPENDENCIES += scp ssh
867 else ifeq ($$($(2)_SITE_METHOD),hg)
868 DL_TOOLS_DEPENDENCIES += hg
869 else ifeq ($$($(2)_SITE_METHOD),cvs)
870 DL_TOOLS_DEPENDENCIES += cvs
873 # $(firstword) is used here because the extractor can have arguments, like
874 # ZCAT="gzip -d -c", and to check for the dependency we only want 'gzip'.
875 # Do not add xzcat to the list of required dependencies, as it gets built
876 # automatically if it isn't found.
877 ifneq ($$(call suitable-extractor,$$($(2)_SOURCE)),$$(XZCAT))
878 DL_TOOLS_DEPENDENCIES += $$(firstword $$(call suitable-extractor,$$($(2)_SOURCE)))
881 # Ensure all virtual targets are PHONY. Listed alphabetically.
883 $(1)-all-external-deps \
884 $(1)-all-legal-info \
886 $(1)-all-source-check \
888 $(1)-clean-for-rebuild \
889 $(1)-clean-for-reconfigure \
890 $(1)-clean-for-reinstall \
899 $(1)-install-images \
900 $(1)-install-staging \
901 $(1)-install-target \
913 ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
914 $$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
917 endif # $(2)_KCONFIG_VAR
918 endef # inner-generic-package
920 ################################################################################
921 # generic-package -- the target generator macro for generic packages
922 ################################################################################
924 # In the case of target packages, keep the package name "pkg"
925 generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
926 # In the case of host packages, turn the package name "pkg" into "host-pkg"
927 host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)