[OpenBIOS] [PATCH] Support any build directory

Blue Swirl blauwirbel at gmail.com
Sun Aug 28 17:28:11 CEST 2011


Detect source path from switch-arch call path. Always use absolute
paths. Fix bootstrap.c so that for absolute paths, in addition to
include directives (-I), the bare path is checked.

Signed-off-by: Blue Swirl <blauwirbel at gmail.com>
---
The motivation is to integrate OpenBIOS to QEMU build system.
---
 Makefile                   |    3 +-
 Makefile.target            |    3 +-
 config/scripts/switch-arch |  107 ++++++++++++++++++++++---------------------
 kernel/bootstrap.c         |   53 +++++++++++++--------
 4 files changed, 91 insertions(+), 75 deletions(-)

diff --git a/Makefile b/Makefile
index 74e462c..d7c0422 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,4 @@
-ODIRS=$(wildcard obj-*)
-TARGETS=$(subst obj-,,$(ODIRS))
+include config.mak

 all: requirements info build

diff --git a/Makefile.target b/Makefile.target
index 934b95a..ecb9ad4 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -3,10 +3,11 @@
 # (C) 2004-2009 by the OpenBIOS team
 #

+include ../config.mak
 include config.mak

 ODIR := .
-SRCDIR := ..
+
 HOSTCC := gcc

 HOSTCFLAGS+= -O2 -g -DFCOMPILER -DBOOTSTRAP $(CROSSCFLAGS)
diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch
index 1e630da..883de42 100755
--- a/config/scripts/switch-arch
+++ b/config/scripts/switch-arch
@@ -117,21 +117,18 @@ config_set_boolean()
     echo "<option name=\"$option\" type=\"boolean\" value=\"true\" />"
 }

-if ! test -f utils/dist/debian/rules; then
-	echo "switch-arch must be run from the top-level source directory" >&2
-	exit 1
-fi

-# This is needed because viewvc messes with the permissions of executables:
-chmod 755 utils/dist/debian/rules
-chmod 755 config/scripts/switch-arch
-chmod 755 config/scripts/reldir
+SRCDIR=`dirname "$0"`/../..
+BUILDDIR=`pwd`
+
+# make source path absolute
+SRCDIR=`cd "$SRCDIR"; pwd`

 if test "x$HOSTARCH" = "x"; then
     archname
 fi

-VERSION=`head VERSION`
+VERSION=`head $SRCDIR/VERSION`

 echo "Configuring OpenBIOS on $HOSTARCH for $*"

@@ -156,8 +153,8 @@ done
 arch_list=""
 for target in $target_list; do
     arch=`echo $target | sed s/.*-//g`
-    if ! test -f config/examples/${arch}_config.xml; then
-        echo "Cannot find config/examples/${arch}_config.xml" >&2
+    if ! test -f $SRCDIR/config/examples/${arch}_config.xml; then
+        echo "Cannot find $SRCDIR/config/examples/${arch}_config.xml" >&2
         exit 1
     fi
     if ! echo $arch_list | grep -q "$arch"; then
@@ -268,7 +265,8 @@ for ARCH in $arch_list; do
         cross="yes"
     fi
     crosscflags $HOSTARCH $ARCH
-    OBJDIR=obj-$ARCH
+    OBJDIR=$BUILDDIR/obj-$ARCH
+    ODIRS="$ODIRS $OBJDIR"

     printf "Initializing build tree $OBJDIR..."
     rm -rf "$OBJDIR"
@@ -293,9 +291,9 @@ for ARCH in $arch_list; do
     mkdir -p $OBJDIR/host/include
     mkdir -p $OBJDIR/host/kernel
     mkdir -p $OBJDIR/forth
-    ln -s ../../../include/arch/$BASEARCH $OBJDIR/target/include/asm
+    ln -s  $SRCDIR/include/arch/$BASEARCH $OBJDIR/target/include/asm
     #compile the host binary with target settings instead
-    #ln -s ../../../include/arch/$HOSTARCH $OBJDIR/host/include/asm
+    #ln -s $SRCDIR/include/arch/$HOSTARCH $OBJDIR/host/include/asm
     if [ "$mol" = "yes" ]; then
         printf "\nUsing MOL path $MOLPATH...\n"
         mkdir -p $OBJDIR/target/arch/ppc/mol
@@ -323,73 +321,78 @@ for ARCH in $arch_list; do
     fi
     echo "ok."

-    cd $OBJDIR
-    SRCDIR=..
-    ODIR=.
-
-    printf "Creating target Makefile..."
-    echo "ARCH=$ARCH" > $ODIR/config.mak
+    printf "Creating target config.mak..."
+    echo "ARCH=$ARCH" > $OBJDIR/config.mak
     if [ "$cross" = "yes" ]; then
-        echo "TARGET=$TARGET" >> $ODIR/config.mak
+        echo "TARGET=$TARGET" >> $OBJDIR/config.mak
     fi
-    echo "CFLAGS=$CFLAGS" >> $ODIR/config.mak
-    echo "AS_FLAGS=$AS_FLAGS" >> $ODIR/config.mak
-    echo "HOSTARCH?=$HOSTARCH" >> $ODIR/config.mak
-    echo "CROSSCFLAGS=$CROSSCFLAGS" >> $ODIR/config.mak
-    echo "VERSION=\"$VERSION\"" >> $ODIR/config.mak
-
-    ln -s $SRCDIR/config/xml/rules.xml $ODIR/rules.xml
-    echo "<?xml version=\"1.0\"?><config>" > $ODIR/config.xml
+    echo "CFLAGS=$CFLAGS" >> $OBJDIR/config.mak
+    echo "AS_FLAGS=$AS_FLAGS" >> $OBJDIR/config.mak
+    echo "HOSTARCH?=$HOSTARCH" >> $OBJDIR/config.mak
+    echo "CROSSCFLAGS=$CROSSCFLAGS" >> $OBJDIR/config.mak
+    echo "VERSION=\"$VERSION\"" >> $OBJDIR/config.mak
+    echo "ok."
+
+    printf "Creating target rules.mak..."
+    ln -s $SRCDIR/config/xml/rules.xml $OBJDIR/rules.xml
+    echo "<?xml version=\"1.0\"?><config>" > $OBJDIR/config.xml
     # Generic
-    config_set_boolean CONFIG_$ARCH >> $ODIR/config.xml
+    config_set_boolean CONFIG_$ARCH >> $OBJDIR/config.xml
     if [ "$BASEARCH" != "$ARCH" ]; then
-        config_set_boolean CONFIG_$BASEARCH >> $ODIR/config.xml
+        config_set_boolean CONFIG_$BASEARCH >> $OBJDIR/config.xml
     fi
     if [ "$mol" = "yes" ]; then
-        config_set_boolean CONFIG_MOL >> $ODIR/config.xml
+        config_set_boolean CONFIG_MOL >> $OBJDIR/config.xml
     fi
     if [ "$briq" = "yes" ]; then
-        config_set_boolean CONFIG_BRIQ >> $ODIR/config.xml
+        config_set_boolean CONFIG_BRIQ >> $OBJDIR/config.xml
     fi
     if [ "$pearpc" = "yes" ]; then
-        config_set_boolean CONFIG_PEARPC >> $ODIR/config.xml
+        config_set_boolean CONFIG_PEARPC >> $OBJDIR/config.xml
     fi
     if [ "$qemu" = "yes" ]; then
-        config_set_boolean CONFIG_QEMU >> $ODIR/config.xml
+        config_set_boolean CONFIG_QEMU >> $OBJDIR/config.xml
     fi
     if [ "$xbox" = "yes" ]; then
-        config_set_boolean CONFIG_XBOX >> $ODIR/config.xml
+        config_set_boolean CONFIG_XBOX >> $OBJDIR/config.xml
     fi
     if [ "$targetbigendian" = "yes" ]; then
-        config_set_boolean CONFIG_BIG_ENDIAN >> $ODIR/config.xml
+        config_set_boolean CONFIG_BIG_ENDIAN >> $OBJDIR/config.xml
     else
-        config_set_boolean CONFIG_LITTLE_ENDIAN >> $ODIR/config.xml
+        config_set_boolean CONFIG_LITTLE_ENDIAN >> $OBJDIR/config.xml
     fi
     # Kernel binaries
     if [ "$plain" = "yes" ]; then
-        config_set_boolean CONFIG_IMAGE_ELF >> $ODIR/config.xml
+        config_set_boolean CONFIG_IMAGE_ELF >> $OBJDIR/config.xml
     fi
     if [ "$builtin" = "yes" ]; then
-        config_set_boolean CONFIG_IMAGE_ELF_EMBEDDED >> $ODIR/config.xml
+        config_set_boolean CONFIG_IMAGE_ELF_EMBEDDED >> $OBJDIR/config.xml
     fi
     # Build hosted Unix binary?
     if [ "$unix" = "yes" ]; then
-        config_set_boolean CONFIG_HOST_UNIX >> $ODIR/config.xml
-        #config_set_boolean CONFIG_UNIX_QT >> $ODIR/config.xml
-        #config_set_boolean CONFIG_PLUGINS >> $ODIR/config.xml
+        config_set_boolean CONFIG_HOST_UNIX >> $OBJDIR/config.xml
+        #config_set_boolean CONFIG_UNIX_QT >> $OBJDIR/config.xml
+        #config_set_boolean CONFIG_PLUGINS >> $OBJDIR/config.xml
     fi
-    cat $SRCDIR/config/examples/${ARCH}_config.xml >> $ODIR/config.xml
+    cat $SRCDIR/config/examples/${ARCH}_config.xml >> $OBJDIR/config.xml

-    echo "</config>" >> $ODIR/config.xml
-    ln -s ../Makefile.target $ODIR/Makefile
-    xsltproc $SRCDIR/config/xml/xinclude.xsl $SRCDIR/build.xml >
$ODIR/build-full.xml
-    xsltproc $SRCDIR/config/xml/makefile.xsl $ODIR/build-full.xml >
$ODIR/rules.mak
+    cd $OBJDIR
+    echo "</config>" >> $OBJDIR/config.xml
+    ln -s $SRCDIR/Makefile.target $OBJDIR/Makefile
+    xsltproc $SRCDIR/config/xml/xinclude.xsl $SRCDIR/build.xml >
$OBJDIR/build-full.xml
+    xsltproc $SRCDIR/config/xml/makefile.xsl $OBJDIR/build-full.xml >
$OBJDIR/rules.mak
     echo "ok."
     printf "Creating config files..."
-    xsltproc $SRCDIR/config/xml/config-c.xsl $ODIR/config.xml >
$ODIR/host/include/autoconf.h
-    xsltproc $SRCDIR/config/xml/config-c.xsl $ODIR/config.xml >
$ODIR/target/include/autoconf.h
-    xsltproc $SRCDIR/config/xml/config-forth.xsl $ODIR/config.xml >
$ODIR/forth/config.fs
+    xsltproc $SRCDIR/config/xml/config-c.xsl $OBJDIR/config.xml >
$OBJDIR/host/include/autoconf.h
+    xsltproc $SRCDIR/config/xml/config-c.xsl $OBJDIR/config.xml >
$OBJDIR/target/include/autoconf.h
+    xsltproc $SRCDIR/config/xml/config-forth.xsl $OBJDIR/config.xml >
$OBJDIR/forth/config.fs
     echo "ok."

-    cd $SRCDIR
+    cd $BUILDDIR
 done
+
+ln -s $SRCDIR/Makefile $BUILDDIR
+
+echo "SRCDIR=$SRCDIR" > $BUILDDIR/config.mak
+echo "ODIRS=$ODIRS" >> $BUILDDIR/config.mak
+echo "TARGETS=$arch_list" >> $BUILDDIR/config.mak
diff --git a/kernel/bootstrap.c b/kernel/bootstrap.c
index 546ffee..59f504f 100644
--- a/kernel/bootstrap.c
+++ b/kernel/bootstrap.c
@@ -499,6 +499,25 @@ static void add_includepath(char *path)
 	newpath->next = NULL;
 }

+static FILE *try_path(const char *file)
+{
+    FILE *ret;
+
+    ret = fopen(file, "r");
+    if (ret != NULL) {
+#ifdef CONFIG_DEBUG_INTERPRETER
+        printk("Including '%s'\n", file);
+#endif
+        srcfilenames[cursrc] = strdup(file);
+        srclines[cursrc] = 1;
+        srcfiles[cursrc++] = ret;
+
+        if (depfile) {
+            fprintf(depfile, " %s", file);
+        }
+    }
+    return ret;
+}

 static FILE *fopen_include(const char *fil)
 {
@@ -506,28 +525,22 @@ static FILE *fopen_include(const char *fil)
 	FILE *ret;
 	include *incl = &includes;

-	while (incl) {
-                snprintf(fullpath, sizeof(fullpath), "%s/%s", incl->path, fil);
-
-		ret = fopen(fullpath, "r");
-		if (ret != NULL) {
+        while (incl) {
+            snprintf(fullpath, sizeof(fullpath), "%s/%s", incl->path, fil);

-#ifdef CONFIG_DEBUG_INTERPRETER
-			printk("Including '%s'\n", name );
-#endif
-                        srcfilenames[cursrc] = strdup(fil);
-			srclines [ cursrc ] = 1;
-			srcfiles [ cursrc++ ] = ret;
-
-                        if (depfile) {
-                                fprintf(depfile, " %s", fullpath);
-                        }
-
-			return ret;
-		}
+            ret = try_path(fullpath);
+            if (ret) {
+                return ret;
+            }

-		incl = incl->next;
-	}
+            incl = incl->next;
+        }
+        if (fil[0] == '/') {
+            ret = try_path(fil);
+            if (ret) {
+                return ret;
+            }
+        }
 	return NULL;
 }

-- 
1.6.2.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Support-any-build-directory.patch
Type: text/x-diff
Size: 10483 bytes
Desc: not available
URL: <http://lists.openbios.org/pipermail/openbios/attachments/20110828/4cd7c987/attachment.bin>


More information about the OpenBIOS mailing list