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