diff mbox

[1/2] kbuild: merge bounds.h and asm-offsets.h rules

Message ID 1419403765-3377-2-git-send-email-yamada.m@jp.panasonic.com (mailing list archive)
State New, archived
Headers show

Commit Message

Masahiro Yamada Dec. 24, 2014, 6:49 a.m. UTC
The rules "cmd_bounds" and "cmd_offsets" are almost the same.
(The difference is only the include guards.)  They can be merged.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

 Kbuild | 59 +++++++++++++++++++++--------------------------------------
 1 file changed, 21 insertions(+), 38 deletions(-)

Comments

Michal Marek Jan. 2, 2015, 4:04 p.m. UTC | #1
On 2014-12-24 07:49, Masahiro Yamada wrote:
> The rules "cmd_bounds" and "cmd_offsets" are almost the same.
> (The difference is only the include guards.)  They can be merged.

Good idea.


> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> ---
> 
>  Kbuild | 59 +++++++++++++++++++++--------------------------------------
>  1 file changed, 21 insertions(+), 38 deletions(-)
> 
> diff --git a/Kbuild b/Kbuild
> index 5d7c729..55a639f 100644
> --- a/Kbuild
> +++ b/Kbuild
> @@ -5,19 +5,20 @@
>  # 2) Generate asm-offsets.h (may need bounds.h)
>  # 3) Check for missing system calls
>  
> -#####
> -# 1) Generate bounds.h
> -
> -bounds-file := include/generated/bounds.h
> -
> -always  := $(bounds-file)
> -targets := $(bounds-file) kernel/bounds.s
> +# Default sed regexp - multiline due to syntax constraints
> +define sed-y
> +	"/^->/{s:->#\(.*\):/* \1 */:; \
> +	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
> +	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
> +	s:->::; p;}"
> +endef
>  
> -quiet_cmd_bounds = GEN     $@
> -define cmd_bounds
> +quiet_cmd_offsets = GEN     $@
> +define cmd_offsets
>  	(set -e; \
> -	 echo "#ifndef __LINUX_BOUNDS_H__"; \
> -	 echo "#define __LINUX_BOUNDS_H__"; \
> +	 INCLUDE_GUARD=$$(echo __$(notdir $@)__ | tr '[a-z].-' '[A-Z]__'); \
> +	 echo "#ifndef $$INCLUDE_GUARD"; \
> +	 echo "#define $$INCLUDE_GUARD"; \

I think it would be more readable to write it as

  echo "#ifndef $(2)"; \
  ...

and pass the include guard name as an argument to cmd_offsets.

Otherwise it's a great cleanup.

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Masahiro Yamada Jan. 5, 2015, 6:58 a.m. UTC | #2
Hi Michal,



On Fri, 02 Jan 2015 17:04:42 +0100
Michal Marek <mmarek@suse.cz> wrote:

> >  
> > -quiet_cmd_bounds = GEN     $@
> > -define cmd_bounds
> > +quiet_cmd_offsets = GEN     $@
> > +define cmd_offsets
> >  	(set -e; \
> > -	 echo "#ifndef __LINUX_BOUNDS_H__"; \
> > -	 echo "#define __LINUX_BOUNDS_H__"; \
> > +	 INCLUDE_GUARD=$$(echo __$(notdir $@)__ | tr '[a-z].-' '[A-Z]__'); \
> > +	 echo "#ifndef $$INCLUDE_GUARD"; \
> > +	 echo "#define $$INCLUDE_GUARD"; \
> 
> I think it would be more readable to write it as
> 
>   echo "#ifndef $(2)"; \
>   ...
> 
> and pass the include guard name as an argument to cmd_offsets.
> 
> Otherwise it's a great cleanup.
> 
> Michal


OK.  I have posted v2.


Best Regards
Masahiro Yamada

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Kbuild b/Kbuild
index 5d7c729..55a639f 100644
--- a/Kbuild
+++ b/Kbuild
@@ -5,19 +5,20 @@ 
 # 2) Generate asm-offsets.h (may need bounds.h)
 # 3) Check for missing system calls
 
-#####
-# 1) Generate bounds.h
-
-bounds-file := include/generated/bounds.h
-
-always  := $(bounds-file)
-targets := $(bounds-file) kernel/bounds.s
+# Default sed regexp - multiline due to syntax constraints
+define sed-y
+	"/^->/{s:->#\(.*\):/* \1 */:; \
+	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
+	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
+	s:->::; p;}"
+endef
 
-quiet_cmd_bounds = GEN     $@
-define cmd_bounds
+quiet_cmd_offsets = GEN     $@
+define cmd_offsets
 	(set -e; \
-	 echo "#ifndef __LINUX_BOUNDS_H__"; \
-	 echo "#define __LINUX_BOUNDS_H__"; \
+	 INCLUDE_GUARD=$$(echo __$(notdir $@)__ | tr '[a-z].-' '[A-Z]__'); \
+	 echo "#ifndef $$INCLUDE_GUARD"; \
+	 echo "#define $$INCLUDE_GUARD"; \
 	 echo "/*"; \
 	 echo " * DO NOT MODIFY."; \
 	 echo " *"; \
@@ -30,6 +31,14 @@  define cmd_bounds
 	 echo "#endif" ) > $@
 endef
 
+#####
+# 1) Generate bounds.h
+
+bounds-file := include/generated/bounds.h
+
+always  := $(bounds-file)
+targets := $(bounds-file) kernel/bounds.s
+
 # We use internal kbuild rules to avoid the "is up to date" message from make
 kernel/bounds.s: kernel/bounds.c FORCE
 	$(Q)mkdir -p $(dir $@)
@@ -37,7 +46,7 @@  kernel/bounds.s: kernel/bounds.c FORCE
 
 $(obj)/$(bounds-file): kernel/bounds.s Kbuild
 	$(Q)mkdir -p $(dir $@)
-	$(call cmd,bounds)
+	$(call cmd,offsets)
 
 #####
 # 2) Generate asm-offsets.h
@@ -49,32 +58,6 @@  always  += $(offsets-file)
 targets += $(offsets-file)
 targets += arch/$(SRCARCH)/kernel/asm-offsets.s
 
-
-# Default sed regexp - multiline due to syntax constraints
-define sed-y
-	"/^->/{s:->#\(.*\):/* \1 */:; \
-	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
-	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
-	s:->::; p;}"
-endef
-
-quiet_cmd_offsets = GEN     $@
-define cmd_offsets
-	(set -e; \
-	 echo "#ifndef __ASM_OFFSETS_H__"; \
-	 echo "#define __ASM_OFFSETS_H__"; \
-	 echo "/*"; \
-	 echo " * DO NOT MODIFY."; \
-	 echo " *"; \
-	 echo " * This file was generated by Kbuild"; \
-	 echo " *"; \
-	 echo " */"; \
-	 echo ""; \
-	 sed -ne $(sed-y) $<; \
-	 echo ""; \
-	 echo "#endif" ) > $@
-endef
-
 # We use internal kbuild rules to avoid the "is up to date" message from make
 arch/$(SRCARCH)/kernel/asm-offsets.s: arch/$(SRCARCH)/kernel/asm-offsets.c \
                                       $(obj)/$(bounds-file) FORCE