Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762135AbYCAEIt (ORCPT ); Fri, 29 Feb 2008 23:08:49 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757629AbYCAEGw (ORCPT ); Fri, 29 Feb 2008 23:06:52 -0500 Received: from relay2.sgi.com ([192.48.171.30]:58164 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751806AbYCAEGY (ORCPT ); Fri, 29 Feb 2008 23:06:24 -0500 Message-Id: <20080301040621.242006634@sgi.com> References: <20080301040534.797979115@sgi.com> User-Agent: quilt/0.46-1 Date: Fri, 29 Feb 2008 20:05:40 -0800 From: Christoph Lameter To: linux-kernel@vger.kernel.org Cc: Mel Gorman Cc: Nick Piggin Cc: Rik van Riel Cc: Andrew Morton Cc: apw@shadowen.org Cc: linux-mm@kback.org Subject: [rfc 06/10] Kbuild: Create a way to create preprocessor constants from C expressions Content-Disposition: inline; filename=kbuild_cpp_export Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3403 Lines: 115 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. 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)) @@ -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 + +#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 -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/