xref: /OK3568_Linux_fs/buildroot/package/pkg-generic.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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
37define step_start
38	$(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),start,$(1),$($(PKG)_NAME))$(sep))
39endef
40
41# End step
42# $1: step name
43define step_end
44	$(foreach hook,$(GLOBAL_INSTRUMENTATION_HOOKS),$(call $(hook),end,$(1),$($(PKG)_NAME))$(sep))
45endef
46
47#######################################
48# Actual steps hooks
49
50# Time steps
51define step_time
52	printf "%s:%-5.5s:%-20.20s: %s\n"           \
53	       "$$(date +%s.%N)" "$(1)" "$(2)" "$(3)"  \
54	       >>"$(BUILD_DIR)/build-time.log"
55endef
56GLOBAL_INSTRUMENTATION_HOOKS += step_time
57
58# This hook checks that host packages that need libraries that we build
59# have a proper DT_RPATH or DT_RUNPATH tag
60define check_host_rpath
61	$(if $(filter install-host,$(2)),\
62		$(if $(filter end,$(1)),support/scripts/check-host-rpath $(3) $(HOST_DIR) $(PER_PACKAGE_DIR)))
63endef
64GLOBAL_INSTRUMENTATION_HOOKS += check_host_rpath
65
66define step_check_build_dir_one
67	if [ -d $(2) ]; then \
68		printf "%s: installs files in %s\n" $(1) $(2) >&2; \
69		exit 1; \
70	fi
71endef
72
73define step_check_build_dir
74	$(if $(filter install-staging,$(2)),\
75		$(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(STAGING_DIR)/$(O))))
76	$(if $(filter install-target,$(2)),\
77		$(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))
78endef
79GLOBAL_INSTRUMENTATION_HOOKS += step_check_build_dir
80
81# User-supplied script
82ifneq ($(BR2_INSTRUMENTATION_SCRIPTS),)
83define step_user
84	@$(foreach user_hook, $(BR2_INSTRUMENTATION_SCRIPTS), \
85		$(EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
86endef
87GLOBAL_INSTRUMENTATION_HOOKS += step_user
88endif
89
90#######################################
91# Helper functions
92
93define log_commands
94	$(Q)$(eval SCRIPT := $(@D)/.$(1).sh)
95	$(Q)$(file > $(SCRIPT),#!/bin/sh -e)
96	$(Q)$(file >> $(SCRIPT),[ -z "$$DEBUG" ] || set -x)
97	$(Q)$(file >> $(SCRIPT), \
98		echo "########## $($(PKG)_BASENAME): $(subst _, ,$(1)) ##########")
99	$(Q)$(foreach cmd,$(2),$(file >> $(SCRIPT),cd $(TOPDIR))
100		$(file >> $(SCRIPT),$($(cmd)))$(sep))
101	$(Q)$(SED) 's/^[ \t@-]*//' -e '/^$$/d' $(SCRIPT)
102	$(Q)chmod +x $(SCRIPT)
103endef
104
105define run_commands
106	@$(call log_commands,$(1),$(2))
107	+$(foreach cmd,$(2),$(call $(cmd))$(sep))
108endef
109
110# Make sure .la files only reference the current per-package
111# directory.
112
113# $1: package name (lower case)
114# $2: staging directory of the package
115ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),y)
116define fixup-libtool-files
117	$(Q)find $(2) \( -path '$(2)/lib*' -o -path '$(2)/usr/lib*' \) \
118		-name "*.la" -print0 | xargs -0 --no-run-if-empty \
119		$(SED) "s:$(PER_PACKAGE_DIR)/[^/]\+/:$(PER_PACKAGE_DIR)/$(1)/:g"
120endef
121endif
122
123# Make sure python _sysconfigdata*.py files only reference the current
124# per-package directory.
125#
126# Can't use $(foreach d, $(HOST_DIR)/lib/python* $(STAGING_DIR)/usr/lib/python*, ...)
127# because those directories may be created in the same recipe this macro will
128# be expanded in.
129# Additionally, either or both may be missing, which would make find whine and
130# fail.
131# So we just use HOST_DIR as a starting point, and filter on the two directories
132# of interest.
133ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),y)
134define FIXUP_PYTHON_SYSCONFIGDATA
135	$(Q)find $(HOST_DIR) \
136		\(    -path '$(HOST_DIR)/lib/python*' \
137		   -o -path '$(STAGING_DIR)/usr/lib/python*' \
138		\) \
139		\(    \( -name "_sysconfigdata*.pyc" -delete \) \
140		   -o \( -name "_sysconfigdata*.py" -print0 \) \
141		\) \
142	| xargs -0 --no-run-if-empty \
143		$(SED) 's:$(PER_PACKAGE_DIR)/[^/]\+/:$(PER_PACKAGE_DIR)/$($(PKG)_NAME)/:g'
144endef
145endif
146
147# Functions to collect statistics about installed files
148
149# $(1): base directory to search in
150# $(2): suffix of file (optional)
151define pkg_size_before
152	cd $(1); \
153	LC_ALL=C find . -not -path './$(STAGING_SUBDIR)/*' \( -type f -o -type l \) -printf '%T@:%i:%#m:%y:%s,%p\n' \
154		| LC_ALL=C sort > $($(PKG)_DIR)/.files-list$(2).before
155endef
156
157# $(1): base directory to search in
158# $(2): suffix of file (optional)
159define pkg_size_after
160	cd $(1); \
161	LC_ALL=C find . -not -path './$(STAGING_SUBDIR)/*' \( -type f -o -type l \) -printf '%T@:%i:%#m:%y:%s,%p\n' \
162		| LC_ALL=C sort > $($(PKG)_DIR)/.files-list$(2).after
163	LC_ALL=C comm -13 \
164		$($(PKG)_DIR)/.files-list$(2).before \
165		$($(PKG)_DIR)/.files-list$(2).after \
166		| sed -r -e 's/^[^,]+/$($(PKG)_NAME)/' \
167		> $($(PKG)_DIR)/.files-list$(2).txt 2>/dev/null
168	rm -f $($(PKG)_DIR)/.files-list$(2).before
169	rm -f $($(PKG)_DIR)/.files-list$(2).after
170endef
171
172define check_bin_arch
173	support/scripts/check-bin-arch -p $($(PKG)_NAME) \
174		-l $($(PKG)_DIR)/.files-list.txt \
175		$(foreach i,$($(PKG)_BIN_ARCH_EXCLUDE),-i "$(i)") \
176		-r $(TARGET_READELF) \
177		-a $(BR2_READELF_ARCH_NAME)
178endef
179
180# Functions to remove conflicting and useless files
181
182# $1: base directory (target, staging, host)
183define remove-conflicting-useless-files
184	$(if $(strip $($(PKG)_DROP_FILES_OR_DIRS)),
185		$(Q)$(RM) -rf $(patsubst %, $(1)%, $($(PKG)_DROP_FILES_OR_DIRS)))
186endef
187define REMOVE_CONFLICTING_USELESS_FILES_IN_HOST
188	$(call remove-conflicting-useless-files,$(HOST_DIR))
189endef
190define REMOVE_CONFLICTING_USELESS_FILES_IN_STAGING
191	$(call remove-conflicting-useless-files,$(STAGING_DIR))
192endef
193define REMOVE_CONFLICTING_USELESS_FILES_IN_TARGET
194	$(call remove-conflicting-useless-files,$(TARGET_DIR))
195endef
196
197################################################################################
198# Implicit targets -- produce a stamp file for each step of a package build
199################################################################################
200
201# Retrieve the archive
202$(BUILD_DIR)/%/.stamp_downloaded:
203	@$(call step_start,download)
204	$(call prepare-per-package-directory,$($(PKG)_FINAL_DOWNLOAD_DEPENDENCIES))
205	$(foreach hook,$($(PKG)_PRE_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
206# Only show the download message if it isn't already downloaded
207	$(Q)for p in $($(PKG)_ALL_DOWNLOADS); do \
208		if test ! -e $($(PKG)_DL_DIR)/`basename $$p` ; then \
209			$(call MESSAGE,"Downloading") ; \
210			break ; \
211		fi ; \
212	done
213	$(foreach p,$($(PKG)_ALL_DOWNLOADS),$(call DOWNLOAD,$(p),$(PKG))$(sep))
214	$(foreach hook,$($(PKG)_POST_DOWNLOAD_HOOKS),$(call $(hook))$(sep))
215	$(Q)mkdir -p $(@D)
216	@$(call step_end,download)
217	$(Q)touch $@
218
219# Retrieve actual source archive, e.g. for prebuilt external toolchains
220$(BUILD_DIR)/%/.stamp_actual_downloaded:
221	@$(call step_start,actual-download)
222	$(call DOWNLOAD,$($(PKG)_ACTUAL_SOURCE_SITE)/$($(PKG)_ACTUAL_SOURCE_TARBALL),$(PKG))
223	$(Q)mkdir -p $(@D)
224	@$(call step_end,actual-download)
225	$(Q)touch $@
226
227# Unpack the archive
228$(BUILD_DIR)/%/.stamp_extracted:
229	@$(call step_start,extract)
230	@$(call MESSAGE,"Extracting")
231	$(call prepare-per-package-directory,$($(PKG)_FINAL_EXTRACT_DEPENDENCIES))
232	$(foreach hook,$($(PKG)_PRE_EXTRACT_HOOKS),$(call $(hook))$(sep))
233	$(Q)mkdir -p $(@D)
234	$($(PKG)_EXTRACT_CMDS)
235# some packages have messed up permissions inside
236	$(Q)chmod -R +rw $(@D)
237	$(foreach hook,$($(PKG)_POST_EXTRACT_HOOKS),$(call $(hook))$(sep))
238	@$(call step_end,extract)
239	$(Q)touch $@
240
241# Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
242# used.
243$(BUILD_DIR)/%/.stamp_rsynced:
244	@$(call step_start,rsync)
245	@$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
246	@mkdir -p $(@D)
247	$(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
248	@test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
249	rsync -au --chmod=u=rwX,go=rX $($(PKG)_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS) $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
250	$(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
251	@$(call step_end,rsync)
252	$(Q)touch $@
253
254	@test -d $(SRCDIR)/.git && (cd $(SRCDIR) && git status --ignored -s | \
255		grep "" && echo "WARN: $(SRCDIR) is dirty!") || true
256
257# Patch
258#
259# The RAWNAME variable is the lowercased package name, which allows to
260# find the package directory (typically package/<pkgname>) and the
261# prefix of the patches
262#
263# For BR2_GLOBAL_PATCH_DIR, only generate if it is defined
264$(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS =  $(PKGDIR)
265$(BUILD_DIR)/%/.stamp_patched: PATCH_BASE_DIRS += $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))
266$(BUILD_DIR)/%/.stamp_patched:
267	@$(call step_start,patch)
268	@$(call MESSAGE,"Patching")
269	$(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
270	$(foreach p,$($(PKG)_PATCH),$(APPLY_PATCHES) $(@D) $($(PKG)_DL_DIR) $(notdir $(p))$(sep))
271	$(Q)( \
272	for D in $(PATCH_BASE_DIRS); do \
273	  if test -d $${D}; then \
274	    if test -d $${D}/$($(PKG)_VERSION); then \
275	      $(APPLY_PATCHES) $(@D) $${D}/$($(PKG)_VERSION) \*.patch \*.patch.$(ARCH) || exit 1; \
276	    else \
277	      $(APPLY_PATCHES) $(@D) $${D} \*.patch \*.patch.$(ARCH) || exit 1; \
278	    fi; \
279	  fi; \
280	done; \
281	)
282	$(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
283	@$(call step_end,patch)
284	$(Q)touch $@
285
286# Check that all directories specified in BR2_GLOBAL_PATCH_DIR exist.
287$(foreach dir,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)),\
288	$(if $(wildcard $(dir)),,\
289		$(error BR2_GLOBAL_PATCH_DIR contains nonexistent directory $(dir))))
290
291# Configure
292$(BUILD_DIR)/%/.stamp_configured:
293	@$(call step_start,configure)
294	@$(call MESSAGE,"Configuring")
295	$(Q)mkdir -p $(HOST_DIR) $(TARGET_DIR) $(STAGING_DIR) $(BINARIES_DIR)
296	$(call prepare-per-package-directory,$($(PKG)_FINAL_DEPENDENCIES))
297	@$(call pkg_size_before,$(TARGET_DIR))
298	@$(call pkg_size_before,$(STAGING_DIR),-staging)
299	@$(call pkg_size_before,$(BINARIES_DIR),-images)
300	@$(call pkg_size_before,$(HOST_DIR),-host)
301	$(call fixup-libtool-files,$(NAME),$(HOST_DIR))
302	$(call fixup-libtool-files,$(NAME),$(STAGING_DIR))
303	$(foreach hook,$($(PKG)_POST_PREPARE_HOOKS),$(call $(hook))$(sep))
304	$(Q)$(call run_commands,configure,$($(PKG)_PRE_CONFIGURE_HOOKS) \
305		$(PKG)_CONFIGURE_CMDS $($(PKG)_POST_CONFIGURE_HOOKS))
306	@$(call step_end,configure)
307	$(Q)touch $@
308
309# Build
310$(BUILD_DIR)/%/.stamp_built::
311	@$(call step_start,build)
312	@$(call MESSAGE,"Building")
313	$(Q)$(call run_commands,build,$($(PKG)_PRE_BUILD_HOOKS) \
314		$(PKG)_BUILD_CMDS $($(PKG)_POST_BUILD_HOOKS))
315	@$(call step_end,build)
316	$(Q)touch $@
317
318# Install to host dir
319$(BUILD_DIR)/%/.stamp_host_installed:
320	@$(call step_start,install-host)
321	@$(call MESSAGE,"Installing to host directory")
322	$(Q)$(call run_commands,host_install,$($(PKG)_PRE_INSTALL_HOOKS) \
323		$(PKG)_INSTALL_CMDS $($(PKG)_POST_INSTALL_HOOKS))
324	@$(call step_end,install-host)
325	$(Q)touch $@
326
327# Install to staging dir
328#
329# Some packages install libtool .la files alongside any installed
330# libraries. These .la files sometimes refer to paths relative to the
331# sysroot, which libtool will interpret as absolute paths to host
332# libraries instead of the target libraries. Since this is not what we
333# want, these paths are fixed by prefixing them with $(STAGING_DIR).
334# As we configure with --prefix=/usr, this fix needs to be applied to
335# any path that starts with /usr.
336#
337# To protect against the case that the output or staging directories or
338# the pre-installed external toolchain themselves are under /usr, we first
339# substitute away any occurrences of these directories with @BASE_DIR@,
340# @STAGING_DIR@ and @TOOLCHAIN_EXTERNAL_INSTALL_DIR@ respectively.
341#
342# Note that STAGING_DIR can be outside BASE_DIR when the user sets
343# BR2_HOST_DIR to a custom value. Note that TOOLCHAIN_EXTERNAL_INSTALL_DIR
344# can be under @BASE_DIR@ when it's a downloaded toolchain, and can be
345# empty when we use an internal toolchain.
346#
347define POST_INSTALL_STAGING
348	$(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
349		$(call MESSAGE,"Fixing package configuration files") ;\
350			$(SED)  "s,$(HOST_DIR),@HOST_DIR@,g" \
351				-e "s,$(BASE_DIR),@BASE_DIR@,g" \
352				-e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" \
353				-e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" \
354				-e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" \
355				-e 's,@STAGING_DIR@,$$(dirname $$(readlink -e $$0))/../..,g' \
356				-e 's,@HOST_DIR@,$$(dirname $$(readlink -e $$0))/../../../..,g' \
357				-e "s,@BASE_DIR@,$(BASE_DIR),g" \
358				$(addprefix $(STAGING_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ;\
359	fi
360	@$(call MESSAGE,"Fixing libtool files")
361	for la in $$(find $(STAGING_DIR)/usr/lib* -name "*.la"); do \
362		cp -a "$${la}" "$${la}.fixed" && \
363		$(SED) "s:$(BASE_DIR):@BASE_DIR@:g" \
364			-e "s:$(STAGING_DIR):@STAGING_DIR@:g" \
365			$(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
366				-e "s:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:g") \
367			-e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" \
368			-e "s:\(['= ]\)/lib:\\1@STAGING_DIR@/lib:g" \
369			$(if $(TOOLCHAIN_EXTERNAL_INSTALL_DIR),\
370				-e "s:@TOOLCHAIN_EXTERNAL_INSTALL_DIR@:$(TOOLCHAIN_EXTERNAL_INSTALL_DIR):g") \
371			-e "s:@STAGING_DIR@:$(STAGING_DIR):g" \
372			-e "s:@BASE_DIR@:$(BASE_DIR):g" \
373			"$${la}.fixed" && \
374		if cmp -s "$${la}" "$${la}.fixed"; then \
375			rm -f "$${la}.fixed"; \
376		else \
377			mv "$${la}.fixed" "$${la}"; \
378		fi || exit 1; \
379	done
380endef
381$(BUILD_DIR)/%/.stamp_staging_installed:
382	@$(call step_start,install-staging)
383	@$(call MESSAGE,"Installing to staging directory")
384	$(Q)$(call run_commands,staging_install,$($(PKG)_PRE_INSTALL_STAGING_HOOKS) \
385		$(PKG)_INSTALL_STAGING_CMDS $($(PKG)_POST_INSTALL_STAGING_HOOKS) \
386		POST_INSTALL_STAGING)
387	@$(call step_end,install-staging)
388	$(Q)touch $@
389
390# Install to images dir
391$(BUILD_DIR)/%/.stamp_images_installed:
392	@$(call step_start,install-image)
393	@$(call MESSAGE,"Installing to images directory")
394	$(Q)$(call run_commands,image_install,$($(PKG)_PRE_INSTALL_IMAGES_HOOKS) \
395		$(PKG)_INSTALL_IMAGES_CMDS $($(PKG)_POST_INSTALL_IMAGES_HOOKS))
396	@$(call step_end,install-image)
397	$(Q)touch $@
398
399# Install to target dir
400define PRE_INSTALL_TARGET
401	$(Q)touch $($(PKG)_DIR)/.stamp_installed
402	$(Q)if [ -r $(@D)/.files-list-target.txt ]; then \
403		cd $(TARGET_DIR); \
404		cat $(@D)/.files-list-target.txt | \
405			xargs md5sum /dev/null > $(@D)/.md5 2>/dev/null || true; \
406		cd -; \
407	fi
408endef
409
410define POST_INSTALL_TARGET
411	$(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
412		$(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
413	fi
414
415	$(Q)cd $(TARGET_DIR); find . \( -type f -o -type l \) \
416		-cnewer $(@D)/.stamp_installed | \
417		tee $(@D)/.files-list-target.txt | \
418		$(TAR) --no-recursion --ignore-failed-read \
419			-cf $(@D)/$($(PKG)_BASENAME).tar -T -; true;
420
421	$(Q)cd $(TARGET_DIR); if [ -r $(@D)/.md5 ]; then \
422		md5sum -c $(@D)/.md5 2>&1 | grep "FAILED$$" | \
423			cut -d':' -f1 > $(@D)/.files-list-target-update.txt; \
424	fi
425endef
426
427define DEPLOY_CMDS
428	cd $(TARGET_DIR)
429	$(TAR) --no-recursion --ignore-failed-read \
430		-cf $(@D)/$($(PKG)_BASENAME).tar \
431		-T $(@D)/.files-list-target.txt
432	adb shell true >/dev/null
433	adb push $(@D)/$($(PKG)_BASENAME).tar /tmp/
434	adb shell tar xvf /tmp/$($(PKG)_BASENAME).tar
435endef
436
437define UPDATE_CMDS
438	[ -r $(@D)/.files-list-target-update.txt ] || exit 0
439	cd $(TARGET_DIR)
440	$(TAR) --no-recursion --ignore-failed-read \
441		-cf $(@D)/$($(PKG)_BASENAME)-update.tar \
442		-T $(@D)/.files-list-target-update.txt
443	adb shell true >/dev/null
444	adb push $(@D)/$($(PKG)_BASENAME)-update.tar /tmp/
445	adb shell tar xvf /tmp/$($(PKG)_BASENAME)-update.tar
446endef
447$(BUILD_DIR)/%/.stamp_target_installed:
448	$(Q)touch $($(PKG)_DIR)/.stamp_installed
449
450	@$(call step_start,install-target)
451	@$(call MESSAGE,"Installing to target")
452	$(Q)$(call run_commands,target_install, PRE_INSTALL_TARGET \
453		$($(PKG)_PRE_INSTALL_TARGET_HOOKS) \
454		$(PKG)_INSTALL_TARGET_CMDS \
455		$(if $(BR2_INIT_SYSTEMD),$(PKG)_INSTALL_INIT_SYSTEMD) \
456		$(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),$(PKG)_INSTALL_INIT_SYSV) \
457		$(if $(BR2_INIT_OPENRC),$(or $(PKG)_INSTALL_INIT_OPENRC,\
458		$(PKG)_INSTALL_INIT_SYSV)) \
459		$($(PKG)_POST_INSTALL_TARGET_HOOKS) POST_INSTALL_TARGET)
460	@$(call step_end,install-target)
461	$(Q)touch $@
462
463	@$(call log_commands,deploy,DEPLOY_CMDS)
464	@$(call log_commands,update,UPDATE_CMDS)
465
466# Final installation step, completed when all installation steps
467# (host, images, staging, target) have completed
468$(BUILD_DIR)/%/.stamp_installed:
469	@$(call pkg_size_after,$(TARGET_DIR))
470	@$(call pkg_size_after,$(STAGING_DIR),-staging)
471	@$(call pkg_size_after,$(BINARIES_DIR),-images)
472	@$(call pkg_size_after,$(HOST_DIR),-host)
473	@$(call check_bin_arch)
474	$(Q)touch $@
475
476# Remove package sources
477$(BUILD_DIR)/%/.stamp_dircleaned:
478	$(if $(BR2_PER_PACKAGE_DIRECTORIES),rm -Rf $(PER_PACKAGE_DIR)/$(NAME))
479	rm -Rf $(@D)
480
481################################################################################
482# virt-provides-single -- check that provider-pkg is the declared provider for
483# the virtual package virt-pkg
484#
485# argument 1 is the lower-case name of the virtual package
486# argument 2 is the upper-case name of the virtual package
487# argument 3 is the lower-case name of the provider
488#
489# example:
490#   $(call virt-provides-single,libegl,LIBEGL,rpi-userland)
491################################################################################
492define virt-provides-single
493ifneq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),$(3))
494$$(error Configuration error: both "$(3)" and $$(BR2_PACKAGE_PROVIDES_$(2))\
495are selected as providers for virtual package "$(1)". Only one provider can\
496be selected at a time. Please fix your configuration)
497endif
498endef
499
500define pkg-graph-depends
501	@$$(INSTALL) -d $$(GRAPHS_DIR)
502	@cd "$$(CONFIG_DIR)"; \
503	$$(TOPDIR)/support/scripts/graph-depends $$(BR2_GRAPH_DEPS_OPTS) \
504		-p $(1) $(2) -o $$(GRAPHS_DIR)/$$(@).dot
505	dot $$(BR2_GRAPH_DOT_OPTS) -T$$(BR_GRAPH_OUT) \
506		-o $$(GRAPHS_DIR)/$$(@).$$(BR_GRAPH_OUT) \
507		$$(GRAPHS_DIR)/$$(@).dot
508endef
509
510################################################################################
511# inner-generic-package -- generates the make targets needed to build a
512# generic package
513#
514#  argument 1 is the lowercase package name
515#  argument 2 is the uppercase package name, including a HOST_ prefix
516#             for host packages
517#  argument 3 is the uppercase package name, without the HOST_ prefix
518#             for host packages
519#  argument 4 is the type (target or host)
520#
521# Note about variable and function references: inside all blocks that are
522# evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
523# specific rules apply with respect to variable and function references.
524# - Numbered variables (parameters to the block) can be referenced with a single
525#   dollar sign: $(1), $(2), $(3), etc.
526# - pkgdir and pkgname should be referenced with a single dollar sign too. These
527#   functions rely on 'the most recently parsed makefile' which is supposed to
528#   be the package .mk file. If we defer the evaluation of these functions using
529#   double dollar signs, then they may be evaluated too late, when other
530#   makefiles have already been parsed. One specific case is when $$(pkgdir) is
531#   assigned to a variable using deferred evaluation with '=' and this variable
532#   is used in a target rule outside the eval'ed inner block. In this case, the
533#   pkgdir will be that of the last makefile parsed by buildroot, which is not
534#   the expected value. This mechanism is for example used for the TARGET_PATCH
535#   rule.
536# - All other variables should be referenced with a double dollar sign:
537#   $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all make functions should be
538#   referenced with a double dollar sign: $$(subst), $$(call), $$(filter-out),
539#   etc. This rule ensures that these variables and functions are only expanded
540#   during the $(eval) step, and not earlier. Otherwise, unintuitive and
541#   undesired behavior occurs with respect to these variables and functions.
542#
543################################################################################
544
545define inner-generic-package
546
547# When doing a package, we're definitely not doing a rootfs, but we
548# may inherit it via the dependency chain, so we reset it.
549$(1): ROOTFS=
550
551# Ensure the package is only declared once, i.e. do not accept that a
552# package be re-defined by a br2-external tree
553ifneq ($(call strip,$(filter $(1),$(PACKAGES_ALL))),)
554$$(error Package '$(1)' defined a second time in '$(pkgdir)'; \
555	previous definition was in '$$($(2)_PKGDIR)')
556endif
557PACKAGES_ALL += $(1)
558
559# Define default values for various package-related variables, if not
560# already defined. For some variables (version, source, site and
561# subdir), if they are undefined, we try to see if a variable without
562# the HOST_ prefix is defined. If so, we use such a variable, so that
563# this information has only to be specified once, for both the
564# target and host packages of a given .mk file.
565
566$(2)_TYPE                       =  $(4)
567$(2)_NAME			=  $(1)
568$(2)_RAWNAME			=  $$(patsubst host-%,%,$(1))
569$(2)_PKGDIR			=  $(pkgdir)
570
571# Keep the package version that may contain forward slashes in the _DL_VERSION
572# variable, then replace all forward slashes ('/') by underscores ('_') to
573# sanitize the package version that is used in paths, directory and file names.
574# Forward slashes may appear in the package's version when pointing to a
575# version control system branch or tag, for example remotes/origin/1_10_stable.
576# Similar for spaces and colons (:) that may appear in date-based revisions for
577# CVS.
578ifndef $(2)_VERSION
579 ifdef $(3)_DL_VERSION
580  $(2)_DL_VERSION := $$($(3)_DL_VERSION)
581 else ifdef $(3)_VERSION
582  $(2)_DL_VERSION := $$($(3)_VERSION)
583 endif
584else
585 $(2)_DL_VERSION := $$(strip $$($(2)_VERSION))
586endif
587$(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
588
589$(2)_HASH_FILE = \
590	$$(strip \
591		$$(if $$(wildcard $$($(2)_PKGDIR)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash),\
592			$$($(2)_PKGDIR)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash,\
593			$$($(2)_PKGDIR)/$$($(2)_RAWNAME).hash))
594
595ifdef $(3)_OVERRIDE_SRCDIR
596  $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
597endif
598
599$(2)_BASENAME	= $$(if $$($(2)_VERSION),$(1)-$$($(2)_VERSION),$(1))
600$(2)_BASENAME_RAW = $$(if $$($(2)_VERSION),$$($(2)_RAWNAME)-$$($(2)_VERSION),$$($(2)_RAWNAME))
601$(2)_DL_SUBDIR ?= $$($(2)_RAWNAME)
602$(2)_DL_DIR = $$(DL_DIR)/$$($(2)_DL_SUBDIR)
603$(2)_DIR	=  $$(BUILD_DIR)/$$($(2)_BASENAME)
604
605ifndef $(2)_SUBDIR
606 ifdef $(3)_SUBDIR
607  $(2)_SUBDIR = $$($(3)_SUBDIR)
608 else
609  $(2)_SUBDIR ?=
610 endif
611endif
612
613ifndef $(2)_STRIP_COMPONENTS
614 ifdef $(3)_STRIP_COMPONENTS
615  $(2)_STRIP_COMPONENTS = $$($(3)_STRIP_COMPONENTS)
616 else
617  $(2)_STRIP_COMPONENTS ?= 1
618 endif
619endif
620
621$(2)_SRCDIR		       = $$($(2)_DIR)/$$($(2)_SUBDIR)
622$(2)_BUILDDIR		       ?= $$($(2)_SRCDIR)
623
624ifneq ($$($(2)_OVERRIDE_SRCDIR),)
625$(2)_VERSION = custom
626endif
627
628ifndef $(2)_SOURCE
629 ifdef $(3)_SOURCE
630  $(2)_SOURCE = $$($(3)_SOURCE)
631 else ifdef $(2)_VERSION
632  $(2)_SOURCE			?= $$($(2)_BASENAME_RAW)$$(call pkg_source_ext,$(2))
633 endif
634endif
635
636# If FOO_ACTUAL_SOURCE_TARBALL is explicitly defined, it means FOO_SOURCE is
637# indeed a binary (e.g. external toolchain) and FOO_ACTUAL_SOURCE_TARBALL/_SITE
638# point to the actual sources tarball. Use the actual sources for legal-info.
639# For most packages the FOO_SITE/FOO_SOURCE pair points to real source code,
640# so these are the defaults for FOO_ACTUAL_*.
641$(2)_ACTUAL_SOURCE_TARBALL ?= $$($(2)_SOURCE)
642$(2)_ACTUAL_SOURCE_SITE    ?= $$(call qstrip,$$($(2)_SITE))
643
644ifndef $(2)_PATCH
645 ifdef $(3)_PATCH
646  $(2)_PATCH = $$($(3)_PATCH)
647 endif
648endif
649
650$(2)_ALL_DOWNLOADS = \
651	$$(if $$($(2)_SOURCE),$$($(2)_SITE_METHOD)+$$($(2)_SITE)/$$($(2)_SOURCE)) \
652	$$(foreach p,$$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
653		$$(if $$(findstring ://,$$(p)),$$(p),\
654			$$($(2)_SITE_METHOD)+$$($(2)_SITE)/$$(p)))
655
656ifndef $(2)_SITE
657 ifdef $(3)_SITE
658  $(2)_SITE = $$($(3)_SITE)
659 endif
660endif
661
662ifndef $(2)_SITE_METHOD
663 ifdef $(3)_SITE_METHOD
664  $(2)_SITE_METHOD = $$($(3)_SITE_METHOD)
665 else
666	# Try automatic detection using the scheme part of the URI
667	$(2)_SITE_METHOD = $$(call geturischeme,$$($(2)_SITE))
668 endif
669endif
670
671ifndef $(2)_DL_OPTS
672 ifdef $(3)_DL_OPTS
673  $(2)_DL_OPTS = $$($(3)_DL_OPTS)
674 endif
675endif
676
677ifneq ($$(filter bzr cvs hg,$$($(2)_SITE_METHOD)),)
678BR_NO_CHECK_HASH_FOR += $$($(2)_SOURCE)
679endif
680
681ifndef $(2)_GIT_SUBMODULES
682 ifdef $(3)_GIT_SUBMODULES
683  $(2)_GIT_SUBMODULES = $$($(3)_GIT_SUBMODULES)
684 endif
685endif
686
687# Do not accept to download git submodule if not using the git method
688ifneq ($$($(2)_GIT_SUBMODULES),)
689 ifneq ($$($(2)_SITE_METHOD),git)
690  $$(error $(2) declares having git sub-modules, but does not use the \
691	   'git' method (uses '$$($(2)_SITE_METHOD)' instead))
692 endif
693endif
694
695ifeq ($$($(2)_SITE_METHOD),local)
696ifeq ($$($(2)_OVERRIDE_SRCDIR),)
697$(2)_OVERRIDE_SRCDIR = $$($(2)_SITE)
698endif
699ifeq ($$($(2)_OVERRIDE_SRCDIR),)
700$$(error $(1) has local site method, but `$(2)_SITE` is not defined)
701endif
702endif
703
704ifndef $(2)_LICENSE
705 ifdef $(3)_LICENSE
706  $(2)_LICENSE = $$($(3)_LICENSE)
707 endif
708endif
709
710$(2)_LICENSE			?= unknown
711
712ifndef $(2)_LICENSE_FILES
713 ifdef $(3)_LICENSE_FILES
714  $(2)_LICENSE_FILES = $$($(3)_LICENSE_FILES)
715 endif
716endif
717
718ifndef $(2)_REDISTRIBUTE
719 ifdef $(3)_REDISTRIBUTE
720  $(2)_REDISTRIBUTE = $$($(3)_REDISTRIBUTE)
721 endif
722endif
723
724$(2)_REDISTRIBUTE		?= YES
725
726$(2)_REDIST_SOURCES_DIR = $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))/$$($(2)_BASENAME_RAW)
727
728# If any of the <pkg>_CPE_ID_* variables are set, we assume the CPE ID
729# information is valid for this package.
730ifneq ($$($(2)_CPE_ID_VENDOR)$$($(2)_CPE_ID_PRODUCT)$$($(2)_CPE_ID_VERSION)$$($(2)_CPE_ID_UPDATE)$$($(2)_CPE_ID_PREFIX),)
731$(2)_CPE_ID_VALID = YES
732endif
733
734# When we're a host package, make sure to use the variables of the
735# corresponding target package, if any.
736ifneq ($$($(3)_CPE_ID_VENDOR)$$($(3)_CPE_ID_PRODUCT)$$($(3)_CPE_ID_VERSION)$$($(3)_CPE_ID_UPDATE)$$($(3)_CPE_ID_PREFIX),)
737$(2)_CPE_ID_VALID = YES
738endif
739
740# If the CPE ID is valid for the target package so it is for the host
741# package
742ifndef $(2)_CPE_ID_VALID
743 ifdef $(3)_CPE_ID_VALID
744   $(2)_CPE_ID_VALID = $$($(3)_CPE_ID_VALID)
745 endif
746endif
747
748ifeq ($$($(2)_CPE_ID_VALID),YES)
749 # CPE_ID_VENDOR
750 ifndef $(2)_CPE_ID_VENDOR
751  ifdef $(3)_CPE_ID_VENDOR
752   $(2)_CPE_ID_VENDOR = $$($(3)_CPE_ID_VENDOR)
753  else
754   $(2)_CPE_ID_VENDOR = $$($(2)_RAWNAME)_project
755 endif
756 endif
757
758 # CPE_ID_PRODUCT
759 ifndef $(2)_CPE_ID_PRODUCT
760  ifdef $(3)_CPE_ID_PRODUCT
761   $(2)_CPE_ID_PRODUCT = $$($(3)_CPE_ID_PRODUCT)
762  else
763   $(2)_CPE_ID_PRODUCT = $$($(2)_RAWNAME)
764  endif
765 endif
766
767 # CPE_ID_VERSION
768 ifndef $(2)_CPE_ID_VERSION
769  ifdef $(3)_CPE_ID_VERSION
770   $(2)_CPE_ID_VERSION = $$($(3)_CPE_ID_VERSION)
771  else
772   $(2)_CPE_ID_VERSION = $$($(2)_VERSION)
773  endif
774 endif
775
776 # CPE_ID_UPDATE
777 ifndef $(2)_CPE_ID_UPDATE
778  ifdef $(3)_CPE_ID_UPDATE
779   $(2)_CPE_ID_UPDATE = $$($(3)_CPE_ID_UPDATE)
780  else
781   $(2)_CPE_ID_UPDATE = *
782  endif
783 endif
784
785 # CPE_ID_PREFIX
786 ifndef $(2)_CPE_ID_PREFIX
787  ifdef $(3)_CPE_ID_PREFIX
788   $(2)_CPE_ID_PREFIX = $$($(3)_CPE_ID_PREFIX)
789  else
790   $(2)_CPE_ID_PREFIX = cpe:2.3:a
791  endif
792 endif
793
794 # Calculate complete CPE ID
795 $(2)_CPE_ID = $$($(2)_CPE_ID_PREFIX):$$($(2)_CPE_ID_VENDOR):$$($(2)_CPE_ID_PRODUCT):$$($(2)_CPE_ID_VERSION):$$($(2)_CPE_ID_UPDATE):*:*:*:*:*:*
796endif # ifeq ($$($(2)_CPE_ID_VALID),YES)
797
798# When a target package is a toolchain dependency set this variable to
799# 'NO' so the 'toolchain' dependency is not added to prevent a circular
800# dependency.
801# Similarly for the skeleton.
802$(2)_ADD_TOOLCHAIN_DEPENDENCY	?= YES
803$(2)_ADD_SKELETON_DEPENDENCY	?= YES
804
805
806ifeq ($(4),target)
807ifeq ($$($(2)_ADD_SKELETON_DEPENDENCY),YES)
808$(2)_DEPENDENCIES += skeleton
809endif
810ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
811$(2)_DEPENDENCIES += toolchain
812endif
813endif
814
815ifneq ($(1),host-skeleton)
816$(2)_DEPENDENCIES += host-skeleton
817endif
818
819ifneq ($$(filter cvs git svn,$$($(2)_SITE_METHOD)),)
820$(2)_DOWNLOAD_DEPENDENCIES += \
821	$(BR2_GZIP_HOST_DEPENDENCY) \
822	$(BR2_TAR_HOST_DEPENDENCY)
823endif
824
825ifeq ($$(filter host-tar host-skeleton host-fakedate,$(1)),)
826$(2)_EXTRACT_DEPENDENCIES += $$(BR2_TAR_HOST_DEPENDENCY)
827endif
828
829ifeq ($$(filter host-tar host-skeleton host-xz host-lzip host-fakedate,$(1)),)
830$(2)_EXTRACT_DEPENDENCIES += \
831	$$(foreach dl,$$($(2)_ALL_DOWNLOADS),\
832		$$(call extractor-pkg-dependency,$$(notdir $$(dl))))
833endif
834
835ifeq ($$(BR2_CCACHE),y)
836ifeq ($$(filter host-tar host-skeleton host-xz host-lzip host-fakedate host-ccache,$(1)),)
837$(2)_DEPENDENCIES += host-ccache
838endif
839endif
840
841ifeq ($$(BR2_REPRODUCIBLE),y)
842ifeq ($$(filter host-skeleton host-fakedate,$(1)),)
843$(2)_DEPENDENCIES += host-fakedate
844endif
845endif
846
847# Eliminate duplicates in dependencies
848$(2)_FINAL_DEPENDENCIES = $$(sort $$($(2)_DEPENDENCIES))
849$(2)_FINAL_DOWNLOAD_DEPENDENCIES = $$(sort $$($(2)_DOWNLOAD_DEPENDENCIES))
850$(2)_FINAL_EXTRACT_DEPENDENCIES = $$(sort $$($(2)_EXTRACT_DEPENDENCIES))
851$(2)_FINAL_PATCH_DEPENDENCIES = $$(sort $$($(2)_PATCH_DEPENDENCIES))
852$(2)_FINAL_ALL_DEPENDENCIES = \
853	$$(sort \
854		$$($(2)_FINAL_DEPENDENCIES) \
855		$$($(2)_FINAL_DOWNLOAD_DEPENDENCIES) \
856		$$($(2)_FINAL_EXTRACT_DEPENDENCIES) \
857		$$($(2)_FINAL_PATCH_DEPENDENCIES))
858$(2)_FINAL_RECURSIVE_DEPENDENCIES = $$(sort \
859	$$(if $$(filter undefined,$$(origin $(2)_FINAL_RECURSIVE_DEPENDENCIES__X)), \
860		$$(eval $(2)_FINAL_RECURSIVE_DEPENDENCIES__X := \
861			$$(foreach p, \
862				$$($(2)_FINAL_ALL_DEPENDENCIES), \
863				$$(p) \
864				$$($$(call UPPERCASE,$$(p))_FINAL_RECURSIVE_DEPENDENCIES) \
865			) \
866		) \
867	) \
868	$$($(2)_FINAL_RECURSIVE_DEPENDENCIES__X))
869
870$(2)_FINAL_RECURSIVE_RDEPENDENCIES = $$(sort \
871	$$(if $$(filter undefined,$$(origin $(2)_FINAL_RECURSIVE_RDEPENDENCIES__X)), \
872		$$(eval $(2)_FINAL_RECURSIVE_RDEPENDENCIES__X := \
873			$$(foreach p, \
874				$$($(2)_RDEPENDENCIES), \
875				$$(p) \
876				$$($$(call UPPERCASE,$$(p))_FINAL_RECURSIVE_RDEPENDENCIES) \
877			) \
878		) \
879	) \
880	$$($(2)_FINAL_RECURSIVE_RDEPENDENCIES__X))
881
882# define sub-target stamps
883$(2)_TARGET_INSTALL =           $$($(2)_DIR)/.stamp_installed
884$(2)_TARGET_INSTALL_TARGET =	$$($(2)_DIR)/.stamp_target_installed
885$(2)_TARGET_INSTALL_STAGING =	$$($(2)_DIR)/.stamp_staging_installed
886$(2)_TARGET_INSTALL_IMAGES =	$$($(2)_DIR)/.stamp_images_installed
887$(2)_TARGET_INSTALL_HOST =	$$($(2)_DIR)/.stamp_host_installed
888$(2)_TARGET_BUILD =		$$($(2)_DIR)/.stamp_built
889$(2)_TARGET_CONFIGURE =		$$($(2)_DIR)/.stamp_configured
890$(2)_TARGET_RSYNC =		$$($(2)_DIR)/.stamp_rsynced
891$(2)_TARGET_PATCH =		$$($(2)_DIR)/.stamp_patched
892$(2)_TARGET_EXTRACT =		$$($(2)_DIR)/.stamp_extracted
893$(2)_TARGET_SOURCE =		$$($(2)_DIR)/.stamp_downloaded
894$(2)_TARGET_ACTUAL_SOURCE =	$$($(2)_DIR)/.stamp_actual_downloaded
895$(2)_TARGET_DIRCLEAN =		$$($(2)_DIR)/.stamp_dircleaned
896
897# default extract command
898$(2)_EXTRACT_CMDS ?= \
899	$$(if $$($(2)_SOURCE),$$(INFLATE$$(suffix $$($(2)_SOURCE))) $$($(2)_DL_DIR)/$$($(2)_SOURCE) | \
900	$$(TAR) --strip-components=$$($(2)_STRIP_COMPONENTS) \
901		-C $$($(2)_DIR) \
902		$$(foreach x,$$($(2)_EXCLUDES),--exclude='$$(x)' ) \
903		$$(TAR_OPTIONS) -)
904
905# pre/post-steps hooks
906$(2)_PRE_DOWNLOAD_HOOKS         ?=
907$(2)_POST_DOWNLOAD_HOOKS        ?=
908$(2)_PRE_EXTRACT_HOOKS          ?=
909$(2)_POST_EXTRACT_HOOKS         ?=
910$(2)_PRE_RSYNC_HOOKS            ?=
911$(2)_POST_RSYNC_HOOKS           ?=
912$(2)_PRE_PATCH_HOOKS            ?=
913$(2)_POST_PATCH_HOOKS           ?=
914$(2)_PRE_CONFIGURE_HOOKS        ?=
915$(2)_POST_CONFIGURE_HOOKS       ?=
916$(2)_PRE_BUILD_HOOKS            ?=
917$(2)_POST_BUILD_HOOKS           ?=
918$(2)_PRE_INSTALL_HOOKS          ?=
919$(2)_POST_INSTALL_HOOKS         ?=
920$(2)_PRE_INSTALL_STAGING_HOOKS  ?=
921$(2)_POST_INSTALL_STAGING_HOOKS ?=
922$(2)_PRE_INSTALL_TARGET_HOOKS   ?=
923$(2)_POST_INSTALL_TARGET_HOOKS  ?=
924$(2)_PRE_INSTALL_IMAGES_HOOKS   ?=
925$(2)_POST_INSTALL_IMAGES_HOOKS  ?=
926$(2)_PRE_LEGAL_INFO_HOOKS       ?=
927$(2)_POST_LEGAL_INFO_HOOKS      ?=
928$(2)_TARGET_FINALIZE_HOOKS      ?=
929$(2)_ROOTFS_PRE_CMD_HOOKS       ?=
930
931$(2)_POST_PREPARE_HOOKS += FIXUP_PYTHON_SYSCONFIGDATA
932
933ifeq ($$($(2)_TYPE),target)
934ifneq ($$(HOST_$(2)_KCONFIG_VAR),)
935$$(error "Package $(1) defines host variant before target variant!")
936endif
937endif
938
939# Globaly remove following conflicting and useless files
940$(2)_DROP_FILES_OR_DIRS += /share/info/dir
941
942ifeq ($$($(2)_TYPE),host)
943$(2)_POST_INSTALL_HOOKS += REMOVE_CONFLICTING_USELESS_FILES_IN_HOST
944else
945$(2)_POST_INSTALL_STAGING_HOOKS += REMOVE_CONFLICTING_USELESS_FILES_IN_STAGING
946$(2)_POST_INSTALL_TARGET_HOOKS += REMOVE_CONFLICTING_USELESS_FILES_IN_TARGET
947endif
948
949# human-friendly targets and target sequencing
950$(1):			$(1)-install
951$(1)-install:		$$($(2)_TARGET_INSTALL)
952$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_BUILD)
953
954ifeq ($$($(2)_TYPE),host)
955$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_HOST)
956else
957$(2)_INSTALL_STAGING	?= NO
958$(2)_INSTALL_IMAGES	?= NO
959$(2)_INSTALL_TARGET	?= YES
960ifeq ($$($(2)_INSTALL_TARGET),YES)
961$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_TARGET)
962endif
963ifeq ($$($(2)_INSTALL_STAGING),YES)
964$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_STAGING)
965endif
966ifeq ($$($(2)_INSTALL_IMAGES),YES)
967$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_IMAGES)
968endif
969endif
970
971ifeq ($$($(2)_INSTALL_TARGET),YES)
972$(1)-install-target:		$$($(2)_TARGET_INSTALL_TARGET)
973$$($(2)_TARGET_INSTALL_TARGET):	$$($(2)_TARGET_BUILD)
974else
975$(1)-install-target:
976endif
977
978ifeq ($$($(2)_INSTALL_STAGING),YES)
979$(1)-install-staging:			$$($(2)_TARGET_INSTALL_STAGING)
980$$($(2)_TARGET_INSTALL_STAGING):	$$($(2)_TARGET_BUILD)
981# Some packages use install-staging stuff for install-target
982$$($(2)_TARGET_INSTALL_TARGET):		$$($(2)_TARGET_INSTALL_STAGING)
983else
984$(1)-install-staging:
985endif
986
987ifeq ($$($(2)_INSTALL_IMAGES),YES)
988$(1)-install-images:		$$($(2)_TARGET_INSTALL_IMAGES)
989$$($(2)_TARGET_INSTALL_IMAGES):	$$($(2)_TARGET_BUILD)
990else
991$(1)-install-images:
992endif
993
994$(1)-install-host:		$$($(2)_TARGET_INSTALL_HOST)
995$$($(2)_TARGET_INSTALL_HOST):	$$($(2)_TARGET_BUILD)
996
997$(1)-build:		$$($(2)_TARGET_BUILD)
998$$($(2)_TARGET_BUILD):	$$($(2)_TARGET_CONFIGURE)
999
1000# Since $(2)_FINAL_DEPENDENCIES are phony targets, they are always "newer"
1001# than $(2)_TARGET_CONFIGURE. This would force the configure step (and
1002# therefore the other steps as well) to be re-executed with every
1003# invocation of make.  Therefore, make $(2)_FINAL_DEPENDENCIES an order-only
1004# dependency by using |.
1005
1006$(1)-configure:			$$($(2)_TARGET_CONFIGURE)
1007$$($(2)_TARGET_CONFIGURE):	| $$($(2)_FINAL_DEPENDENCIES)
1008
1009$$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | prepare
1010$$($(2)_TARGET_SOURCE) $$($(2)_TARGET_RSYNC): | dependencies
1011
1012ifeq ($$($(2)_OVERRIDE_SRCDIR),)
1013# In the normal case (no package override), the sequence of steps is
1014#  source, by downloading
1015#  depends
1016#  extract
1017#  patch
1018#  configure
1019$$($(2)_TARGET_CONFIGURE):	$$($(2)_TARGET_PATCH)
1020
1021$(1)-patch:		$$($(2)_TARGET_PATCH)
1022$$($(2)_TARGET_PATCH):	$$($(2)_TARGET_EXTRACT)
1023# Order-only dependency
1024$$($(2)_TARGET_PATCH):  | $$(patsubst %,%-patch,$$($(2)_FINAL_PATCH_DEPENDENCIES))
1025
1026$(1)-extract:			$$($(2)_TARGET_EXTRACT)
1027$$($(2)_TARGET_EXTRACT):	$$($(2)_TARGET_SOURCE)
1028$$($(2)_TARGET_EXTRACT): | $$($(2)_FINAL_EXTRACT_DEPENDENCIES)
1029
1030$(1)-depends:		$$($(2)_FINAL_ALL_DEPENDENCIES)
1031
1032$(1)-source:		$$($(2)_TARGET_SOURCE)
1033$$($(2)_TARGET_SOURCE): | $$($(2)_FINAL_DOWNLOAD_DEPENDENCIES)
1034
1035$(1)-all-source:	$(1)-legal-source
1036$(1)-legal-info:	$(1)-legal-source
1037$(1)-legal-source:	$(1)-source
1038
1039# Only download the actual source if it differs from the 'main' archive
1040ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),)
1041ifneq ($$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_SOURCE))
1042$(1)-legal-source:	$$($(2)_TARGET_ACTUAL_SOURCE)
1043endif # actual sources != sources
1044endif # actual sources != ""
1045
1046$(1)-external-deps:
1047	@for p in $$($(2)_SOURCE) $$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS) ; do \
1048		echo `basename $$$$p` ; \
1049	done
1050else
1051# In the package override case, the sequence of steps
1052#  source, by rsyncing
1053#  depends
1054#  configure
1055
1056# Use an order-only dependency so the "<pkg>-clean-for-rebuild" rule
1057# can remove the stamp file without triggering the configure step.
1058$$($(2)_TARGET_CONFIGURE): | $$($(2)_TARGET_RSYNC)
1059
1060$(1)-depends:		$$($(2)_FINAL_DEPENDENCIES)
1061
1062$(1)-patch:		$(1)-rsync
1063$(1)-extract:		$(1)-rsync
1064
1065$(1)-rsync:		$$($(2)_TARGET_RSYNC)
1066
1067$(1)-source:
1068$(1)-legal-source:
1069
1070$(1)-external-deps:
1071	@echo "file://$$($(2)_OVERRIDE_SRCDIR)"
1072endif
1073
1074$(1)-show-version:
1075			@echo $$($(2)_VERSION)
1076
1077$(1)-show-depends:
1078			@echo $$($(2)_FINAL_ALL_DEPENDENCIES)
1079
1080$(1)-show-recursive-depends:
1081			@echo $$($(2)_FINAL_RECURSIVE_DEPENDENCIES)
1082
1083$(1)-show-rdepends:
1084			@echo $$($(2)_RDEPENDENCIES)
1085
1086$(1)-show-recursive-rdepends:
1087			@echo $$($(2)_FINAL_RECURSIVE_RDEPENDENCIES)
1088
1089$(1)-show-build-order: $$(patsubst %,%-show-build-order,$$($(2)_FINAL_ALL_DEPENDENCIES))
1090	@:
1091	$$(info $(1))
1092
1093$(1)-show-info:
1094	@:
1095	$$(info $$(call clean-json,{ $$(call json-info,$(2)) }))
1096
1097$(1)-graph-depends: graph-depends-requirements
1098	$(call pkg-graph-depends,$(1),--direct)
1099
1100$(1)-graph-rdepends: graph-depends-requirements
1101	$(call pkg-graph-depends,$(1),--reverse)
1102
1103$(1)-all-source:	$(1)-source
1104$(1)-all-source:	$$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-source)
1105
1106$(1)-all-external-deps:	$(1)-external-deps
1107$(1)-all-external-deps:	$$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-external-deps)
1108
1109$(1)-all-legal-info:	$(1)-legal-info
1110$(1)-all-legal-info:	$$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
1111
1112$(1)-dirclean:		$$($(2)_TARGET_DIRCLEAN)
1113
1114$(1)-clean-for-reinstall:
1115ifneq ($$($(2)_OVERRIDE_SRCDIR),)
1116			rm -f $$($(2)_TARGET_RSYNC)
1117endif
1118			rm -f $$($(2)_TARGET_INSTALL)
1119			rm -f $$($(2)_TARGET_INSTALL_STAGING)
1120			rm -f $$($(2)_TARGET_INSTALL_TARGET)
1121			rm -f $$($(2)_TARGET_INSTALL_IMAGES)
1122			rm -f $$($(2)_TARGET_INSTALL_HOST)
1123
1124$(1)-reinstall:		$(1)-clean-for-reinstall $(1)
1125
1126$(1)-clean-for-rebuild: $(1)-clean-for-reinstall
1127			rm -f $$($(2)_TARGET_BUILD)
1128
1129$(1)-rebuild:		$(1)-clean-for-rebuild $(1)
1130
1131$(1)-clean-for-reconfigure: $(1)-clean-for-rebuild
1132			rm -f $$($(2)_TARGET_CONFIGURE)
1133
1134$(1)-reconfigure:	$(1)-clean-for-reconfigure $(1)
1135
1136# define the PKG variable for all targets, containing the
1137# uppercase package variable prefix
1138$$($(2)_TARGET_INSTALL):		PKG=$(2)
1139$$($(2)_TARGET_INSTALL_TARGET):		PKG=$(2)
1140$$($(2)_TARGET_INSTALL_STAGING):	PKG=$(2)
1141$$($(2)_TARGET_INSTALL_IMAGES):		PKG=$(2)
1142$$($(2)_TARGET_INSTALL_HOST):		PKG=$(2)
1143$$($(2)_TARGET_BUILD):			PKG=$(2)
1144$$($(2)_TARGET_CONFIGURE):		PKG=$(2)
1145$$($(2)_TARGET_CONFIGURE):		NAME=$(1)
1146$$($(2)_TARGET_RSYNC):			SRCDIR=$$($(2)_OVERRIDE_SRCDIR)
1147$$($(2)_TARGET_RSYNC):			PKG=$(2)
1148$$($(2)_TARGET_PATCH):			PKG=$(2)
1149$$($(2)_TARGET_PATCH):			RAWNAME=$$(patsubst host-%,%,$(1))
1150$$($(2)_TARGET_PATCH):			PKGDIR=$(pkgdir)
1151$$($(2)_TARGET_EXTRACT):		PKG=$(2)
1152$$($(2)_TARGET_SOURCE):			PKG=$(2)
1153$$($(2)_TARGET_SOURCE):			PKGDIR=$(pkgdir)
1154$$($(2)_TARGET_ACTUAL_SOURCE):		PKG=$(2)
1155$$($(2)_TARGET_ACTUAL_SOURCE):		PKGDIR=$(pkgdir)
1156$$($(2)_TARGET_DIRCLEAN):		PKG=$(2)
1157$$($(2)_TARGET_DIRCLEAN):		NAME=$(1)
1158
1159# Compute the name of the Kconfig option that correspond to the
1160# package being enabled. We handle three cases: the special Linux
1161# kernel case, the bootloaders case, and the normal packages case.
1162# Virtual packages are handled separately (see below).
1163ifeq ($(1),linux)
1164$(2)_KCONFIG_VAR = BR2_LINUX_KERNEL
1165else ifneq ($$(filter boot/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/boot/%),$(pkgdir)),)
1166$(2)_KCONFIG_VAR = BR2_TARGET_$(2)
1167else ifneq ($$(filter toolchain/% $$(foreach dir,$$(BR2_EXTERNAL_DIRS),$$(dir)/toolchain/%),$(pkgdir)),)
1168$(2)_KCONFIG_VAR = BR2_$(2)
1169else
1170$(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
1171endif
1172
1173# legal-info: declare dependencies and set values used later for the manifest
1174ifneq ($$($(2)_LICENSE_FILES),)
1175$(2)_MANIFEST_LICENSE_FILES = $$($(2)_LICENSE_FILES)
1176endif
1177
1178# We need to extract and patch a package to be able to retrieve its
1179# license files (if any) and the list of patches applied to it (if
1180# any).
1181$(1)-legal-info: $(1)-patch
1182
1183# We only save the sources of packages we want to redistribute, that are
1184# non-overriden (local or true override).
1185ifeq ($$($(2)_REDISTRIBUTE),YES)
1186ifeq ($$($(2)_OVERRIDE_SRCDIR),)
1187# Packages that have a tarball need it downloaded beforehand
1188$(1)-legal-info: $(1)-source $$(REDIST_SOURCES_DIR_$$(call UPPERCASE,$(4)))
1189endif
1190endif
1191
1192# legal-info: produce legally relevant info.
1193$(1)-legal-info: PKG=$(2)
1194$(1)-legal-info:
1195	@$$(call MESSAGE,"Collecting legal info")
1196# Packages without a source are assumed to be part of Buildroot, skip them.
1197	$$(foreach hook,$$($(2)_PRE_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
1198ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
1199
1200# Save license files if defined
1201# We save the license files for any kind of package: normal, local,
1202# overridden, or non-redistributable alike.
1203# The reason to save license files even for no-redistribute packages
1204# is that the license still applies to the files distributed as part
1205# of the rootfs, even if the sources are not themselves redistributed.
1206ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
1207	$(Q)$$(call legal-warning-pkg,$$($(2)_BASENAME_RAW),cannot save license ($(2)_LICENSE_FILES not defined))
1208else
1209	$(Q)$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$($(2)_RAWNAME),$$($(2)_BASENAME_RAW),$$($(2)_HASH_FILE),$$(F),$$($(2)_DIR)/$$(F),$$(call UPPERCASE,$(4)))$$(sep))
1210endif # license files
1211
1212ifeq ($$($(2)_SITE_METHOD),local)
1213# Packages without a tarball: don't save and warn
1214	@$$(call legal-warning-nosource,$$($(2)_RAWNAME),local)
1215
1216else ifneq ($$($(2)_OVERRIDE_SRCDIR),)
1217	@$$(call legal-warning-nosource,$$($(2)_RAWNAME),override)
1218
1219else
1220# Other packages
1221
1222ifeq ($$($(2)_REDISTRIBUTE),YES)
1223# Save the source tarball and any extra downloads, but not
1224# patches, as they are handled specially afterwards.
1225	$$(foreach e,$$($(2)_ACTUAL_SOURCE_TARBALL) $$(notdir $$($(2)_EXTRA_DOWNLOADS)),\
1226		$$(Q)support/scripts/hardlink-or-copy \
1227			$$($(2)_DL_DIR)/$$(e) \
1228			$$($(2)_REDIST_SOURCES_DIR)$$(sep))
1229# Save patches and generate the series file
1230	$$(Q)while read f; do \
1231		support/scripts/hardlink-or-copy \
1232			$$$${f} \
1233			$$($(2)_REDIST_SOURCES_DIR) || exit 1; \
1234		printf "%s\n" "$$$${f##*/}" >>$$($(2)_REDIST_SOURCES_DIR)/series || exit 1; \
1235	done <$$($(2)_DIR)/.applied_patches_list
1236endif # redistribute
1237
1238endif # other packages
1239	@$$(call legal-manifest,$$(call UPPERCASE,$(4)),$$($(2)_RAWNAME),$$($(2)_VERSION),$$(subst $$(space)$$(comma),$$(comma),$$($(2)_LICENSE)),$$($(2)_MANIFEST_LICENSE_FILES),$$($(2)_ACTUAL_SOURCE_TARBALL),$$($(2)_ACTUAL_SOURCE_SITE),$$(call legal-deps,$(1)))
1240endif # ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
1241	$$(foreach hook,$$($(2)_POST_LEGAL_INFO_HOOKS),$$(call $$(hook))$$(sep))
1242
1243# add package to the general list of targets if requested by the buildroot
1244# configuration
1245ifeq ($$($$($(2)_KCONFIG_VAR)),y)
1246
1247# Ensure the calling package is the declared provider for all the virtual
1248# packages it claims to be an implementation of.
1249ifneq ($$($(2)_PROVIDES),)
1250$$(foreach pkg,$$($(2)_PROVIDES),\
1251	$$(eval $$(call virt-provides-single,$$(pkg),$$(call UPPERCASE,$$(pkg)),$(1))$$(sep)))
1252endif
1253
1254# Register package as a reverse-dependencies of all its dependencies
1255$$(eval $$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),\
1256	$$(call UPPERCASE,$$(p))_RDEPENDENCIES += $(1)$$(sep)))
1257
1258# Ensure unified variable name conventions between all packages Some
1259# of the variables are used by more than one infrastructure; so,
1260# rather than duplicating the checks in each infrastructure, we check
1261# all variables here in pkg-generic, even though pkg-generic should
1262# have no knowledge of infra-specific variables.
1263$(eval $(call check-deprecated-variable,$(2)_MAKE_OPT,$(2)_MAKE_OPTS))
1264$(eval $(call check-deprecated-variable,$(2)_INSTALL_OPT,$(2)_INSTALL_OPTS))
1265$(eval $(call check-deprecated-variable,$(2)_INSTALL_TARGET_OPT,$(2)_INSTALL_TARGET_OPTS))
1266$(eval $(call check-deprecated-variable,$(2)_INSTALL_STAGING_OPT,$(2)_INSTALL_STAGING_OPTS))
1267$(eval $(call check-deprecated-variable,$(2)_INSTALL_HOST_OPT,$(2)_INSTALL_HOST_OPTS))
1268$(eval $(call check-deprecated-variable,$(2)_AUTORECONF_OPT,$(2)_AUTORECONF_OPTS))
1269$(eval $(call check-deprecated-variable,$(2)_CONF_OPT,$(2)_CONF_OPTS))
1270$(eval $(call check-deprecated-variable,$(2)_BUILD_OPT,$(2)_BUILD_OPTS))
1271$(eval $(call check-deprecated-variable,$(2)_GETTEXTIZE_OPT,$(2)_GETTEXTIZE_OPTS))
1272$(eval $(call check-deprecated-variable,$(2)_KCONFIG_OPT,$(2)_KCONFIG_OPTS))
1273
1274PACKAGES += $(1)
1275
1276ifneq ($$($(2)_PERMISSIONS),)
1277PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
1278endif
1279ifneq ($$($(2)_DEVICES),)
1280PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
1281endif
1282ifneq ($$($(2)_USERS),)
1283PACKAGES_USERS += $$($(2)_USERS)$$(sep)
1284endif
1285ifneq ($$($(2)_LINUX_CONFIG_FIXUPS),)
1286PACKAGES_LINUX_CONFIG_FIXUPS += $$($(2)_LINUX_CONFIG_FIXUPS)$$(sep)
1287endif
1288TARGET_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)
1289ROOTFS_PRE_CMD_HOOKS += $$($(2)_ROOTFS_PRE_CMD_HOOKS)
1290KEEP_PYTHON_PY_FILES += $$($(2)_KEEP_PY_FILES)
1291
1292ifneq ($$($(2)_SELINUX_MODULES),)
1293PACKAGES_SELINUX_MODULES += $$($(2)_SELINUX_MODULES)
1294endif
1295PACKAGES_SELINUX_EXTRA_MODULES_DIRS += \
1296	$$(if $$(wildcard $$($(2)_PKGDIR)/selinux),$$($(2)_PKGDIR)/selinux)
1297
1298ifeq ($$($(2)_SITE_METHOD),svn)
1299DL_TOOLS_DEPENDENCIES += svn
1300else ifeq ($$($(2)_SITE_METHOD),git)
1301DL_TOOLS_DEPENDENCIES += git
1302else ifeq ($$($(2)_SITE_METHOD),bzr)
1303DL_TOOLS_DEPENDENCIES += bzr
1304else ifeq ($$($(2)_SITE_METHOD),scp)
1305DL_TOOLS_DEPENDENCIES += scp ssh
1306else ifeq ($$($(2)_SITE_METHOD),hg)
1307DL_TOOLS_DEPENDENCIES += hg
1308else ifeq ($$($(2)_SITE_METHOD),cvs)
1309DL_TOOLS_DEPENDENCIES += cvs
1310endif # SITE_METHOD
1311
1312DL_TOOLS_DEPENDENCIES += $$(call extractor-system-dependency,$$($(2)_SOURCE))
1313
1314# Ensure all virtual targets are PHONY. Listed alphabetically.
1315.PHONY:	$(1) \
1316	$(1)-all-external-deps \
1317	$(1)-all-legal-info \
1318	$(1)-all-source \
1319	$(1)-build \
1320	$(1)-clean-for-rebuild \
1321	$(1)-clean-for-reconfigure \
1322	$(1)-clean-for-reinstall \
1323	$(1)-configure \
1324	$(1)-depends \
1325	$(1)-dirclean \
1326	$(1)-external-deps \
1327	$(1)-extract \
1328	$(1)-graph-depends \
1329	$(1)-graph-rdepends \
1330	$(1)-install \
1331	$(1)-install-host \
1332	$(1)-install-images \
1333	$(1)-install-staging \
1334	$(1)-install-target \
1335	$(1)-legal-info \
1336	$(1)-legal-source \
1337	$(1)-patch \
1338	$(1)-rebuild \
1339	$(1)-reconfigure \
1340	$(1)-reinstall \
1341	$(1)-rsync \
1342	$(1)-show-depends \
1343	$(1)-show-info \
1344	$(1)-show-version \
1345	$(1)-source
1346
1347ifneq ($$($(2)_SOURCE),)
1348ifeq ($$($(2)_SITE),)
1349$$(error $(2)_SITE cannot be empty when $(2)_SOURCE is not)
1350endif
1351endif
1352
1353ifeq ($$(patsubst %/,ERROR,$$($(2)_SITE)),ERROR)
1354$$(error $(2)_SITE ($$($(2)_SITE)) cannot have a trailing slash)
1355endif
1356
1357ifneq ($$($(2)_HELP_CMDS),)
1358HELP_PACKAGES += $(2)
1359endif
1360
1361# Virtual packages are not built but it's useful to allow them to have
1362# permission/device/user tables and target-finalize/rootfs-pre-cmd hooks.
1363else ifeq ($$(BR2_PACKAGE_HAS_$(2)),y) # $(2)_KCONFIG_VAR
1364
1365ifneq ($$($(2)_PERMISSIONS),)
1366PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
1367endif
1368ifneq ($$($(2)_DEVICES),)
1369PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
1370endif
1371ifneq ($$($(2)_USERS),)
1372PACKAGES_USERS += $$($(2)_USERS)$$(sep)
1373endif
1374TARGET_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)
1375ROOTFS_PRE_CMD_HOOKS += $$($(2)_ROOTFS_PRE_CMD_HOOKS)
1376
1377endif # $(2)_KCONFIG_VAR
1378endef # inner-generic-package
1379
1380################################################################################
1381# generic-package -- the target generator macro for generic packages
1382################################################################################
1383
1384# In the case of target packages, keep the package name "pkg"
1385generic-package = $(call inner-generic-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
1386# In the case of host packages, turn the package name "pkg" into "host-pkg"
1387host-generic-package = $(call inner-generic-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
1388
1389# :mode=makefile:
1390