Skip to content

Commit 09b4848

Browse files
Matthias Kaehlckenickdesaulniers
Matthias Kaehlcke
authored andcommitted
UPSTREAM: 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 <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Bug: 67861121 (cherry picked from commit ebf003f0cfb3705e60d40dedc3ec949176c741af) Signed-off-by: Nick Desaulniers <[email protected]> Change-Id: I0cebb0d69b22a562938404dde2a1566b939e62b4
1 parent 43637c1 commit 09b4848

File tree

4 files changed

+32
-75
lines changed

4 files changed

+32
-75
lines changed

Kbuild

-25
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

+2-24
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

+28
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,31 @@ quiet_cmd_xzmisc = XZMISC $@
420420
cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
421421
xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
422422
(rm -f $@ ; false)
423+
424+
# ASM offsets
425+
# ---------------------------------------------------------------------------
426+
427+
# Default sed regexp - multiline due to syntax constraints
428+
define sed-offsets
429+
"/^->/{s:->#\(.*\):/* \1 */:; \
430+
s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
431+
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
432+
s:->::; p;}"
433+
endef
434+
435+
# Use filechk to avoid rebuilds when a header changes, but the resulting file
436+
# does not
437+
define filechk_offsets
438+
(set -e; \
439+
echo "#ifndef $2"; \
440+
echo "#define $2"; \
441+
echo "/*"; \
442+
echo " * DO NOT MODIFY."; \
443+
echo " *"; \
444+
echo " * This file was generated by Kbuild"; \
445+
echo " */"; \
446+
echo ""; \
447+
sed -ne $(sed-offsets); \
448+
echo ""; \
449+
echo "#endif" )
450+
endef

scripts/mod/Makefile

+2-26
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)