* [PATCH] kbuild: Consolidate header generation from ASM offset information
@ 2017-04-03 19:37 Matthias Kaehlcke
2017-04-12 0:03 ` Masahiro Yamada
0 siblings, 1 reply; 3+ messages in thread
From: Matthias Kaehlcke @ 2017-04-03 19:37 UTC (permalink / raw)
To: Tony Luck, Fenghua Yu, Michal Marek, Jan Kiszka, Kieran Bingham,
Andrew Morton
Cc: linux-kernel, linux-ia64, linux-kbuild, Grant Grundler,
Michael Davidson, Greg Hackmann, Matthias Kaehlcke
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
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
--
2.12.2.564.g063fe858b8-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] kbuild: Consolidate header generation from ASM offset information
2017-04-03 19:37 [PATCH] kbuild: Consolidate header generation from ASM offset information Matthias Kaehlcke
@ 2017-04-12 0:03 ` Masahiro Yamada
2017-04-12 1:38 ` Matthias Kaehlcke
0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2017-04-12 0:03 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: Tony Luck, Fenghua Yu, Michal Marek, Jan Kiszka, Kieran Bingham,
Andrew Morton, Linux Kernel Mailing List, linux-ia64,
Linux Kbuild mailing list, Grant Grundler, Michael Davidson,
Greg Hackmann
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__)
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] kbuild: Consolidate header generation from ASM offset information
2017-04-12 0:03 ` Masahiro Yamada
@ 2017-04-12 1:38 ` Matthias Kaehlcke
0 siblings, 0 replies; 3+ messages in thread
From: Matthias Kaehlcke @ 2017-04-12 1:38 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Tony Luck, Fenghua Yu, Michal Marek, Jan Kiszka, Kieran Bingham,
Andrew Morton, Linux Kernel Mailing List, linux-ia64,
Linux Kbuild mailing list, Grant Grundler, Michael Davidson,
Greg Hackmann
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-12 1:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-03 19:37 [PATCH] kbuild: Consolidate header generation from ASM offset information Matthias Kaehlcke
2017-04-12 0:03 ` Masahiro Yamada
2017-04-12 1:38 ` Matthias Kaehlcke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox