lkml.org 
[lkml]   [2008]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[rfc 07/10] Kbuild: Create a way to create preprocessor constants from C expressions
The use of enums create constants that are not available to the preprocessor
when building the kernel (f.e. MAX_NR_ZONES).

Arch code already has a way to export constants calculated to the
preprocessor through the asm-offsets.c file. Generate something
similar for the core kernel through kbuild.

Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Christoph Lameter <clameter@sgi.com>

---
Kbuild | 31 +++++++++++++++++++++++++++++--
include/linux/bounds.h | 10 ++++++++++
kernel/bounds.c | 16 ++++++++++++++++
3 files changed, 55 insertions(+), 2 deletions(-)

Index: linux-2.6/Kbuild
===================================================================
--- linux-2.6.orig/Kbuild 2008-02-29 19:27:40.000000000 -0800
+++ linux-2.6/Kbuild 2008-02-29 19:29:38.000000000 -0800
@@ -9,9 +9,10 @@
#

offsets-file := include/asm-$(SRCARCH)/asm-offsets.h
+bounds := include/linux/bounds.h

-always := $(offsets-file)
-targets := $(offsets-file)
+always := $(offsets-file) $(bounds)
+targets := $(offsets-file) $(bounds)
targets += arch/$(SRCARCH)/kernel/asm-offsets.s
clean-files := $(addprefix $(objtree)/,$(targets))

@@ -39,6 +40,23 @@ define cmd_offsets
echo "#endif" ) > $@
endef

+quiet_cmd_bounds = GEN $@
+define cmd_bounds
+ (set -e; \
+ echo "#ifndef __LINUX_BOUNDS_H__"; \
+ echo "#define __LINUX_BOUNDS_H__"; \
+ echo "/*"; \
+ echo " * DO NOT MODIFY."; \
+ echo " *"; \
+ echo " * This file was generated by Kbuild"; \
+ echo " *"; \
+ echo " */"; \
+ echo ""; \
+ sed -ne $(sed-y) $<; \
+ echo ""; \
+ echo "#endif" ) > $@
+endef
+
# 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 FORCE
$(Q)mkdir -p $(dir $@)
@@ -48,6 +66,15 @@ $(obj)/$(offsets-file): arch/$(SRCARCH)/
$(Q)mkdir -p $(dir $@)
$(call cmd,offsets)

+# 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)
+
+$(obj)/$(bounds): kernel/bounds.s Kbuild
+ $(Q)mkdir -p $(dir $@)
+ $(call cmd,bounds)
+
#####
# 2) Check for missing system calls
#
Index: linux-2.6/kernel/bounds.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/kernel/bounds.c 2008-02-29 19:29:38.000000000 -0800
@@ -0,0 +1,16 @@
+/*
+ * Generate definitions needed by the preprocessor.
+ * This code generates raw asm output which is post-processed
+ * to extract and format the required data.
+ */
+
+#include <linux/mm.h>
+
+#define DEFINE(sym, val) \
+ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+void foo(void)
+{
+}
Index: linux-2.6/include/linux/bounds.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/include/linux/bounds.h 2008-02-29 19:29:50.000000000 -0800
@@ -0,0 +1,10 @@
+#ifndef __LINUX_BOUNDS_H__
+#define __LINUX_BOUNDS_H__
+/*
+ * DO NOT MODIFY.
+ *
+ * This file was generated by Kbuild
+ *
+ */
+
+#endif
--


\
 
 \ /
  Last update: 2008-03-04 01:13    [W:0.063 / U:28.776 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site