[OpenBIOS] [PATCH v2] Allow building on Mac OS X

Programmingkid programmingkidx at gmail.com
Fri Apr 17 06:25:50 CEST 2015


This is version two of the patch that allows for building on Mac OS X. It addresses 
several issues that needed to be changed. This version has these changes:
- Keeps sh as the shell to build OpenBIOS on.
- Removed the prefix_specified() function.
- Replaced Bash shell code with awk functionality.
- Added error handling for missing -prefix and -arch values.
- Allows for using more that one compiler even if the -prefix option is used. 
- Keeps the -Werror option.

I would like to note that this patch has been tested on Debian Linux and 
Mac OS X. 


Index: config/scripts/switch-arch
===================================================================
--- config/scripts/switch-arch	(revision 1334)
+++ config/scripts/switch-arch	(working copy)
@@ -6,7 +6,7 @@
 MOLPATH=$HOME/mol-0.9.71
 
 if [ x"$1" = x -o "$1" = "-help" ]; then
-  printf "Usage:\n  $0 [arch-config]...\n"
+  printf "Usage:\n  $0 [arch-config] [-arch architecture] [-prefix compiler prefix]\n"
   printf "arch-config values supported for native or cross compiled builds:\n"
   printf " amd64, ppc, sparc32, sparc64, x86\n\n"
   printf "Add \"unix-\" prefix to compile openbios-unix executable (native only)\n"
@@ -13,7 +13,13 @@
   printf "Add \"builtin-\" prefix to compile openbios-builtin executables\n\n"
   printf "Without prefixes, builtin and unix targets are selected\n\n"
   printf "Special targets: mol-ppc briq-ppc pearpc-ppc qemu-ppc qemu-ppc64 xbox-x86\n\n"
-  printf "Example: $0 builtin-sparc32 unix-amd64 builtin-amd64\n"
+  printf "Example: $0 builtin-sparc32 unix-amd64 builtin-amd64\n\n"
+  printf "The -arch option is used if your uname command does not output the correct\n"
+  printf "value for your system. This is an issue for some versions of Mac OS X.\n"
+  printf "Example: -arch amd64\n\n"
+  printf "The -prefix option is for specifying your compiler prefix.\n"
+  printf "If your compiler is called ppc-elf-gcc, then your prefix would be ppc-elf-\n"
+  printf "In this case you would use -prefix ppc-elf-\n\n"
   exit 0
 fi
 
@@ -89,17 +95,77 @@
     CROSSCFLAGS=$cflags
 }
 
+
+## Determines if user specified an architecture ##
+architecture_specified()
+{
+    for arg in $SCRIPT_ARGS
+    do
+        if [ "$arg" = "-arch" ]
+        then
+            return 1
+        fi
+    done
+    return 0
+}
+
+## Returns the user specified architecture ##
+get_specified_architecture()
+{
+    while [ "$1" != "" ]
+    do
+        if [ "$1" = "-arch" ]
+        then
+            shift
+            if [ "$1" ]
+            then
+                echo "$1"
+            else
+                echo "ERROR-MISSING-ARCHITECTURE!!!"
+            fi
+            return
+        fi
+        shift
+    done
+}
+
 archname()
 {
-    HOSTARCH=`uname -m | sed -e s/i.86/x86/ -e s/i86pc/x86/ \
-	-e s/sun4u/sparc64/ -e s/sparc$/sparc32/ \
-	-e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
-	-e "s/Power Macintosh/ppc/"`
+    architecture_specified $SCRIPT_ARGS
+    if [ "$?" -eq 1 ]
+    then
+        HOSTARCH=`get_specified_architecture $SCRIPT_ARGS`
+    else
+        HOSTARCH=`uname -m | sed -e s/i.86/x86/ -e s/i86pc/x86/ \
+        -e s/sun4u/sparc64/ -e s/sparc$/sparc32/ \
+        -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
+        -e "s/Power Macintosh/ppc/"`
+    fi
 }
 
+## Returns the user specified compiler prefix ##
+get_specified_prefix()
+{
+    while [ "$1" != "" ]
+    do
+        if [ "$1" = "-prefix" ]
+        then
+            shift
+            if [ "$1" ]
+            then
+                echo "$1"
+            else
+                echo "MISSING-PREFIX-VALUE!!!"
+            fi
+            return
+        fi
+        shift
+    done
+}
+
 select_prefix()
 {
-    for TARGET in ${1}-unknown-linux-gnu- ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi-
+    for TARGET in ${1}-unknown-linux-gnu- ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi- $(get_specified_prefix $SCRIPT_ARGS)
     do
         if type ${TARGET}gcc > /dev/null 2>&1
         then
@@ -127,6 +193,7 @@
 
 SRCDIR=`dirname "$0"`/../..
 BUILDDIR=`pwd`
+SCRIPT_ARGS=$*  # needed for functions that need to know arguments send to this script
 
 # make source path absolute
 SRCDIR=`cd "$SRCDIR"; pwd`
@@ -147,7 +214,34 @@
 fi
 
 target_list=""
-for target in $*; do
+
+# filters out the -prefix and -arch options from the target list
+filtered_list=`awk -v arg_string="$*" 'BEGIN { 
+    prefix_position = index(arg_string, "-prefix")
+    arch_position = index(arg_string, "-arch")
+    end = 0 # The end of the target list string before the other options
+    
+    ### Find the end of the substring to keep ###
+    
+    if(prefix_position == 0 && arch_position == 0) {
+        end = length(arg_string)
+    }
+    else if(prefix_position == 0) {
+        end = (arch_position - 1)
+    }
+    else if (arch_position == 0) {
+        end = (prefix_position - 1)
+    }
+    else if(arch_position < prefix_position) {
+        end = (arch_position - 1)
+    }
+    else {
+        end = (prefix_position - 1)
+    }
+    print substr(arg_string, 1, end)
+}'`
+
+for target in $filtered_list; do
     case $target in
         unix-*|builtin-*|plain-*|mol-ppc|briq-ppc|pearpc-ppc|qemu-ppc|qemu-ppc64|xbox-x86)
         target_list="$target_list $target"


More information about the OpenBIOS mailing list