From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 6 Mar 2008 21:51:14 +0100 From: Sam Ravnborg Subject: Re: [patch 2/8] Kbuild: Create a way to create preprocessor constants from C expressions Message-ID: <20080306205114.GA29026@uranus.ravnborg.org> References: <20080305223815.574326323@sgi.com> <20080305223845.436523065@sgi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080305223845.436523065@sgi.com> Sender: owner-linux-mm@kvack.org Return-Path: To: Christoph Lameter Cc: Andrew Morton , ak@suse.de, Mel Gorman , apw@shadowen.org, KAMEZAWA Hiroyuki , KOSAKI Motohiro , Rik van Riel , linux-mm@kvack.org List-ID: Hi Christoph Sorry for getting back to you so late. Too busy with day-time job atm. On Wed, Mar 05, 2008 at 02:38:17PM -0800, Christoph Lameter wrote: > 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 > Signed-off-by: Christoph Lameter > > --- > 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)) We build a bounds.s file later so it needs to be listed as we do with asm-offsets.s: targets += kernel/bounds.s > > @@ -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) OK > + > +$(obj)/$(bounds): kernel/bounds.s Kbuild > + $(Q)mkdir -p $(dir $@) > + $(call cmd,bounds) OK > + > ##### > # 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 > + > +#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 @@ NO NO - we do not add files to the tree we overwrite. The kbuild stuff will take care that the file is generated before we start the kernel build. I have fixed it up and rearranged stuff to follow the style of the Kbuild file. diff --git a/Kbuild b/Kbuild index 1570d24..0198e3f 100644 --- a/Kbuild +++ b/Kbuild @@ -2,7 +2,8 @@ # Kbuild for top-level directory of the kernel # This file takes care of the following: # 1) Generate asm-offsets.h -# 2) Check for missing system calls +# 2) Generate bounds.h +# 3) Check for missing system calls ##### # 1) Generate asm-offsets.h @@ -13,7 +14,7 @@ offsets-file := include/asm-$(SRCARCH)/asm-offsets.h always := $(offsets-file) targets := $(offsets-file) targets += arch/$(SRCARCH)/kernel/asm-offsets.s -clean-files := $(addprefix $(objtree)/,$(targets)) + # Default sed regexp - multiline due to syntax constraints define sed-y @@ -49,7 +50,41 @@ $(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s Kbuild $(call cmd,offsets) ##### -# 2) Check for missing system calls +# 2) Generate bounds.h + +bounds-file := include/linux/bounds.h + +always += $(bounds-file) +targets += $(bounds-file) kernel/bounds.s + +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 +kernel/bounds.s: kernel/bounds.c FORCE + $(Q)mkdir -p $(dir $@) + $(call if_changed_dep,cc_s_c) + +$(obj)/$(bounds-file): kernel/bounds.s Kbuild + $(Q)mkdir -p $(dir $@) + $(call cmd,bounds) + +##### +# 3) Check for missing system calls # quiet_cmd_syscalls = CALL $< @@ -58,3 +93,7 @@ quiet_cmd_syscalls = CALL $< PHONY += missing-syscalls missing-syscalls: scripts/checksyscalls.sh FORCE $(call cmd,syscalls) + +# Delete all targets during make clean +clean-files := $(addprefix $(objtree)/,$(targets)) + -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org