Skip to contentSkip to conversation

Makefile: Do not create empty autoconf.mk on error

PATCH New Masahiro Yamada 2 participants 2 messages Dec 2, 2013 – Dec 16, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Makefile: Do not create empty autoconf.mk on error

The build rules of
- include/autoconf.mk.dep
- include/autoconf.mk
- include/spl-autoconf.mk
- include/tpl-autoconf.mk
were not nice.

They created empty files (which are never updated) if an error occurs during preprocessing.

---

Before this commit, Makefile created empty files such as
- include/autoconf.mk
- include/spl-autoconf.mk
- include/tpl-autoconf.mk
- include/autoconf.mk.dep
on error.

For example, try "make" with wrong CROSS_COMPILE like follows:

    $ make mrproper
    $ make omap4_panda_config
    Configuring for omap4_panda board...
    $ make CROSS_COMPILE=foobar- all
    ---<snip>---
    /bin/bash: foobar-gcc: command not found
    make[1]: *** [lib/asm-offsets.s] Error 127

Of cource, make fails.

And just check include/autoconf.mk, include/spl-autoconf.mk, etc. They exist and are all empty.

And then, try "make" with correct CROSS_COMPILE:

    $ make CROSS_COMPILE=arm-linux-gnueabi- all

make will proceed with empty include/autoconf.mk and fail again.

A build rule of include/autoconf.mk does not work as we expect:

$(obj)include/autoconf.mk: $(obj)include/config.h

	@$(XECHO) Generating $@ ; \
	set -e ; \
	: Extract the config macros ; \
	$(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
		sed -n -f tools/scripts/define2mk.sed > [email protected] && \
	mv [email protected] $@

Above code does not detect the error of $(CPP).
An error usually occurs during $(CPP), whereas sed always succeeds. ( "set -e" is also meaningless, here. )
A empty include/autoconf.mk is created on error.
(And it is never updated because it is newer than include/config.h)

FYI:
A series of commands connected with a "pipe" returns the exit status of the last command.

For example,

    $ command1 | command2

returns exit status of "command2", not "command1".

Changes in v2:
- delete *.tmp file on success

 Makefile | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
Makefile +11 -14
index a2fb037..4be871f 100644
@@ -637,36 +637,33 @@ checkdtc:
 # to regenerate the autoconf.mk file.
 $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h
 	@$(XECHO) Generating $@ ; \
-	set -e ; \
 	: Generate the dependancies ; \
 	$(CC) -x c -DDO_DEPS_ONLY -M $(CFLAGS) $(CPPFLAGS) \
-		-MQ $(obj)include/autoconf.mk include/common.h > $@
+		-MQ $(obj)include/autoconf.mk include/common.h > $@ || \
+		rm $@
 
 $(obj)include/autoconf.mk: $(obj)include/config.h
 	@$(XECHO) Generating $@ ; \
-	set -e ; \
 	: Extract the config macros ; \
-	$(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
-		sed -n -f tools/scripts/define2mk.sed > [email protected] && \
-	mv [email protected] $@
+	$(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h > [email protected] && \
+		sed -n -f tools/scripts/define2mk.sed [email protected] > $@; \
+	rm [email protected]
 
 # Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
 $(obj)include/tpl-autoconf.mk: $(obj)include/config.h
 	@$(XECHO) Generating $@ ; \
-	set -e ; \
 	: Extract the config macros ; \
 	$(CPP) $(CFLAGS) -DCONFIG_TPL_BUILD  -DCONFIG_SPL_BUILD\
-			-DDO_DEPS_ONLY -dM include/common.h | \
-	sed -n -f tools/scripts/define2mk.sed > [email protected] && \
-	mv [email protected] $@
+			-DDO_DEPS_ONLY -dM include/common.h > [email protected] && \
+		sed -n -f tools/scripts/define2mk.sed [email protected] > $@; \
+	rm [email protected]
 
 $(obj)include/spl-autoconf.mk: $(obj)include/config.h
 	@$(XECHO) Generating $@ ; \
-	set -e ; \
 	: Extract the config macros ; \
-	$(CPP) $(CFLAGS) -DCONFIG_SPL_BUILD -DDO_DEPS_ONLY -dM include/common.h | \
-	sed -n -f tools/scripts/define2mk.sed > [email protected] && \
-	mv [email protected] $@
+	$(CPP) $(CFLAGS) -DCONFIG_SPL_BUILD -DDO_DEPS_ONLY -dM include/common.h > [email protected] && \
+		sed -n -f tools/scripts/define2mk.sed [email protected] > $@; \
+	rm [email protected]
 
 $(obj)include/generated/generic-asm-offsets.h:	$(obj)include/autoconf.mk.dep \
 	$(obj)include/spl-autoconf.mk \
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH v2 1/1 Makefile: Do not create empty autoconf.mk on error

Quoted 11 lines · Masahiro Yamada

The build rules of
- include/autoconf.mk.dep
- include/autoconf.mk
- include/spl-autoconf.mk
- include/tpl-autoconf.mk
were not nice.

They created empty files (which are never updated) if an error occurs during preprocessing.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131216/8901666d/attachment.pgp>