Skip to content

Commit ebf003f

Browse files
mkaehlckemasahir0y
authored andcommitted
kbuild: Consolidate header generation from ASM offset information
Largely redundant code is used in different places to generate C headers from offset information extracted from assembly language output. Consolidate the code in Makefile.lib and use this instead. Signed-off-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 6748cb3 commit ebf003f

4 files changed

Lines changed: 32 additions & 75 deletions

File tree

‎Kbuild‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,6 @@
77
# 4) Check for missing system calls
88
# 5) Generate constants.py (may need bounds.h)
99

10-
# Default sed regexp - multiline due to syntax constraints
11-
define sed-y
12-
"/^->/{s:->#\(.*\):/* \1 */:; \
13-
s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
14-
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
15-
s:->::; p;}"
16-
endef
17-
18-
# Use filechk to avoid rebuilds when a header changes, but the resulting file
19-
# does not
20-
define filechk_offsets
21-
(set -e; \
22-
echo "#ifndef $2"; \
23-
echo "#define $2"; \
24-
echo "/*"; \
25-
echo " * DO NOT MODIFY."; \
26-
echo " *"; \
27-
echo " * This file was generated by Kbuild"; \
28-
echo " */"; \
29-
echo ""; \
30-
sed -ne $(sed-y); \
31-
echo ""; \
32-
echo "#endif" )
33-
endef
34-
3510
#####
3611
# 1) Generate bounds.h
3712

‎arch/ia64/kernel/Makefile‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,10 @@ CFLAGS_traps.o += -mfixed-range=f2-f5,f16-f31
5050
# The gate DSO image is built using a special linker script.
5151
include $(src)/Makefile.gate
5252

53-
# Calculate NR_IRQ = max(IA64_NATIVE_NR_IRQS, XEN_NR_IRQS, ...) based on config
54-
define sed-y
55-
"/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"
56-
endef
57-
quiet_cmd_nr_irqs = GEN $@
58-
define cmd_nr_irqs
59-
(set -e; \
60-
echo "#ifndef __ASM_NR_IRQS_H__"; \
61-
echo "#define __ASM_NR_IRQS_H__"; \
62-
echo "/*"; \
63-
echo " * DO NOT MODIFY."; \
64-
echo " *"; \
65-
echo " * This file was generated by Kbuild"; \
66-
echo " *"; \
67-
echo " */"; \
68-
echo ""; \
69-
sed -ne $(sed-y) $<; \
70-
echo ""; \
71-
echo "#endif" ) > $@
72-
endef
73-
7453
# We use internal kbuild rules to avoid the "is up to date" message from make
7554
arch/$(SRCARCH)/kernel/nr-irqs.s: arch/$(SRCARCH)/kernel/nr-irqs.c
7655
$(Q)mkdir -p $(dir $@)
7756
$(call if_changed_dep,cc_s_c)
7857

79-
include/generated/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s
80-
$(Q)mkdir -p $(dir $@)
81-
$(call cmd,nr_irqs)
58+
include/generated/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s FORCE
59+
$(call filechk,offsets,__ASM_NR_IRQS_H__)

‎scripts/Makefile.lib‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,31 @@ quiet_cmd_xzmisc = XZMISC $@
408408
cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
409409
xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
410410
(rm -f $@ ; false)
411+
412+
# ASM offsets
413+
# ---------------------------------------------------------------------------
414+
415+
# Default sed regexp - multiline due to syntax constraints
416+
define sed-offsets
417+
"/^->/{s:->#\(.*\):/* \1 */:; \
418+
s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
419+
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
420+
s:->::; p;}"
421+
endef
422+
423+
# Use filechk to avoid rebuilds when a header changes, but the resulting file
424+
# does not
425+
define filechk_offsets
426+
(set -e; \
427+
echo "#ifndef $2"; \
428+
echo "#define $2"; \
429+
echo "/*"; \
430+
echo " * DO NOT MODIFY."; \
431+
echo " *"; \
432+
echo " * This file was generated by Kbuild"; \
433+
echo " */"; \
434+
echo ""; \
435+
sed -ne $(sed-offsets); \
436+
echo ""; \
437+
echo "#endif" )
438+
endef

‎scripts/mod/Makefile‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,8 @@ modpost-objs := modpost.o file2alias.o sumversion.o
77

88
devicetable-offsets-file := devicetable-offsets.h
99

10-
define sed-y
11-
"/^->/{s:->#\(.*\):/* \1 */:; \
12-
s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
13-
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
14-
s:->::; p;}"
15-
endef
16-
17-
quiet_cmd_offsets = GEN $@
18-
define cmd_offsets
19-
(set -e; \
20-
echo "#ifndef __DEVICETABLE_OFFSETS_H__"; \
21-
echo "#define __DEVICETABLE_OFFSETS_H__"; \
22-
echo "/*"; \
23-
echo " * DO NOT MODIFY."; \
24-
echo " *"; \
25-
echo " * This file was generated by Kbuild"; \
26-
echo " *"; \
27-
echo " */"; \
28-
echo ""; \
29-
sed -ne $(sed-y) $<; \
30-
echo ""; \
31-
echo "#endif" ) > $@
32-
endef
33-
34-
$(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s
35-
$(call if_changed,offsets)
10+
$(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s FORCE
11+
$(call filechk,offsets,__DEVICETABLE_OFFSETS_H__)
3612

3713
targets += $(devicetable-offsets-file) devicetable-offsets.s
3814

0 commit comments

Comments
 (0)