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

Programmingkid programmingkidx at gmail.com
Mon Apr 13 05:21:11 CEST 2015


This patch allows for the building of OpenBIOS on Mac OS X. Version 2 of this patch is a complete rewrite. Rather than adding compiler prefix after compiler prefix, we give the user the ability to specify their compiler's prefix using the -prefix option. My compiler is called ppc-elf-gcc. So I would use -prefix ppc-elf-. This way the user is free to decide what they want to use as a prefix. 

Another feature this patch gives is the ability to specify the computer's architecture. This feature fixes a problem with compiling on Mac OS X. Its uname command doesn't always return the correct cpu architecture. To go around this problem, the user can just specify the architecture with the -arch option like this: -arch amd64. 

This patch has been tested on Mac OS 10.6 and Debian Linux without problem.

Index: Makefile.target
===================================================================
--- Makefile.target	(revision 1334)
+++ Makefile.target	(working copy)
@@ -29,7 +29,7 @@
 CFLAGS+= -Wall -Wredundant-decls -Wshadow -Wpointer-arith
 CFLAGS+= -Wstrict-prototypes -Wmissing-declarations -Wundef -Wendif-labels
 CFLAGS+= -Wstrict-aliasing -Wwrite-strings -Wmissing-prototypes -Wnested-externs
-CFLAGS+= -Werror
+# CFLAGS+= -Werror
 # Flags for dependency generation
 CFLAGS+= -MMD -MP -MT $@ -MF '$(*D)/$(*F).d'
 INCLUDES := -I$(SRCDIR)/include -I$(SRCDIR)/kernel/include -I$(ODIR)/target/include
Index: config/scripts/switch-arch
===================================================================
--- config/scripts/switch-arch	(revision 1334)
+++ config/scripts/switch-arch	(working copy)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 #
 # MOLPATH is needed if you want to build openbios-mol.elf
@@ -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,28 +95,106 @@
     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
+            echo "$1"
+            return
+        fi
+        shift
+    done    
+    echo "ERROR: architecture value not found!"
+}
+
 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
 }
 
-select_prefix()
+## Determines if user specified compiler prefix ##
+prefix_specified()
 {
-    for TARGET in ${1}-unknown-linux-gnu- ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi-
+    for arg in $SCRIPT_ARGS
     do
-        if type ${TARGET}gcc > /dev/null 2>&1
+        if [ "$arg" = "-prefix" ]
         then
+            return 1
+        fi
+    done    
+    return 0
+}
+
+## Returns the user specified compiler prefix ##
+get_specified_prefix()
+{
+    while [ "$1" != "" ]
+    do
+        if [ "$1" = "-prefix" ]
+        then
+            shift
+            echo "$1"
             return
         fi
-    done
-    if [ "$ARCH" = "$HOSTARCH" ]; then
-        return
+        shift
+    done    
+    echo "ERROR: prefix value not found!"
+}
+
+select_prefix()
+{
+    prefix_specified
+    if [ "$?" -eq 1 ]   # if the -prefix option is used
+    then
+        if type $(get_specified_prefix $SCRIPT_ARGS)"gcc" > /dev/null 2>&1
+        then
+            TARGET=$(get_specified_prefix $SCRIPT_ARGS)
+            return
+        else
+            echo "Error: can't find specified prefix!"
+            return
+        fi
+    else
+        for TARGET in ${1}-unknown-linux-gnu- ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi-
+        do
+            if type ${TARGET}gcc > /dev/null 2>&1
+            then
+                return
+            fi
+        done
+        if [ "$ARCH" = "$HOSTARCH" ]; then
+            return
+        fi
+        echo "ERROR: no ${1} cross-compiler found !" 1>&2
+        exit 1
     fi
-    echo "ERROR: no ${1} cross-compiler found !" 1>&2
-    exit 1
 }
 
 config_set_boolean()
@@ -127,6 +211,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 +232,32 @@
 fi
 
 target_list=""
-for target in $*; do
+
+# filters out the -prefix and -arch options from the target list
+awk -v arg_string="$*" 'BEGIN { 
+    prefix_position = index(arg_string, "-prefix")
+    arch_position = index(arg_string, "-arch")
+    if(prefix_position == 0 && arch_position == 0) {
+        exit length(arg_string)
+    }
+    if(prefix_position == 0) {
+        exit (arch_position - 1)
+    }
+    else if (arch_position == 0) {
+        exit (prefix_position - 1)
+    }
+    
+    if(arch_position < prefix_position)
+        exit (arch_position - 1)
+    else
+        exit (prefix_position - 1)
+}'
+
+end=$?
+filtered_list=$*
+filtered_list=${filtered_list:0:$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