diff mbox

kbuild: Consolidate header generation from ASM offset information

Message ID 20170403193739.84905-1-mka@chromium.org (mailing list archive)
State New, archived
Headers show

Commit Message

Matthias Kaehlcke April 3, 2017, 7:37 p.m. UTC
Largely redundant code is used in different places to generate C headers
from offset information extracted from assembly language output.
Consolidate the code in a Makefile include and use this instead.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 Kbuild                       | 21 ++-------------------
 arch/ia64/kernel/Makefile    | 19 +++----------------
 scripts/Makefile.asm-offsets | 22 ++++++++++++++++++++++
 scripts/mod/Makefile         | 21 ++-------------------
 4 files changed, 29 insertions(+), 54 deletions(-)
 create mode 100644 scripts/Makefile.asm-offsets

Comments

Masahiro Yamada April 12, 2017, 12:03 a.m. UTC | #1
Hi Matthias,


2017-04-04 4:37 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> Largely redundant code is used in different places to generate C headers
> from offset information extracted from assembly language output.
> Consolidate the code in a Makefile include and use this instead.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>


Please move sed-y and filechk_offsets to scripts/Makefile.lib .
(You may need to rename sed-y
because arch/xtensa/kernel/Makefile uses this name.)


We see various helpers in scripts/Makefile.lib,
so I do not think we need to create a new file just for this one.

Then, please reuse it from arch/ia64/kernel/Makefile and scripts/mod/Makefile.
Like this:

include/generated/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s FORCE
        $(call filechk,offsets,__ASM_NR_IRQS_H__)

$(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s FORCE
        $(call filechk,offsets,__DEVICETABLE_OFFSETS_H__)
Matthias Kaehlcke April 12, 2017, 1:38 a.m. UTC | #2
Hi Masahiro,

El Wed, Apr 12, 2017 at 09:03:28AM +0900 Masahiro Yamada ha dit:

> 2017-04-04 4:37 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> > Largely redundant code is used in different places to generate C headers
> > from offset information extracted from assembly language output.
> > Consolidate the code in a Makefile include and use this instead.
> >
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> 
> 
> Please move sed-y and filechk_offsets to scripts/Makefile.lib .
> (You may need to rename sed-y
> because arch/xtensa/kernel/Makefile uses this name.)
> 
> 
> We see various helpers in scripts/Makefile.lib,
> so I do not think we need to create a new file just for this one.
> 
> Then, please reuse it from arch/ia64/kernel/Makefile and scripts/mod/Makefile.
> Like this:
> 
> include/generated/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s FORCE
>         $(call filechk,offsets,__ASM_NR_IRQS_H__)
> 
> $(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s FORCE
>         $(call filechk,offsets,__DEVICETABLE_OFFSETS_H__)

Thanks for your comments, I'll rework the patch accordingly.

Cheers

Matthias
--
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 3d0ae152af7c..e3789c9611fd 100644
--- a/Kbuild
+++ b/Kbuild
@@ -7,29 +7,12 @@ 
 # 4) Check for missing system calls
 # 5) Generate constants.py (may need bounds.h)
 
-# 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
+include scripts/Makefile.asm-offsets
 
 # Use filechk to avoid rebuilds when a header changes, but the resulting file
 # does not
 define filechk_offsets
-	(set -e; \
-	 echo "#ifndef $2"; \
-	 echo "#define $2"; \
-	 echo "/*"; \
-	 echo " * DO NOT MODIFY."; \
-	 echo " *"; \
-	 echo " * This file was generated by Kbuild"; \
-	 echo " */"; \
-	 echo ""; \
-	 sed -ne $(sed-y); \
-	 echo ""; \
-	 echo "#endif" )
+	$(call gen_header_from_asm_offsets,$2)
 endef
 
 #####
diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile
index 3686d6abafde..186ba553ff26 100644
--- a/arch/ia64/kernel/Makefile
+++ b/arch/ia64/kernel/Makefile
@@ -50,25 +50,12 @@  CFLAGS_traps.o  += -mfixed-range=f2-f5,f16-f31
 # The gate DSO image is built using a special linker script.
 include $(src)/Makefile.gate
 
+include $(srctree)/scripts/Makefile.asm-offsets
+
 # Calculate NR_IRQ = max(IA64_NATIVE_NR_IRQS, XEN_NR_IRQS, ...) based on config
-define sed-y
-	"/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"
-endef
 quiet_cmd_nr_irqs = GEN     $@
 define cmd_nr_irqs
-	(set -e; \
-	 echo "#ifndef __ASM_NR_IRQS_H__"; \
-	 echo "#define __ASM_NR_IRQS_H__"; \
-	 echo "/*"; \
-	 echo " * DO NOT MODIFY."; \
-	 echo " *"; \
-	 echo " * This file was generated by Kbuild"; \
-	 echo " *"; \
-	 echo " */"; \
-	 echo ""; \
-	 sed -ne $(sed-y) $<; \
-	 echo ""; \
-	 echo "#endif" ) > $@
+	$(call gen_header_from_asm_offsets,__ASM_NR_IRQS_H__) < $< > $@
 endef
 
 # We use internal kbuild rules to avoid the "is up to date" message from make
diff --git a/scripts/Makefile.asm-offsets b/scripts/Makefile.asm-offsets
new file mode 100644
index 000000000000..4ba80ba29b82
--- /dev/null
+++ b/scripts/Makefile.asm-offsets
@@ -0,0 +1,22 @@ 
+# Default sed regexp - multiline due to syntax constraints
+define sed-asm-offsets-to-c
+	"/^->/{s:->#\(.*\):/* \1 */:; \
+	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
+	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
+	s:->::; p;}"
+endef
+
+define gen_header_from_asm_offsets
+	(set -e; \
+	 echo "#ifndef $1"; \
+	 echo "#define $1"; \
+	 echo "/*"; \
+	 echo " * DO NOT MODIFY."; \
+	 echo " *"; \
+	 echo " * This file was generated by Kbuild"; \
+	 echo " */"; \
+	 echo ""; \
+	 sed -ne $(sed-asm-offsets-to-c); \
+	 echo ""; \
+	 echo "#endif" )
+endef
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index 19d9bcadc0cc..5858bebfaf32 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -7,28 +7,11 @@  modpost-objs	:= modpost.o file2alias.o sumversion.o
 
 devicetable-offsets-file := devicetable-offsets.h
 
-define sed-y
-	"/^->/{s:->#\(.*\):/* \1 */:; \
-	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
-	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
-	s:->::; p;}"
-endef
+include $(srctree)/scripts/Makefile.asm-offsets
 
 quiet_cmd_offsets = GEN     $@
 define cmd_offsets
-	(set -e; \
-	 echo "#ifndef __DEVICETABLE_OFFSETS_H__"; \
-	 echo "#define __DEVICETABLE_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" ) > $@
+	$(call gen_header_from_asm_offsets,__DEVICETABLE_OFFSETS_H__) < $< > $@
 endef
 
 $(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s