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 define _step_pkg_size_get_file_list
63 find . -xtype f -print0 | xargs -0 md5sum ; \
64 find . -xtype d -print0 | xargs -0 -I{} printf 'directory {}\n'; \
69 # This hook will be called before the installation of a package. We store in
70 # a file named .br_filelist_before the list of files currently installed.
71 # Note that the MD5 is also stored, in order to identify if the files are
73 # $(1): package name (ignored)
74 # $(2): base directory to search in
75 define step_pkg_size_start
76 $(call _step_pkg_size_get_file_list,$($(PKG)_DIR)/.br_filelist_before,$(2))
79 # This hook will be called after the installation of a package. We store in
80 # a file named .br_filelist_after the list of files (and their MD5) currently
81 # installed. We then do a diff with the .br_filelist_before to compute the
82 # list of files installed by this package.
83 # The suffix is typically empty for the target variant, for legacy backward
85 # $(1): package name (ignored)
86 # $(2): base directory to search in
87 # $(3): suffix of file (optional)
88 define step_pkg_size_end
89 $(call _step_pkg_size_get_file_list,$($(PKG)_DIR)/.br_filelist_after,$(2))
90 comm -13 $($(PKG)_DIR)/.br_filelist_before $($(PKG)_DIR)/.br_filelist_after | \
91 while read hash file ; do \
92 echo "$(1),$${file}" ; \
93 done >> $(BUILD_DIR)/packages-file-list$(3).txt
94 rm -f $($(PKG)_DIR)/.br_filelist_before $($(PKG)_DIR)/.br_filelist_after
98 $(if $(filter install-target,$(2)),\
99 $(if $(filter start,$(1)),$(call step_pkg_size_start,$(3),$(TARGET_DIR))) \
100 $(if $(filter end,$(1)),$(call step_pkg_size_end,$(3),$(TARGET_DIR))))
101 $(if $(filter install-staging,$(2)),\
102 $(if $(filter start,$(1)),$(call step_pkg_size_start,$(3),$(STAGING_DIR),-staging)) \
103 $(if $(filter end,$(1)),$(call step_pkg_size_end,$(3),$(STAGING_DIR),-staging)))
104 $(if $(filter install-host,$(2)),\
105 $(if $(filter start,$(1)),$(call step_pkg_size_start,$(3),$(HOST_DIR),-host)) \
106 $(if $(filter end,$(1)),$(call step_pkg_size_end,$(3),$(HOST_DIR),-host)))
108 GLOBAL_INSTRUMENTATION_HOOKS += step_pkg_size
110 # Relies on step_pkg_size, so must be after
111 define check_bin_arch
112 $(if $(filter end-install-target,$(1)-$(2)),\
113 support/scripts/check-bin-arch -p $(3) \
114 -l $(BUILD_DIR)/packages-file-list.txt \
115 -r $(TARGET_READELF) \
116 -a $(BR2_READELF_ARCH_NAME))
119 GLOBAL_INSTRUMENTATION_HOOKS += check_bin_arch
121 # This hook checks that host packages that need libraries that we build
122 # have a proper DT_RPATH or DT_RUNPATH tag
123 define check_host_rpath
124 $(if $(filter install-host,$(2)),\
125 $(if $(filter end,$(1)),support/scripts/check-host-rpath $(3) $(HOST_DIR)))
127 GLOBAL_INSTRUMENTATION_HOOKS += check_host_rpath
129 define step_check_build_dir_one
130 if [ -d $(2) ]; then \
131 printf "%s: installs files in %s\n" $(1) $(2) >&2; \
136 define step_check_build_dir
137 $(if $(filter install-staging,$(2)),\
138 $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(STAGING_DIR)/$(O))))
139 $(if $(filter install-target,$(2)),\
140 $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))
142 GLOBAL_INSTRUMENTATION_HOOKS += step_check_build_dir
144 # User-supplied script
145 ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
147 @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
148 $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
150 GLOBAL_INSTRUMENTATION_HOOKS += step_user
153 ################################################################################
154 # Implicit targets -- produce a stamp file for each step of a package build
155 ################################################################################
157 # Retrieve the archive
158 $(BUILD_DIR)/%/.stamp_downloaded:
159 $(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
160 # Only show the download message if it isn't already downloaded
161 $(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
162 if test ! -e $(DL_DIR)/`basename $$p` ; then \
163 $(call MESSAGE,"Downloading") ; \
167 $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p))$(sep))
168 $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
172 # Retrieve actual source archive, e.g. for prebuilt external toolchains
173 $(BUILD_DIR)/%/.stamp_actual_downloaded:
174 $(call DOWNLOAD,$($(PKG)_ACTUAL_SOURCE_SITE)/$($(PKG)_ACTUAL_SOURCE_TARBALL)); \
179 $(BUILD_DIR)/%/.stamp_extracted:
180 @$(call step_start,extract)
181 @$(call MESSAGE,"Extracting")
182 $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
184 $($(PKG)_EXTRACT_CMDS)
185 # some packages have messed up permissions inside
186 $(Q)chmod -R +rw $(@D)
187 $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
188 @$(call step_end,extract)
191 # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
193 $(BUILD_DIR)/%/.stamp_rsynced:
194 @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
195 $(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
196 @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
197 rsync -au --chmod=u=rwX,go=rX $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
198 $(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
203 # The RAWNAME variable is the lowercased package name, which allows to
204 # find the package directory (typically package/<pkgname>) and the
205 # prefix of the patches
207 # For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
208 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS = $(PKGDIR)
209 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
210 $(BUILD_DIR)/%/.stamp_patched:
211 @$(call step_start,patch)
212 @$(call MESSAGE,"Patching")
213 $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
214 $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $(DL_DIR) $(notdir $(p))$(sep))
216 for D in $(PATCH_BASE_DIRS); do \
217 if test -d $${D}; then \
218 if test -d $${D}/$($(PKG)_VERSION); then \
219 $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
221 $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
226 $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
227 @$(call step_end,patch)
230 # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
231 $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
232 $(if $(wildcard $(dir)),,\
233 $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
236 $(BUILD_DIR)/%/.stamp_configured:
237 @$(call step_start,configure)
238 @$(call MESSAGE,"Configuring")
239 $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
240 $($(PKG)_CONFIGURE_CMDS)
241 $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
242 @$(call step_end,configure)
246 $(BUILD_DIR)/%/.stamp_built::
247 @$(call step_start,build)
248 @$(call MESSAGE,"Building")
249 $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
250 +$($(PKG)_BUILD_CMDS)
251 $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
252 @$(call step_end,build)
255 # Install to host dir
256 $(BUILD_DIR)/%/.stamp_host_installed:
257 @$(call step_start,install-host)
258 @$(call MESSAGE,"Installing to host directory")
259 $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
260 +$($(PKG)_INSTALL_CMDS)
261 $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
262 @$(call step_end,install-host)
265 # Install to staging dir
267 # Some packages install libtool .la files alongside any installed
268 # libraries. These .la files sometimes refer to paths relative to the
269 # sysroot, which libtool will interpret as absolute paths to host
270 # libraries instead of the target libraries. Since this is not what we
271 # want, these paths are fixed by prefixing them with $(STAGING_DIR).
272 # As we configure with --prefix=/usr, this fix needs to be applied to
273 # any path that starts with /usr.
275 # To protect against the case that the output or staging directories or
276 # the pre-installed external toolchain themselves are under /usr, we first
277 # substitute away any occurrences of these directories with @BASE_DIR@,
278 # @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
280 # Note that STAGING_DIR can be outside BASE_DIR when the user sets
281 # BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
282 # can be under @BASE_DIR@ when it's a downloaded toolchain, and can be
283 # empty when we use an internal toolchain.
285 $(BUILD_DIR)/%/.stamp_staging_installed:
286 @$(call step_start,install-staging)
287 @$(call MESSAGE,"Installing to staging directory")
288 $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
289 +$($(PKG)_INSTALL_STAGING_CMDS)
290 $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
291 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
292 $(call MESSAGE,"Fixing package configuration files") ;\
293 $(SED) "s,$(BASE_DIR),@BASE_DIR@,g" \
294 -e "s,$(STAGING_DIR),@STAGING_DIR@,g" \
295 -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
296 -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
297 -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
298 -e "s,@STAGING_DIR@,$(STAGING_DIR),g" \
299 -e "s,@BASE_DIR@,$(BASE_DIR),g" \
300 $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
302 @$(call MESSAGE,"Fixing libtool files")
303 $(Q)find $(STAGING_DIR)/usr/lib* -name "*.la" | xargs --no-run-if-empty \
304 $(SED) "s:$(BASE_DIR):@BASE_DIR@:g" \
305 -e "s:$(STAGING_DIR):@STAGING_DIR@:g" \
306 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
307 -e "s:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
308 -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
309 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
310 -e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
311 -e "s:@STAGING_DIR@:$(STAGING_DIR):g" \
312 -e "s:@BASE_DIR@:$(BASE_DIR):g"
313 @$(call step_end,install-staging)
316 # Install to images dir
317 $(BUILD_DIR)/%/.stamp_images_installed:
318 @$(call step_start,install-image)
319 $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
320 @$(call MESSAGE,"Installing to images directory")
321 +$($(PKG)_INSTALL_IMAGES_CMDS)
322 $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
323 @$(call step_end,install-image)
326 # Install to target dir
327 $(BUILD_DIR)/%/.stamp_target_installed:
328 @$(call step_start,install-target)
329 @$(call MESSAGE,"Installing to target")
330 $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
331 +$($(PKG)_INSTALL_TARGET_CMDS)
332 $(if $(BR2_INIT_SYSTEMD),\
333 $($(PKG)_INSTALL_INIT_SYSTEMD))
334 $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
335 $($(PKG)_INSTALL_INIT_SYSV))
336 $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
337 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
338 $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
340 @$(call step_end,install-target)
343 # Remove package sources
344 $(BUILD_DIR)/%/.stamp_dircleaned:
347 ################################################################################
348 # virt-provides-single -- check that provider-pkg is the declared provider for
349 # the virtual package virt-pkg
351 # argument 1 is the lower-case name of the virtual package
352 # argument 2 is the upper-case name of the virtual package
353 # argument 3 is the lower-case name of the provider
356 # $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
357 ################################################################################
358 define virt-provides-single
359 ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
360 $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
361 are selected as providers for virtual package "$(1)". Only one provider can\
362 be selected at a time. Please fix your configuration)
366 define pkg-graph-depends
367 @$$(INSTALL) -d $$(GRAPHS_DIR)
368 @cd "$$(CONFIG_DIR)"; \
369 $$(TOPDIR)/support/scripts/graph-depends $$(BR2_GRAPH_DEPS_OPTS) \
370 -p $(1) $(2) -o $$(GRAPHS_DIR)/$$(@).dot
371 dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) \
372 -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT) \
373 $$(GRAPHS_DIR)/$$(@).dot
376 ################################################################################
377 # inner-generic-package -- generates the make targets needed to build a
380 # argument 1 is the lowercase package name
381 # argument 2 is the uppercase package name, including a HOST_ prefix
383 # argument 3 is the uppercase package name, without the HOST_ prefix
385 # argument 4 is the type (target or host)
387 # Note about variable and function references: inside all blocks that are
388 # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
389 # specific rules apply with respect to variable and function references.
390 # - Numbered variables (parameters to the block) can be referenced with a single
391 # dollar sign: $(1), $(2), $(3), etc.
392 # - pkgdir and pkgname should be referenced with a single dollar sign too. These
393 # functions rely on 'the most recently parsed makefile' which is supposed to
394 # be the package .mk file. If we defer the evaluation of these functions using
395 # double dollar signs, then they may be evaluated too late, when other
396 # makefiles have already been parsed. One specific case is when $$(pkgdir) is
397 # assigned to a variable using deferred evaluation with '=' and this variable
398 # is used in a target rule outside the eval'ed inner block. In this case, the
399 # pkgdir will be that of the last makefile parsed by buildroot, which is not
400 # the expected value. This mechanism is for example used for the TARGET_PATCH
402 # - All other variables should be referenced with a double dollar sign:
403 # $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
404 # referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
405 # etc. This rule ensures that these variables and functions are only expanded
406 # during the $(eval) step, and not earlier. Otherwise, unintuitive and
407 # undesired behavior occurs with respect to these variables and functions.
409 ################################################################################
411 define inner-generic-package
413 # Ensure the package is only declared once, i.e. do not accept that a
414 # package be re-defined by a br2-external tree
415 ifneq ($(call strip,$(filter $(1),$(PACKAGES_ALL))),)
416 $$(error Package '$(1)' defined a second time in '$(pkgdir)'; \
417 previous definition was in '$$($(2)_PKGDIR)')
421 # Define default values for various package-related variables, if not
422 # already defined. For some variables (version, source, site and
423 # subdir), if they are undefined, we try to see if a variable without
424 # the HOST_ prefix is defined. If so, we use such a variable, so that
425 # this information has only to be specified once, for both the
426 # target and host packages of a given .mk file.
430 $(2)_RAWNAME = $$(patsubst host-%,%,$(1))
431 $(2)_PKGDIR = $(pkgdir)
433 # Keep the package version that may contain forward slashes in the _DL_VERSION
434 # variable, then replace all forward slashes ('/') by underscores ('_') to
435 # sanitize the package version that is used in paths, directory and file names.
436 # Forward slashes may appear in the package's version when pointing to a
437 # version control system branch or tag, for example remotes/origin/1_10_stable.
438 # Similar for spaces and colons (:) that may appear in date-based revisions for
441 ifdef $(3)_DL_VERSION
442 $(2)_DL_VERSION := $$($(3)_DL_VERSION)
443 else ifdef $(3)_VERSION
444 $(2)_DL_VERSION := $$($(3)_VERSION)
447 $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
449 $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
451 ifdef $(3)_OVERRIDE_SRCDIR
452 $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
455 $(2)_BASE_NAME = $$(if $$($(2)_VERSION),$(1)-$$($(2)_VERSION),$(1))
456 $(2)_RAW_BASE_NAME = $$(if $$($(2)_VERSION),$$($(2)_RAWNAME)-$$($(2)_VERSION),$$($(2)_RAWNAME))
457 $(2)_DL_DIR = $$(DL_DIR)
458 $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
462 $(2)_SUBDIR = $$($(3)_SUBDIR)
468 ifndef $(2)_STRIP_COMPONENTS
469 ifdef $(3)_STRIP_COMPONENTS
470 $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
472 $(2)_STRIP_COMPONENTS ?= 1
476 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
477 $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
479 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
480 $(2)_VERSION = custom
485 $(2)_SOURCE = $$($(3)_SOURCE)
486 else ifdef $(2)_VERSION
487 $(2)_SOURCE ?= $$($(2)_RAW_BASE_NAME).tar.gz
491 # If FOO_ACTUAL_SOURCE_TARBALL is explicitly defined, it means FOO_SOURCE is
492 # indeed a binary (e.g. external toolchain) and FOO_ACTUAL_SOURCE_TARBALL/_SITE
493 # point to the actual sources tarball. Use the actual sources for legal-info.
494 # For most packages the FOO_SITE/FOO_SOURCE pair points to real source code,
495 # so these are the defaults for FOO_ACTUAL_*.
496 $(2)_ACTUAL_SOURCE_TARBALL ?= $$($(2)_SOURCE)
497 $(2)_ACTUAL_SOURCE_SITE ?= $$(call qstrip,$$($(2)_SITE))
501 $(2)_PATCH = $$($(3)_PATCH)
505 $(2)_ALL_DOWNLOADS = \
506 $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
507 $$(if $$(findstring ://,$$(p)),$$(p),\
508 $$($(2)_SITE)/$$(p)))
512 $(2)_SITE = $$($(3)_SITE)
516 ifndef $(2)_SITE_METHOD
517 ifdef $(3)_SITE_METHOD
518 $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
520 # Try automatic detection using the scheme part of the URI
521 $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
525 # Do not accept to download git submodule if not using the git method
526 ifneq ($$($(2)_GIT_SUBMODULES),)
527 ifneq ($$($(2)_SITE_METHOD),git)
528 $$(error $(2) declares having git sub-modules, but does not use the \
529 'git' method (uses '$$($(2)_SITE_METHOD)' instead))
533 ifeq ($$($(2)_SITE_METHOD),local)
534 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
535 $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
541 $(2)_LICENSE = $$($(3)_LICENSE)
545 $(2)_LICENSE ?= unknown
547 ifndef $(2)_LICENSE_FILES
548 ifdef $(3)_LICENSE_FILES
549 $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
553 ifndef $(2)_REDISTRIBUTE
554 ifdef $(3)_REDISTRIBUTE
555 $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
559 $(2)_REDISTRIBUTE ?= YES
561 $(2)_REDIST_SOURCES_DIR = $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))/$$($(2)_RAW_BASE_NAME)
563 # When a target package is a toolchain dependency set this variable to
564 # 'NO' so the 'toolchain' dependency is not added to prevent a circular
566 # Similarly for the skeleton.
567 $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
568 $(2)_ADD_SKELETON_DEPENDENCY ?= YES
572 ifeq ($$($(2)_ADD_SKELETON_DEPENDENCY),YES)
573 $(2)_DEPENDENCIES += skeleton
575 ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
576 $(2)_DEPENDENCIES += toolchain
580 # Eliminate duplicates in dependencies
581 $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
582 $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
583 $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
585 $(2)_INSTALL_STAGING ?= NO
586 $(2)_INSTALL_IMAGES ?= NO
587 $(2)_INSTALL_TARGET ?= YES
589 # define sub-target stamps
590 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
591 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
592 $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
593 $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
594 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
595 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
596 $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
597 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
598 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
599 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
600 $(2)_TARGET_ACTUAL_SOURCE = $$($(2)_DIR)/.stamp_actual_downloaded
601 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
603 # default extract command
604 $(2)_EXTRACT_CMDS ?= \
605 $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
606 $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
608 $$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
611 # pre/post-steps hooks
612 $(2)_PRE_DOWNLOAD_HOOKS ?=
613 $(2)_POST_DOWNLOAD_HOOKS ?=
614 $(2)_PRE_EXTRACT_HOOKS ?=
615 $(2)_POST_EXTRACT_HOOKS ?=
616 $(2)_PRE_RSYNC_HOOKS ?=
617 $(2)_POST_RSYNC_HOOKS ?=
618 $(2)_PRE_PATCH_HOOKS ?=
619 $(2)_POST_PATCH_HOOKS ?=
620 $(2)_PRE_CONFIGURE_HOOKS ?=
621 $(2)_POST_CONFIGURE_HOOKS ?=
622 $(2)_PRE_BUILD_HOOKS ?=
623 $(2)_POST_BUILD_HOOKS ?=
624 $(2)_PRE_INSTALL_HOOKS ?=
625 $(2)_POST_INSTALL_HOOKS ?=
626 $(2)_PRE_INSTALL_STAGING_HOOKS ?=
627 $(2)_POST_INSTALL_STAGING_HOOKS ?=
628 $(2)_PRE_INSTALL_TARGET_HOOKS ?=
629 $(2)_POST_INSTALL_TARGET_HOOKS ?=
630 $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
631 $(2)_POST_INSTALL_IMAGES_HOOKS ?=
632 $(2)_PRE_LEGAL_INFO_HOOKS ?=
633 $(2)_POST_LEGAL_INFO_HOOKS ?=
634 $(2)_TARGET_FINALIZE_HOOKS ?=
635 $(2)_ROOTFS_PRE_CMD_HOOKS ?=
636 $(2)_ROOTFS_POST_CMD_HOOKS ?=
638 # human-friendly targets and target sequencing
641 ifeq ($$($(2)_TYPE),host)
642 $(1)-install: $(1)-install-host
644 $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
647 ifeq ($$($(2)_INSTALL_TARGET),YES)
648 $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
649 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
654 ifeq ($$($(2)_INSTALL_STAGING),YES)
655 $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
656 $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
657 # Some packages use install-staging stuff for install-target
658 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
660 $(1)-install-staging:
663 ifeq ($$($(2)_INSTALL_IMAGES),YES)
664 $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
665 $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
670 $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
671 $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
673 $(1)-build: $$($(2)_TARGET_BUILD)
674 $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
676 # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
677 # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
678 # therefore the other steps as well) to be re-executed with every
679 # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
680 # dependency by using |.
682 $(1)-configure: $$($(2)_TARGET_CONFIGURE)
683 $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
685 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
686 ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
687 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
690 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
691 # In the normal case (no package override), the sequence of steps is
692 # source, by downloading
697 $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
699 $(1)-patch: $$($(2)_TARGET_PATCH)
700 $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
701 # Order-only dependency
702 $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
704 $(1)-extract: $$($(2)_TARGET_EXTRACT)
705 $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
707 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
709 $(1)-source: $$($(2)_TARGET_SOURCE)
711 $(1)-all-source: $(1)-legal-source
712 $(1)-legal-info: $(1)-legal-source
713 $(1)-legal-source: $(1)-source
715 # Only download the actual source if it differs from the 'main' archive
716 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),)
717 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
718 $(1)-legal-source: $$($(2)_TARGET_ACTUAL_SOURCE)
719 endif # actual sources != sources
720 endif # actual sources != ""
723 @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
724 echo `basename $$$$p` ; \
727 # In the package override case, the sequence of steps
728 # source, by rsyncing
732 # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
733 # can remove the stamp file without triggering the configure step.
734 $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
736 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
738 $(1)-patch: $(1)-rsync
739 $(1)-extract: $(1)-rsync
741 $(1)-rsync: $$($(2)_TARGET_RSYNC)
747 @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
751 @echo $$($(2)_VERSION)
754 @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
757 @echo $$($(2)_RDEPENDENCIES)
759 $(1)-show-build-order: $$(patsubst %,%-show-build-order,$$($(2)_FINAL_ALL_DEPENDENCIES))
762 $(1)-graph-depends: graph-depends-requirements
763 $(call pkg-graph-depends,$(1),--direct)
765 $(1)-graph-rdepends: graph-depends-requirements
766 $(call pkg-graph-depends,$(1),--reverse)
768 $(1)-all-source: $(1)-source
769 $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
771 $(1)-all-external-deps: $(1)-external-deps
772 $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
774 $(1)-all-legal-info: $(1)-legal-info
775 $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
777 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
779 $(1)-clean-for-reinstall:
780 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
781 rm -f $$($(2)_TARGET_RSYNC)
783 rm -f $$($(2)_TARGET_INSTALL_STAGING)
784 rm -f $$($(2)_TARGET_INSTALL_TARGET)
785 rm -f $$($(2)_TARGET_INSTALL_IMAGES)
786 rm -f $$($(2)_TARGET_INSTALL_HOST)
788 $(1)-reinstall: $(1)-clean-for-reinstall $(1)
790 $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
791 rm -f $$($(2)_TARGET_BUILD)
793 $(1)-rebuild: $(1)-clean-for-rebuild $(1)
795 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
796 rm -f $$($(2)_TARGET_CONFIGURE)
798 $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
800 # define the PKG variable for all targets, containing the
801 # uppercase package variable prefix
802 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
803 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
804 $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
805 $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
806 $$($(2)_TARGET_BUILD): PKG=$(2)
807 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
808 $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
809 $$($(2)_TARGET_RSYNC): PKG=$(2)
810 $$($(2)_TARGET_PATCH): PKG=$(2)
811 $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
812 $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
813 $$($(2)_TARGET_EXTRACT): PKG=$(2)
814 $$($(2)_TARGET_SOURCE): PKG=$(2)
815 $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
816 $$($(2)_TARGET_ACTUAL_SOURCE): PKG=$(2)
817 $$($(2)_TARGET_ACTUAL_SOURCE): PKGDIR=$(pkgdir)
818 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
820 # Compute the name of the Kconfig option that correspond to the
821 # package being enabled. We handle three cases: the special Linux
822 # kernel case, the bootloaders case, and the normal packages case.
824 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
825 else ifneq ($$(filter boot/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/boot/%),$(pkgdir)),)
826 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
827 else ifneq ($$(filter toolchain/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/toolchain/%),$(pkgdir)),)
828 $(2)_KCONFIG_VAR = BR2_$(2)
830 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
833 # legal-info: declare dependencies and set values used later for the manifest
834 ifneq ($$($(2)_LICENSE_FILES),)
835 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
838 # We need to extract and patch a package to be able to retrieve its
839 # license files (if any) and the list of patches applied to it (if
841 $(1)-legal-info: $(1)-patch
843 # We only save the sources of packages we want to redistribute, that are
844 # non-overriden (local or true override).
845 ifeq ($$($(2)_REDISTRIBUTE),YES)
846 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
847 # Packages that have a tarball need it downloaded beforehand
848 $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
852 # legal-info: produce legally relevant info.
853 $(1)-legal-info: PKG=$(2)
855 @$$(call MESSAGE,"Collecting legal info")
856 # Packages without a source are assumed to be part of Buildroot, skip them.
857 $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
858 ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
860 # Save license files if defined
861 # We save the license files for any kind of package: normal, local,
862 # overridden, or non-redistributable alike.
863 # The reason to save license files even for no-redistribute packages
864 # is that the license still applies to the files distributed as part
865 # of the rootfs, even if the sources are not themselves redistributed.
866 ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
867 $(Q)$$(call legal-warning-pkg,$$($(2)_RAW_BASE_NAME),cannot save license ($(2)_LICENSE_FILES not defined))
869 $(Q)$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$($(2)_RAW_BASE_NAME),$$($(2)_PKGDIR),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
870 endif # license files
872 ifeq ($$($(2)_SITE_METHOD),local)
873 # Packages without a tarball: don't save and warn
874 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
876 else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
877 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
882 ifeq ($$($(2)_REDISTRIBUTE),YES)
883 # Save the source tarball and any extra downloads, but not
884 # patches, as they are handled specially afterwards.
885 $$(foreach e,$$($(2)_ACTUAL_SOURCE_TARBALL) $$(notdir $$($(2)_EXTRA_DOWNLOADS)),\
886 $$(Q)support/scripts/hardlink-or-copy \
888 $$($(2)_REDIST_SOURCES_DIR)$$(sep))
889 # Save patches and generate the series file
890 $$(Q)while read f; do \
891 support/scripts/hardlink-or-copy \
893 $$($(2)_REDIST_SOURCES_DIR) || exit 1; \
894 printf "%s\n" "$$$${f##*/}" >>$$($(2)_REDIST_SOURCES_DIR)/series || exit 1; \
895 done <$$($(2)_DIR)/.applied_patches_list
898 endif # other packages
899 @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call UPPERCASE,$(4)))
900 endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
901 $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
903 # add package to the general list of targets if requested by the buildroot
905 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
907 # Ensure the calling package is the declared provider for all the virtual
908 # packages it claims to be an implementation of.
909 ifneq ($$($(2)_PROVIDES),)
910 $$(foreach pkg,$$($(2)_PROVIDES),\
911 $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
914 # Register package as a reverse-dependencies of all its dependencies
915 $$(eval $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),\
916 $$(call UPPERCASE,$$(p))_RDEPENDENCIES += $(1)$$(sep)))
918 # Ensure unified variable name conventions between all packages Some
919 # of the variables are used by more than one infrastructure; so,
920 # rather than duplicating the checks in each infrastructure, we check
921 # all variables here in pkg-generic, even though pkg-generic should
922 # have no knowledge of infra-specific variables.
923 $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
924 $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
925 $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
926 $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
927 $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
928 $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
929 $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
930 $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
931 $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
932 $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
936 ifneq ($$($(2)_PERMISSIONS),)
937 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
939 ifneq ($$($(2)_DEVICES),)
940 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
942 ifneq ($$($(2)_USERS),)
943 PACKAGES_USERS += $$($(2)_USERS)$$(sep)
945 TARGET_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)
946 ROOTFS_PRE_CMD_HOOKS += $$($(2)_ROOTFS_PRE_CMD_HOOKS)
947 ROOTFS_POST_CMD_HOOKS += $$($(2)_ROOTFS_POST_CMD_HOOKS)
949 ifeq ($$($(2)_SITE_METHOD),svn)
950 DL_TOOLS_DEPENDENCIES += svn
951 else ifeq ($$($(2)_SITE_METHOD),git)
952 DL_TOOLS_DEPENDENCIES += git
953 else ifeq ($$($(2)_SITE_METHOD),bzr)
954 DL_TOOLS_DEPENDENCIES += bzr
955 else ifeq ($$($(2)_SITE_METHOD),scp)
956 DL_TOOLS_DEPENDENCIES += scp ssh
957 else ifeq ($$($(2)_SITE_METHOD),hg)
958 DL_TOOLS_DEPENDENCIES += hg
959 else ifeq ($$($(2)_SITE_METHOD),cvs)
960 DL_TOOLS_DEPENDENCIES += cvs
963 DL_TOOLS_DEPENDENCIES += $$(call extractor-dependency,$$($(2)_SOURCE))
965 # Ensure all virtual targets are PHONY. Listed alphabetically.
967 $(1)-all-external-deps \
968 $(1)-all-legal-info \
971 $(1)-clean-for-rebuild \
972 $(1)-clean-for-reconfigure \
973 $(1)-clean-for-reinstall \
982 $(1)-install-images \
983 $(1)-install-staging \
984 $(1)-install-target \
996 ifneq ($$($(2)_SOURCE),)
997 ifeq ($$($(2)_SITE),)
998 $$(error $(2)_SITE cannot be empty when $(2)_SOURCE is not)
1002 ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
1003 $$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
1006 ifneq ($$($(2)_HELP_CMDS),)
1007 HELP_PACKAGES += $(2)
1010 endif # $(2)_KCONFIG_VAR
1011 endef # inner-generic-package
1013 ################################################################################
1014 # generic-package -- the target generator macro for generic packages
1015 ################################################################################
1017 # In the case of target packages, keep the package name "pkg"
1018 generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
1019 # In the case of host packages, turn the package name "pkg" into "host-pkg"
1020 host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)