diff mbox

make clean: improve when no .config present

Message ID dc1ad257f9e5b8d5b999.1380744400@argentina
State Accepted
Commit bb33517511f5c6e173bfdb0d84bcb6e21240b387
Headers show

Commit Message

Thomas De Schampheleire Oct. 2, 2013, 8:06 p.m. UTC
The 'make clean' recipe is using variables that are not defined without .config
file, causing only a partial cleanup when the .config file is accidentally
deleted.

This patch moves those variables that do not depend on values from .config
outside the BR2_HAVE_DOT_CONFIG check, so that 'make clean' is much more similar
with and without .config.

Since HOST_DIR is determined from BR2_HOST_DIR in .config, the host directory
cannot be cleaned correctly without making assumptions, if no .config is
present. However, to cover most people's use cases, we assume the default value
of $(BASE_DIR)/host in this specific case.

Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>

---
v2: implement initial HOST_DIR value (and move everything to before .config is
    included.

 Makefile |  48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)

Comments

Peter Korsgaard Oct. 2, 2013, 8:40 p.m. UTC | #1
>>>>> "Thomas" == Thomas De Schampheleire <patrickdepinguin@gmail.com> writes:

 Thomas> The 'make clean' recipe is using variables that are not defined
 Thomas> without .config file, causing only a partial cleanup when the
 Thomas> .config file is accidentally deleted.

 Thomas> This patch moves those variables that do not depend on values
 Thomas> from .config outside the BR2_HAVE_DOT_CONFIG check, so that
 Thomas> 'make clean' is much more similar with and without .config.

 Thomas> Since HOST_DIR is determined from BR2_HOST_DIR in .config, the
 Thomas> host directory cannot be cleaned correctly without making
 Thomas> assumptions, if no .config is present. However, to cover most
 Thomas> people's use cases, we assume the default value of
 Thomas> $(BASE_DIR)/host in this specific case.

Nit: please wrap the commit text so it fits within 80 chars when
displayed through git log (which indents by 4 spaces).

 Thomas> Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>

 Thomas> ---
 Thomas> v2: implement initial HOST_DIR value (and move everything to before .config is
 Thomas>     included.

 Thomas>  Makefile |  48 ++++++++++++++++++++++++------------------------
 Thomas>  1 files changed, 24 insertions(+), 24 deletions(-)

 Thomas> diff --git a/Makefile b/Makefile
 Thomas> --- a/Makefile
 Thomas> +++ b/Makefile
 Thomas> @@ -91,6 +91,30 @@ EXTRAMAKEARGS = O=$(O)
 Thomas>  NEED_WRAPPER=y
 Thomas>  endif
 
 Thomas> +# bash prints the name of the directory on 'cd <dir>' if CDPATH is
 Thomas> +# set, so unset it here to not cause problems. Notice that the export
 Thomas> +# line doesn't affect the environment of $(shell ..) calls, so
 Thomas> +# explictly throw away any output from 'cd' here.
 Thomas> +export CDPATH:=
 Thomas> +BASE_DIR := $(shell mkdir -p $(O) && cd $(O) >/dev/null && pwd)
 Thomas> +$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))

Hmm, this means that we always create ./output, even when you run
E.G. 'make help, make print-version or make <blah>'.

I guess it isn't a big problem, and I don't see a solution for it right
away, but it doesn't seem "nice".

Committed, thanks.
Thomas De Schampheleire Oct. 3, 2013, 7:42 a.m. UTC | #2
Hi Peter,

On Wed, Oct 2, 2013 at 10:40 PM, Peter Korsgaard <jacmet@uclibc.org> wrote:
>>>>>> "Thomas" == Thomas De Schampheleire <patrickdepinguin@gmail.com> writes:
>
>  Thomas> The 'make clean' recipe is using variables that are not defined
>  Thomas> without .config file, causing only a partial cleanup when the
>  Thomas> .config file is accidentally deleted.
>
>  Thomas> This patch moves those variables that do not depend on values
>  Thomas> from .config outside the BR2_HAVE_DOT_CONFIG check, so that
>  Thomas> 'make clean' is much more similar with and without .config.
>
>  Thomas> Since HOST_DIR is determined from BR2_HOST_DIR in .config, the
>  Thomas> host directory cannot be cleaned correctly without making
>  Thomas> assumptions, if no .config is present. However, to cover most
>  Thomas> people's use cases, we assume the default value of
>  Thomas> $(BASE_DIR)/host in this specific case.
>
> Nit: please wrap the commit text so it fits within 80 chars when
> displayed through git log (which indents by 4 spaces).

Thanks for mentioning, I will take this into account next time.

>
>  Thomas> Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
>
>  Thomas> ---
>  Thomas> v2: implement initial HOST_DIR value (and move everything to before .config is
>  Thomas>     included.
>
>  Thomas>  Makefile |  48 ++++++++++++++++++++++++------------------------
>  Thomas>  1 files changed, 24 insertions(+), 24 deletions(-)
>
>  Thomas> diff --git a/Makefile b/Makefile
>  Thomas> --- a/Makefile
>  Thomas> +++ b/Makefile
>  Thomas> @@ -91,6 +91,30 @@ EXTRAMAKEARGS = O=$(O)
>  Thomas>  NEED_WRAPPER=y
>  Thomas>  endif
>
>  Thomas> +# bash prints the name of the directory on 'cd <dir>' if CDPATH is
>  Thomas> +# set, so unset it here to not cause problems. Notice that the export
>  Thomas> +# line doesn't affect the environment of $(shell ..) calls, so
>  Thomas> +# explictly throw away any output from 'cd' here.
>  Thomas> +export CDPATH:=
>  Thomas> +BASE_DIR := $(shell mkdir -p $(O) && cd $(O) >/dev/null && pwd)
>  Thomas> +$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
>
> Hmm, this means that we always create ./output, even when you run
> E.G. 'make help, make print-version or make <blah>'.
>
> I guess it isn't a big problem, and I don't see a solution for it right
> away, but it doesn't seem "nice".

It's probably possible to determine BASE_DIR initially without
creating the directory:
- if O starts with a slash, it's an absolute path, and we can do
'BASE_DIR := $(O)'
- otherwise, BASE_DIR := $(TOPDIR)/$(O) . If needed we can strip ../
to make it cleaner, but that's not really mandatory.

>
> Committed, thanks.

Thanks,
Thomas
diff mbox

Patch

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,30 @@  EXTRAMAKEARGS = O=$(O)
 NEED_WRAPPER=y
 endif
 
+# bash prints the name of the directory on 'cd <dir>' if CDPATH is
+# set, so unset it here to not cause problems. Notice that the export
+# line doesn't affect the environment of $(shell ..) calls, so
+# explictly throw away any output from 'cd' here.
+export CDPATH:=
+BASE_DIR := $(shell mkdir -p $(O) && cd $(O) >/dev/null && pwd)
+$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
+
+BUILD_DIR:=$(BASE_DIR)/build
+STAMP_DIR:=$(BASE_DIR)/stamps
+BINARIES_DIR:=$(BASE_DIR)/images
+TARGET_DIR:=$(BASE_DIR)/target
+# initial definition so that 'make clean' works for most users, even without
+# .config. HOST_DIR will be overwritten later when .config is included.
+HOST_DIR:=$(BASE_DIR)/host
+
+LEGAL_INFO_DIR=$(BASE_DIR)/legal-info
+REDIST_SOURCES_DIR=$(LEGAL_INFO_DIR)/sources
+LICENSE_FILES_DIR=$(LEGAL_INFO_DIR)/licenses
+LEGAL_MANIFEST_CSV=$(LEGAL_INFO_DIR)/manifest.csv
+LEGAL_LICENSES_TXT=$(LEGAL_INFO_DIR)/licenses.txt
+LEGAL_WARNINGS=$(LEGAL_INFO_DIR)/.warnings
+LEGAL_REPORT=$(LEGAL_INFO_DIR)/README
+
 BUILDROOT_CONFIG=$(CONFIG_DIR)/.config
 
 # Pull in the user's configuration file
@@ -184,17 +208,6 @@  unexport DESTDIR
 # Causes breakage with packages that needs host-ruby
 unexport RUBYOPT
 
-# bash prints the name of the directory on 'cd <dir>' if CDPATH is
-# set, so unset it here to not cause problems. Notice that the export
-# line doesn't affect the environment of $(shell ..) calls, so
-# explictly throw away any output from 'cd' here.
-export CDPATH:=
-BASE_DIR := $(shell mkdir -p $(O) && cd $(O) >/dev/null && pwd)
-$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
-
-BUILD_DIR:=$(BASE_DIR)/build
-
-
 ifeq ($(BR2_HAVE_DOT_CONFIG),y)
 
 ################################################################################
@@ -262,21 +275,8 @@  HOST_DIR:=$(call qstrip,$(BR2_HOST_DIR))
 # locales to generate
 GENERATE_LOCALE=$(call qstrip,$(BR2_GENERATE_LOCALE))
 
-# stamp (dependency) files go here
-STAMP_DIR:=$(BASE_DIR)/stamps
-
-BINARIES_DIR:=$(BASE_DIR)/images
-TARGET_DIR:=$(BASE_DIR)/target
 TARGET_SKELETON=$(TOPDIR)/system/skeleton
 
-LEGAL_INFO_DIR=$(BASE_DIR)/legal-info
-REDIST_SOURCES_DIR=$(LEGAL_INFO_DIR)/sources
-LICENSE_FILES_DIR=$(LEGAL_INFO_DIR)/licenses
-LEGAL_MANIFEST_CSV=$(LEGAL_INFO_DIR)/manifest.csv
-LEGAL_LICENSES_TXT=$(LEGAL_INFO_DIR)/licenses.txt
-LEGAL_WARNINGS=$(LEGAL_INFO_DIR)/.warnings
-LEGAL_REPORT=$(LEGAL_INFO_DIR)/README
-
 # Location of a file giving a big fat warning that output/target
 # should not be used as the root filesystem.
 TARGET_DIR_WARNING_FILE=$(TARGET_DIR)/THIS_IS_NOT_YOUR_ROOT_FILESYSTEM