Skip to contentSkip to conversation

kbuild: do not delete $@ explicitly on failure

PATCH Applied Masahiro Yamada 2 participants 5 messages Apr 30, 2020 – May 4, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 kbuild: do not delete $@ explicitly on failure

The .DELETE_ON_ERROR special target is specified in scripts/Kbuild.include

You do not need to delete $@ explicitly when the command fails. GNU Make automatically does it.

---

 Makefile                | 6 +-----
 arch/arm/tools/Makefile | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)
Makefile +1 -5
index de9b40ade..967c27909 100644
@@ -643,11 +643,7 @@ define rule_barebox__
 
 	$(Q)$(if $($(quiet)cmd_sysmap),                                      \
 	  echo '  $($(quiet)cmd_sysmap)  System.map' &&)                     \
-	$(cmd_sysmap) $@ System.map;                                         \
-	if [ $$? -ne 0 ]; then                                               \
-		rm -f $@;                                                    \
-		false;                                                       \
-	fi;
+	$(cmd_sysmap) $@ System.map
 endef
 
 ifdef CONFIG_KALLSYMS
arch/arm/tools/Makefile +1 -1
index 67ae9e701..bff825e58 100644
@@ -7,4 +7,4 @@
 include/generated/mach-types.h: $(src)/gen-mach-types $(src)/mach-types
 	$(Q)$(kecho) '  Generating $@'
 	$(Q)mkdir -p $(dir $@)
-	$(Q)$(AWK) -f $^ > $@ || { rm -f $@; /bin/false; }
+	$(Q)$(AWK) -f $^ > $@
Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/4 kbuild: sync filechk rule with Linux 5.7-rc2

The 'filechk' in the latest Linux works more simply, reliably.

- Do not show CHK every time
- Delete the *.tmp file when the filechk_$(1) fails
- Do not open the first prerequisite. This is unneeded in most cases.

I deleted pointeless dependency on Makefile.

Also delete the meaningless assignment to 'targets' because filechk does not generate .cmd file.

---

 Makefile               | 10 +++++-----
 common/Makefile        |  4 +---
 scripts/Kbuild.include | 24 +++++++++++-------------
 3 files changed, 17 insertions(+), 21 deletions(-)
Makefile +5 -5
index 967c27909..59e041fed 100644
@@ -883,16 +883,16 @@ define filechk_utsrelease.h
 	  echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2;    \
 	  exit 1;                                                         \
 	fi;                                                               \
-	(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";)
+	echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
 endef
 
 define filechk_version.h
-	(echo \#define LINUX_VERSION_CODE $(shell                             \
-	expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL));     \
-	echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
+	echo \#define LINUX_VERSION_CODE $(shell                         \
+	expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \
+	echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'
 endef
 
-include/generated/version.h: $(srctree)/Makefile FORCE
+include/generated/version.h: FORCE
 	$(call filechk,version.h)
 
 include/generated/utsrelease.h: include/config/kernel.release FORCE
common/Makefile +1 -3
index 84463b4d4..c14af692f 100644
@@ -86,11 +86,9 @@ echo "\";"						\
 endef
 endif
 
-include/generated/passwd.h: $(srctree)/$(src)/Makefile FORCE
+include/generated/passwd.h: FORCE
 	$(call filechk,passwd)
 
-targets += include/generated/passwd.h
-
 $(obj)/password.o: include/generated/passwd.h
 endif # CONFIG_PASSWORD
 
scripts/Kbuild.include +11 -13
index 227a022b4..983329e40 100644
@@ -37,11 +37,11 @@ kecho := $($(quiet)kecho)
 ###
 # filechk is used to check if the content of a generated file is updated.
 # Sample usage:
-# define filechk_sample
-#	echo $KERNELRELEASE
-# endef
-# version.h : Makefile
+#
+# filechk_sample = echo $(KERNELRELEASE)
+# version.h: FORCE
 #	$(call filechk,sample)
+#
 # The rule defined shall write to stdout the content of the new file.
 # The existing file will be compared with the new one.
 # - If no file exist it is created
@@ -50,15 +50,13 @@ kecho := $($(quiet)kecho)
 # - stdin is piped in from the first prerequisite ($<) so one has
 #   to specify a valid file as first prerequisite (often the kbuild file)
 define filechk
-	$(Q)set -e;				\
-	$(kecho) '  CHK     $@';		\
-	mkdir -p $(dir $@);			\
-	$(filechk_$(1)) < $< > [email protected];		\
-	if [ -r $@ ] && cmp -s $@ [email protected]; then	\
-		rm -f [email protected];			\
-	else					\
-		$(kecho) '  UPD     $@';	\
-		mv -f [email protected] $@;		\
+	$(Q)set -e;						\
+	mkdir -p $(dir $@);					\
+	trap "rm -f $(dot-target).tmp" EXIT;			\
+	{ $(filechk_$(1)); } > $(dot-target).tmp;		\
+	if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then	\
+		$(kecho) '  UPD     $@';			\
+		mv -f $(dot-target).tmp $@;			\
 	fi
 endef
 
Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/4 kbuild: sync if_changed and friends with Linux 5.7-rc2

In reply to Masahiro Yamada

Resync cmd, if_change, if_changed_dep, and if_changed_rule.

Clean up the users of if_changed_rule.

I deleted the modversions rule. It is dead code because barebox does not define CONFIG_MODVERSIONS. It does not work without scripts/genksyms/ anyway.

---

 Makefile               | 14 ++-------
 scripts/Kbuild.include | 47 +++++++++++++++---------------
 scripts/Makefile.build | 66 +++++-------------------------------------
 3 files changed, 34 insertions(+), 93 deletions(-)
Makefile +3 -11
index 59e041fed..9485f5551 100644
@@ -626,24 +626,18 @@ quiet_cmd_barebox_version = GEN     .version
 	$(MAKE) $(build)=common
 
 # Generate System.map
-quiet_cmd_sysmap = SYSMAP
-      cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
+quiet_cmd_sysmap = SYSMAP  System.map
+      cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap $@ System.map
 
 # Link of barebox
 # If CONFIG_KALLSYMS is set .version is already updated
 # Generate System.map and verify that the content is consistent
 # Use + in front of the barebox_version rule to silent warning with make -j2
-# First command is ':' to allow us to use + in front of the rule
 define rule_barebox__
-	:
 	$(if $(CONFIG_KALLSYMS),,+$(call cmd,barebox_version))
 	$(call cmd,barebox__)
-
 	$(Q)echo 'cmd_$@ := $(cmd_barebox__)' > $(@D)/.$(@F).cmd
-
-	$(Q)$(if $($(quiet)cmd_sysmap),                                      \
-	  echo '  $($(quiet)cmd_sysmap)  System.map' &&)                     \
-	$(cmd_sysmap) $@ System.map
+	$(call cmd,sysmap)
 endef
 
 ifdef CONFIG_KALLSYMS
@@ -684,10 +678,8 @@ endef
 
 # Update barebox version before link
 # Use + in front of this rule to silent warning about make -j1
-# First command is ':' to allow us to use + in front of this rule
 cmd_ksym_ld = $(cmd_barebox__)
 define rule_ksym_ld
-	:
 	+$(call cmd,barebox_version)
 	$(call cmd,barebox__)
 	$(Q)echo 'cmd_$@ := $(cmd_barebox__)' > $(@D)/.$(@F).cmd
scripts/Kbuild.include +23 -24

87 lines not on this page · raw message

scripts/Makefile.build +8 -58

91 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 4/4 kbuild: sync scripts/Kbuild.include with Linux 5.7-rc2

In reply to Masahiro Yamada

More random cherry-picks for scripts/Kbuild.include

---

 scripts/Kbuild.include | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)
scripts/Kbuild.include +22 -20
index 074d2db04..838ab11e7 100644
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
 ####
 # kbuild: Generic definitions
 
@@ -23,10 +24,18 @@ depfile = $(subst $(comma),_,$(dot-target).d)
 # filename of target with directory and extension stripped
 basetarget = $(basename $(notdir $@))
 
+###
+# real prerequisites without phony targets
+real-prereqs = $(filter-out $(PHONY), $^)
+
 ###
 # Escape single quote for use in echo statements
 escsq = $(subst $(squote),'\$(squote)',$1)
 
+###
+# Quote a string to pass it to C files. foo => '"foo"'
+stringify = $(squote)$(quote)$1$(quote)$(squote)
+
 ###
 # Easy method for doing a status message
        kecho := :
@@ -62,18 +71,19 @@ endef
 
 ######
 # gcc support functions
-# See documentation in Documentation/kbuild/makefiles.txt
+# See documentation in Documentation/kbuild/makefiles.rst
 
 # cc-cross-prefix
 # Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
-# Return first prefix where a prefix$(CC) is found in PATH.
-# If no $(CC) found in PATH with listed prefixes return nothing
-cc-cross-prefix =  \
-	$(word 1, $(foreach c,$(1),                                   \
-		$(shell set -e;                                       \
-		if (which $(strip $(c))$(CC)) > /dev/null 2>&1 ; then \
-			echo $(c);                                    \
-		fi)))
+# Return first <prefix> where a <prefix>gcc is found in PATH.
+# If no gcc found in PATH with listed prefixes return nothing
+#
+# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
+# would try to directly execute the shell builtin 'command'. This workaround
+# should be kept for a long time since this issue was fixed only after the
+# GNU Make 4.2.1 release.
+cc-cross-prefix = $(firstword $(foreach c, $(1), \
+			$(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
 
 # output directory for tests below
 TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
@@ -138,18 +148,13 @@ ld-option = $(call try-run,\
 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
 # Usage:
 # $(Q)$(MAKE) $(build)=dir
-build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
+build := -f $(srctree)/scripts/Makefile.build obj
 
 ###
-# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
-# Usage:
-# $(Q)$(MAKE) $(modbuiltin)=dir
-modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj
-
-# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
 # Usage:
 # $(Q)$(MAKE) $(clean)=dir
-clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
+clean := -f $(srctree)/scripts/Makefile.clean obj
 
 # Prefix -I with $(srctree) if it is not an absolute path.
 # skip if -I has no parameter
@@ -167,9 +172,6 @@ echo-cmd = $(if $($(quiet)cmd_$(1)),\
 # printing commands
 cmd = @set -e; $(echo-cmd) $(cmd_$(1))
 
-# Add $(obj)/ for paths that are not absolute
-objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
-
 ###
 # if_changed      - execute command if any prerequisite is newer than
 #                   target, or command line has changed
Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#4 lore raw
In reply to Masahiro Yamada
Quoted 7 lines · Masahiro Yamada

The .DELETE_ON_ERROR special target is specified in scripts/Kbuild.include

You do not need to delete $@ explicitly when the command fails. GNU Make automatically does it.

---

Applied, thanks

Sascha

Quoted 41 lines
 Makefile                | 6 +-----
 arch/arm/tools/Makefile | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)
Makefile +1 -5
index de9b40ade..967c27909 100644
@@ -643,11 +643,7 @@ define rule_barebox__
 
 	$(Q)$(if $($(quiet)cmd_sysmap),                                      \
 	  echo '  $($(quiet)cmd_sysmap)  System.map' &&)                     \
-	$(cmd_sysmap) $@ System.map;                                         \
-	if [ $$? -ne 0 ]; then                                               \
-		rm -f $@;                                                    \
-		false;                                                       \
-	fi;
+	$(cmd_sysmap) $@ System.map
 endef
 
 ifdef CONFIG_KALLSYMS
arch/arm/tools/Makefile +1 -1
index 67ae9e701..bff825e58 100644
@@ -7,4 +7,4 @@
 include/generated/mach-types.h: $(src)/gen-mach-types $(src)/mach-types
 	$(Q)$(kecho) '  Generating $@'
 	$(Q)mkdir -p $(dir $@)
-	$(Q)$(AWK) -f $^ > $@ || { rm -f $@; /bin/false; }
+	$(Q)$(AWK) -f $^ > $@
Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox