diff mbox

[PATCHv3,19/20] package: package-based implementation of source, external-deps and legal-info

Message ID 1381256237-27948-20-git-send-email-thomas.petazzoni@free-electrons.com
State RFC
Headers show

Commit Message

Thomas Petazzoni Oct. 8, 2013, 6:17 p.m. UTC
Until now, the make source, make external-deps and make legal-info
where relying on enumerating the packages by looking at $(TARGETS)
which contains only the target packages and not the host
packages. Thanks to the TARGET_HOST_DEPS and HOST_DEPS variables, it
was doing a two-level resolution of host package dependencies, but it
was not entirely correct since the dependency chain might be deeper
than that: some packages could be missed.

From an idea of Arnout, this patch introduces in each package
additional targets <pkg>-all-source, <pkg>-all-legal-info and
<pkg>-all-external-deps that executes the 'source', 'legal-info' and
'external-deps' targets for this package and all its dependencies, be
they target or host dependencies.

This provides a much cleaner implementation of this mechanism, which
is also more robust.

In order to achieve this, this patch also separates the "package"
targets from other targets: instead of mixing them both in the global
TARGETS variable, the new PACKAGES variable contains the name of all
packages that are enabled in the configuration, while TARGETS is only
used for additional things to be done (target-finalize, etc.). This
separation is needed so that we don't try to use targets (such as
<foo>-all-external-deps) on things that are not packages. Some further
cleanups in this direction are possible, this commit takes a
relatively minimal approach for now.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 Makefile               | 53 +++++++++++++-------------------------------------
 package/pkg-generic.mk | 16 ++++++++++++++-
 2 files changed, 28 insertions(+), 41 deletions(-)

Comments

Arnout Vandecappelle Oct. 10, 2013, 5:24 p.m. UTC | #1
On 08/10/13 20:17, Thomas Petazzoni wrote:
> Until now, the make source, make external-deps and make legal-info
> where relying on enumerating the packages by looking at $(TARGETS)
> which contains only the target packages and not the host
> packages. Thanks to the TARGET_HOST_DEPS and HOST_DEPS variables, it
> was doing a two-level resolution of host package dependencies, but it
> was not entirely correct since the dependency chain might be deeper
> than that: some packages could be missed.
>
>>From an idea of Arnout, this patch introduces in each package
> additional targets <pkg>-all-source, <pkg>-all-legal-info and
> <pkg>-all-external-deps that executes the 'source', 'legal-info' and
> 'external-deps' targets for this package and all its dependencies, be
> they target or host dependencies.
>
> This provides a much cleaner implementation of this mechanism, which
> is also more robust.
>
> In order to achieve this, this patch also separates the "package"
> targets from other targets: instead of mixing them both in the global
> TARGETS variable, the new PACKAGES variable contains the name of all
> packages that are enabled in the configuration, while TARGETS is only
> used for additional things to be done (target-finalize, etc.). This
> separation is needed so that we don't try to use targets (such as
> <foo>-all-external-deps) on things that are not packages. Some further
> cleanups in this direction are possible, this commit takes a
> relatively minimal approach for now.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
>   Makefile               | 53 +++++++++++++-------------------------------------
>   package/pkg-generic.mk | 16 ++++++++++++++-
>   2 files changed, 28 insertions(+), 41 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index f266e2d..702e7d4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -238,8 +238,6 @@ GNU_HOST_NAME:=$(shell support/gnuconfig/config.guess)
>
>   BASE_TARGETS = toolchain
>
> -TARGETS:=
> -
>   # silent mode requested?
>   QUIET:=$(if $(findstring s,$(MAKEFLAGS)),-q)
>
> @@ -310,9 +308,6 @@ endif
>   include package/Makefile.in
>   include support/dependencies/dependencies.mk
>

  You could remove this empty line as well.

> -# We also need the various per-package makefiles, which also add
> -# each selected package to TARGETS if that package was selected
> -# in the .config file.
>   include toolchain/helpers.mk
>   include toolchain/*/*.mk
>
> @@ -349,34 +344,11 @@ include fs/common.mk
>
>   TARGETS+=target-post-image
>
> -TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
> -TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
> -TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
> -TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
> -
> -# host-* dependencies have to be handled specially, as those aren't
> -# visible in Kconfig and hence not added to a variable like TARGETS.
> -# instead, find all the host-* targets listed in each <PKG>_DEPENDENCIES
> -# variable for each enabled target.
> -# Notice: this only works for newstyle gentargets/autotargets packages
> -TARGETS_HOST_DEPS = $(sort $(filter host-%,$(foreach dep,\
> -		$(addsuffix _DEPENDENCIES,$(call UPPERCASE,$(TARGETS))),\
> -		$($(dep)))))
> -# Host packages can in turn have their own dependencies. Likewise find
> -# all the package names listed in the HOST_<PKG>_DEPENDENCIES for each
> -# host package found above. Ideally this should be done recursively until
> -# no more packages are found, but that's hard to do in make, so limit to
> -# 1 level for now.
> -HOST_DEPS = $(sort $(foreach dep,\
> -		$(addsuffix _DEPENDENCIES,$(call UPPERCASE,$(TARGETS_HOST_DEPS))),\
> -		$($(dep))))
> -HOST_SOURCE += $(addsuffix -source,$(sort $(TARGETS_HOST_DEPS) $(HOST_DEPS)))
> -
> -TARGETS_LEGAL_INFO:=$(patsubst %,%-legal-info,\
> -		$(TARGETS) $(BASE_TARGETS) $(TARGETS_HOST_DEPS) $(HOST_DEPS))))
> -
> -# all targets depend on the crosscompiler and it's prerequisites
> -$(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) %
> +PACKAGES_CLEAN:=$(patsubst %,%-clean,$(PACKAGES))

  Can you make these match the coding style? PACKAGES_CLEAN = ...

> +PACKAGES_SOURCE:=$(patsubst %,%-all-source,$(PACKAGES) $(BASE_TARGETS))

  BASE_TARGETS is just "toolchain", right? And that is already part of 
the dependencies of PACKAGES, right? So why is that still needed here?

> +PACKAGES_EXTERNAL_DEPS:=$(patsubst %,%-all-external-deps,$(PACKAGES) $(BASE_TARGETS))
> +PACKAGES_DIRCLEAN:=$(patsubst %,%-dirclean,$(PACKAGES))

  The PACKAGES_DIRCLEAN is really redundant, it is only used to define 
them as .PHONY but that is not done for e.g. -build.

> +PACKAGES_LEGAL_INFO:=$(patsubst %,%-all-legal-info,$(PACKAGES) $(BASE_TARGETS))
>
>   dirs: $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
>   	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
> @@ -386,12 +358,13 @@ $(BUILD_DIR)/buildroot-config/auto.conf: $(BUILDROOT_CONFIG)
>
>   prepare: $(BUILD_DIR)/buildroot-config/auto.conf
>
> -world: $(BASE_TARGETS) $(TARGETS_ALL)
> +world: $(BASE_TARGETS) $(PACKAGES) $(TARGETS)
>
>   .PHONY: all world toolchain dirs clean distclean source outputmakefile \
>   	legal-info legal-info-prepare legal-info-clean printvars \
> -	$(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
> -	$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) $(TARGETS_LEGAL_INFO) \
> +	$(BASE_TARGETS) $(PACKAGES) $(TARGETS) \
> +	$(PACKAGES_CLEAN) $(PACKAGES_DIRCLEAN) $(PACKAGES_SOURCE) $(PACKAGES_LEGAL_INFO) \
> +	$(PACKAGES_EXTERNAL_DEPS) \
>   	$(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
>   	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
>
> @@ -562,10 +535,10 @@ target-post-image:
>   toolchain-eclipse-register:
>   	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` $(notdir $(TARGET_CROSS)) $(BR2_ARCH)
>
> -source: dirs $(TARGETS_SOURCE) $(HOST_SOURCE)
> +source: dirs $(PACKAGES_SOURCE)
>
>   external-deps:
> -	@$(MAKE) -Bs DL_MODE=SHOW_EXTERNAL_DEPS $(EXTRAMAKEARGS) source | sort -u
> +	@$(MAKE) -s $(EXTRAMAKEARGS) $(PACKAGES_EXTERNAL_DEPS) | sort -u
>
>   legal-info-clean:
>   	@rm -fr $(LEGAL_INFO_DIR)
> @@ -580,7 +553,7 @@ legal-info-prepare: $(LEGAL_INFO_DIR)
>   	@cp $(BUILDROOT_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config
>
>   legal-info: dirs legal-info-clean legal-info-prepare $(REDIST_SOURCES_DIR) \
> -		$(TARGETS_LEGAL_INFO)
> +		$(PACKAGES_LEGAL_INFO)
>   	@cat support/legal-info/README.header >>$(LEGAL_REPORT)
>   	@if [ -r $(LEGAL_WARNINGS) ]; then \
>   		cat support/legal-info/README.warnings-header \
> @@ -590,7 +563,7 @@ legal-info: dirs legal-info-clean legal-info-prepare $(REDIST_SOURCES_DIR) \
>   	@rm -f $(LEGAL_WARNINGS)
>
>   show-targets:
> -	@echo $(TARGETS)
> +	@echo $(BASE_TARGETS) $(PACKAGES) $(TARGETS)
>
>   else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
>
> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> index a46457c..bd6169c 100644
> --- a/package/pkg-generic.mk
> +++ b/package/pkg-generic.mk
> @@ -424,6 +424,20 @@ endif
>   $(1)-show-depends:
>   			@echo $$($(2)_DEPENDENCIES)
>
> +$(1)-all-source: 	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-source) $(1)-source
> +
> +$(1)-external-deps:
> +ifneq ($$($(2)_SOURCE),)
> +			@echo $$($(2)_SOURCE)
> +endif
> +ifneq ($$($(2)_EXTRA_DOWNLOADS),y)
> +			@echo $$($(2)_EXTRA_DOWNLOADS)
> +endif

  While you're at it, you could add $(2)_PATCH.

  Are the double dollars really needed? They're not used in -all-source 
so why would you use them here...

> +
> +$(1)-all-external-deps:	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-external-deps) $(1)-external-deps
> +
> +$(1)-all-legal-info:	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-legal-info) $(1)-legal-info
> +
>   $(1)-uninstall:		$(1)-configure $$($(2)_TARGET_UNINSTALL)
>
>   $(1)-clean:		$(1)-uninstall \
> @@ -528,7 +542,7 @@ endif # ifneq ($(call qstrip,$$($(2)_SOURCE)),)
>   # configuration
>   ifeq ($$($$($(2)_KCONFIG_VAR)),y)
>
> -TARGETS += $(1)
> +PACKAGES += $(1)
>   PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
>   PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
>   PACKAGES_USERS += $$($(2)_USERS)$$(sep)


  Shouldn't you do something similar in fs/ ? Otherwise 'make source' 
will not download e.g. mtd.

  Regards,
  Arnout
Thomas Petazzoni Oct. 10, 2013, 9:33 p.m. UTC | #2
Arnout,

Thanks a lot for your review!

On Thu, 10 Oct 2013 19:24:12 +0200, Arnout Vandecappelle wrote:
> > @@ -310,9 +308,6 @@ endif
> >   include package/Makefile.in
> >   include support/dependencies/dependencies.mk
> >
> 
>   You could remove this empty line as well.

Right.

> > -# all targets depend on the crosscompiler and it's prerequisites
> > -$(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) %
> > +PACKAGES_CLEAN:=$(patsubst %,%-clean,$(PACKAGES))
> 
>   Can you make these match the coding style? PACKAGES_CLEAN = ...

Yes, certainly.

> > +PACKAGES_SOURCE:=$(patsubst %,%-all-source,$(PACKAGES) $(BASE_TARGETS))
> 
>   BASE_TARGETS is just "toolchain", right? And that is already part of 
> the dependencies of PACKAGES, right? So why is that still needed here?

Yes, BASE_TARGETS is just toolchain now. However no, "toolchain" is not
yet part of the dependencies of all packages. This is something the
patch series from Fabio Porcedda is doing, and I don't want to solve
all problems in this patch set :)

The main reason I've kept BASE_TARGETS for now is because I knew Fabio
would be cleaning up that further with his patch set.

> > +PACKAGES_EXTERNAL_DEPS:=$(patsubst %,%-all-external-deps,$(PACKAGES) $(BASE_TARGETS))
> > +PACKAGES_DIRCLEAN:=$(patsubst %,%-dirclean,$(PACKAGES))
> 
>   The PACKAGES_DIRCLEAN is really redundant, it is only used to define 
> them as .PHONY but that is not done for e.g. -build.

True, will remove.

> > +PACKAGES_LEGAL_INFO:=$(patsubst %,%-all-legal-info,$(PACKAGES) $(BASE_TARGETS))
> >
> >   dirs: $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
> >   	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
> > @@ -386,12 +358,13 @@ $(BUILD_DIR)/buildroot-config/auto.conf: $(BUILDROOT_CONFIG)
> >
> >   prepare: $(BUILD_DIR)/buildroot-config/auto.conf
> >
> > -world: $(BASE_TARGETS) $(TARGETS_ALL)
> > +world: $(BASE_TARGETS) $(PACKAGES) $(TARGETS)
> >
> >   .PHONY: all world toolchain dirs clean distclean source outputmakefile \
> >   	legal-info legal-info-prepare legal-info-clean printvars \
> > -	$(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
> > -	$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) $(TARGETS_LEGAL_INFO) \
> > +	$(BASE_TARGETS) $(PACKAGES) $(TARGETS) \
> > +	$(PACKAGES_CLEAN) $(PACKAGES_DIRCLEAN) $(PACKAGES_SOURCE) $(PACKAGES_LEGAL_INFO) \
> > +	$(PACKAGES_EXTERNAL_DEPS) \
> >   	$(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
> >   	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
> >
> > @@ -562,10 +535,10 @@ target-post-image:
> >   toolchain-eclipse-register:
> >   	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` $(notdir $(TARGET_CROSS)) $(BR2_ARCH)
> >
> > -source: dirs $(TARGETS_SOURCE) $(HOST_SOURCE)
> > +source: dirs $(PACKAGES_SOURCE)
> >
> >   external-deps:
> > -	@$(MAKE) -Bs DL_MODE=SHOW_EXTERNAL_DEPS $(EXTRAMAKEARGS) source | sort -u
> > +	@$(MAKE) -s $(EXTRAMAKEARGS) $(PACKAGES_EXTERNAL_DEPS) | sort -u
> >
> >   legal-info-clean:
> >   	@rm -fr $(LEGAL_INFO_DIR)
> > @@ -580,7 +553,7 @@ legal-info-prepare: $(LEGAL_INFO_DIR)
> >   	@cp $(BUILDROOT_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config
> >
> >   legal-info: dirs legal-info-clean legal-info-prepare $(REDIST_SOURCES_DIR) \
> > -		$(TARGETS_LEGAL_INFO)
> > +		$(PACKAGES_LEGAL_INFO)
> >   	@cat support/legal-info/README.header >>$(LEGAL_REPORT)
> >   	@if [ -r $(LEGAL_WARNINGS) ]; then \
> >   		cat support/legal-info/README.warnings-header \
> > @@ -590,7 +563,7 @@ legal-info: dirs legal-info-clean legal-info-prepare $(REDIST_SOURCES_DIR) \
> >   	@rm -f $(LEGAL_WARNINGS)
> >
> >   show-targets:
> > -	@echo $(TARGETS)
> > +	@echo $(BASE_TARGETS) $(PACKAGES) $(TARGETS)
> >
> >   else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
> >
> > diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> > index a46457c..bd6169c 100644
> > --- a/package/pkg-generic.mk
> > +++ b/package/pkg-generic.mk
> > @@ -424,6 +424,20 @@ endif
> >   $(1)-show-depends:
> >   			@echo $$($(2)_DEPENDENCIES)
> >
> > +$(1)-all-source: 	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-source) $(1)-source
> > +
> > +$(1)-external-deps:
> > +ifneq ($$($(2)_SOURCE),)
> > +			@echo $$($(2)_SOURCE)
> > +endif
> > +ifneq ($$($(2)_EXTRA_DOWNLOADS),y)
> > +			@echo $$($(2)_EXTRA_DOWNLOADS)
> > +endif
> 
>   While you're at it, you could add $(2)_PATCH.

Ahh, yes, true. I thought about it at some point, and then forgot.

>   Are the double dollars really needed? They're not used in -all-source 
> so why would you use them here...

I'll check that, maybe not.

> > -TARGETS += $(1)
> > +PACKAGES += $(1)
> >   PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
> >   PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
> >   PACKAGES_USERS += $$($(2)_USERS)$$(sep)
> 
>   Shouldn't you do something similar in fs/ ? Otherwise 'make source' 
> will not download e.g. mtd.

That's a weakness of this patch series. I believe I might need to
convert the fs/ stuff to packages (after all they are packages that
have dependencies, and install something in the images/ directory), so
that the legal-info/source/external-deps logic works for them as well,
without doing hacks. What do you think about this?

Best regards,

Thomas
Arnout Vandecappelle Oct. 10, 2013, 10:38 p.m. UTC | #3
On 10/10/13 23:33, Thomas Petazzoni wrote:
>> >   Shouldn't you do something similar in fs/ ? Otherwise 'make source'
>> >will not download e.g. mtd.
> That's a weakness of this patch series. I believe I might need to
> convert the fs/ stuff to packages (after all they are packages that
> have dependencies, and install something in the images/ directory), so
> that the legal-info/source/external-deps logic works for them as well,
> without doing hacks. What do you think about this?

  I don't think it's useful to make them packages, because they are 
really different. Adding the propagation of -all-source etc. to the 
dependencies can easily be done in ROOTFS_TARGET_INTERNAL.

  In a later stage, we could consider to move the (few) common parts into 
some common package/rootfs infrastructure, but the gain is limited I expect.

  Regards,
  Arnout
Thomas Petazzoni Oct. 11, 2013, 7:20 a.m. UTC | #4
Dear Arnout Vandecappelle,

On Fri, 11 Oct 2013 00:38:25 +0200, Arnout Vandecappelle wrote:

>   I don't think it's useful to make them packages, because they are 
> really different. Adding the propagation of -all-source etc. to the 
> dependencies can easily be done in ROOTFS_TARGET_INTERNAL.

Yeah, that's indeed another option. We're already doing it with
$(1)-show-depends.

>   In a later stage, we could consider to move the (few) common parts into 
> some common package/rootfs infrastructure, but the gain is limited I expect.

Note that we have another strange location for a dependency on a
package: the target-root-passwd target, which sets the root password,
might depend on the host-mkpasswd package. So while normally, we
consider all the target-<foo> targets in system/system.mk as useless
for 'make source', 'make external-deps' and so on, it's not really the
case for this one. Except that host-mkpasswd in fact has all its source
code directly in package/mkpasswd/ (we don't download anything), and
it's used purely on the host, so maybe we can ignore this problem?

Best regards,

Thomas
Fabio Porcedda Oct. 11, 2013, 8 a.m. UTC | #5
On Thu, Oct 10, 2013 at 11:33 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Arnout,
>
> Thanks a lot for your review!
>
> On Thu, 10 Oct 2013 19:24:12 +0200, Arnout Vandecappelle wrote:
> [...]
>> > +PACKAGES_SOURCE:=$(patsubst %,%-all-source,$(PACKAGES) $(BASE_TARGETS))
>>
>>   BASE_TARGETS is just "toolchain", right? And that is already part of
>> the dependencies of PACKAGES, right? So why is that still needed here?
>
> Yes, BASE_TARGETS is just toolchain now. However no, "toolchain" is not
> yet part of the dependencies of all packages. This is something the
> patch series from Fabio Porcedda is doing, and I don't want to solve
> all problems in this patch set :)
>
> The main reason I've kept BASE_TARGETS for now is because I knew Fabio
> would be cleaning up that further with his patch set.

Sure, I will send a rebased patch set when this patch set is merged.

> [...]

Regards
Arnout Vandecappelle Oct. 11, 2013, 8:10 a.m. UTC | #6
On 11/10/13 09:20, Thomas Petazzoni wrote:
> Dear Arnout Vandecappelle,
>
> On Fri, 11 Oct 2013 00:38:25 +0200, Arnout Vandecappelle wrote:
>
>>    I don't think it's useful to make them packages, because they are
>> really different. Adding the propagation of -all-source etc. to the
>> dependencies can easily be done in ROOTFS_TARGET_INTERNAL.
>
> Yeah, that's indeed another option. We're already doing it with
> $(1)-show-depends.
>
>>    In a later stage, we could consider to move the (few) common parts into
>> some common package/rootfs infrastructure, but the gain is limited I expect.
>
> Note that we have another strange location for a dependency on a
> package: the target-root-passwd target, which sets the root password,
> might depend on the host-mkpasswd package. So while normally, we
> consider all the target-<foo> targets in system/system.mk as useless
> for 'make source', 'make external-deps' and so on, it's not really the
> case for this one. Except that host-mkpasswd in fact has all its source
> code directly in package/mkpasswd/ (we don't download anything), and
> it's used purely on the host, so maybe we can ignore this problem?

  For now, yes. If we ever refactor the common parts from fs and 
pkg-generic, then we can also include the system stuff in there.

  Regards,
  Arnout
diff mbox

Patch

diff --git a/Makefile b/Makefile
index f266e2d..702e7d4 100644
--- a/Makefile
+++ b/Makefile
@@ -238,8 +238,6 @@  GNU_HOST_NAME:=$(shell support/gnuconfig/config.guess)
 
 BASE_TARGETS = toolchain
 
-TARGETS:=
-
 # silent mode requested?
 QUIET:=$(if $(findstring s,$(MAKEFLAGS)),-q)
 
@@ -310,9 +308,6 @@  endif
 include package/Makefile.in
 include support/dependencies/dependencies.mk
 
-# We also need the various per-package makefiles, which also add
-# each selected package to TARGETS if that package was selected
-# in the .config file.
 include toolchain/helpers.mk
 include toolchain/*/*.mk
 
@@ -349,34 +344,11 @@  include fs/common.mk
 
 TARGETS+=target-post-image
 
-TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
-TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
-TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
-TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
-
-# host-* dependencies have to be handled specially, as those aren't
-# visible in Kconfig and hence not added to a variable like TARGETS.
-# instead, find all the host-* targets listed in each <PKG>_DEPENDENCIES
-# variable for each enabled target.
-# Notice: this only works for newstyle gentargets/autotargets packages
-TARGETS_HOST_DEPS = $(sort $(filter host-%,$(foreach dep,\
-		$(addsuffix _DEPENDENCIES,$(call UPPERCASE,$(TARGETS))),\
-		$($(dep)))))
-# Host packages can in turn have their own dependencies. Likewise find
-# all the package names listed in the HOST_<PKG>_DEPENDENCIES for each
-# host package found above. Ideally this should be done recursively until
-# no more packages are found, but that's hard to do in make, so limit to
-# 1 level for now.
-HOST_DEPS = $(sort $(foreach dep,\
-		$(addsuffix _DEPENDENCIES,$(call UPPERCASE,$(TARGETS_HOST_DEPS))),\
-		$($(dep))))
-HOST_SOURCE += $(addsuffix -source,$(sort $(TARGETS_HOST_DEPS) $(HOST_DEPS)))
-
-TARGETS_LEGAL_INFO:=$(patsubst %,%-legal-info,\
-		$(TARGETS) $(BASE_TARGETS) $(TARGETS_HOST_DEPS) $(HOST_DEPS))))
-
-# all targets depend on the crosscompiler and it's prerequisites
-$(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) %
+PACKAGES_CLEAN:=$(patsubst %,%-clean,$(PACKAGES))
+PACKAGES_SOURCE:=$(patsubst %,%-all-source,$(PACKAGES) $(BASE_TARGETS))
+PACKAGES_EXTERNAL_DEPS:=$(patsubst %,%-all-external-deps,$(PACKAGES) $(BASE_TARGETS))
+PACKAGES_DIRCLEAN:=$(patsubst %,%-dirclean,$(PACKAGES))
+PACKAGES_LEGAL_INFO:=$(patsubst %,%-all-legal-info,$(PACKAGES) $(BASE_TARGETS))
 
 dirs: $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
 	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
@@ -386,12 +358,13 @@  $(BUILD_DIR)/buildroot-config/auto.conf: $(BUILDROOT_CONFIG)
 
 prepare: $(BUILD_DIR)/buildroot-config/auto.conf
 
-world: $(BASE_TARGETS) $(TARGETS_ALL)
+world: $(BASE_TARGETS) $(PACKAGES) $(TARGETS)
 
 .PHONY: all world toolchain dirs clean distclean source outputmakefile \
 	legal-info legal-info-prepare legal-info-clean printvars \
-	$(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
-	$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) $(TARGETS_LEGAL_INFO) \
+	$(BASE_TARGETS) $(PACKAGES) $(TARGETS) \
+	$(PACKAGES_CLEAN) $(PACKAGES_DIRCLEAN) $(PACKAGES_SOURCE) $(PACKAGES_LEGAL_INFO) \
+	$(PACKAGES_EXTERNAL_DEPS) \
 	$(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
 	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
 
@@ -562,10 +535,10 @@  target-post-image:
 toolchain-eclipse-register:
 	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` $(notdir $(TARGET_CROSS)) $(BR2_ARCH)
 
-source: dirs $(TARGETS_SOURCE) $(HOST_SOURCE)
+source: dirs $(PACKAGES_SOURCE)
 
 external-deps:
-	@$(MAKE) -Bs DL_MODE=SHOW_EXTERNAL_DEPS $(EXTRAMAKEARGS) source | sort -u
+	@$(MAKE) -s $(EXTRAMAKEARGS) $(PACKAGES_EXTERNAL_DEPS) | sort -u
 
 legal-info-clean:
 	@rm -fr $(LEGAL_INFO_DIR)
@@ -580,7 +553,7 @@  legal-info-prepare: $(LEGAL_INFO_DIR)
 	@cp $(BUILDROOT_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config
 
 legal-info: dirs legal-info-clean legal-info-prepare $(REDIST_SOURCES_DIR) \
-		$(TARGETS_LEGAL_INFO)
+		$(PACKAGES_LEGAL_INFO)
 	@cat support/legal-info/README.header >>$(LEGAL_REPORT)
 	@if [ -r $(LEGAL_WARNINGS) ]; then \
 		cat support/legal-info/README.warnings-header \
@@ -590,7 +563,7 @@  legal-info: dirs legal-info-clean legal-info-prepare $(REDIST_SOURCES_DIR) \
 	@rm -f $(LEGAL_WARNINGS)
 
 show-targets:
-	@echo $(TARGETS)
+	@echo $(BASE_TARGETS) $(PACKAGES) $(TARGETS)
 
 else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
 
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index a46457c..bd6169c 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -424,6 +424,20 @@  endif
 $(1)-show-depends:
 			@echo $$($(2)_DEPENDENCIES)
 
+$(1)-all-source: 	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-source) $(1)-source
+
+$(1)-external-deps:
+ifneq ($$($(2)_SOURCE),)
+			@echo $$($(2)_SOURCE)
+endif
+ifneq ($$($(2)_EXTRA_DOWNLOADS),y)
+			@echo $$($(2)_EXTRA_DOWNLOADS)
+endif
+
+$(1)-all-external-deps:	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-external-deps) $(1)-external-deps
+
+$(1)-all-legal-info:	$(foreach p,$($(2)_DEPENDENCIES),$(p)-all-legal-info) $(1)-legal-info
+
 $(1)-uninstall:		$(1)-configure $$($(2)_TARGET_UNINSTALL)
 
 $(1)-clean:		$(1)-uninstall \
@@ -528,7 +542,7 @@  endif # ifneq ($(call qstrip,$$($(2)_SOURCE)),)
 # configuration
 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
 
-TARGETS += $(1)
+PACKAGES += $(1)
 PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep)
 PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep)
 PACKAGES_USERS += $$($(2)_USERS)$$(sep)