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 informations 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 # Implicit targets -- produce a stamp file for each step of a package build
25 ################################################################################
27 # Retrieve the archive
28 $(BUILD_DIR)/%/.stamp_downloaded:
29 ifeq ($(DL_MODE),DOWNLOAD)
30 # Only show the download message if it isn't already downloaded
31 $(Q)(test -e $(DL_DIR)/$($(PKG)_SOURCE) && \
32 (test -z $($(PKG)_PATCH) || test -e $(DL_DIR)$($(PKG)_PATCH))) || \
33 $(call MESSAGE,"Downloading")
35 $(if $($(PKG)_SOURCE),$(call DOWNLOAD,$($(PKG)_SITE)/$($(PKG)_SOURCE)))
36 $(if $($(PKG)_PATCH),$(call DOWNLOAD,$($(PKG)_SITE)/$($(PKG)_PATCH)))
37 $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
38 ifeq ($(DL_MODE),DOWNLOAD)
44 $(BUILD_DIR)/%/.stamp_extracted:
45 @$(call MESSAGE,"Extracting")
47 $($(PKG)_EXTRACT_CMDS)
48 # some packages have messed up permissions inside
49 $(Q)chmod -R +rw $(@D)
50 $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
53 # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
55 $(BUILD_DIR)/%/.stamp_rsynced:
56 @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
57 @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
58 rsync -au $(SRCDIR)/ $(@D)
61 # Handle the SOURCE_CHECK and SHOW_EXTERNAL_DEPS cases for rsynced
63 $(BUILD_DIR)/%/.stamp_rsync_sourced:
64 ifeq ($(DL_MODE),SOURCE_CHECK)
66 else ifeq ($(DL_MODE),SHOW_EXTERNAL_DEPS)
67 echo "file://$(SRCDIR)"
69 @true # Nothing to do to source a local package
74 # The RAWNAME variable is the lowercased package name, which allows to
75 # find the package directory (typically package/<pkgname>) and the
76 # prefix of the patches
77 $(BUILD_DIR)/%/.stamp_patched: NAMEVER = $(RAWNAME)-$($(PKG)_VERSION)
78 $(BUILD_DIR)/%/.stamp_patched:
79 @$(call MESSAGE,"Patching $($(PKG)_DIR_PREFIX)/$(RAWNAME)")
80 $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
81 $(if $($(PKG)_PATCH),support/scripts/apply-patches.sh $(@D) $(DL_DIR) $($(PKG)_PATCH))
83 if test -d $($(PKG)_DIR_PREFIX)/$(RAWNAME); then \
84 if test "$(wildcard $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER)*.patch*)"; then \
85 support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME) $(NAMEVER)\*.patch $(NAMEVER)\*.patch.$(ARCH) || exit 1; \
87 support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME) $(RAWNAME)\*.patch $(RAWNAME)\*.patch.$(ARCH) || exit 1; \
88 if test -d $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER); then \
89 support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER) \*.patch \*.patch.$(ARCH) || exit 1; \
94 $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
98 $(BUILD_DIR)/%/.stamp_configured:
99 $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
100 @$(call MESSAGE,"Configuring")
101 $($(PKG)_CONFIGURE_CMDS)
102 $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
106 $(BUILD_DIR)/%/.stamp_built::
107 @$(call MESSAGE,"Building")
109 $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
112 # Install to host dir
113 $(BUILD_DIR)/%/.stamp_host_installed:
114 @$(call MESSAGE,"Installing to host directory")
115 $($(PKG)_INSTALL_CMDS)
116 $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
119 # Install to staging dir
120 $(BUILD_DIR)/%/.stamp_staging_installed:
121 @$(call MESSAGE,"Installing to staging directory")
122 $($(PKG)_INSTALL_STAGING_CMDS)
123 $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
126 # Install to images dir
127 $(BUILD_DIR)/%/.stamp_images_installed:
128 @$(call MESSAGE,"Installing to images directory")
129 $($(PKG)_INSTALL_IMAGES_CMDS)
130 $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
133 # Install to target dir
134 $(BUILD_DIR)/%/.stamp_target_installed:
135 @$(call MESSAGE,"Installing to target")
136 $(if $(BR2_INIT_SYSTEMD),\
137 $($(PKG)_INSTALL_INIT_SYSTEMD))
138 $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
139 $($(PKG)_INSTALL_INIT_SYSV))
140 $($(PKG)_INSTALL_TARGET_CMDS)
141 $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
145 $(BUILD_DIR)/%/.stamp_cleaned:
146 @$(call MESSAGE,"Cleaning up")
148 rm -f $(@D)/.stamp_built
150 # Uninstall package from target and staging
151 # Uninstall commands tend to fail, so remove the stamp files first
152 $(BUILD_DIR)/%/.stamp_uninstalled:
153 @$(call MESSAGE,"Uninstalling")
154 rm -f $($(PKG)_TARGET_INSTALL_STAGING)
155 rm -f $($(PKG)_TARGET_INSTALL_TARGET)
156 $($(PKG)_UNINSTALL_STAGING_CMDS)
157 $($(PKG)_UNINSTALL_TARGET_CMDS)
158 $(if $(BR2_INIT_SYSTEMD),\
159 $($(PKG)_UNINSTALL_INIT_SYSTEMD))
160 $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
161 $($(PKG)_UNINSTALL_INIT_SYSV))
163 # Remove package sources
164 $(BUILD_DIR)/%/.stamp_dircleaned:
167 ################################################################################
168 # inner-generic-package -- generates the make targets needed to build a
171 # argument 1 is the lowercase package name
172 # argument 2 is the uppercase package name, including an HOST_ prefix
174 # argument 3 is the uppercase package name, without the HOST_ prefix
176 # argument 4 is the package directory prefix
177 # argument 5 is the type (target or host)
178 ################################################################################
180 define inner-generic-package
182 # Define default values for various package-related variables, if not
183 # already defined. For some variables (version, source, site and
184 # subdir), if they are undefined, we try to see if a variable without
185 # the HOST_ prefix is defined. If so, we use such a variable, so that
186 # these informations have only to be specified once, for both the
187 # target and host packages of a given .mk file.
191 $(2)_RAWNAME = $(patsubst host-%,%,$(1))
193 # Keep the package version that may contain forward slashes in the _DL_VERSION
194 # variable, then replace all forward slashes ('/') by underscores ('_') to
195 # sanitize the package version that is used in paths, directory and file names.
196 # Forward slashes may appear in the package's version when pointing to a
197 # version control system branch or tag, for example remotes/origin/1_10_stable.
200 $(2)_DL_VERSION = $($(3)_VERSION)
201 $(2)_VERSION = $(subst /,_,$($(3)_VERSION))
203 $(2)_VERSION = undefined
204 $(2)_DL_VERSION = undefined
207 $(2)_DL_VERSION = $($(2)_VERSION)
208 $(2)_VERSION = $(subst /,_,$($(2)_VERSION))
211 $(2)_BASE_NAME = $(1)-$$($(2)_VERSION)
212 $(2)_DL_DIR = $$(DL_DIR)/$$($(2)_BASE_NAME)
213 $(2)_DIR = $$(BUILD_DIR)/$$($(2)_BASE_NAME)
217 $(2)_SUBDIR = $$($(3)_SUBDIR)
223 $(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
224 $(2)_BUILDDIR ?= $$($(2)_SRCDIR)
226 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
227 $(2)_VERSION = custom
232 $(2)_SOURCE = $($(3)_SOURCE)
234 $(2)_SOURCE ?= $$($(2)_RAWNAME)-$$($(2)_VERSION).tar.gz
240 $(2)_PATCH = $($(3)_PATCH)
246 $(2)_SITE = $($(3)_SITE)
250 ifndef $(2)_SITE_METHOD
251 ifdef $(3)_SITE_METHOD
252 $(2)_SITE_METHOD = $($(3)_SITE_METHOD)
254 # Try automatic detection using the scheme part of the URI
255 $(2)_SITE_METHOD = $(firstword $(subst ://, ,$(call qstrip,$($(2)_SITE))))
259 ifeq ($$($(2)_SITE_METHOD),local)
260 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
261 $(2)_OVERRIDE_SRCDIR = $($(2)_SITE)
267 $(2)_LICENSE = $($(3)_LICENSE)
271 $(2)_LICENSE ?= unknown
273 ifndef $(2)_LICENSE_FILES
274 ifdef $(3)_LICENSE_FILES
275 $(2)_LICENSE_FILES = $($(3)_LICENSE_FILES)
279 ifndef $(2)_REDISTRIBUTE
280 ifdef $(3)_REDISTRIBUTE
281 $(2)_REDISTRIBUTE = $($(3)_REDISTRIBUTE)
285 $(2)_REDISTRIBUTE ?= YES
288 $(2)_DEPENDENCIES ?= $(filter-out $(1),$(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
290 $(2)_INSTALL_STAGING ?= NO
291 $(2)_INSTALL_IMAGES ?= NO
292 $(2)_INSTALL_TARGET ?= YES
293 $(2)_DIR_PREFIX = $(if $(4),$(4),$(TOP_SRCDIR)/package)
295 # define sub-target stamps
296 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
297 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
298 $(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
299 $(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
300 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
301 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
302 $(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
303 $(2)_TARGET_RSYNC_SOURCE = $$($(2)_DIR)/.stamp_rsync_sourced
304 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
305 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
306 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
307 $(2)_TARGET_UNINSTALL = $$($(2)_DIR)/.stamp_uninstalled
308 $(2)_TARGET_CLEAN = $$($(2)_DIR)/.stamp_cleaned
309 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
311 # default extract command
312 $(2)_EXTRACT_CMDS ?= \
313 $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $(DL_DIR)/$$($(2)_SOURCE) | \
314 $(TAR) $(TAR_STRIP_COMPONENTS)=1 -C $$($(2)_DIR) $(TAR_OPTIONS) -)
317 $(2)_POST_DOWNLOAD_HOOKS ?=
318 $(2)_POST_EXTRACT_HOOKS ?=
319 $(2)_PRE_PATCH_HOOKS ?=
320 $(2)_POST_PATCH_HOOKS ?=
321 $(2)_PRE_CONFIGURE_HOOKS ?=
322 $(2)_POST_CONFIGURE_HOOKS ?=
323 $(2)_POST_BUILD_HOOKS ?=
324 $(2)_POST_INSTALL_HOOKS ?=
325 $(2)_POST_INSTALL_STAGING_HOOKS ?=
326 $(2)_POST_INSTALL_TARGET_HOOKS ?=
327 $(2)_POST_INSTALL_IMAGES_HOOKS ?=
328 $(2)_POST_LEGAL_INFO_HOOKS ?=
330 # human-friendly targets and target sequencing
333 ifeq ($$($(2)_TYPE),host)
334 $(1)-install: $(1)-install-host
336 $(1)-install: $(1)-install-staging $(1)-install-target $(1)-install-images
339 ifeq ($$($(2)_INSTALL_TARGET),YES)
340 $(1)-install-target: $(1)-build \
341 $$($(2)_TARGET_INSTALL_TARGET)
346 ifeq ($$($(2)_INSTALL_STAGING),YES)
347 $(1)-install-staging: $(1)-build \
348 $$($(2)_TARGET_INSTALL_STAGING)
350 $(1)-install-staging:
353 ifeq ($$($(2)_INSTALL_IMAGES),YES)
354 $(1)-install-images: $(1)-build \
355 $$($(2)_TARGET_INSTALL_IMAGES)
360 $(1)-install-host: $(1)-build $$($(2)_TARGET_INSTALL_HOST)
362 $(1)-build: $(1)-configure \
363 $$($(2)_TARGET_BUILD)
365 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
366 # In the normal case (no package override), the sequence of steps is
367 # source, by downloading
372 $(1)-configure: $(1)-patch $(1)-depends \
373 $$($(2)_TARGET_CONFIGURE)
375 $(1)-patch: $(1)-extract $$($(2)_TARGET_PATCH)
377 $(1)-extract: $(1)-source \
378 $$($(2)_TARGET_EXTRACT)
380 $(1)-depends: $$($(2)_DEPENDENCIES)
382 $(1)-source: $$($(2)_TARGET_SOURCE)
384 # In the package override case, the sequence of steps
385 # source, by rsyncing
388 $(1)-configure: $(1)-depends \
389 $$($(2)_TARGET_CONFIGURE)
391 $(1)-depends: $(1)-rsync $$($(2)_DEPENDENCIES)
393 $(1)-patch: $(1)-rsync
394 $(1)-extract: $(1)-rsync
396 $(1)-rsync: $$($(2)_TARGET_RSYNC)
398 $(1)-source: $$($(2)_TARGET_RSYNC_SOURCE)
402 @echo $$($(2)_DEPENDENCIES)
404 $(1)-uninstall: $(1)-configure $$($(2)_TARGET_UNINSTALL)
406 $(1)-clean: $(1)-uninstall \
407 $$($(2)_TARGET_CLEAN)
409 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
411 $(1)-clean-for-rebuild:
412 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
413 rm -f $$($(2)_TARGET_RSYNC)
415 rm -f $$($(2)_TARGET_BUILD)
416 rm -f $$($(2)_TARGET_INSTALL_STAGING)
417 rm -f $$($(2)_TARGET_INSTALL_TARGET)
418 rm -f $$($(2)_TARGET_INSTALL_IMAGES)
419 rm -f $$($(2)_TARGET_INSTALL_HOST)
421 $(1)-rebuild: $(1)-clean-for-rebuild all
423 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
424 rm -f $$($(2)_TARGET_CONFIGURE)
426 $(1)-reconfigure: $(1)-clean-for-reconfigure all
428 # define the PKG variable for all targets, containing the
429 # uppercase package variable prefix
430 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
431 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
432 $$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
433 $$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
434 $$($(2)_TARGET_BUILD): PKG=$(2)
435 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
436 $$($(2)_TARGET_RSYNC): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
437 $$($(2)_TARGET_RSYNC): PKG=$(2)
438 $$($(2)_TARGET_RSYNC_SOURCE): SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
439 $$($(2)_TARGET_RSYNC_SOURCE): PKG=$(2)
440 $$($(2)_TARGET_PATCH): PKG=$(2)
441 $$($(2)_TARGET_PATCH): RAWNAME=$(patsubst host-%,%,$(1))
442 $$($(2)_TARGET_EXTRACT): PKG=$(2)
443 $$($(2)_TARGET_SOURCE): PKG=$(2)
444 $$($(2)_TARGET_UNINSTALL): PKG=$(2)
445 $$($(2)_TARGET_CLEAN): PKG=$(2)
446 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
448 # Compute the name of the Kconfig option that correspond to the
449 # package being enabled. We handle three cases: the special Linux
450 # kernel case, the bootloaders case, and the normal packages case.
452 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
453 else ifeq ($(4),boot/)
454 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
456 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
459 # legal-info: declare dependencies and set values used later for the manifest
460 ifneq ($$($(2)_LICENSE_FILES),)
461 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
463 $(2)_MANIFEST_LICENSE_FILES ?= not saved
465 ifeq ($$($(2)_REDISTRIBUTE),YES)
466 ifneq ($$($(2)_SITE_METHOD),local)
467 ifneq ($$($(2)_SITE_METHOD),override)
468 # Packages that have a tarball need it downloaded and extracted beforehand
469 $(1)-legal-info: $(1)-extract $(REDIST_SOURCES_DIR)
470 $(2)_MANIFEST_TARBALL = $$($(2)_SOURCE)
474 $(2)_MANIFEST_TARBALL ?= not saved
476 # legal-info: produce legally relevant info.
478 # Packages without a source are assumed to be part of Buildroot, skip them.
479 ifneq ($(call qstrip,$$($(2)_SOURCE)),)
480 ifeq ($$($(2)_SITE_METHOD),local)
481 # Packages without a tarball: don't save and warn
482 @$(call legal-warning-pkg-savednothing,$$($(2)_RAWNAME),local)
483 else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
484 @$(call legal-warning-pkg-savednothing,$$($(2)_RAWNAME),override)
487 # Save license files if defined
488 ifeq ($(call qstrip,$$($(2)_LICENSE_FILES)),)
489 @$(call legal-license-nofiles,$$($(2)_RAWNAME))
490 @$(call legal-warning-pkg,$$($(2)_RAWNAME),cannot save license ($(2)_LICENSE_FILES not defined))
492 @for F in $$($(2)_LICENSE_FILES); do \
493 $(call legal-license-file,$$($(2)_RAWNAME),$$$${F},$$($(2)_DIR)/$$$${F}); \
496 ifeq ($$($(2)_REDISTRIBUTE),YES)
497 # Copy the source tarball (just hardlink if possible)
498 @cp -l $(DL_DIR)/$$($(2)_SOURCE) $(REDIST_SOURCES_DIR) 2>/dev/null || \
499 cp $(DL_DIR)/$$($(2)_SOURCE) $(REDIST_SOURCES_DIR)
502 @$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_MANIFEST_TARBALL))
503 endif # ifneq ($(call qstrip,$$($(2)_SOURCE)),)
504 $(foreach hook,$($(2)_POST_LEGAL_INFO_HOOKS),$(call $(hook))$(sep))
506 # add package to the general list of targets if requested by the buildroot
508 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
511 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
512 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
514 ifeq ($$($(2)_SITE_METHOD),svn)
515 DL_TOOLS_DEPENDENCIES += svn
516 else ifeq ($$($(2)_SITE_METHOD),git)
517 DL_TOOLS_DEPENDENCIES += git
518 else ifeq ($$($(2)_SITE_METHOD),bzr)
519 DL_TOOLS_DEPENDENCIES += bzr
520 else ifeq ($$($(2)_SITE_METHOD),scp)
521 DL_TOOLS_DEPENDENCIES += scp ssh
522 else ifeq ($$($(2)_SITE_METHOD),hg)
523 DL_TOOLS_DEPENDENCIES += hg
526 DL_TOOLS_DEPENDENCIES += $(firstword $(INFLATE$(suffix $($(2)_SOURCE))))
528 endif # $(2)_KCONFIG_VAR
529 endef # inner-generic-package
531 ################################################################################
532 # generic-package -- the target generator macro for generic packages
533 ################################################################################
535 # In the case of target packages, keep the package name "pkg"
536 generic-package = $(call inner-generic-package,$(call pkgname),$(call UPPERCASE,$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),target)
537 # In the case of host packages, turn the package name "pkg" into "host-pkg"
538 host-generic-package = $(call inner-generic-package,host-$(call pkgname),$(call UPPERCASE,host-$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),host)