-#!/bin/sh
+#!/bin/bash
PACKAGEMAKER="/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
XCODEBUILD="xcodebuild"
-# configure for Universal Binaries
-./configure --disable-dependency-tracking --with-quartz CFLAGS="-arch i386 -arch ppc" LDFLAGS="-arch i386 -arch ppc"
-make
+GRAPHVIZ_BUILDING=
+PACKAGE=
-# make into the macosx build directory
-rm -rf macosx/build/usr/local/*
-make DESTDIR=$PWD/macosx/build install
+# first pass -- getting + prepping
-# build the GUI application
-$XCODEBUILD -project macosx/graphviz.xcodeproj -configuration Release
+for ARG
+do
+ GET=
+ PREP=
+ BUILD=
+ case $ARG in
+ --help )
+ cat <<EOF
+Usage: macbuild [options]
-# convert the build directory into a package
-$PACKAGEMAKER --doc macosx/graphviz.pmdoc --out $1
+ --help display this help and exit
+
+Choose one of the following for each project to build:
+ --get=URL get the url, prep, build and package
+ --prep=TARBALL prep the tarball, build and package
+ --build=DIR build the dir and package
+
+Optionally specify the following for the output:
+ --package=PACK output a OS X flat package
+
+EOF
+ exit 0
+ ;;
+ --get=* )
+ GET=${ARG#*=}
+ ;;
+ --prep=* )
+ PREP=${ARG#*=}
+ ;;
+ --build=* )
+ BUILD=${ARG#*=}
+ ;;
+ --package=* )
+ PACKAGE=${ARG$*=}
+ ;;
+ esac
+
+ # get the URL of the tarball
+ if [[ $GET != "" ]]
+ then
+ echo
+ echo "GETTING $GET ..."
+ echo
+
+ PREP=`basename $GET`
+ if [[ ${PREP%%://*} == "scp" ]]
+ then
+ HOSTFILE="${PREP#scp://}"
+ scp "${HOSTFILE%%/*}:${HOSTFILE#*/}" "$PREP"
+ else
+ curl --url "$GET" --output "$PREP"
+ fi
+ fi
+
+ # prep the tarball
+ if [[ $PREP != "" ]]
+ then
+ echo
+ echo "PREPPING $PREP ..."
+ echo
+
+ BUILD=`tar -tzf "$PREP" | head -1`
+ BUILD=${BUILD%/}
+ # rm -rf "$BUILD"
+ tar -xzf "$PREP"
+ fi
+
+ # record the build location for now
+ if [[ $BUILD != "" ]]
+ then
+ pushd "$BUILD"
+ if [[ `expr "${PWD##*/}" : '.*\(graphviz\)'` ]]
+ then
+ GRAPHVIZ_BUILDING=$PWD
+ fi
+ BUILDINGS[${#BUILDINGS[@]}]=$BUILD
+ popd
+ fi
+done
+
+if [[ $GRAPHVIZ_BUILDING == "" ]]
+then
+ echo
+ echo "Need to specify graphviz URL, tarball or directory for building. Use --get, --prep or --build first."
+ exit 1
+fi
+
+# second pass -- building
+
+for BUILDING in ${BUILDINGS[@]}
+do
+ pushd "$BUILDING"
+ if [[ `expr "${PWD##*/}" : '.*\(graphviz\)'` ]]
+ then
+ echo
+ echo "CONFIGURING $BUILDING ..."
+ echo
+
+ ./configure --disable-dependency-tracking --with-quartz CFLAGS="-arch i386 -arch ppc -I$GRAPHVIZ_BUILDING/macosx/build/usr/local/include" LDFLAGS="-arch i386 -arch ppc -L$GRAPHVIZ_BUILDING/macosx/build/usr/local/lib"
+
+ echo
+ echo "MAKING $BUILDING ..."
+ echo
+
+ make
+
+ echo
+ echo "XCODEBUILDING $BUILDING ..."
+ echo
+
+ $XCODEBUILD -project macosx/graphviz.xcodeproj -configuration Release
+
+ echo
+ echo "INSTALLING $BUILDING ..."
+ echo
+
+ make DESTDIR="$GRAPHVIZ_BUILDING/macosx/build" install
+ else
+ echo
+ echo "CONFIGURING $BUILDING ..."
+ echo
+
+ ./configure --disable-dependency-tracking CFLAGS="-arch i386 -arch ppc -I$GRAPHVIZ_BUILDING/macosx/build/usr/local/include" LDFLAGS="-arch i386 -arch ppc -L$GRAPHVIZ_BUILDING/macosx/build/usr/local/lib"
+
+ echo
+ echo "MAKING $BUILDING ..."
+ echo
+
+ make
+
+ echo
+ echo "INSTALLING $BUILDING ..."
+ echo
+
+ make DESTDIR="$GRAPHVIZ_BUILDING/macosx/build" install
+ fi
+ popd
+done
+
+# third pass -- package everything up
+
+if [[ $PACKAGE == "" ]]
+then
+ PACKAGE="${GRAPHVIZ_BUILDING##*/}.pkg"
+fi
+
+echo
+echo "PACKAGING $PACKAGE ..."
+echo
+
+$PACKAGEMAKER --doc "$GRAPHVIZ_BUILDING/macosx/graphviz.pmdoc" --out $PACKAGE