[RFC PATCH 3/5] kbuild: add kernel-offset file

From: Lai Jiangshan
Date: Sun Mar 27 2011 - 22:57:37 EST



Add kernel/kernel-offset.c, include/generated/kernel-offsets.h will
be generated from this file and some difines need by kernel
is generated in this file.

This generating is assigned as the last step of the kbuild generating,
it would require the other earier generated files.

__KBUILD_GENARATING__ is defined when generating, it will be
used to avoid compiling errror when generating.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
Kbuild | 41 ++++++++++++++++++++++++++++++++---------
kernel/kernel-offsets.c | 14 ++++++++++++++
2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/Kbuild b/Kbuild
index 5c2ee83..fdfde56 100644
--- a/Kbuild
+++ b/Kbuild
@@ -3,7 +3,8 @@
# This file takes care of the following:
# 1) Generate bounds.h
# 2) Generate asm-offsets.h (may need bounds.h)
-# 3) Check for missing system calls
+# 3) Generate kernel-offsets.h (may need bounds.h and asm-offsets.h)
+# 4) Check for missing system calls

# Default sed regexp - multiline due to syntax constraints
define sed-y
@@ -30,6 +31,10 @@ define cmd_kbuild_gen
echo "#endif" ) > $@
endef

+quiet_cmd_gen_cc_s_c = CC $(quiet_modtag) $@
+cmd_gen_cc_s_c = $(CC) -D__KBUILD_GENARATING__ \
+ $(c_flags) -fverbose-asm -S -o $@ $<
+
#####
# 1) Generate bounds.h

@@ -41,7 +46,7 @@ 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 $@)
- $(call if_changed_dep,cc_s_c)
+ $(call if_changed_dep,gen_cc_s_c)

$(obj)/$(bounds-file): kernel/bounds.s Kbuild
$(Q)mkdir -p $(dir $@)
@@ -51,23 +56,41 @@ $(obj)/$(bounds-file): kernel/bounds.s Kbuild
# 2) Generate asm-offsets.h
#

-offsets-file := include/generated/asm-offsets.h
+asm-offsets-file := include/generated/asm-offsets.h

-always += $(offsets-file)
-targets += $(offsets-file)
+always += $(asm-offsets-file)
+targets += $(asm-offsets-file)
targets += arch/$(SRCARCH)/kernel/asm-offsets.s

# 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
$(Q)mkdir -p $(dir $@)
- $(call if_changed_dep,cc_s_c)
+ $(call if_changed_dep,gen_cc_s_c)
+
+$(obj)/$(asm-offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s Kbuild
+ $(call cmd,kbuild_gen)
+
+#####
+# 3) Generate kernel-offsets.h
+#
+
+kernel-offsets-file := include/generated/kernel-offsets.h
+
+always += $(kernel-offsets-file)
+targets += $(kernel-offsets-file) kernel/kernel-offsets.s
+
+# We use internal kbuild rules to avoid the "is up to date" message from make
+kernel/kernel-offsets.s: kernel/kernel-offsets.c $(obj)/$(asm-offsets-file) \
+ $(obj)/$(bounds-file) FORCE
+ $(Q)mkdir -p $(dir $@)
+ $(call if_changed_dep,gen_cc_s_c)

-$(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s Kbuild
+$(obj)/$(kernel-offsets-file): kernel/kernel-offsets.s Kbuild
$(call cmd,kbuild_gen)

#####
-# 3) Check for missing system calls
+# 4) Check for missing system calls
#

quiet_cmd_syscalls = CALL $<
@@ -78,4 +101,4 @@ missing-syscalls: scripts/checksyscalls.sh FORCE
$(call cmd,syscalls)

# Keep these two files during make clean
-no-clean-files := $(bounds-file) $(offsets-file)
+no-clean-files := $(bounds-file) $(asm-offsets-file) $(kernel-offsets-file)
diff --git a/kernel/kernel-offsets.c b/kernel/kernel-offsets.c
new file mode 100644
index 0000000..fb73ccf
--- /dev/null
+++ b/kernel/kernel-offsets.c
@@ -0,0 +1,14 @@
+/*
+ * Generate definitions needed by assembly language modules.
+ *
+ * Copyright (C) 2010 Lai Jiangshan
+ */
+
+#include <linux/kbuild.h>
+
+void foo(void);
+
+void foo(void)
+{
+}
+
--
1.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/