Re: [AD] gcc universal wrapper script for OS X

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2007-07-21, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
>  Attached is a shell script that wraps around gcc in OS X to create
>  universal binaries. It's main purpose is to work with generic UNIX
>  makefiles. It may create binaries that have better support with older
>  versions of OS X, although I cannot verify that it is still the case.
>  (Judging by the output of "otool -L", they appear to be the same, but
>  I don't know if that's a valid conclusion.) The script only handles
>  the simplest of scenarios, but it's good enough to build Allegro and
>  every other 3rd party library I've had to compile to work with
>  Allegro.
> 
>  So to be clear: There's nothing wrong with Allegro's current universal
>  build process, other than it might not be achieving maximum backward
>  compatibility.
> 
>  As I cannot confirm if either approach produces better binaries than
>  the other, I don't really care which way Allegro uses. But even if the
>  patch isn't applied, it wouldn't hurt to include the script for use
>  with 3rd party libraries.

Committed.  I made some minor changes to the shell script.  The only
change which should be of any real consequence is the way we detect if
"g++" is in the script name (it no longer invokes an external tool).

Peter
--- /mnt/ramfs/gcc-uni.sh.orig	2007-07-22 12:22:59.845389000 +1000
+++ gcc-uni.sh	2007-07-22 12:48:08.000000000 +1000
@@ -25,11 +25,14 @@
 
 # check whether to use gcc or g++
 # (using a symlink with g++ in name is recommended)
-if [ `echo "$0" | fgrep "g++"` ]; then
-	gcc=g++
-else
-	gcc=gcc
-fi
+case "$0" in
+	*g++*)
+		gcc=g++
+		;;
+	*)
+		gcc=gcc
+		;;
+esac
 
 # which OSX to target (used for PPC)
 OSX_TARGET=10.2
@@ -52,49 +55,55 @@
 #   looks for -o to determine the name of the output
 
 if [ $# -eq 0 ]; then
-	echo This is a wrapper around gcc that builds universal binaries.
-	echo It can only be used to compile or link.
-        exit 1;
-fi;
-
-while [ "$1" ]; do
-	case $1 in
-	-arch)
-		shift
-	;;
-
-	-c)
-		mode=compile
-		cmd="$cmd -c"
-	;;
-
-	-o)
-		shift
-		output=$1
-	;;
+	echo "This is a wrapper around gcc that builds universal binaries."
+	echo "It can only be used to compile or link."
+	exit 1
+fi
 
-	*)
-		cmd="$cmd $1"
-	;;
+while [ -n "$1" ]; do
+	case "$1" in
+		-arch)
+			shift
+			;;
+		-c)
+			mode=compile
+			cmd="$cmd -c"
+			;;
+		-o)
+			shift
+			output="$1"
+			;;
+		*)
+			cmd="$cmd $1"
+			;;
 	esac
-	
+    
 	shift
 done
 
 # if no output, bail...
-if [ "$output" = "" ]; then
-	echo Error! $0 requires the -o switch.
+if [ -z "$output" ]; then
+	echo "Error! $0 requires the -o switch."
 	exit 1
 fi
 
 # figure out if we are compiling or linking
-if [ "$mode" = "link" ]; then
-	FLAGS_i386="$LDFLAGS_i386"
-	FLAGS_PPC="$LDFLAGS_PPC"
-elif [ "$mode" = "compile" ]; then
-	FLAGS_i386="$CFLAGS_i386"
-	FLAGS_PPC="$CFLAGS_PPC"
-fi
+case "$mode" in
+	link)
+		FLAGS_i386="$LDFLAGS_i386"
+		FLAGS_PPC="$LDFLAGS_PPC"
+		;;
+	compile)
+		FLAGS_i386="$CFLAGS_i386"
+		FLAGS_PPC="$CFLAGS_PPC"
+		;;
+	*)
+		echo "internal error in gcc-uni.sh script"
+		exit 1
+		;;
+esac
+
+# TODO: use trap to cleanup
 
 # build the i386 version
 $gcc $cmd $FLAGS_i386 -arch i386 -o $output.i386
@@ -105,16 +114,16 @@
 # build the PPC version
 MACOSX_DEPLOYMENT_TARGET=$OSX_TARGET /usr/bin/$gcc-3.3 $cmd $FLAGS_PPC -arch ppc -o $output.ppc
 if [ $? -ne 0 ]; then
-	rm $output.i386
+	rm -f $output.i386
 	exit 1 
 fi
 
 # create the universal version
 lipo -create $output.i386 $output.ppc -output $output
 if [ $? -ne 0 ]; then
-	rm $output.i386 $output.ppc
+	rm -f $output.i386 $output.ppc
 	exit 1 
 fi
 
 # cleanup
-rm $output.i386 $output.ppc
+rm -f $output.i386 $output.ppc


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/