edid-decode: new package
[buildroot-gz.git] / package / pkg-generic.mk
blob357a5c7b9e8398d518b8461699c58750a4e6436a
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: NAMEVER = $(RAWNAME)-$($(PKG)_VERSION)
157 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS = $(PKGDIR)
158 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
159 $(BUILD_DIR)/%/.stamp_patched:
160 @$(call step_start,patch)
161 @$(call MESSAGE,"Patching")
162 $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
163 $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $(DL_DIR) $(notdir $(p))$(sep))
164 $(Q)( \
165 for D in $(PATCH_BASE_DIRS); do \
166 if test -d $${D}; then \
167 if test -d $${D}/$($(PKG)_VERSION); then \
168 $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
169 else \
170 $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
171 fi; \
172 fi; \
173 done; \
175 $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
176 @$(call step_end,patch)
177 $(Q)touch $@
179 # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
180 $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
181 $(if $(wildcard $(dir)),,\
182 $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
184 # Configure
185 $(BUILD_DIR)/%/.stamp_configured:
186 @$(call step_start,configure)
187 @$(call MESSAGE,"Configuring")
188 $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
189 $($(PKG)_CONFIGURE_CMDS)
190 $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
191 @$(call step_end,configure)
192 $(Q)touch $@
194 # Build
195 $(BUILD_DIR)/%/.stamp_built::
196 @$(call step_start,build)
197 @$(call MESSAGE,"Building")
198 $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
199 +$($(PKG)_BUILD_CMDS)
200 $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
201 @$(call step_end,build)
202 $(Q)touch $@
204 # Install to host dir
205 $(BUILD_DIR)/%/.stamp_host_installed:
206 @$(call step_start,install-host)
207 @$(call MESSAGE,"Installing to host directory")
208 $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
209 +$($(PKG)_INSTALL_CMDS)
210 $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
211 @$(call step_end,install-host)
212 $(Q)touch $@
214 # Install to staging dir
216 # Some packages install libtool .la files alongside any installed
217 # libraries. These .la files sometimes refer to paths relative to the
218 # sysroot, which libtool will interpret as absolute paths to host
219 # libraries instead of the target libraries. Since this is not what we
220 # want, these paths are fixed by prefixing them with $(STAGING_DIR).
221 # As we configure with --prefix=/usr, this fix needs to be applied to
222 # any path that starts with /usr.
224 # To protect against the case that the output or staging directories or
225 # the pre-installed external toolchain themselves are under /usr, we first
226 # substitute away any occurrences of these directories with @BASE_DIR@,
227 # @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
229 # Note that STAGING_DIR can be outside BASE_DIR when the user sets
230 # BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
231 # can be under @BASE_DIR@ when it's a downloaded toolchain, and can be
232 # empty when we use an internal toolchain.
234 $(BUILD_DIR)/%/.stamp_staging_installed:
235 @$(call step_start,install-staging)
236 @$(call MESSAGE,"Installing to staging directory")
237 $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
238 +$($(PKG)_INSTALL_STAGING_CMDS)
239 $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
240 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
241 $(call MESSAGE,"Fixing package configuration files") ;\
242 $(SED) "s,$(BASE_DIR),@BASE_DIR@,g" \
243 -e "s,$(STAGING_DIR),@STAGING_DIR@,g" \
244 -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
245 -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
246 -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
247 -e "s,@STAGING_DIR@,$(STAGING_DIR),g" \
248 -e "s,@BASE_DIR@,$(BASE_DIR),g" \
249 $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
251 @$(call MESSAGE,"Fixing libtool files")
252 $(Q)find $(STAGING_DIR)/usr/lib* -name "*.la" | xargs --no-run-if-empty \
253 $(SED) "s:$(BASE_DIR):@BASE_DIR@:g" \
254 -e "s:$(STAGING_DIR):@STAGING_DIR@:g" \
255 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
256 -e "s:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
257 -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
258 $(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
259 -e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
260 -e "s:@STAGING_DIR@:$(STAGING_DIR):g" \
261 -e "s:@BASE_DIR@:$(BASE_DIR):g"
262 @$(call step_end,install-staging)
263 $(Q)touch $@
265 # Install to images dir
266 $(BUILD_DIR)/%/.stamp_images_installed:
267 @$(call step_start,install-image)
268 $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
269 @$(call MESSAGE,"Installing to images directory")
270 +$($(PKG)_INSTALL_IMAGES_CMDS)
271 $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
272 @$(call step_end,install-image)
273 $(Q)touch $@
275 # Install to target dir
276 $(BUILD_DIR)/%/.stamp_target_installed:
277 @$(call step_start,install-target)
278 @$(call MESSAGE,"Installing to target")
279 $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
280 +$($(PKG)_INSTALL_TARGET_CMDS)
281 $(if $(BR2_INIT_SYSTEMD),\
282 $($(PKG)_INSTALL_INIT_SYSTEMD))
283 $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
284 $($(PKG)_INSTALL_INIT_SYSV))
285 $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
286 $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
287 $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
289 @$(call step_end,install-target)
290 $(Q)touch $@
292 # Remove package sources
293 $(BUILD_DIR)/%/.stamp_dircleaned:
294 rm -Rf $(@D)
296 ################################################################################
297 # virt-provides-single -- check that provider-pkg is the declared provider for
298 # the virtual package virt-pkg
300 # argument 1 is the lower-case name of the virtual package
301 # argument 2 is the upper-case name of the virtual package
302 # argument 3 is the lower-case name of the provider
304 # example:
305 # $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
306 ################################################################################
307 define virt-provides-single
308 ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
309 $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
310 are selected as providers for virtual package "$(1)". Only one provider can\
311 be selected at a time. Please fix your configuration)
312 endif
313 endef
315 ################################################################################
316 # inner-generic-package -- generates the make targets needed to build a
317 # generic package
319 # argument 1 is the lowercase package name
320 # argument 2 is the uppercase package name, including a HOST_ prefix
321 # for host packages
322 # argument 3 is the uppercase package name, without the HOST_ prefix
323 # for host packages
324 # argument 4 is the type (target or host)
326 # Note about variable and function references: inside all blocks that are
327 # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
328 # specific rules apply with respect to variable and function references.
329 # - Numbered variables (parameters to the block) can be referenced with a single
330 # dollar sign: $(1), $(2), $(3), etc.
331 # - pkgdir and pkgname should be referenced with a single dollar sign too. These
332 # functions rely on 'the most recently parsed makefile' which is supposed to
333 # be the package .mk file. If we defer the evaluation of these functions using
334 # double dollar signs, then they may be evaluated too late, when other
335 # makefiles have already been parsed. One specific case is when $$(pkgdir) is
336 # assigned to a variable using deferred evaluation with '=' and this variable
337 # is used in a target rule outside the eval'ed inner block. In this case, the
338 # pkgdir will be that of the last makefile parsed by buildroot, which is not
339 # the expected value. This mechanism is for example used for the TARGET_PATCH
340 # rule.
341 # - All other variables should be referenced with a double dollar sign:
342 # $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
343 # referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
344 # etc. This rule ensures that these variables and functions are only expanded
345 # during the $(eval) step, and not earlier. Otherwise, unintuitive and
346 # undesired behavior occurs with respect to these variables and functions.
348 ################################################################################
350 define inner-generic-package
352 # Ensure the package is only declared once, i.e. do not accept that a
353 # package be re-defined by a br2-external tree
354 ifneq ($(call strip,$(filter $(1),$(PACKAGES_ALL))),)
355 $$(error Package '$(1)' defined a second time in '$(pkgdir)'; \
356 previous definition was in '$$($(2)_PKGDIR)')
357 endif
358 PACKAGES_ALL += $(1)
360 # Define default values for various package-related variables, if not
361 # already defined. For some variables (version, source, site and
362 # subdir), if they are undefined, we try to see if a variable without
363 # the HOST_ prefix is defined. If so, we use such a variable, so that
364 # this information has only to be specified once, for both the
365 # target and host packages of a given .mk file.
367 $(2)_TYPE = $(4)
368 $(2)_NAME = $(1)
369 $(2)_RAWNAME = $$(patsubst host-%,%,$(1))
370 $(2)_PKGDIR = $(pkgdir)
372 # Keep the package version that may contain forward slashes in the _DL_VERSION
373 # variable, then replace all forward slashes ('/') by underscores ('_') to
374 # sanitize the package version that is used in paths, directory and file names.
375 # Forward slashes may appear in the package's version when pointing to a
376 # version control system branch or tag, for example remotes/origin/1_10_stable.
377 # Similar for spaces and colons (:) that may appear in date-based revisions for
378 # CVS.
379 ifndef $(2)_VERSION
380 ifdef $(3)_DL_VERSION
381 $(2)_DL_VERSION := $$($(3)_DL_VERSION)
382 else ifdef $(3)_VERSION
383 $(2)_DL_VERSION := $$($(3)_VERSION)
384 else
385 $(2)_DL_VERSION = undefined
386 endif
387 else
388 $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
389 endif
390 $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
392 ifdef $(3)_OVERRIDE_SRCDIR
393 $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
394 endif
396 $(2)_BASE_NAME = $(1)-$$($(2)_VERSION)
397 $(2)_DL_DIR = $$(DL_DIR)/$$($(2)_BASE_NAME)
398 $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
400 ifndef $(2)_SUBDIR
401 ifdef $(3)_SUBDIR
402 $(2)_SUBDIR = $$($(3)_SUBDIR)
403 else
404 $(2)_SUBDIR ?=
405 endif
406 endif
408 ifndef $(2)_STRIP_COMPONENTS
409 ifdef $(3)_STRIP_COMPONENTS
410 $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
411 else
412 $(2)_STRIP_COMPONENTS ?= 1
413 endif
414 endif
416 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
417 $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
419 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
420 $(2)_VERSION = custom
421 endif
423 ifndef $(2)_SOURCE
424 ifdef $(3)_SOURCE
425 $(2)_SOURCE = $$($(3)_SOURCE)
426 else
427 $(2)_SOURCE ?= $$($(2)_RAWNAME)-$$($(2)_VERSION).tar.gz
428 endif
429 endif
431 ifndef $(2)_PATCH
432 ifdef $(3)_PATCH
433 $(2)_PATCH = $$($(3)_PATCH)
434 endif
435 endif
437 $(2)_ALL_DOWNLOADS = \
438 $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
439 $$(if $$(findstring ://,$$(p)),$$(p),\
440 $$($(2)_SITE)/$$(p)))
442 ifndef $(2)_SITE
443 ifdef $(3)_SITE
444 $(2)_SITE = $$($(3)_SITE)
445 endif
446 endif
448 ifndef $(2)_SITE_METHOD
449 ifdef $(3)_SITE_METHOD
450 $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
451 else
452 # Try automatic detection using the scheme part of the URI
453 $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
454 endif
455 endif
457 ifeq ($$($(2)_SITE_METHOD),local)
458 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
459 $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
460 endif
461 endif
463 ifndef $(2)_LICENSE
464 ifdef $(3)_LICENSE
465 $(2)_LICENSE = $$($(3)_LICENSE)
466 endif
467 endif
469 $(2)_LICENSE ?= unknown
471 ifndef $(2)_LICENSE_FILES
472 ifdef $(3)_LICENSE_FILES
473 $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
474 endif
475 endif
477 ifndef $(2)_REDISTRIBUTE
478 ifdef $(3)_REDISTRIBUTE
479 $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
480 endif
481 endif
483 $(2)_REDISTRIBUTE ?= YES
485 # When a target package is a toolchain dependency set this variable to
486 # 'NO' so the 'toolchain' dependency is not added to prevent a circular
487 # dependency
488 $(2)_ADD_TOOLCHAIN_DEPENDENCY ?= YES
490 ifeq ($(4),host)
491 $(2)_DEPENDENCIES ?= $$(filter-out host-skeleton host-toolchain $(1),\
492 $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
493 endif
494 ifeq ($(4),target)
495 ifneq ($(1),skeleton)
496 $(2)_DEPENDENCIES += skeleton
497 endif
498 ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
499 $(2)_DEPENDENCIES += toolchain
500 endif
501 endif
503 # Eliminate duplicates in dependencies
504 $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
505 $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
506 $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
508 $(2)_INSTALL_STAGING ?= NO
509 $(2)_INSTALL_IMAGES ?= NO
510 $(2)_INSTALL_TARGET ?= YES
512 # define sub-target stamps
513 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
514 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
515 $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
516 $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
517 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
518 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
519 $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
520 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
521 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
522 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
523 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
525 # default extract command
526 $(2)_EXTRACT_CMDS ?= \
527 $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
528 $$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
529 -C $$($(2)_DIR) \
530 $$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
531 $$(TAR_OPTIONS) -)
533 # pre/post-steps hooks
534 $(2)_PRE_DOWNLOAD_HOOKS ?=
535 $(2)_POST_DOWNLOAD_HOOKS ?=
536 $(2)_PRE_EXTRACT_HOOKS ?=
537 $(2)_POST_EXTRACT_HOOKS ?=
538 $(2)_PRE_RSYNC_HOOKS ?=
539 $(2)_POST_RSYNC_HOOKS ?=
540 $(2)_PRE_PATCH_HOOKS ?=
541 $(2)_POST_PATCH_HOOKS ?=
542 $(2)_PRE_CONFIGURE_HOOKS ?=
543 $(2)_POST_CONFIGURE_HOOKS ?=
544 $(2)_PRE_BUILD_HOOKS ?=
545 $(2)_POST_BUILD_HOOKS ?=
546 $(2)_PRE_INSTALL_HOOKS ?=
547 $(2)_POST_INSTALL_HOOKS ?=
548 $(2)_PRE_INSTALL_STAGING_HOOKS ?=
549 $(2)_POST_INSTALL_STAGING_HOOKS ?=
550 $(2)_PRE_INSTALL_TARGET_HOOKS ?=
551 $(2)_POST_INSTALL_TARGET_HOOKS ?=
552 $(2)_PRE_INSTALL_IMAGES_HOOKS ?=
553 $(2)_POST_INSTALL_IMAGES_HOOKS ?=
554 $(2)_PRE_LEGAL_INFO_HOOKS ?=
555 $(2)_POST_LEGAL_INFO_HOOKS ?=
557 # human-friendly targets and target sequencing
558 $(1): $(1)-install
560 ifeq ($$($(2)_TYPE),host)
561 $(1)-install: $(1)-install-host
562 else
563 $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
564 endif
566 ifeq ($$($(2)_INSTALL_TARGET),YES)
567 $(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET)
568 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
569 else
570 $(1)-install-target:
571 endif
573 ifeq ($$($(2)_INSTALL_STAGING),YES)
574 $(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING)
575 $$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
576 # Some packages use install-staging stuff for install-target
577 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_INSTALL_STAGING)
578 else
579 $(1)-install-staging:
580 endif
582 ifeq ($$($(2)_INSTALL_IMAGES),YES)
583 $(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES)
584 $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
585 else
586 $(1)-install-images:
587 endif
589 $(1)-install-host: $$($(2)_TARGET_INSTALL_HOST)
590 $$($(2)_TARGET_INSTALL_HOST): $$($(2)_TARGET_BUILD)
592 $(1)-build: $$($(2)_TARGET_BUILD)
593 $$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
595 # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
596 # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
597 # therefore the other steps as well) to be re-executed with every
598 # invocation of make. Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
599 # dependency by using |.
601 $(1)-configure: $$($(2)_TARGET_CONFIGURE)
602 $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
604 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
605 ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
606 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
607 endif
609 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
610 # In the normal case (no package override), the sequence of steps is
611 # source, by downloading
612 # depends
613 # extract
614 # patch
615 # configure
616 $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
618 $(1)-patch: $$($(2)_TARGET_PATCH)
619 $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
620 # Order-only dependency
621 $$($(2)_TARGET_PATCH): | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
623 $(1)-extract: $$($(2)_TARGET_EXTRACT)
624 $$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
626 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
628 $(1)-source: $$($(2)_TARGET_SOURCE)
630 $(1)-source-check:
631 $$(foreach p,$$($(2)_ALL_DOWNLOADS),$$(call SOURCE_CHECK,$$(p))$$(sep))
633 $(1)-external-deps:
634 @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
635 echo `basename $$$$p` ; \
636 done
637 else
638 # In the package override case, the sequence of steps
639 # source, by rsyncing
640 # depends
641 # configure
643 # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
644 # can remove the stamp file without triggering the configure step.
645 $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
647 $(1)-depends: $$($(2)_FINAL_DEPENDENCIES)
649 $(1)-patch: $(1)-rsync
650 $(1)-extract: $(1)-rsync
652 $(1)-rsync: $$($(2)_TARGET_RSYNC)
654 $(1)-source:
656 $(1)-source-check:
657 test -d $$($(2)_OVERRIDE_SRCDIR)
659 $(1)-external-deps:
660 @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
661 endif
663 $(1)-show-version:
664 @echo $$($(2)_VERSION)
666 $(1)-show-depends:
667 @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
669 $(1)-graph-depends: graph-depends-requirements
670 @$$(INSTALL) -d $$(GRAPHS_DIR)
671 @cd "$$(CONFIG_DIR)"; \
672 $$(TOPDIR)/support/scripts/graph-depends -p $(1) $$(BR2_GRAPH_DEPS_OPTS) \
673 |tee $$(GRAPHS_DIR)/$$(@).dot \
674 |dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT)
676 $(1)-all-source: $(1)-source
677 $(1)-all-source: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
679 $(1)-all-source-check: $(1)-source-check
680 $(1)-all-source-check: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source-check)
682 $(1)-all-external-deps: $(1)-external-deps
683 $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
685 $(1)-all-legal-info: $(1)-legal-info
686 $(1)-all-legal-info: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
688 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
690 $(1)-clean-for-reinstall:
691 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
692 rm -f $$($(2)_TARGET_RSYNC)
693 endif
694 rm -f $$($(2)_TARGET_INSTALL_STAGING)
695 rm -f $$($(2)_TARGET_INSTALL_TARGET)
696 rm -f $$($(2)_TARGET_INSTALL_IMAGES)
697 rm -f $$($(2)_TARGET_INSTALL_HOST)
699 $(1)-reinstall: $(1)-clean-for-reinstall $(1)
701 $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
702 rm -f $$($(2)_TARGET_BUILD)
704 $(1)-rebuild: $(1)-clean-for-rebuild $(1)
706 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
707 rm -f $$($(2)_TARGET_CONFIGURE)
709 $(1)-reconfigure: $(1)-clean-for-reconfigure $(1)
711 # define the PKG variable for all targets, containing the
712 # uppercase package variable prefix
713 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
714 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
715 $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
716 $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
717 $$($(2)_TARGET_BUILD): PKG=$(2)
718 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
719 $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
720 $$($(2)_TARGET_RSYNC): PKG=$(2)
721 $$($(2)_TARGET_PATCH): PKG=$(2)
722 $$($(2)_TARGET_PATCH): RAWNAME=$$(patsubst host-%,%,$(1))
723 $$($(2)_TARGET_PATCH): PKGDIR=$(pkgdir)
724 $$($(2)_TARGET_EXTRACT): PKG=$(2)
725 $$($(2)_TARGET_SOURCE): PKG=$(2)
726 $$($(2)_TARGET_SOURCE): PKGDIR=$(pkgdir)
727 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
729 # Compute the name of the Kconfig option that correspond to the
730 # package being enabled. We handle three cases: the special Linux
731 # kernel case, the bootloaders case, and the normal packages case.
732 ifeq ($(1),linux)
733 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
734 else ifneq ($$(filter boot/% $(BR2_EXTERNAL)/boot/%,$(pkgdir)),)
735 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
736 else ifneq ($$(filter toolchain/% $(BR2_EXTERNAL)/toolchain/%,$(pkgdir)),)
737 $(2)_KCONFIG_VAR = BR2_$(2)
738 else
739 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
740 endif
742 # legal-info: declare dependencies and set values used later for the manifest
743 ifneq ($$($(2)_LICENSE_FILES),)
744 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
745 endif
746 $(2)_MANIFEST_LICENSE_FILES ?= not saved
748 # If the package declares _LICENSE_FILES, we need to extract it,
749 # for overriden, local or normal remote packages alike, whether
750 # we want to redistribute it or not.
751 ifneq ($$($(2)_LICENSE_FILES),)
752 $(1)-legal-info: $(1)-patch
753 endif
755 # We only save the sources of packages we want to redistribute, that are
756 # non-local, and non-overriden. So only store, in the manifest, the tarball
757 # name of those packages.
758 ifeq ($$($(2)_REDISTRIBUTE),YES)
759 ifneq ($$($(2)_SITE_METHOD),local)
760 ifneq ($$($(2)_SITE_METHOD),override)
761 # Packages that have a tarball need it downloaded beforehand
762 $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
763 endif
764 endif
765 endif
767 # If FOO_ACTUAL_SOURCE_TARBALL is explicitly defined, it means FOO_SOURCE is
768 # indeed a binary (e.g. external toolchain) and FOO_ACTUAL_SOURCE_TARBALL/_SITE
769 # point to the actual sources tarball. Use the actual sources for legal-info.
770 # For most packages the FOO_SITE/FOO_SOURCE pair points to real source code,
771 # so these are the defaults for FOO_ACTUAL_*.
772 $(2)_ACTUAL_SOURCE_TARBALL ?= $$($(2)_SOURCE)
773 $(2)_ACTUAL_SOURCE_SITE ?= $$(call qstrip,$$($(2)_SITE))
775 # legal-info: produce legally relevant info.
776 $(1)-legal-info:
777 # Packages without a source are assumed to be part of Buildroot, skip them.
778 $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
779 ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
781 # Save license files if defined
782 # We save the license files for any kind of package: normal, local,
783 # overridden, or non-redistributable alike.
784 # The reason to save license files even for no-redistribute packages
785 # is that the license still applies to the files distributed as part
786 # of the rootfs, even if the sources are not themselves redistributed.
787 ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
788 @$$(call legal-license-nofiles,$$($(2)_RAWNAME),$$(call UPPERCASE,$(4)))
789 @$$(call legal-warning-pkg,$$($(2)_RAWNAME),cannot save license ($(2)_LICENSE_FILES not defined))
790 else
791 @$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
792 endif # license files
794 ifeq ($$($(2)_SITE_METHOD),local)
795 # Packages without a tarball: don't save and warn
796 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
798 else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
799 @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
801 else
802 # Other packages
804 ifeq ($$($(2)_REDISTRIBUTE),YES)
805 ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
806 $$(call DOWNLOAD,$$($(2)_ACTUAL_SOURCE_SITE)/$$($(2)_ACTUAL_SOURCE_TARBALL))
807 endif
808 # Copy the source tarball (just hardlink if possible)
809 @cp -l $$(DL_DIR)/$$($(2)_ACTUAL_SOURCE_TARBALL) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4))) 2>/dev/null || \
810 cp $$(DL_DIR)/$$($(2)_ACTUAL_SOURCE_TARBALL) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
811 endif # redistribute
813 endif # other packages
814 @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call UPPERCASE,$(4)))
815 endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
816 $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
818 # add package to the general list of targets if requested by the buildroot
819 # configuration
820 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
822 # Ensure the calling package is the declared provider for all the virtual
823 # packages it claims to be an implementation of.
824 ifneq ($$($(2)_PROVIDES),)
825 $$(foreach pkg,$$($(2)_PROVIDES),\
826 $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
827 endif
829 # Ensure unified variable name conventions between all packages Some
830 # of the variables are used by more than one infrastructure; so,
831 # rather than duplicating the checks in each infrastructure, we check
832 # all variables here in pkg-generic, even though pkg-generic should
833 # have no knowledge of infra-specific variables.
834 $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
835 $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
836 $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
837 $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
838 $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
839 $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
840 $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
841 $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
842 $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
843 $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
845 PACKAGES += $(1)
847 ifneq ($$($(2)_PERMISSIONS),)
848 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
849 endif
850 ifneq ($$($(2)_DEVICES),)
851 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
852 endif
853 ifneq ($$($(2)_USERS),)
854 PACKAGES_USERS += $$($(2)_USERS)$$(sep)
855 endif
857 ifeq ($$($(2)_SITE_METHOD),svn)
858 DL_TOOLS_DEPENDENCIES += svn
859 else ifeq ($$($(2)_SITE_METHOD),git)
860 DL_TOOLS_DEPENDENCIES += git
861 else ifeq ($$($(2)_SITE_METHOD),bzr)
862 DL_TOOLS_DEPENDENCIES += bzr
863 else ifeq ($$($(2)_SITE_METHOD),scp)
864 DL_TOOLS_DEPENDENCIES += scp ssh
865 else ifeq ($$($(2)_SITE_METHOD),hg)
866 DL_TOOLS_DEPENDENCIES += hg
867 else ifeq ($$($(2)_SITE_METHOD),cvs)
868 DL_TOOLS_DEPENDENCIES += cvs
869 endif # SITE_METHOD
871 # $(firstword) is used here because the extractor can have arguments, like
872 # ZCAT="gzip -d -c", and to check for the dependency we only want 'gzip'.
873 # Do not add xzcat to the list of required dependencies, as it gets built
874 # automatically if it isn't found.
875 ifneq ($$(call suitable-extractor,$$($(2)_SOURCE)),$$(XZCAT))
876 DL_TOOLS_DEPENDENCIES += $$(firstword $$(call suitable-extractor,$$($(2)_SOURCE)))
877 endif
879 # Ensure all virtual targets are PHONY. Listed alphabetically.
880 .PHONY: $(1) \
881 $(1)-all-external-deps \
882 $(1)-all-legal-info \
883 $(1)-all-source \
884 $(1)-all-source-check \
885 $(1)-build \
886 $(1)-clean-for-rebuild \
887 $(1)-clean-for-reconfigure \
888 $(1)-clean-for-reinstall \
889 $(1)-configure \
890 $(1)-depends \
891 $(1)-dirclean \
892 $(1)-external-deps \
893 $(1)-extract \
894 $(1)-graph-depends \
895 $(1)-install \
896 $(1)-install-host \
897 $(1)-install-images \
898 $(1)-install-staging \
899 $(1)-install-target \
900 $(1)-legal-info \
901 $(1)-patch \
902 $(1)-rebuild \
903 $(1)-reconfigure \
904 $(1)-reinstall \
905 $(1)-rsync \
906 $(1)-show-depends \
907 $(1)-show-version \
908 $(1)-source \
909 $(1)-source-check
911 ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
912 $$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
913 endif
915 endif # $(2)_KCONFIG_VAR
916 endef # inner-generic-package
918 ################################################################################
919 # generic-package -- the target generator macro for generic packages
920 ################################################################################
922 # In the case of target packages, keep the package name "pkg"
923 generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
924 # In the case of host packages, turn the package name "pkg" into "host-pkg"
925 host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
927 # :mode=makefile: