d5b29f08215e7d3b1debb84ac1e402e723abf521
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / pkg-generic.mk
1 ################################################################################
2 # Generic package infrastructure
3 #
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).
9 #
10 # See the Buildroot documentation for details on the usage of this
11 # infrastructure
12 #
13 # In terms of implementation, this generic infrastructure requires the
14 # .mk file to specify:
15 #
16 #   1. Metadata information about the package: name, version,
17 #      download URL, etc.
18 #
19 #   2. Description of the commands to be executed to configure, build
20 #      and install the package
21 ################################################################################
22
23 ################################################################################
24 # Helper functions to catch start/end of each step
25 ################################################################################
26
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
34
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
40
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
46
47 #######################################
48 # Actual steps hooks
49
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
57
58 # User-supplied script
59 ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
60 define step_user
61         @$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
62                 $(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
63 endef
64 GLOBAL_INSTRUMENTATION_HOOKS += step_user
65 endif
66
67 ################################################################################
68 # Implicit targets -- produce a stamp file for each step of a package build
69 ################################################################################
70
71 # Retrieve the archive
72 $(BUILD_DIR)/%/.stamp_downloaded:
73         $(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
74 # Only show the download message if it isn't already downloaded
75         $(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
76                 if test ! -e $(DL_DIR)/`basename $$p` ; then \
77                         $(call MESSAGE,"Downloading") ; \
78                         break ; \
79                 fi ; \
80         done
81         $(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p))$(sep))
82         $(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
83         $(Q)mkdir -p $(@D)
84         $(Q)touch $@
85
86 # Unpack the archive
87 $(BUILD_DIR)/%/.stamp_extracted:
88         @$(call step_start,extract)
89         @$(call MESSAGE,"Extracting")
90         $(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
91         $(Q)mkdir -p $(@D)
92         $($(PKG)_EXTRACT_CMDS)
93 # some packages have messed up permissions inside
94         $(Q)chmod -R +rw $(@D)
95         $(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
96         $(Q)touch $@
97         @$(call step_end,extract)
98
99 # Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
100 # used.
101 $(BUILD_DIR)/%/.stamp_rsynced:
102         @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
103         @test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
104         $(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
105         rsync -au $(RSYNC_VCS_EXCLUSIONS) $(SRCDIR)/ $(@D)
106         $(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
107         $(Q)touch $@
108
109 # Patch
110 #
111 # The RAWNAME variable is the lowercased package name, which allows to
112 # find the package directory (typically package/<pkgname>) and the
113 # prefix of the patches
114 #
115 # For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
116 $(BUILD_DIR)/%/.stamp_patched: NAMEVER = $(RAWNAME)-$($(PKG)_VERSION)
117 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS =  $(PKGDIR)
118 $(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
119 $(BUILD_DIR)/%/.stamp_patched:
120         @$(call step_start,patch)
121         @$(call MESSAGE,"Patching")
122         $(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
123         $(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $(DL_DIR) $(notdir $(p))$(sep))
124         $(Q)( \
125         for D in $(PATCH_BASE_DIRS); do \
126           if test -d $${D}; then \
127             if test -d $${D}/$($(PKG)_VERSION); then \
128               $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
129             else \
130               $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
131             fi; \
132           fi; \
133         done; \
134         )
135         $(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
136         $(Q)touch $@
137         @$(call step_end,patch)
138
139 # Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
140 $(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
141         $(if $(wildcard $(dir)),,\
142                 $(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
143
144 # Configure
145 $(BUILD_DIR)/%/.stamp_configured:
146         @$(call step_start,configure)
147         @$(call MESSAGE,"Configuring")
148         $(foreach hook,$($(PKG)_PRE_CONFIGURE_HOOKS),$(call $(hook))$(sep))
149         $($(PKG)_CONFIGURE_CMDS)
150         $(foreach hook,$($(PKG)_POST_CONFIGURE_HOOKS),$(call $(hook))$(sep))
151         $(Q)touch $@
152         @$(call step_end,configure)
153
154 # Build
155 $(BUILD_DIR)/%/.stamp_built::
156         @$(call step_start,build)
157         @$(call MESSAGE,"Building")
158         $(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
159         +$($(PKG)_BUILD_CMDS)
160         $(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
161         $(Q)touch $@
162         @$(call step_end,build)
163
164 # Install to host dir
165 $(BUILD_DIR)/%/.stamp_host_installed:
166         @$(call step_start,install-host)
167         @$(call MESSAGE,"Installing to host directory")
168         $(foreach hook,$($(PKG)_PRE_INSTALL_HOOKS),$(call $(hook))$(sep))
169         +$($(PKG)_INSTALL_CMDS)
170         $(foreach hook,$($(PKG)_POST_INSTALL_HOOKS),$(call $(hook))$(sep))
171         $(Q)touch $@
172         @$(call step_end,install-host)
173
174 # Install to staging dir
175 $(BUILD_DIR)/%/.stamp_staging_installed:
176         @$(call step_start,install-staging)
177         @$(call MESSAGE,"Installing to staging directory")
178         $(foreach hook,$($(PKG)_PRE_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
179         +$($(PKG)_INSTALL_STAGING_CMDS)
180         $(foreach hook,$($(PKG)_POST_INSTALL_STAGING_HOOKS),$(call $(hook))$(sep))
181         $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
182                 $(call MESSAGE,"Fixing package configuration files") ;\
183                         $(SED)  "s,$(BASE_DIR),@BASE_DIR@,g" \
184                                 -e "s,$(STAGING_DIR),@STAGING_DIR@,g" \
185                                 -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
186                                 -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
187                                 -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
188                                 -e "s,@STAGING_DIR@,$(STAGING_DIR),g" \
189                                 -e "s,@BASE_DIR@,$(BASE_DIR),g" \
190                                 $(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
191         fi
192         $(Q)touch $@
193         @$(call step_end,install-staging)
194
195 # Install to images dir
196 $(BUILD_DIR)/%/.stamp_images_installed:
197         @$(call step_start,install-image)
198         $(foreach hook,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
199         @$(call MESSAGE,"Installing to images directory")
200         +$($(PKG)_INSTALL_IMAGES_CMDS)
201         $(foreach hook,$($(PKG)_POST_INSTALL_IMAGES_HOOKS),$(call $(hook))$(sep))
202         $(Q)touch $@
203         @$(call step_end,install-image)
204
205 # Install to target dir
206 $(BUILD_DIR)/%/.stamp_target_installed:
207         @$(call step_start,install-target)
208         @$(call MESSAGE,"Installing to target")
209         $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
210         +$($(PKG)_INSTALL_TARGET_CMDS)
211         $(if $(BR2_INIT_SYSTEMD),\
212                 $($(PKG)_INSTALL_INIT_SYSTEMD))
213         $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
214                 $($(PKG)_INSTALL_INIT_SYSV))
215         $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
216         $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
217                 $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
218         fi
219         $(Q)touch $@
220         @$(call step_end,install-target)
221
222 # Remove package sources
223 $(BUILD_DIR)/%/.stamp_dircleaned:
224         rm -Rf $(@D)
225
226 ################################################################################
227 # virt-provides-single -- check that provider-pkg is the declared provider for
228 # the virtual package virt-pkg
229 #
230 # argument 1 is the lower-case name of the virtual package
231 # argument 2 is the upper-case name of the virtual package
232 # argument 3 is the lower-case name of the provider
233 #
234 # example:
235 #   $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
236 ################################################################################
237 define virt-provides-single
238 ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
239 $$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
240 are selected as providers for virtual package "$(1)". Only one provider can\
241 be selected at a time. Please fix your configuration)
242 endif
243 endef
244
245 ################################################################################
246 # inner-generic-package -- generates the make targets needed to build a
247 # generic package
248 #
249 #  argument 1 is the lowercase package name
250 #  argument 2 is the uppercase package name, including a HOST_ prefix
251 #             for host packages
252 #  argument 3 is the uppercase package name, without the HOST_ prefix
253 #             for host packages
254 #  argument 4 is the type (target or host)
255 #
256 # Note about variable and function references: inside all blocks that are
257 # evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
258 # specific rules apply with respect to variable and function references.
259 # - Numbered variables (parameters to the block) can be referenced with a single
260 #   dollar sign: $(1), $(2), $(3), etc.
261 # - pkgdir and pkgname should be referenced with a single dollar sign too. These
262 #   functions rely on 'the most recently parsed makefile' which is supposed to
263 #   be the package .mk file. If we defer the evaluation of these functions using
264 #   double dollar signs, then they may be evaluated too late, when other
265 #   makefiles have already been parsed. One specific case is when $$(pkgdir) is
266 #   assigned to a variable using deferred evaluation with '=' and this variable
267 #   is used in a target rule outside the eval'ed inner block. In this case, the
268 #   pkgdir will be that of the last makefile parsed by buildroot, which is not
269 #   the expected value. This mechanism is for example used for the TARGET_PATCH
270 #   rule.
271 # - All other variables should be referenced with a double dollar sign:
272 #   $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
273 #   referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
274 #   etc. This rule ensures that these variables and functions are only expanded
275 #   during the $(eval) step, and not earlier. Otherwise, unintuitive and
276 #   undesired behavior occurs with respect to these variables and functions.
277 #
278 ################################################################################
279
280 define inner-generic-package
281
282 # Define default values for various package-related variables, if not
283 # already defined. For some variables (version, source, site and
284 # subdir), if they are undefined, we try to see if a variable without
285 # the HOST_ prefix is defined. If so, we use such a variable, so that
286 # this information has only to be specified once, for both the
287 # target and host packages of a given .mk file.
288
289 $(2)_TYPE                       =  $(4)
290 $(2)_NAME                       =  $(1)
291 $(2)_RAWNAME                    =  $$(patsubst host-%,%,$(1))
292
293 # Keep the package version that may contain forward slashes in the _DL_VERSION
294 # variable, then replace all forward slashes ('/') by underscores ('_') to
295 # sanitize the package version that is used in paths, directory and file names.
296 # Forward slashes may appear in the package's version when pointing to a
297 # version control system branch or tag, for example remotes/origin/1_10_stable.
298 # Similar for spaces and colons (:) that may appear in date-based revisions for
299 # CVS.
300 ifndef $(2)_VERSION
301  ifdef $(3)_VERSION
302   $(2)_DL_VERSION := $$(strip $$($(3)_VERSION))
303   $(2)_VERSION := $$(call sanitize,$$($(3)_VERSION))
304  else
305   $(2)_VERSION = undefined
306   $(2)_DL_VERSION = undefined
307  endif
308 else
309   $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
310   $(2)_VERSION := $$(call sanitize,$$($(2)_VERSION))
311 endif
312
313 $(2)_BASE_NAME  =  $(1)-$$($(2)_VERSION)
314 $(2)_DL_DIR     =  $$(DL_DIR)/$$($(2)_BASE_NAME)
315 $(2)_DIR        =  $$(BUILD_DIR)/$$($(2)_BASE_NAME)
316
317 ifndef $(2)_SUBDIR
318  ifdef $(3)_SUBDIR
319   $(2)_SUBDIR = $$($(3)_SUBDIR)
320  else
321   $(2)_SUBDIR ?=
322  endif
323 endif
324
325 $(2)_SRCDIR                    = $$($(2)_DIR)/$$($(2)_SUBDIR)
326 $(2)_BUILDDIR                  ?= $$($(2)_SRCDIR)
327
328 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
329 $(2)_VERSION = custom
330 endif
331
332 ifndef $(2)_SOURCE
333  ifdef $(3)_SOURCE
334   $(2)_SOURCE = $$($(3)_SOURCE)
335  else
336   $(2)_SOURCE                   ?= $$($(2)_RAWNAME)-$$($(2)_VERSION).tar.gz
337  endif
338 endif
339
340 ifndef $(2)_PATCH
341  ifdef $(3)_PATCH
342   $(2)_PATCH = $$($(3)_PATCH)
343  endif
344 endif
345
346 $(2)_ALL_DOWNLOADS = \
347         $$(foreach p,$$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
348                 $$(if $$(findstring ://,$$(p)),$$(p),\
349                         $$($(2)_SITE:/=)/$$(p)))
350
351 ifndef $(2)_SITE
352  ifdef $(3)_SITE
353   $(2)_SITE = $$($(3)_SITE)
354  endif
355 endif
356
357 ifndef $(2)_SITE_METHOD
358  ifdef $(3)_SITE_METHOD
359   $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
360  else
361         # Try automatic detection using the scheme part of the URI
362         $(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
363  endif
364 endif
365
366 ifeq ($$($(2)_SITE_METHOD),local)
367 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
368 $(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
369 endif
370 endif
371
372 ifndef $(2)_LICENSE
373  ifdef $(3)_LICENSE
374   $(2)_LICENSE = $$($(3)_LICENSE)
375  endif
376 endif
377
378 $(2)_LICENSE                    ?= unknown
379
380 ifndef $(2)_LICENSE_FILES
381  ifdef $(3)_LICENSE_FILES
382   $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
383  endif
384 endif
385
386 ifndef $(2)_REDISTRIBUTE
387  ifdef $(3)_REDISTRIBUTE
388   $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
389  endif
390 endif
391
392 $(2)_REDISTRIBUTE               ?= YES
393
394 # When a target package is a toolchain dependency set this variable to
395 # 'NO' so the 'toolchain' dependency is not added to prevent a circular
396 # dependency
397 $(2)_ADD_TOOLCHAIN_DEPENDENCY   ?= YES
398
399 ifeq ($(4),host)
400 $(2)_DEPENDENCIES ?= $$(filter-out  host-toolchain $(1),\
401         $$(patsubst host-host-%,host-%,$$(addprefix host-,$$($(3)_DEPENDENCIES))))
402 endif
403 ifeq ($(4),target)
404 ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
405 $(2)_DEPENDENCIES += toolchain
406 endif
407 endif
408
409 # Eliminate duplicates in dependencies
410 $(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
411 $(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
412 $(2)_FINAL_ALL_DEPENDENCIES = $$(sort $$($(2)_FINAL_DEPENDENCIES) $$($(2)_FINAL_PATCH_DEPENDENCIES))
413
414 $(2)_INSTALL_STAGING            ?= NO
415 $(2)_INSTALL_IMAGES             ?= NO
416 $(2)_INSTALL_TARGET             ?= YES
417
418 # define sub-target stamps
419 $(2)_TARGET_INSTALL_TARGET =    $$($(2)_DIR)/.stamp_target_installed
420 $(2)_TARGET_INSTALL_STAGING =   $$($(2)_DIR)/.stamp_staging_installed
421 $(2)_TARGET_INSTALL_IMAGES =    $$($(2)_DIR)/.stamp_images_installed
422 $(2)_TARGET_INSTALL_HOST =      $$($(2)_DIR)/.stamp_host_installed
423 $(2)_TARGET_BUILD =             $$($(2)_DIR)/.stamp_built
424 $(2)_TARGET_CONFIGURE =         $$($(2)_DIR)/.stamp_configured
425 $(2)_TARGET_RSYNC =             $$($(2)_DIR)/.stamp_rsynced
426 $(2)_TARGET_PATCH =             $$($(2)_DIR)/.stamp_patched
427 $(2)_TARGET_EXTRACT =           $$($(2)_DIR)/.stamp_extracted
428 $(2)_TARGET_SOURCE =            $$($(2)_DIR)/.stamp_downloaded
429 $(2)_TARGET_DIRCLEAN =          $$($(2)_DIR)/.stamp_dircleaned
430
431 # default extract command
432 $(2)_EXTRACT_CMDS ?= \
433         $$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$(DL_DIR)/$$($(2)_SOURCE) | \
434         $$(TAR) $$(TAR_STRIP_COMPONENTS)=1 -C $$($(2)_DIR) $$(TAR_OPTIONS) -)
435
436 # pre/post-steps hooks
437 $(2)_PRE_DOWNLOAD_HOOKS         ?=
438 $(2)_POST_DOWNLOAD_HOOKS        ?=
439 $(2)_PRE_EXTRACT_HOOKS          ?=
440 $(2)_POST_EXTRACT_HOOKS         ?=
441 $(2)_PRE_RSYNC_HOOKS            ?=
442 $(2)_POST_RSYNC_HOOKS           ?=
443 $(2)_PRE_PATCH_HOOKS            ?=
444 $(2)_POST_PATCH_HOOKS           ?=
445 $(2)_PRE_CONFIGURE_HOOKS        ?=
446 $(2)_POST_CONFIGURE_HOOKS       ?=
447 $(2)_PRE_BUILD_HOOKS            ?=
448 $(2)_POST_BUILD_HOOKS           ?=
449 $(2)_PRE_INSTALL_HOOKS          ?=
450 $(2)_POST_INSTALL_HOOKS         ?=
451 $(2)_PRE_INSTALL_STAGING_HOOKS  ?=
452 $(2)_POST_INSTALL_STAGING_HOOKS ?=
453 $(2)_PRE_INSTALL_TARGET_HOOKS   ?=
454 $(2)_POST_INSTALL_TARGET_HOOKS  ?=
455 $(2)_PRE_INSTALL_IMAGES_HOOKS   ?=
456 $(2)_POST_INSTALL_IMAGES_HOOKS  ?=
457 $(2)_PRE_LEGAL_INFO_HOOKS       ?=
458 $(2)_POST_LEGAL_INFO_HOOKS      ?=
459
460 # human-friendly targets and target sequencing
461 $(1):                   $(1)-install
462
463 ifeq ($$($(2)_TYPE),host)
464 $(1)-install:           $(1)-install-host
465 else
466 $(1)-install:           $(1)-install-staging $(1)-install-target $(1)-install-images
467 endif
468
469 ifeq ($$($(2)_INSTALL_TARGET),YES)
470 $(1)-install-target:            $$($(2)_TARGET_INSTALL_TARGET)
471 $$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
472 else
473 $(1)-install-target:
474 endif
475
476 ifeq ($$($(2)_INSTALL_STAGING),YES)
477 $(1)-install-staging:                   $$($(2)_TARGET_INSTALL_STAGING)
478 $$($(2)_TARGET_INSTALL_STAGING):        $$($(2)_TARGET_BUILD)
479 # Some packages use install-staging stuff for install-target
480 $$($(2)_TARGET_INSTALL_TARGET):         $$($(2)_TARGET_INSTALL_STAGING)
481 else
482 $(1)-install-staging:
483 endif
484
485 ifeq ($$($(2)_INSTALL_IMAGES),YES)
486 $(1)-install-images:            $$($(2)_TARGET_INSTALL_IMAGES)
487 $$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
488 else
489 $(1)-install-images:
490 endif
491
492 $(1)-install-host:              $$($(2)_TARGET_INSTALL_HOST)
493 $$($(2)_TARGET_INSTALL_HOST):   $$($(2)_TARGET_BUILD)
494
495 $(1)-build:             $$($(2)_TARGET_BUILD)
496 $$($(2)_TARGET_BUILD):  $$($(2)_TARGET_CONFIGURE)
497
498 # Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
499 # than $(2)_TARGET_CONFIGURE. This would force the configure step (and
500 # therefore the other steps as well) to be re-executed with every
501 # invocation of make.  Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
502 # dependency by using |.
503
504 $(1)-configure:                 $$($(2)_TARGET_CONFIGURE)
505 $$($(2)_TARGET_CONFIGURE):      | $$($(2)_FINAL_DEPENDENCIES)
506
507 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dirs prepare
508 ifeq ($$(filter $(1),$$(DEPENDENCIES_HOST_PREREQ)),)
509 $$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
510 endif
511
512 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
513 # In the normal case (no package override), the sequence of steps is
514 #  source, by downloading
515 #  depends
516 #  extract
517 #  patch
518 #  configure
519 $$($(2)_TARGET_CONFIGURE):      $$($(2)_TARGET_PATCH)
520
521 $(1)-patch:             $$($(2)_TARGET_PATCH)
522 $$($(2)_TARGET_PATCH):  $$($(2)_TARGET_EXTRACT)
523 # Order-only dependency
524 $$($(2)_TARGET_PATCH):  | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
525
526 $(1)-extract:                   $$($(2)_TARGET_EXTRACT)
527 $$($(2)_TARGET_EXTRACT):        $$($(2)_TARGET_SOURCE)
528
529 $(1)-depends:           $$($(2)_FINAL_DEPENDENCIES)
530
531 $(1)-source:            $$($(2)_TARGET_SOURCE)
532
533 $(1)-source-check:
534         $$(foreach p,$$($(2)_ALL_DOWNLOADS),$$(call SOURCE_CHECK,$$(p))$$(sep))
535
536 $(1)-external-deps:
537         @for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
538                 echo `basename $$$$p` ; \
539         done
540 else
541 # In the package override case, the sequence of steps
542 #  source, by rsyncing
543 #  depends
544 #  configure
545
546 # Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
547 # can remove the stamp file without triggering the configure step.
548 $$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
549
550 $(1)-depends:           $$($(2)_FINAL_DEPENDENCIES)
551
552 $(1)-patch:             $(1)-rsync
553 $(1)-extract:           $(1)-rsync
554
555 $(1)-rsync:             $$($(2)_TARGET_RSYNC)
556
557 $(1)-source:
558
559 $(1)-source-check:
560         test -d $$($(2)_OVERRIDE_SRCDIR)
561
562 $(1)-external-deps:
563         @echo "file://$$($(2)_OVERRIDE_SRCDIR)"
564 endif
565
566 $(1)-show-version:
567                         @echo $$($(2)_VERSION)
568
569 $(1)-show-depends:
570                         @echo $$($(2)_FINAL_ALL_DEPENDENCIES)
571
572 $(1)-graph-depends: graph-depends-requirements
573                         @$$(INSTALL) -d $$(GRAPHS_DIR)
574                         @cd "$$(CONFIG_DIR)"; \
575                         $$(TOPDIR)/support/scripts/graph-depends -p $(1) $$(BR2_GRAPH_DEPS_OPTS) \
576                         |tee $$(GRAPHS_DIR)/$$(@).dot \
577                         |dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) -o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT)
578
579 $(1)-all-source:        $(1)-source
580 $(1)-all-source:        $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
581
582 $(1)-all-source-check:  $(1)-source-check
583 $(1)-all-source-check:  $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source-check)
584
585 $(1)-all-external-deps: $(1)-external-deps
586 $(1)-all-external-deps: $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
587
588 $(1)-all-legal-info:    $(1)-legal-info
589 $(1)-all-legal-info:    $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
590
591 $(1)-dirclean:          $$($(2)_TARGET_DIRCLEAN)
592
593 $(1)-clean-for-reinstall:
594 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
595                         rm -f $$($(2)_TARGET_RSYNC)
596 endif
597                         rm -f $$($(2)_TARGET_INSTALL_STAGING)
598                         rm -f $$($(2)_TARGET_INSTALL_TARGET)
599                         rm -f $$($(2)_TARGET_INSTALL_IMAGES)
600                         rm -f $$($(2)_TARGET_INSTALL_HOST)
601
602 $(1)-reinstall:         $(1)-clean-for-reinstall $(1)
603
604 $(1)-clean-for-rebuild: $(1)-clean-for-reinstall
605                         rm -f $$($(2)_TARGET_BUILD)
606
607 $(1)-rebuild:           $(1)-clean-for-rebuild $(1)
608
609 $(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
610                         rm -f $$($(2)_TARGET_CONFIGURE)
611
612 $(1)-reconfigure:       $(1)-clean-for-reconfigure $(1)
613
614 # define the PKG variable for all targets, containing the
615 # uppercase package variable prefix
616 $$($(2)_TARGET_INSTALL_TARGET):         PKG=$(2)
617 $$($(2)_TARGET_INSTALL_STAGING):        PKG=$(2)
618 $$($(2)_TARGET_INSTALL_IMAGES):         PKG=$(2)
619 $$($(2)_TARGET_INSTALL_HOST):           PKG=$(2)
620 $$($(2)_TARGET_BUILD):                  PKG=$(2)
621 $$($(2)_TARGET_CONFIGURE):              PKG=$(2)
622 $$($(2)_TARGET_RSYNC):                  SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
623 $$($(2)_TARGET_RSYNC):                  PKG=$(2)
624 $$($(2)_TARGET_PATCH):                  PKG=$(2)
625 $$($(2)_TARGET_PATCH):                  RAWNAME=$$(patsubst host-%,%,$(1))
626 $$($(2)_TARGET_PATCH):                  PKGDIR=$(pkgdir)
627 $$($(2)_TARGET_EXTRACT):                PKG=$(2)
628 $$($(2)_TARGET_SOURCE):                 PKG=$(2)
629 $$($(2)_TARGET_SOURCE):                 PKGDIR=$(pkgdir)
630 $$($(2)_TARGET_DIRCLEAN):               PKG=$(2)
631
632 # Compute the name of the Kconfig option that correspond to the
633 # package being enabled. We handle three cases: the special Linux
634 # kernel case, the bootloaders case, and the normal packages case.
635 ifeq ($(1),linux)
636 $(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
637 else ifneq ($$(filter boot/%,$(pkgdir)),)
638 $(2)_KCONFIG_VAR = BR2_TARGET_$(2)
639 else ifneq ($$(filter toolchain/%,$(pkgdir)),)
640 $(2)_KCONFIG_VAR = BR2_$(2)
641 else
642 $(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
643 endif
644
645 # legal-info: declare dependencies and set values used later for the manifest
646 ifneq ($$($(2)_LICENSE_FILES),)
647 $(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
648 endif
649 $(2)_MANIFEST_LICENSE_FILES ?= not saved
650
651 # If the package declares _LICENSE_FILES, we need to extract it,
652 # for overriden, local or normal remote packages alike, whether
653 # we want to redistribute it or not.
654 ifneq ($$($(2)_LICENSE_FILES),)
655 $(1)-legal-info: $(1)-patch
656 endif
657
658 # We only save the sources of packages we want to redistribute, that are
659 # non-local, and non-overriden. So only store, in the manifest, the tarball
660 # name of those packages.
661 ifeq ($$($(2)_REDISTRIBUTE),YES)
662 ifneq ($$($(2)_SITE_METHOD),local)
663 ifneq ($$($(2)_SITE_METHOD),override)
664 # Packages that have a tarball need it downloaded beforehand
665 $(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
666 $(2)_MANIFEST_TARBALL = $$($(2)_SOURCE)
667 $(2)_MANIFEST_SITE = $$(call qstrip,$$($(2)_SITE))
668 endif
669 endif
670 endif
671
672 # legal-info: produce legally relevant info.
673 $(1)-legal-info:
674 # Packages without a source are assumed to be part of Buildroot, skip them.
675         $$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
676 ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
677
678 # Save license files if defined
679 # We save the license files for any kind of package: normal, local,
680 # overridden, or non-redistributable alike.
681 # The reason to save license files even for no-redistribute packages
682 # is that the license still applies to the files distributed as part
683 # of the rootfs, even if the sources are not themselves redistributed.
684 ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
685         @$$(call legal-license-nofiles,$$($(2)_RAWNAME),$$(call UPPERCASE,$(4)))
686         @$$(call legal-warning-pkg,$$($(2)_RAWNAME),cannot save license ($(2)_LICENSE_FILES not defined))
687 else
688         @$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
689 endif # license files
690
691 ifeq ($$($(2)_SITE_METHOD),local)
692 # Packages without a tarball: don't save and warn
693         @$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
694
695 else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
696         @$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
697
698 else
699 # Other packages
700
701 ifeq ($$($(2)_REDISTRIBUTE),YES)
702 # Copy the source tarball (just hardlink if possible)
703         @cp -l $$(DL_DIR)/$$($(2)_SOURCE) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4))) 2>/dev/null || \
704            cp $$(DL_DIR)/$$($(2)_SOURCE) $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
705 endif # redistribute
706
707 endif # other packages
708         @$$(call legal-manifest,$$($(2)_RAWNAME),$$($(2)_VERSION),$$($(2)_LICENSE),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_MANIFEST_TARBALL),$$($(2)_MANIFEST_SITE),$$(call UPPERCASE,$(4)))
709 endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
710         $$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
711
712 # add package to the general list of targets if requested by the buildroot
713 # configuration
714 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
715
716 # Ensure the calling package is the declared provider for all the virtual
717 # packages it claims to be an implementation of.
718 ifneq ($$($(2)_PROVIDES),)
719 $$(foreach pkg,$$($(2)_PROVIDES),\
720         $$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
721 endif
722
723 # Ensure unified variable name conventions between all packages Some
724 # of the variables are used by more than one infrastructure; so,
725 # rather than duplicating the checks in each infrastructure, we check
726 # all variables here in pkg-generic, even though pkg-generic should
727 # have no knowledge of infra-specific variables.
728 $(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
729 $(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
730 $(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
731 $(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
732 $(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
733 $(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
734 $(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
735 $(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
736 $(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
737 $(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
738
739 PACKAGES += $(1)
740
741 ifneq ($$($(2)_PERMISSIONS),)
742 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
743 endif
744 ifneq ($$($(2)_DEVICES),)
745 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
746 endif
747 ifneq ($$($(2)_USERS),)
748 PACKAGES_USERS += $$($(2)_USERS)$$(sep)
749 endif
750
751 ifeq ($$($(2)_SITE_METHOD),svn)
752 DL_TOOLS_DEPENDENCIES += svn
753 else ifeq ($$($(2)_SITE_METHOD),git)
754 DL_TOOLS_DEPENDENCIES += git
755 else ifeq ($$($(2)_SITE_METHOD),bzr)
756 DL_TOOLS_DEPENDENCIES += bzr
757 else ifeq ($$($(2)_SITE_METHOD),scp)
758 DL_TOOLS_DEPENDENCIES += scp ssh
759 else ifeq ($$($(2)_SITE_METHOD),hg)
760 DL_TOOLS_DEPENDENCIES += hg
761 else ifeq ($$($(2)_SITE_METHOD),cvs)
762 DL_TOOLS_DEPENDENCIES += cvs
763 endif # SITE_METHOD
764
765 # $(firstword) is used here because the extractor can have arguments, like
766 # ZCAT="gzip -d -c", and to check for the dependency we only want 'gzip'.
767 # Do not add xzcat to the list of required dependencies, as it gets built
768 # automatically if it isn't found.
769 ifneq ($$(call suitable-extractor,$$($(2)_SOURCE)),$$(XZCAT))
770 DL_TOOLS_DEPENDENCIES += $$(firstword $$(call suitable-extractor,$$($(2)_SOURCE)))
771 endif
772
773 # Ensure all virtual targets are PHONY. Listed alphabetically.
774 .PHONY: $(1) \
775         $(1)-all-external-deps \
776         $(1)-all-legal-info \
777         $(1)-all-source \
778         $(1)-all-source-check \
779         $(1)-build \
780         $(1)-clean-for-rebuild \
781         $(1)-clean-for-reconfigure \
782         $(1)-clean-for-reinstall \
783         $(1)-configure \
784         $(1)-depends \
785         $(1)-dirclean \
786         $(1)-external-deps \
787         $(1)-extract \
788         $(1)-graph-depends \
789         $(1)-install \
790         $(1)-install-host \
791         $(1)-install-images \
792         $(1)-install-staging \
793         $(1)-install-target \
794         $(1)-legal-info \
795         $(1)-patch \
796         $(1)-rebuild \
797         $(1)-reconfigure \
798         $(1)-reinstall \
799         $(1)-rsync \
800         $(1)-show-depends \
801         $(1)-show-version \
802         $(1)-source \
803         $(1)-source-check
804
805 endif # $(2)_KCONFIG_VAR
806 endef # inner-generic-package
807
808 ################################################################################
809 # generic-package -- the target generator macro for generic packages
810 ################################################################################
811
812 # In the case of target packages, keep the package name "pkg"
813 generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
814 # In the case of host packages, turn the package name "pkg" into "host-pkg"
815 host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
816
817 # :mode=makefile: