Skip to contentSkip to conversation

make clean: improve when no .config present

PATCH New Thomas De Schampheleire 2 participants 3 messages Oct 2, 2013 – Oct 3, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make clean: improve when no .config present

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.

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

 Makefile |  48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)
Makefile +24 -24
@@ -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
#1 lore raw

PATCH 1/1 make clean: improve when no .config present

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas De Schampheleire <[email protected]> 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 <[email protected]>

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.

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH 1/1 make clean: improve when no .config present

Hi Peter,

Quoted 10 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas De Schampheleire <[email protected]> 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.

Quoted 8 lines

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.

Quoted 25 lines

Thomas> Signed-off-by: Thomas De Schampheleire <[email protected]>

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))

Quoted 5 lines

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.

Quoted 2 lines

Committed, thanks.

Thanks,
Thomas