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 $(foreach i,$($(PKG)_BIN_ARCH_EXCLUDE),-i "$(i)") \
116 -r $(TARGET_READELF) \
117 -a $(BR2_READELF_ARCH_NAME))
120 GLOBAL_INSTRUMENTATION_HOOKS += check_bin_arch
122 # This hook checks that host packages that need libraries that we build
123 # have a proper DT_RPATH or DT_RUNPATH tag
124 define check_host_rpath
125 $(if $(filter install-host,$(2)),\
126 $(if $(filter end,$(1)),support/scripts/check-host-rpath $(3) $(HOST_DIR)))
128 GLOBAL_INSTRUMENTATION_HOOKS += check_host_rpath
130 define step_check_build_dir_one
131 if [ -d $(2) ]; then \
132 printf "%s: installs files in %s\n" $(1) $(2) >&2; \
137 define step_check_build_dir
138 $(if $(filter install-staging,$(2)),\
139 $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(STAGING_DIR)/$(O))))
140 $(if $(filter install-target,$(2)),\
141 $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))
143 GLOBAL_INSTRUMENTATION_HOOKS += step_check_build_dir
145 # User-supplied script
146 ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
148 @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
149 $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
151 GLOBAL_INSTRUMENTATION_HOOKS += step_user
154 ################################################################################
155 # Implicit targets -- produce a stamp file for each step of a package build
156 ################################################################################
158 # Retrieve the archive
159 $(BUILD_DIR)/%/.stamp_downloaded:
160 $(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
161 # Only show the download message if it isn't already downloaded
162 $(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
163 if test ! -e $(DL_DIR)/`basename $$p` ; then \
164 $(call MESSAGE,"Downloading") ; \
168 $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p))$(sep))
169 $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
173 # Retrieve actual source archive, e.g. for prebuilt external toolchains
174 $(BUILD_DIR)/%/.stamp_actual_downloaded:
175 $(call DOWNLOAD,$($(PKG)_ACTUAL_SOURCE_SITE)/$($(PKG)_ACTUAL_SOURCE_TARBALL)); \
180 $(BUILD_DIR)/%/.stamp_extracted:
181 @$(call step_start,extract)
182 @$(call MESSAGE,"Extracting")
183 $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
185 $($(PKG)_EXTRACT_CMDS)
186 # some packages have messed up permissions inside
187 $(Q)chmod -R +rw $(@D)
188 $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
189 @$(call step_end,extract)
192 # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
194 $(BUILD_DIR)/%/.stamp_rsynced:
195 @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
196 $(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
197 @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
198 rsync -au --chmod=u=rwX,go=rX $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
199 $(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
204 # The RAWNAME variable is the lowercased package name, which allows to
205 # find the package directory (typically package/<pkgname>) and the
206 # prefix of the patches
208 # For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
209 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS = $(PKGDIR)
210 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
211 $(BUILD_DIR)/%/.stamp_patched:
212 @$(call step_start,patch)
213 @$(call MESSAGE,"Patching")
214 $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
215 $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $(DL_DIR) $(notdir $(p))$(sep))
217 for D in $(PATCH_BASE_DIRS); do \
218 if test -d $${D}; then \
219 if test -d $${D}/$($(PKG)_VERSION); then \
220 $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
222 $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
227 $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
228 @$(call step_end,patch)
231 # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
232 $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
233 $(if $(wildcard $(dir)),,\
234 $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
237 $(BUILD_DIR)/%/.stamp_configured:
238 @$(call step_start,configure)
239 @$(call MESSAGE,"Configuring")
240 $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
241 $($(PKG)_CONFIGURE_CMDS)
242 $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
243 @$(call step_end,configure)
247 $(BUILD_DIR)/%/.stamp_built::
248 @$(call step_start,build)
249 @$(call MESSAGE,"Building")
250 $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
251 +$($(PKG)_BUILD_CMDS)
252 $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
253 @$(call step_end,build)
256 # Install to host dir
257 $(BUILD_DIR)/%/.stamp_host_installed:
258 @$(call step_start,install-host)
259 @$(call MESSAGE,"Installing to host directory")
260 $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
261 +$($(PKG)_INSTALL_CMDS)
262 $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
263 @$(call step_end,install-host)
266 # Install to staging dir
268 # Some packages install libtool .la files alongside any installed
269 # libraries. These .la files sometimes refer to paths relative to the
270 # sysroot, which libtool will interpret as absolute paths to host
271 # libraries instead of the target libraries. Since this is not what we
272 # want, these paths are fixed by prefixing them with $(STAGING_DIR).
273 # As we configure with --prefix=/usr, this fix needs to be applied to
274 # any path that starts with /usr.
276 # To protect against the case that the output or staging directories or
277 # the pre-installed external toolchain themselves are under /usr, we first
278 # substitute away any occurrences of these directories with @BASE_DIR@,
279 # @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
281 # Note that STAGING_DIR can be outside BASE_DIR when the user sets
282 # BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
283 # can be under @BASE_DIR@ when it's a downloaded toolchain, and can be
284 # empty when we use an internal toolchain.
286 $(BUILD_DIR)/%/.stamp_staging_installed:
287 @$(call step_start,install-staging)
288 @$(call MESSAGE,"Installing to staging directory")
289 $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
290 +$($(PKG)_INSTALL_STAGING_CMDS)
291 $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
292 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
293 $(call MESSAGE,"Fixing package configuration files") ;\
294 $(SED) "s,$(BASE_DIR),@BASE_DIR@,g" \
295 -e "s,$(STAGING_DIR),@STAGING_DIR@,g" \
296 -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
297 -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
298 -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
299 -e "s,@STAGING_DIR@,$(STAGING_DIR),g" \
300 -e "s,@BASE_DIR@,$(BASE_DIR),g" \
301 $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
303 @$(call MESSAGE,"Fixing libtool files")
304 $(Q)find $(STAGING_DIR)/usr/lib* -name "*.la" | xargs --no-run-if-empty \
305 $(SED) "s:$(BASE_DIR):@BASE_DIR@:g" \
306 -e "s:$(STAGING_DIR):@STAGING_DIR@:g" \
307 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
308 -e "s:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
309 -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
310 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
311 -e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
312 -e "s:@STAGING_DIR@:$(STAGING_DIR):g" \
313 -e "s:@BASE_DIR@:$(BASE_DIR):g"
314 @$(call step_end,install-staging)
317 # Install to images dir
318 $(BUILD_DIR)/%/.stamp_images_installed:
319 @$(call step_start,install-image)
320 $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
321 @$(call MESSAGE,"Installing to images directory")
322 +$($(PKG)_INSTALL_IMAGES_CMDS)
323 $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
324 @$(call step_end,install-image)
327 # Install to target dir
328 $(BUILD_DIR)/%/.stamp_target_installed:
329 @$(call step_start,install-target)
330 @$(call MESSAGE,"Installing to target")
331 $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
332 +$($(PKG)_INSTALL_TARGET_CMDS)
333 $(if $(BR2_INIT_SYSTEMD),\
334 $($(PKG)_INSTALL_INIT_SYSTEMD))
335 $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
336 $($(PKG)_INSTALL_INIT_SYSV))
337 $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
338 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
339 $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
341 @$(call step_end,install-target)
344 # Remove package sources
345 $(BUILD_DIR)/%/.stamp_dircleaned:
348 ################################################################################
349 # virt-provides-single -- check that provider-pkg is the declared provider for
350 # the virtual package virt-pkg
352 # argument 1 is the lower-case name of the virtual package
353 # argument 2 is the upper-case name of the virtual package
354 # argument 3 is the lower-case name of the provider
357 # $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
358 ################################################################################
359 define virt-provides-single
360 ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
361 $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
362 are selected as providers for virtual package "$(1)". Only one provider can\
363 be selected at a time. Please fix your configuration)
367 define pkg-graph-depends
368 @$$(INSTALL) -d $$(GRAPHS_DIR)
369 @cd "$$(CONFIG_DIR)"; \
370 $$(TOPDIR)/support/scripts/graph-depends $$(BR2_GRAPH_DEPS_OPTS) \
371 -p $(1) $(2) -o $$(GRAPHS_DIR)/$$(@).dot
372 dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) \
373 -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT) \
374 $$(GRAPHS_DIR)/$$(@).dot
377 ################################################################################
378 # inner-generic-package -- generates the make targets needed to build a
381 # argument 1 is the lowercase package name
382 # argument 2 is the uppercase package name, including a HOST_ prefix
384 # argument 3 is the uppercase package name, without the HOST_ prefix
386 # argument 4 is the type (target or host)
388 # Note about variable and function references: inside all blocks that are
389 # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
390 # specific rules apply with respect to variable and function references.
391 # - Numbered variables (parameters to the block) can be referenced with a single
392 # dollar sign: $(1), $(2), $(3), etc.
393 # - pkgdir and pkgname should be referenced with a single dollar sign too. These
394 # functions rely on 'the most recently parsed makefile' which is supposed to
395 # be the package .mk file. If we defer the evaluation of these functions using
396 # double dollar signs, then they may be evaluated too late, when other
397 # makefiles have already been parsed. One specific case is when $$(pkgdir) is
398 # assigned to a variable using deferred evaluation with '=' and this variable
399 # is used in a target rule outside the eval'ed inner block. In this case, the
400 # pkgdir will be that of the last makefile parsed by buildroot, which is not
401 # the expected value. This mechanism is for example used for the TARGET_PATCH
403 # - All other variables should be referenced with a double dollar sign:
404 # $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
405 # referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
406 # etc. This rule ensures that these variables and functions are only expanded
407 # during the $(eval) step, and not earlier. Otherwise, unintuitive and
408 # undesired behavior occurs with respect to these variables and functions.
410 ################################################################################
412 define inner-generic-package
414 # Ensure the package is only declared once, i.e. do not accept that a
415 # package be re-defined by a br2-external tree
416 ifneq ($(call strip,$(filter $(1),$(PACKAGES_ALL))),)
417 $$(error Package '$(1)' defined a second time in '$(pkgdir)'; \
418 previous definition was in '$$($(2)_PKGDIR)')
422 # Define default values for various package-related variables, if not
423 # already defined. For some variables (version, source, site and
424 # subdir), if they are undefined, we try to see if a variable without
425 # the HOST_ prefix is defined. If so, we use such a variable, so that
426 # this information has only to be specified once, for both the
427 # target and host packages of a given .mk file.
431 $(2)_RAWNAME = $$(patsubst host-%,%,$(1))
432 $(2)_PKGDIR = $(pkgdir)
434 # Keep the package version that may contain forward slashes in the _DL_VERSION
435 # variable, then replace all forward slashes ('/') by underscores ('_') to
436 # sanitize the package version that is used in paths, directory and file names.
437 # Forward slashes may appear in the package's version when pointing to a
438 # version control system branch or tag, for example remotes/origin/1_10_stable.
439 # Similar for spaces and colons (:) that may appear in date-based revisions for
442 ifdef $(3)_DL_VERSION
443 $(2)_DL_VERSION := $$($(3)_DL_VERSION)
444 else ifdef $(3)_VERSION
445 $(2)_DL_VERSION := $$($(3)_VERSION)
448 $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
450 $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
452 ifdef $(3)_OVERRIDE_SRCDIR
453 $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
456 $(2)_BASE_NAME = $$(if $$($(2)_VERSION),$(1)-$$($(2)_VERSION),$(1))
457 $(2)_RAW_BASE_NAME = $$(if $$($(2)_VERSION),$$($(2)_RAWNAME)-$$($(2)_VERSION),$$($(2)_RAWNAME))
458 $(2)_DL_DIR = $$(DL_DIR)
459 $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
463 $(2)_SUBDIR = $$($(3)_SUBDIR)
469 ifndef $(2)_STRIP_COMPONENTS
470 ifdef $(3)_STRIP_COMPONENTS
471 $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
473 $(2)_STRIP_COMPONENTS ?= 1
477 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
478 $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
480 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
481 $(2)_VERSION = custom
486 $(2)_SOURCE = $$($(3)_SOURCE)
487 else ifdef $(2)_VERSION
488 $(2)_SOURCE ?= $$($(2)_RAW_BASE_NAME).tar.gz
492 # If FOO_ACTUAL_SOURCE_TARBALL is explicitly defined, it means FOO_SOURCE is
493 # indeed a binary (e.g. external toolchain) and FOO_ACTUAL_SOURCE_TARBALL/_SITE
494 # point to the actual sources tarball. Use the actual sources for legal-info.
495 # For most packages the FOO_SITE/FOO_SOURCE pair points to real source code,
496 # so these are the defaults for FOO_ACTUAL_*.
497 $(2)_ACTUAL_SOURCE_TARBALL ?= $$($(2)_SOURCE)
498 $(2)_ACTUAL_SOURCE_SITE ?= $$(call qstrip,$$($(2)_SITE))
502 $(2)_PATCH = $$($(3)_PATCH)
506 $(2)_ALL_DOWNLOADS = \
507 $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
508 $$(if $$(findstring ://,$$(p)),$$(p),\
509 $$($(2)_SITE)/$$(p)))
513 $(2)_SITE = $$($(3)_SITE)
517 ifndef $(2)_SITE_METHOD
518 ifdef $(3)_SITE_METHOD
519 $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
521 # Try automatic detection using the scheme part of the URI
522 $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
526 # Do not accept to download git submodule if not using the git method
527 ifneq ($$($(2)_GIT_SUBMODULES),)
528 ifneq ($$($(2)_SITE_METHOD),git)
529 $$(error $(2) declares having git sub-modules, but does not use the \
530 'git' method (uses '$$($(2)_SITE_METHOD)' instead))
534 ifeq ($$($(2)_SITE_METHOD),local)
535 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
536 $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
542 $(2)_LICENSE = $$($(3)_LICENSE)
546 $(2)_LICENSE ?= unknown
548 ifndef $(2)_LICENSE_FILES
549 ifdef $(3)_LICENSE_FILES
550 $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
554 ifndef $(2)_REDISTRIBUTE
555 ifdef $(3)_REDISTRIBUTE
556 $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
560 $(2)_REDISTRIBUTE ?= YES
562 $(2)_REDIST_SOURCES_DIR = $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))/$$($(2)_RAW_BASE_NAME)
564 # When a target package is a toolchain dependency set this variable to
565 # 'NO' so the 'toolchain' dependency is not added to prevent a circular
567 # Similarly for the skeleton.
568 $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
569 $(2)_ADD_SKELETON_DEPENDENCY ?= YES
573 ifeq ($$($(2)_ADD_SKELETON_DEPENDENCY),YES)
574 $(2)_DEPENDENCIES += skeleton
576 ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
577 $(2)_DEPENDENCIES += toolchain
581 # Eliminate duplicates in dependencies
582 $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
583 $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
584 $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
586 $(2)_INSTALL_STAGING ?= NO
587 $(2)_INSTALL_IMAGES ?= NO
588 $(2)_INSTALL_TARGET ?= YES
590 # define sub-target stamps
591 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
592 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
593 $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
594 $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
595 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
596 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
597 $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
598 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
599 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
600 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
601 $(2)_TARGET_ACTUAL_SOURCE = $$($(2)_DIR)/.stamp_actual_downloaded
602 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
604 # default extract command
605 $(2)_EXTRACT_CMDS ?= \
606 $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
607 $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
609 $$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
612 # pre/post-steps hooks
613 $(2)_PRE_DOWNLOAD_HOOKS ?=
614 $(2)_POST_DOWNLOAD_HOOKS ?=
615 $(2)_PRE_EXTRACT_HOOKS ?=
616 $(2)_POST_EXTRACT_HOOKS ?=
617 $(2)_PRE_RSYNC_HOOKS ?=
618 $(2)_POST_RSYNC_HOOKS ?=
619 $(2)_PRE_PATCH_HOOKS ?=
620 $(2)_POST_PATCH_HOOKS ?=
621 $(2)_PRE_CONFIGURE_HOOKS ?=
622 $(2)_POST_CONFIGURE_HOOKS ?=
623 $(2)_PRE_BUILD_HOOKS ?=
624 $(2)_POST_BUILD_HOOKS ?=
625 $(2)_PRE_INSTALL_HOOKS ?=
626 $(2)_POST_INSTALL_HOOKS ?=
627 $(2)_PRE_INSTALL_STAGING_HOOKS ?=
628 $(2)_POST_INSTALL_STAGING_HOOKS ?=
629 $(2)_PRE_INSTALL_TARGET_HOOKS ?=
630 $(2)_POST_INSTALL_TARGET_HOOKS ?=
631 $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
632 $(2)_POST_INSTALL_IMAGES_HOOKS ?=
633 $(2)_PRE_LEGAL_INFO_HOOKS ?=
634 $(2)_POST_LEGAL_INFO_HOOKS ?=
635 $(2)_TARGET_FINALIZE_HOOKS ?=
636 $(2)_ROOTFS_PRE_CMD_HOOKS ?=
637 $(2)_ROOTFS_POST_CMD_HOOKS ?=
639 # human-friendly targets and target sequencing
642 ifeq ($$($(2)_TYPE),host)
643 $(1)-install: $(1)-install-host
645 $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
648 ifeq ($$($(2)_INSTALL_TARGET),YES)
649 $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
650 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
655 ifeq ($$($(2)_INSTALL_STAGING),YES)
656 $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
657 $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
658 # Some packages use install-staging stuff for install-target
659 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
661 $(1)-install-staging:
664 ifeq ($$($(2)_INSTALL_IMAGES),YES)
665 $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
666 $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
671 $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
672 $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
674 $(1)-build: $$($(2)_TARGET_BUILD)
675 $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
677 # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
678 # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
679 # therefore the other steps as well) to be re-executed with every
680 # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
681 # dependency by using |.
683 $(1)-configure: $$($(2)_TARGET_CONFIGURE)
684 $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
686 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
687 ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
688 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
691 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
692 # In the normal case (no package override), the sequence of steps is
693 # source, by downloading
698 $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
700 $(1)-patch: $$($(2)_TARGET_PATCH)
701 $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
702 # Order-only dependency
703 $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
705 $(1)-extract: $$($(2)_TARGET_EXTRACT)
706 $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
708 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
710 $(1)-source: $$($(2)_TARGET_SOURCE)
712 $(1)-all-source: $(1)-legal-source
713 $(1)-legal-info: $(1)-legal-source
714 $(1)-legal-source: $(1)-source
716 # Only download the actual source if it differs from the 'main' archive
717 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),)
718 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
719 $(1)-legal-source: $$($(2)_TARGET_ACTUAL_SOURCE)
720 endif # actual sources != sources
721 endif # actual sources != ""
724 @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
725 echo `basename $$$$p` ; \
728 # In the package override case, the sequence of steps
729 # source, by rsyncing
733 # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
734 # can remove the stamp file without triggering the configure step.
735 $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
737 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
739 $(1)-patch: $(1)-rsync
740 $(1)-extract: $(1)-rsync
742 $(1)-rsync: $$($(2)_TARGET_RSYNC)
748 @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
752 @echo $$($(2)_VERSION)
755 @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
758 @echo $$($(2)_RDEPENDENCIES)
760 $(1)-show-build-order: $$(patsubst %,%-show-build-order,$$($(2)_FINAL_ALL_DEPENDENCIES))
763 $(1)-graph-depends: graph-depends-requirements
764 $(call pkg-graph-depends,$(1),--direct)
766 $(1)-graph-rdepends: graph-depends-requirements
767 $(call pkg-graph-depends,$(1),--reverse)
769 $(1)-all-source: $(1)-source
770 $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
772 $(1)-all-external-deps: $(1)-external-deps
773 $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
775 $(1)-all-legal-info: $(1)-legal-info
776 $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
778 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
780 $(1)-clean-for-reinstall:
781 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
782 rm -f $$($(2)_TARGET_RSYNC)
784 rm -f $$($(2)_TARGET_INSTALL_STAGING)
785 rm -f $$($(2)_TARGET_INSTALL_TARGET)
786 rm -f $$($(2)_TARGET_INSTALL_IMAGES)
787 rm -f $$($(2)_TARGET_INSTALL_HOST)
789 $(1)-reinstall: $(1)-clean-for-reinstall $(1)
791 $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
792 rm -f $$($(2)_TARGET_BUILD)
794 $(1)-rebuild: $(1)-clean-for-rebuild $(1)
796 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
797 rm -f $$($(2)_TARGET_CONFIGURE)
799 $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
801 # define the PKG variable for all targets, containing the
802 # uppercase package variable prefix
803 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
804 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
805 $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
806 $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
807 $$($(2)_TARGET_BUILD): PKG=$(2)
808 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
809 $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
810 $$($(2)_TARGET_RSYNC): PKG=$(2)
811 $$($(2)_TARGET_PATCH): PKG=$(2)
812 $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
813 $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
814 $$($(2)_TARGET_EXTRACT): PKG=$(2)
815 $$($(2)_TARGET_SOURCE): PKG=$(2)
816 $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
817 $$($(2)_TARGET_ACTUAL_SOURCE): PKG=$(2)
818 $$($(2)_TARGET_ACTUAL_SOURCE): PKGDIR=$(pkgdir)
819 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
821 # Compute the name of the Kconfig option that correspond to the
822 # package being enabled. We handle three cases: the special Linux
823 # kernel case, the bootloaders case, and the normal packages case.
825 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
826 else ifneq ($$(filter boot/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/boot/%),$(pkgdir)),)
827 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
828 else ifneq ($$(filter toolchain/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/toolchain/%),$(pkgdir)),)
829 $(2)_KCONFIG_VAR = BR2_$(2)
831 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
834 # legal-info: declare dependencies and set values used later for the manifest
835 ifneq ($$($(2)_LICENSE_FILES),)
836 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
839 # We need to extract and patch a package to be able to retrieve its
840 # license files (if any) and the list of patches applied to it (if
842 $(1)-legal-info: $(1)-patch
844 # We only save the sources of packages we want to redistribute, that are
845 # non-overriden (local or true override).
846 ifeq ($$($(2)_REDISTRIBUTE),YES)
847 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
848 # Packages that have a tarball need it downloaded beforehand
849 $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
853 # legal-info: produce legally relevant info.
854 $(1)-legal-info: PKG=$(2)
856 @$$(call MESSAGE,"Collecting legal info")
857 # Packages without a source are assumed to be part of Buildroot, skip them.
858 $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
859 ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
861 # Save license files if defined
862 # We save the license files for any kind of package: normal, local,
863 # overridden, or non-redistributable alike.
864 # The reason to save license files even for no-redistribute packages
865 # is that the license still applies to the files distributed as part
866 # of the rootfs, even if the sources are not themselves redistributed.
867 ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
868 $(Q)$$(call legal-warning-pkg,$$($(2)_RAW_BASE_NAME),cannot save license ($(2)_LICENSE_FILES not defined))
870 $(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))
871 endif # license files
873 ifeq ($$($(2)_SITE_METHOD),local)
874 # Packages without a tarball: don't save and warn
875 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
877 else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
878 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
883 ifeq ($$($(2)_REDISTRIBUTE),YES)
884 # Save the source tarball and any extra downloads, but not
885 # patches, as they are handled specially afterwards.
886 $$(foreach e,$$($(2)_ACTUAL_SOURCE_TARBALL) $$(notdir $$($(2)_EXTRA_DOWNLOADS)),\
887 $$(Q)support/scripts/hardlink-or-copy \
889 $$($(2)_REDIST_SOURCES_DIR)$$(sep))
890 # Save patches and generate the series file
891 $$(Q)while read f; do \
892 support/scripts/hardlink-or-copy \
894 $$($(2)_REDIST_SOURCES_DIR) || exit 1; \
895 printf "%s\n" "$$$${f##*/}" >>$$($(2)_REDIST_SOURCES_DIR)/series || exit 1; \
896 done <$$($(2)_DIR)/.applied_patches_list
899 endif # other packages
900 @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call UPPERCASE,$(4)))
901 endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
902 $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
904 # add package to the general list of targets if requested by the buildroot
906 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
908 # Ensure the calling package is the declared provider for all the virtual
909 # packages it claims to be an implementation of.
910 ifneq ($$($(2)_PROVIDES),)
911 $$(foreach pkg,$$($(2)_PROVIDES),\
912 $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
915 # Register package as a reverse-dependencies of all its dependencies
916 $$(eval $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),\
917 $$(call UPPERCASE,$$(p))_RDEPENDENCIES += $(1)$$(sep)))
919 # Ensure unified variable name conventions between all packages Some
920 # of the variables are used by more than one infrastructure; so,
921 # rather than duplicating the checks in each infrastructure, we check
922 # all variables here in pkg-generic, even though pkg-generic should
923 # have no knowledge of infra-specific variables.
924 $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
925 $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
926 $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
927 $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
928 $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
929 $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
930 $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
931 $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
932 $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
933 $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
937 ifneq ($$($(2)_PERMISSIONS),)
938 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
940 ifneq ($$($(2)_DEVICES),)
941 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
943 ifneq ($$($(2)_USERS),)
944 PACKAGES_USERS += $$($(2)_USERS)$$(sep)
946 TARGET_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)
947 ROOTFS_PRE_CMD_HOOKS += $$($(2)_ROOTFS_PRE_CMD_HOOKS)
948 ROOTFS_POST_CMD_HOOKS += $$($(2)_ROOTFS_POST_CMD_HOOKS)
950 ifeq ($$($(2)_SITE_METHOD),svn)
951 DL_TOOLS_DEPENDENCIES += svn
952 else ifeq ($$($(2)_SITE_METHOD),git)
953 DL_TOOLS_DEPENDENCIES += git
954 else ifeq ($$($(2)_SITE_METHOD),bzr)
955 DL_TOOLS_DEPENDENCIES += bzr
956 else ifeq ($$($(2)_SITE_METHOD),scp)
957 DL_TOOLS_DEPENDENCIES += scp ssh
958 else ifeq ($$($(2)_SITE_METHOD),hg)
959 DL_TOOLS_DEPENDENCIES += hg
960 else ifeq ($$($(2)_SITE_METHOD),cvs)
961 DL_TOOLS_DEPENDENCIES += cvs
964 DL_TOOLS_DEPENDENCIES += $$(call extractor-dependency,$$($(2)_SOURCE))
966 # Ensure all virtual targets are PHONY. Listed alphabetically.
968 $(1)-all-external-deps \
969 $(1)-all-legal-info \
972 $(1)-clean-for-rebuild \
973 $(1)-clean-for-reconfigure \
974 $(1)-clean-for-reinstall \
983 $(1)-install-images \
984 $(1)-install-staging \
985 $(1)-install-target \
997 ifneq ($$($(2)_SOURCE),)
998 ifeq ($$($(2)_SITE),)
999 $$(error $(2)_SITE cannot be empty when $(2)_SOURCE is not)
1003 ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
1004 $$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
1007 ifneq ($$($(2)_HELP_CMDS),)
1008 HELP_PACKAGES += $(2)
1011 endif # $(2)_KCONFIG_VAR
1012 endef # inner-generic-package
1014 ################################################################################
1015 # generic-package -- the target generator macro for generic packages
1016 ################################################################################
1018 # In the case of target packages, keep the package name "pkg"
1019 generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
1020 # In the case of host packages, turn the package name "pkg" into "host-pkg"
1021 host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)