Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763760AbYCDALu (ORCPT ); Mon, 3 Mar 2008 19:11:50 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756551AbYCDAHm (ORCPT ); Mon, 3 Mar 2008 19:07:42 -0500 Received: from relay1.sgi.com ([192.48.171.29]:40107 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753536AbYCDAHg (ORCPT ); Mon, 3 Mar 2008 19:07:36 -0500 Message-Id: <20080304000733.688496611@sgi.com> References: <20080304000452.514878384@sgi.com> User-Agent: quilt/0.46-1 Date: Mon, 03 Mar 2008 16:04:59 -0800 From: Christoph Lameter To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Sam Ravnborg Cc: Mel Gorman Cc: apw@shadowen.org Cc: KAMEZAWA Hiroyuki Cc: KOSAKI Motohiro Cc: Rik van Riel Cc: linux-mm@kvack.org Subject: [rfc 07/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: 3439 Lines: 116 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)) @@ -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/