Skip to contentSkip to conversation

Separate obj dir [2]

CFT Sam Ravnborg 1 participant 2 messages Nov 23, 2002 – Nov 24, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Here goes second version of separate obj dir patch. I have modified kconfig so no need to copy kconfig related files anymore. Patch is sent to Roman already for review.

Usage as before:
cd to the directory where you want to compile call kbuild located in the root of the kernel src.

kbuild passes all options to make.

As the last thread clearly showed there is interest for this feature, but I do not plan to submit it for inclusion before I get some more test-feedback.

Also I want to sort out the kconfig changes separate, since I prefer the maintainer to send this to Linus.

Another related issue is that this patch touches areas in the Makefiles that may interfere with the module stuff, and thats more important to get in right now.

If you try this out based on attached patch make sure to uncomment LKC_GENPARSER in scripts/kconfig/Makefile.

The diff of the three generated files were too big, mainly becasue I do not have the same flex and bison version as Roman.

Testing appreciated,

Sam

Patch on top of 2.5.49.

Can be pulled from http://linux-sam.bkbits.net/sepobjdir

 Makefile                   |   22 ++++++++++++++++------
 scripts/Makefile.build     |   41 ++++++++++++++++++++---------------------
 scripts/Makefile.lib       |    8 +++++++-
 scripts/kconfig/Makefile   |    5 ++++-
 scripts/kconfig/confdata.c |   13 ++++++++++---
 scripts/kconfig/expr.h     |    2 ++
 scripts/kconfig/symbol.c   |    7 +++++++
 scripts/kconfig/zconf.l    |   27 +++++++++++++++++++++++++--
 8 files changed, 91 insertions(+), 34 deletions(-)

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.857 -> 1.858
# scripts/kconfig/symbol.c 1.2 -> 1.3
# scripts/kconfig/zconf.tab.c_shipped 1.2 -> 1.3
# scripts/kconfig/expr.h 1.2 -> 1.3
# scripts/kconfig/zconf.l 1.3 -> 1.4
# scripts/kconfig/lex.zconf.c_shipped 1.3 -> 1.4
# scripts/kconfig/zconf.tab.h_shipped 1.2 -> 1.3
# scripts/kconfig/confdata.c 1.3 -> 1.4
# scripts/kconfig/Makefile 1.2 -> 1.3
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/11/23 [email protected] 1.858
# kconfig: Try to locate files in $srctree
#
# In order to support separate src/obj dir, try locating

# files in tree pointed out by $srctree as second alternative
# --------------------------------------------
#
diff -Nru a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
--- a/scripts/kconfig/symbol.c	Sat Nov 23 22:53:43 2002
+++ b/scripts/kconfig/symbol.c	Sat Nov 23 22:53:43 2002
@@ -75,6 +75,13 @@
 	if (p)
 		sym_add_default(sym, p);

+ sym = sym_lookup(SRCTREE, 0);
+ sym->type = S_STRING;
+ sym->flags |= SYMBOL_AUTO;
+ p = getenv(SRCTREE);
+ if (p)
+ sym_add_default(sym, p);
+
sym = sym_lookup("UNAME_RELEASE", 0); sym->type = S_STRING;
sym->flags |= SYMBOL_AUTO;

scripts/kconfig/zconf.l +25 -2
diff -Nru a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
@@ -249,9 +249,32 @@
 	BEGIN(INITIAL); 
 }
 
+/* 
+   Try to open specified file with following names:
+   ./name
+   $(srctree)/name
+   The latter is used when srctree is separate from objtree
+   when compiling the kernel.
+   Return NULL if file is not found.
+*/
+static FILE *zconf_fopen(const char *name)
+{
+	static char fullname[SYMBOL_MAXLENGTH];
+	static char *p;
+	FILE *f = fopen(name, "r");
+	if (f)
+		return f;
+	p = getenv(SRCTREE);
+	if (p) {
+		sprintf(fullname, "%s/%s", p, name);
+		return fopen(fullname, "r");
+	}
+	return NULL;
+}
+
 void zconf_initscan(const char *name)
 {
-	yyin = fopen(name, "r");
+	yyin = zconf_fopen(name);
 	if (!yyin) {
 		printf("can't find file %s\n", name);
 		exit(1);
@@ -272,7 +295,7 @@
 	memset(buf, 0, sizeof(*buf));
 
 	current_buf->state = YY_CURRENT_BUFFER;
-	yyin = fopen(name, "r");
+	yyin = zconf_fopen(name);
 	if (!yyin) {
 		printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
 		exit(1);
scripts/kconfig/Makefile +4 -1
diff -Nru a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
@@ -77,12 +77,15 @@
 ifdef LKC_GENPARSER
 
 $(obj)/zconf.tab.c: $(obj)/zconf.y 
-$(obj)/zconf.tab.h: $(obj)/zconf.tab.c
+$(obj)/zconf.tab.h: $(obj)/zconf.y
 
 %.tab.c: %.y
 	bison -t -d -v -b $* -p $(notdir $*) $<
+	cp $@ $@_shipped
+	cp $(@:.c=.h) $(@:.c=.h)_shipped
 
 lex.%.c: %.l
 	flex -P$(notdir $*) -o$@ $<
+	cp $@ $@_shipped
 
 endif
scripts/kconfig/confdata.c +10 -3
diff -Nru a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 #define LKC_DIRECT_LINK
@@ -14,14 +15,16 @@
 
 const char conf_def_filename[] = ".config";
 
-const char conf_defname[] = "arch/$ARCH/defconfig";
+#define DEFNAME    4
+#define DEFALTNAME 5
 
 const char *conf_confnames[] = {
 	".config",
 	"/lib/modules/$UNAME_RELEASE/.config",
 	"/etc/kernel-config",
 	"/boot/config-$UNAME_RELEASE",
-	conf_defname,
+	"arch/$ARCH/defconfig",			/* index DEFNAME */
+	"$" SRCTREE "/arch/$ARCH/defconfig",	/* index DEFALTNAME */
 	NULL,
 };
 
@@ -53,7 +56,11 @@
 
 char *conf_get_default_confname(void)
 {
-	return conf_expand_value(conf_defname);
+	struct stat buf;
+	char * name = conf_expand_value(conf_confnames[DEFNAME]);
+	if (!stat(name, &buf))
+		return name;
+	return conf_expand_value(conf_confnames[DEFALTNAME]);
 }
 
 int conf_read(const char *name)
scripts/kconfig/expr.h +2 -0
diff -Nru a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
@@ -127,6 +127,8 @@
 #define SYMBOL_HASHSIZE		257
 #define SYMBOL_HASHMASK		0xff
 
+#define SRCTREE "srctree"
+
 enum prop_type {
 	P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_ROOTMENU, P_DEFAULT, P_CHOICE
 };

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:

#	           ChangeSet	1.858   -> 1.859  
#	            Makefile	1.350   -> 1.351  
#	scripts/Makefile.lib	1.4     -> 1.5    

# scripts/Makefile.build 1.11 -> 1.12
#
# The following is the BitKeeper ChangeSet Log # --------------------------------------------
# 02/11/23 [email protected] 1.859
# kbuild: Support for separate obj dir
# -------------------------------------------- #

Makefile +16 -6
diff -Nru a/Makefile b/Makefile
@@ -135,14 +135,20 @@
 
 export quiet Q KBUILD_VERBOSE
 
-#	Paths to obj / src tree
-
-src	:= .
-obj	:= .
+#       Paths to obj / src tree
+ifneq ($(wildcard .tmp_make_config),)
+include .tmp_make_config
+src     := $(srctree)
+obj     := .
+VPATH   := $(srctree)
+else
+src     := .
+obj     := .
 srctree := .
 objtree := .
+endif
 
-export srctree objtree
+export srctree objtree VPATH
 
 # 	Make variables (CC, etc...)
 
@@ -419,7 +425,11 @@
 
 include/asm:
 	@echo '  Making asm->asm-$(ARCH) symlink'
+ifeq ($(srctree),$(objtree))
 	@ln -s asm-$(ARCH) $@
+else
+	@ln -s $(src)/include/asm-$(ARCH) $@
+endif
 
 # 	Split autoconf.h into include/linux/config/*
 
@@ -598,7 +608,7 @@
 	tar -cvz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \
 	rm $(KERNELPATH) ; \
 	cd $(TOPDIR) ; \
-	. scripts/mkversion > .version ; \
+	$(CONFIG_SHELL) $(src)/scripts/mkversion > .version ; \
 	rpm -ta $(TOPDIR)/../$(KERNELPATH).tar.gz ; \
 	rm $(TOPDIR)/../$(KERNELPATH).tar.gz
 
scripts/Makefile.build +20 -21

99 lines not on this page · raw message

scripts/Makefile.lib +7 -1
diff -Nru a/scripts/Makefile.lib b/scripts/Makefile.lib
@@ -128,6 +128,12 @@
 c_flags        = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
 	         $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
 	         $(basename_flags) $(modname_flags) $(export_flags) 
+a_flags        = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS)\
+		 $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
+hostc_flags    = -Wp,-MD,$(depfile) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS)\
+		 $(HOSTCFLAGS_$(*F).o)
+hostcxx_flags  = -Wp,-MD,$(depfile) $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS)\
+		 $(HOSTCXXFLAGS_$(*F).o)
 
 # Finds the multi-part object the current object will be linked into
 modname-multi = $(subst $(space),_,$(sort $(foreach m,$(multi-used),\
@@ -139,7 +145,7 @@
 quiet_cmd_shipped = SHIPPED $@
 cmd_shipped = cat $< > $@
 
-%:: %_shipped
+$(obj)/%:: $(src)/%_shipped
 	$(call cmd,shipped)
 
 # Commands useful for building a boot image
#1 lore raw

Hi all.

I the previous mail I forgot the kbuild script - sorry. Here it comes (as a patch).

Sam

kbuild new file +48 -0
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# This script is used to build a kernel from a directory
+# separate from the kernel src tree.
+# The location of this script is assumed to be the root of
+# the kernel src tree. Do not copy it elsewhere.
+# Usage: kbuild [Usual options provided to make]
+
+# kbuild prints out SRCTREE and OBJTREE when started, and then makes 
+# symlinks of relevant files from the kernelsrc.
+
+# Files we do not care about in the kernel src
+RCS_FIND_IGNORE="-name SCCS -o -name BitKeeper -o -name .svn -o -name CVS"
+
+# Obtain absolute paths for SRCTREE and OBJTREE
+OBJTREE=$PWD
+cd `dirname $0`
+SRCTREE=$PWD
+cd $OBJTREE
+echo OBJTREE $OBJTREE
+echo SRCTREE $SRCTREE
+
+# If kbuild is executed from the root of the kernel src tree just call make
+if [ "$SRCTREE" == "$OBJTREE" ]; then
+  rm -f .tmp_make_config
+  make $*
+else
+  # A directory separate from kernel src tree
+  # Test if make has been executed in kernel src tree already
+  if [ -f $SRCTREE/.config -o -d $SRCTREE/include/asm ]; then
+    echo '$SRCTREE contains generated files, please run "make mrproper" in the SRCTREE'
+  else
+    # Symlink relevant files
+    for a in `cd $SRCTREE; \
+      find \( $RCS_FIND_IGNORE \) -prune -o -name Makefile\*`; do
+      if [ ! -d `dirname $a` ]; then
+        mkdir -p $a
+      fi
+      ln -fs $SRCTREE/$a $a
+    done
+
+    ( echo "srctree := $SRCTREE";
+      echo "objtree := $OBJTREE";
+    ) > .tmp_make_config
+    echo "#Dummy file" > Rules.make
+    make $*
+  fi
+fi