yad: bump to version 0.33.1
[buildroot-gz.git] / package / pkg-generic.mk
blobe22babbcd0c9716bf2b9eea3822aa3fc07b87de9
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
11 # infrastructure
13 # In terms of implementation, this generic infrastructure requires the
14 # .mk file to specify:
16 # 1. Metadata information about the package: name, version,
17 # download URL, etc.
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
30 # three arguments:
31 # $1: either 'start' or 'end'
32 # $2: the name of the step
33 # $3: the name of the package
35 # Start step
36 # $1: step name
37 define step_start
38 $(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),start,$(1),$($(PKG)_NAME))$(sep))
39 endef
41 # End step
42 # $1: step name
43 define step_end
44 $(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),end,$(1),$($(PKG)_NAME))$(sep))
45 endef
47 #######################################
48 # Actual steps hooks
50 # Time steps
51 define step_time
52 printf "%s:%-5.5s:%-20.20s: %s\n" \
53 "$$(date +%s)" "$(1)" "$(2)" "$(3)" \
54 >>"$(BUILD_DIR)/build-time.log"
55 endef
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
67 endef
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 ; \
80 done
81 endef
83 define step_pkg_size
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))))
87 endef
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)))
95 endef
96 GLOBAL_INSTRUMENTATION_HOOKS += check_host_rpath
98 # User-supplied script
99 ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
100 define step_user
101 @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
102 $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
103 endef
104 GLOBAL_INSTRUMENTATION_HOOKS += step_user
105 endif
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") ; \
118 break ; \
119 fi ; \
120 done
121 $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p))$(sep))
122 $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
123 $(Q)mkdir -p $(@D)
124 $(Q)touch $@
126 # Unpack the archive
127 $(BUILD_DIR)/%/.stamp_extracted:
128 @$(call step_start,extract)
129 @$(call MESSAGE,"Extracting")
130 $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
131 $(Q)mkdir -p $(@D)
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)
137 $(Q)touch $@
139 # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
140 # used.
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))
147 $(Q)touch $@
149 # Patch
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))
163 $(Q)( \
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; \
168 else \
169 $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
170 fi; \
171 fi; \
172 done; \
174 $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
175 @$(call step_end,patch)
176 $(Q)touch $@
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))))
183 # Configure
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)
191 $(Q)touch $@
193 # Build
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)
201 $(Q)touch $@
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)
211 $(Q)touch $@
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)
262 $(Q)touch $@
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)
272 $(Q)touch $@
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)
289 $(Q)touch $@
291 # Remove package sources
292 $(BUILD_DIR)/%/.stamp_dircleaned:
293 rm -Rf $(@D)
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
303 # example:
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)
311 endif
312 endef
314 ################################################################################
315 # inner-generic-package -- generates the make targets needed to build a
316 # generic package
318 # argument 1 is the lowercase package name
319 # argument 2 is the uppercase package name, including a HOST_ prefix
320 # for host packages
321 # argument 3 is the uppercase package name, without the HOST_ prefix
322 # for host packages
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
339 # rule.
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)')
356 endif
357 PACKAGES_ALL += $(1)
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.
366 $(2)_TYPE = $(4)
367 $(2)_NAME = $(1)
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
377 # CVS.
378 ifndef $(2)_VERSION
379 ifdef $(3)_DL_VERSION
380 $(2)_DL_VERSION := $$($(3)_DL_VERSION)
381 else ifdef $(3)_VERSION
382 $(2)_DL_VERSION := $$($(3)_VERSION)
383 else
384 $(2)_DL_VERSION = undefined
385 endif
386 else
387 $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
388 endif
389 $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
391 ifdef $(3)_OVERRIDE_SRCDIR
392 $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
393 endif
395 $(2)_BASE_NAME = $(1)-$$($(2)_VERSION)
396 $(2)_DL_DIR = $$(DL_DIR)/$$($(2)_BASE_NAME)
397 $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
399 ifndef $(2)_SUBDIR
400 ifdef $(3)_SUBDIR
401 $(2)_SUBDIR = $$($(3)_SUBDIR)
402 else
403 $(2)_SUBDIR ?=
404 endif
405 endif
407 ifndef $(2)_STRIP_COMPONENTS
408 ifdef $(3)_STRIP_COMPONENTS
409 $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
410 else
411 $(2)_STRIP_COMPONENTS ?= 1
412 endif
413 endif
415 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
416 $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
418 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
419 $(2)_VERSION = custom
420 endif
422 ifndef $(2)_SOURCE
423 ifdef $(3)_SOURCE
424 $(2)_SOURCE = $$($(3)_SOURCE)
425 else
426 $(2)_SOURCE ?= $$($(2)_RAWNAME)-$$($(2)_VERSION).tar.gz
427 endif
428 endif
430 ifndef $(2)_PATCH
431 ifdef $(3)_PATCH
432 $(2)_PATCH = $$($(3)_PATCH)
433 endif
434 endif
436 $(2)_ALL_DOWNLOADS = \
437 $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
438 $$(if $$(findstring ://,$$(p)),$$(p),\
439 $$($(2)_SITE)/$$(p)))
441 ifndef $(2)_SITE
442 ifdef $(3)_SITE
443 $(2)_SITE = $$($(3)_SITE)
444 endif
445 endif
447 ifndef $(2)_SITE_METHOD
448 ifdef $(3)_SITE_METHOD
449 $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
450 else
451 # Try automatic detection using the scheme part of the URI
452 $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
453 endif
454 endif
456 ifeq ($$($(2)_SITE_METHOD),local)
457 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
458 $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
459 endif
460 endif
462 ifndef $(2)_LICENSE
463 ifdef $(3)_LICENSE
464 $(2)_LICENSE = $$($(3)_LICENSE)
465 endif
466 endif
468 $(2)_LICENSE ?= unknown
470 ifndef $(2)_LICENSE_FILES
471 ifdef $(3)_LICENSE_FILES
472 $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
473 endif
474 endif
476 ifndef $(2)_REDISTRIBUTE
477 ifdef $(3)_REDISTRIBUTE
478 $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
479 endif
480 endif
482 $(2)_REDISTRIBUTE ?= YES
484 # When a target package is a toolchain dependency set this variable to
485 # 'NO' so the 'toolchain' dependency is not added to prevent a circular
486 # dependency
487 $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
489 ifeq ($(4),host)
490 $(2)_DEPENDENCIES ?= $$(filter-out host-skeleton host-toolchain $(1),\
491 $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
492 endif
493 ifeq ($(4),target)
494 ifneq ($(1),skeleton)
495 $(2)_DEPENDENCIES += skeleton
496 endif
497 ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
498 $(2)_DEPENDENCIES += toolchain
499 endif
500 endif
502 # Eliminate duplicates in dependencies
503 $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
504 $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
505 $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
507 $(2)_INSTALL_STAGING ?= NO
508 $(2)_INSTALL_IMAGES ?= NO
509 $(2)_INSTALL_TARGET ?= YES
511 # define sub-target stamps
512 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
513 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
514 $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
515 $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
516 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
517 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
518 $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
519 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
520 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
521 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
522 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
524 # default extract command
525 $(2)_EXTRACT_CMDS ?= \
526 $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
527 $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
528 -C $$($(2)_DIR) \
529 $$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
530 $$(TAR_OPTIONS) -)
532 # pre/post-steps hooks
533 $(2)_PRE_DOWNLOAD_HOOKS ?=
534 $(2)_POST_DOWNLOAD_HOOKS ?=
535 $(2)_PRE_EXTRACT_HOOKS ?=
536 $(2)_POST_EXTRACT_HOOKS ?=
537 $(2)_PRE_RSYNC_HOOKS ?=
538 $(2)_POST_RSYNC_HOOKS ?=
539 $(2)_PRE_PATCH_HOOKS ?=
540 $(2)_POST_PATCH_HOOKS ?=
541 $(2)_PRE_CONFIGURE_HOOKS ?=
542 $(2)_POST_CONFIGURE_HOOKS ?=
543 $(2)_PRE_BUILD_HOOKS ?=
544 $(2)_POST_BUILD_HOOKS ?=
545 $(2)_PRE_INSTALL_HOOKS ?=
546 $(2)_POST_INSTALL_HOOKS ?=
547 $(2)_PRE_INSTALL_STAGING_HOOKS ?=
548 $(2)_POST_INSTALL_STAGING_HOOKS ?=
549 $(2)_PRE_INSTALL_TARGET_HOOKS ?=
550 $(2)_POST_INSTALL_TARGET_HOOKS ?=
551 $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
552 $(2)_POST_INSTALL_IMAGES_HOOKS ?=
553 $(2)_PRE_LEGAL_INFO_HOOKS ?=
554 $(2)_POST_LEGAL_INFO_HOOKS ?=
556 # human-friendly targets and target sequencing
557 $(1): $(1)-install
559 ifeq ($$($(2)_TYPE),host)
560 $(1)-install: $(1)-install-host
561 else
562 $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
563 endif
565 ifeq ($$($(2)_INSTALL_TARGET),YES)
566 $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
567 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
568 else
569 $(1)-install-target:
570 endif
572 ifeq ($$($(2)_INSTALL_STAGING),YES)
573 $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
574 $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
575 # Some packages use install-staging stuff for install-target
576 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
577 else
578 $(1)-install-staging:
579 endif
581 ifeq ($$($(2)_INSTALL_IMAGES),YES)
582 $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
583 $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
584 else
585 $(1)-install-images:
586 endif
588 $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
589 $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
591 $(1)-build: $$($(2)_TARGET_BUILD)
592 $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
594 # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
595 # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
596 # therefore the other steps as well) to be re-executed with every
597 # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
598 # dependency by using |.
600 $(1)-configure: $$($(2)_TARGET_CONFIGURE)
601 $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
603 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
604 ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
605 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
606 endif
608 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
609 # In the normal case (no package override), the sequence of steps is
610 # source, by downloading
611 # depends
612 # extract
613 # patch
614 # configure
615 $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
617 $(1)-patch: $$($(2)_TARGET_PATCH)
618 $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
619 # Order-only dependency
620 $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
622 $(1)-extract: $$($(2)_TARGET_EXTRACT)
623 $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
625 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
627 $(1)-source: $$($(2)_TARGET_SOURCE)
629 $(1)-source-check:
630 $$(foreach p,$$($(2)_ALL_DOWNLOADS),$$(call SOURCE_CHECK,$$(p))$$(sep))
632 $(1)-external-deps:
633 @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
634 echo `basename $$$$p` ; \
635 done
636 else
637 # In the package override case, the sequence of steps
638 # source, by rsyncing
639 # depends
640 # configure
642 # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
643 # can remove the stamp file without triggering the configure step.
644 $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
646 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
648 $(1)-patch: $(1)-rsync
649 $(1)-extract: $(1)-rsync
651 $(1)-rsync: $$($(2)_TARGET_RSYNC)
653 $(1)-source:
655 $(1)-source-check:
656 test -d $$($(2)_OVERRIDE_SRCDIR)
658 $(1)-external-deps:
659 @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
660 endif
662 $(1)-show-version:
663 @echo $$($(2)_VERSION)
665 $(1)-show-depends:
666 @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
668 $(1)-graph-depends: graph-depends-requirements
669 @$$(INSTALL) -d $$(GRAPHS_DIR)
670 @cd "$$(CONFIG_DIR)"; \
671 $$(TOPDIR)/support/scripts/graph-depends $$(BR2_GRAPH_DEPS_OPTS) \
672 -p $(1) -o $$(GRAPHS_DIR)/$$(@).dot
673 dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) \
674 -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT) \
675 $$(GRAPHS_DIR)/$$(@).dot
677 $(1)-all-source: $(1)-source
678 $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
680 $(1)-all-source-check: $(1)-source-check
681 $(1)-all-source-check: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source-check)
683 $(1)-all-external-deps: $(1)-external-deps
684 $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
686 $(1)-all-legal-info: $(1)-legal-info
687 $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
689 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
691 $(1)-clean-for-reinstall:
692 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
693 rm -f $$($(2)_TARGET_RSYNC)
694 endif
695 rm -f $$($(2)_TARGET_INSTALL_STAGING)
696 rm -f $$($(2)_TARGET_INSTALL_TARGET)
697 rm -f $$($(2)_TARGET_INSTALL_IMAGES)
698 rm -f $$($(2)_TARGET_INSTALL_HOST)
700 $(1)-reinstall: $(1)-clean-for-reinstall $(1)
702 $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
703 rm -f $$($(2)_TARGET_BUILD)
705 $(1)-rebuild: $(1)-clean-for-rebuild $(1)
707 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
708 rm -f $$($(2)_TARGET_CONFIGURE)
710 $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
712 # define the PKG variable for all targets, containing the
713 # uppercase package variable prefix
714 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
715 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
716 $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
717 $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
718 $$($(2)_TARGET_BUILD): PKG=$(2)
719 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
720 $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
721 $$($(2)_TARGET_RSYNC): PKG=$(2)
722 $$($(2)_TARGET_PATCH): PKG=$(2)
723 $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
724 $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
725 $$($(2)_TARGET_EXTRACT): PKG=$(2)
726 $$($(2)_TARGET_SOURCE): PKG=$(2)
727 $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
728 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
730 # Compute the name of the Kconfig option that correspond to the
731 # package being enabled. We handle three cases: the special Linux
732 # kernel case, the bootloaders case, and the normal packages case.
733 ifeq ($(1),linux)
734 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
735 else ifneq ($$(filter boot/% $(BR2_EXTERNAL)/boot/%,$(pkgdir)),)
736 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
737 else ifneq ($$(filter toolchain/% $(BR2_EXTERNAL)/toolchain/%,$(pkgdir)),)
738 $(2)_KCONFIG_VAR = BR2_$(2)
739 else
740 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
741 endif
743 # legal-info: declare dependencies and set values used later for the manifest
744 ifneq ($$($(2)_LICENSE_FILES),)
745 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
746 endif
747 $(2)_MANIFEST_LICENSE_FILES ?= not saved
749 # If the package declares _LICENSE_FILES, we need to extract it,
750 # for overriden, local or normal remote packages alike, whether
751 # we want to redistribute it or not.
752 ifneq ($$($(2)_LICENSE_FILES),)
753 $(1)-legal-info: $(1)-patch
754 endif
756 # We only save the sources of packages we want to redistribute, that are
757 # non-local, and non-overriden. So only store, in the manifest, the tarball
758 # name of those packages.
759 ifeq ($$($(2)_REDISTRIBUTE),YES)
760 ifneq ($$($(2)_SITE_METHOD),local)
761 ifneq ($$($(2)_SITE_METHOD),override)
762 # Packages that have a tarball need it downloaded beforehand
763 $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
764 endif
765 endif
766 endif
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.
777 $(1)-legal-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))
791 else
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)
802 else
803 # Other packages
805 ifeq ($$($(2)_REDISTRIBUTE),YES)
806 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
807 $$(call DOWNLOAD,$$($(2)_ACTUAL_SOURCE_SITE)/$$($(2)_ACTUAL_SOURCE_TARBALL))
808 endif
809 # Copy the source tarball (just hardlink if possible)
810 @cp -l $$(DL_DIR)/$$($(2)_ACTUAL_SOURCE_TARBALL) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4))) 2>/dev/null || \
811 cp $$(DL_DIR)/$$($(2)_ACTUAL_SOURCE_TARBALL) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
812 endif # redistribute
814 endif # other packages
815 @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call UPPERCASE,$(4)))
816 endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
817 $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
819 # add package to the general list of targets if requested by the buildroot
820 # configuration
821 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
823 # Ensure the calling package is the declared provider for all the virtual
824 # packages it claims to be an implementation of.
825 ifneq ($$($(2)_PROVIDES),)
826 $$(foreach pkg,$$($(2)_PROVIDES),\
827 $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
828 endif
830 # Ensure unified variable name conventions between all packages Some
831 # of the variables are used by more than one infrastructure; so,
832 # rather than duplicating the checks in each infrastructure, we check
833 # all variables here in pkg-generic, even though pkg-generic should
834 # have no knowledge of infra-specific variables.
835 $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
836 $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
837 $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
838 $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
839 $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
840 $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
841 $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
842 $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
843 $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
844 $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
846 PACKAGES += $(1)
848 ifneq ($$($(2)_PERMISSIONS),)
849 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
850 endif
851 ifneq ($$($(2)_DEVICES),)
852 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
853 endif
854 ifneq ($$($(2)_USERS),)
855 PACKAGES_USERS += $$($(2)_USERS)$$(sep)
856 endif
858 ifeq ($$($(2)_SITE_METHOD),svn)
859 DL_TOOLS_DEPENDENCIES += svn
860 else ifeq ($$($(2)_SITE_METHOD),git)
861 DL_TOOLS_DEPENDENCIES += git
862 else ifeq ($$($(2)_SITE_METHOD),bzr)
863 DL_TOOLS_DEPENDENCIES += bzr
864 else ifeq ($$($(2)_SITE_METHOD),scp)
865 DL_TOOLS_DEPENDENCIES += scp ssh
866 else ifeq ($$($(2)_SITE_METHOD),hg)
867 DL_TOOLS_DEPENDENCIES += hg
868 else ifeq ($$($(2)_SITE_METHOD),cvs)
869 DL_TOOLS_DEPENDENCIES += cvs
870 endif # SITE_METHOD
872 # $(firstword) is used here because the extractor can have arguments, like
873 # ZCAT="gzip -d -c", and to check for the dependency we only want 'gzip'.
874 # Do not add xzcat to the list of required dependencies, as it gets built
875 # automatically if it isn't found.
876 ifneq ($$(call suitable-extractor,$$($(2)_SOURCE)),$$(XZCAT))
877 DL_TOOLS_DEPENDENCIES += $$(firstword $$(call suitable-extractor,$$($(2)_SOURCE)))
878 endif
880 # Ensure all virtual targets are PHONY. Listed alphabetically.
881 .PHONY: $(1) \
882 $(1)-all-external-deps \
883 $(1)-all-legal-info \
884 $(1)-all-source \
885 $(1)-all-source-check \
886 $(1)-build \
887 $(1)-clean-for-rebuild \
888 $(1)-clean-for-reconfigure \
889 $(1)-clean-for-reinstall \
890 $(1)-configure \
891 $(1)-depends \
892 $(1)-dirclean \
893 $(1)-external-deps \
894 $(1)-extract \
895 $(1)-graph-depends \
896 $(1)-install \
897 $(1)-install-host \
898 $(1)-install-images \
899 $(1)-install-staging \
900 $(1)-install-target \
901 $(1)-legal-info \
902 $(1)-patch \
903 $(1)-rebuild \
904 $(1)-reconfigure \
905 $(1)-reinstall \
906 $(1)-rsync \
907 $(1)-show-depends \
908 $(1)-show-version \
909 $(1)-source \
910 $(1)-source-check
912 ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
913 $$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
914 endif
916 endif # $(2)_KCONFIG_VAR
917 endef # inner-generic-package
919 ################################################################################
920 # generic-package -- the target generator macro for generic packages
921 ################################################################################
923 # In the case of target packages, keep the package name "pkg"
924 generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
925 # In the case of host packages, turn the package name "pkg" into "host-pkg"
926 host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
928 # :mode=makefile: