Another pass at the Mac OS X make scripts.

Ironed out issues with generating an application bundle with universal
binaries on supported systems. Fall back to bundling a single
architecture when support for universal binary generation is not
available. Tested on Mac OS X 10.5.8 (and 10.5 SDK).
This commit is contained in:
jeremiah sypult 2013-07-18 10:39:08 -05:00
parent ea49d5d2da
commit b7f5971ab8
3 changed files with 107 additions and 211 deletions

View file

@ -1,8 +1,8 @@
#!/bin/bash
# Let's make the user give us a target to work with
# architecture is optional
# if used, it we will store the .app bundle in the target arch build directory
# Let's make the user give us a target to work with.
# architecture is assumed universal if not specified, and is optional.
# if arch is defined, it we will store the .app bundle in the target arch build directory
if [ $# == 0 ] || [ $# -gt 2 ]; then
echo "Usage: $0 target <arch>"
echo "Example: $0 release x86"
@ -18,6 +18,7 @@ if [ $# == 0 ] || [ $# -gt 2 ]; then
exit 1
fi
# validate target name
if [ "$1" == "release" ]; then
TARGET_NAME="release"
elif [ "$1" == "debug" ]; then
@ -32,6 +33,7 @@ fi
CURRENT_ARCH=""
# validate the architecture if it was specified
if [ "$2" != "" ]; then
if [ "$2" == "x86" ]; then
CURRENT_ARCH="x86"
@ -50,6 +52,9 @@ if [ "$2" != "" ]; then
fi
fi
# symlinkArch() creates a symlink with the architecture suffix.
# meant for universal binaries, but also handles the way this script generates
# application bundles for a single architecture as well.
function symlinkArch()
{
EXT="dylib"
@ -107,13 +112,24 @@ SEARCH_ARCHS=" \
ppc \
"
# if the optional arch parameter is used, we'll set CURRENT_ARCH
HAS_LIPO=`command -v lipo`
HAS_CP=`command -v cp`
# if lipo is not available, we cannot make a universal binary, print a warning
if [ ! -x "${HAS_LIPO}" ]; then
CURRENT_ARCH=`uname -m`
if [ "${CURRENT_ARCH}" == "i386" ]; then CURRENT_ARCH="x86"; fi
echo "$0 cannot make a universal binary, falling back to architecture ${CURRENT_ARCH}"
fi
# if the optional arch parameter is used, replace SEARCH_ARCHS to only work with one
if [ "${CURRENT_ARCH}" != "" ]; then
SEARCH_ARCHS="${CURRENT_ARCH}"
fi
AVAILABLE_ARCHS=""
IOQ3_VERSION=`grep '^VERSION=' Makefile | sed -e 's/.*=\(.*\)/\1/'`
IOQ3_CLIENT_ARCHS=""
IOQ3_SERVER_ARCHS=""
IOQ3_RENDERER_GL1_ARCHS=""
@ -157,6 +173,7 @@ UNLOCALIZED_RESOURCES_FOLDER_PATH="${CONTENTS_FOLDER_PATH}/Resources"
EXECUTABLE_FOLDER_PATH="${CONTENTS_FOLDER_PATH}/MacOS"
EXECUTABLE_NAME="${PRODUCT_NAME}"
# loop through the architectures to build string lists for each universal binary
for ARCH in $SEARCH_ARCHS; do
CURRENT_ARCH=${ARCH}
BUILT_PRODUCTS_DIR="${OBJROOT}/${TARGET_NAME}-darwin-${CURRENT_ARCH}"
@ -213,14 +230,11 @@ for ARCH in $SEARCH_ARCHS; do
if [ -e ${BUILT_PRODUCTS_DIR}/${BASEDIR}/${IOQ3_MP_UI} ]; then
IOQ3_MP_UI_ARCHS="${BUILT_PRODUCTS_DIR}/${MISSIONPACKDIR}/${IOQ3_UI} ${IOQ3_MP_UI_ARCHS}"
fi
#echo "valid arch: ${ARCH}"
done
if [ "${2}" == "" ]; then
BUILT_PRODUCTS_DIR="${OBJROOT}"
else
BUILT_PRODUCTS_DIR="${OBJROOT}/${TARGET_NAME}-darwin-${CURRENT_ARCH}"
fi
# final preparations and checks before attempting to make the application bundle
cd `dirname $0`
if [ ! -f Makefile ]; then
@ -228,21 +242,33 @@ if [ ! -f Makefile ]; then
exit 1
fi
Q3_VERSION=`grep '^VERSION=' Makefile | sed -e 's/.*=\(.*\)/\1/'`
if [ "${IOQ3_CLIENT_ARCHS}" == "" ]; then
echo "$0: no ioquake3 binary architectures were found for target '${TARGET_NAME}'"
exit 1
fi
# set the final application bundle output directory
if [ "${2}" == "" ]; then
BUILT_PRODUCTS_DIR="${OBJROOT}/${TARGET_NAME}-darwin-universal"
if [ ! -d ${BUILT_PRODUCTS_DIR} ]; then
mkdir -p ${BUILT_PRODUCTS_DIR} || exit 1;
fi
else
BUILT_PRODUCTS_DIR="${OBJROOT}/${TARGET_NAME}-darwin-${CURRENT_ARCH}"
fi
BUNDLEBINDIR="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}"
# here we go
echo "Creating bundle '${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}'"
echo "with architectures:"
for ARCH in ${VALID_ARCHS}; do
echo " ${ARCH}"
done
echo ""
fi
# make the application bundle directories
if [ ! -d ${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/$BASEDIR ]; then
mkdir -p ${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/$BASEDIR || exit 1;
fi
@ -253,10 +279,10 @@ if [ ! -d ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH} ]; then
mkdir -p ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH} || exit 1;
fi
# copy and generate some application bundle resources
cp code/libs/macosx/*.dylib ${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}
cp ${ICNSDIR}/${ICNS} ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/$ICNS || exit 1;
echo -n ${PKGINFO} > ${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/PkgInfo || exit 1;
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
@ -276,11 +302,11 @@ echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${Q3_VERSION}</string>
<string>${IOQ3_VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${Q3_VERSION}</string>
<string>${IOQ3_VERSION}</string>
<key>CGDisableCoalescedUpdates</key>
<true/>
<key>LSMinimumSystemVersion</key>
@ -293,52 +319,57 @@ echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
</plist>
" > ${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Info.plist
cp code/libs/macosx/*.dylib ${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}
#
# use lipo to create a universal binary in to the appropriate bundle location
# then symlink appropriate architecture names for universal (fat) binary support
#
BUNDLEDIR="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}"
# TODO: figure out if we can make universal binaries when cross-compiling.
# lipo on non-mac os x platforms? libtool?
# simply copying here might stomp on other architectures....
# action takes care of generating universal binaries if lipo is available
# otherwise, it falls back to using a simple copy, expecting the first item in
# the second parameter list to be the desired architecture
function action()
{
#echo "action ${1} ${2}"
COMMAND=""
if [ -x "/usr/bin/lipo" ]; then
lipo -create -o "${1}" "${2}"
#elif [ "/usr/bin/libtool" ]; then
#libtool -dynamic -o ${1} ${2}
if [ -x "${HAS_LIPO}" ]; then
COMMAND="${HAS_LIPO} -create -o"
$HAS_LIPO -create -o "${1}" ${2} # make sure $2 is treated as a list of files
elif [ -x ${HAS_CP} ]; then
COMMAND="${HAS_CP}"
SRC="${2// */}" # in case there is a list here, use only the first item
$HAS_CP "${SRC}" "${1}"
else
cp "${2}" "${1}"
"$0 cannot create an application bundle."
exit 1
fi
#echo "${COMMAND}" "${1}" "${2}"
}
#
# the meat of universal binary creation
# destination file names do not have architecture suffix.
# action will handle merging universal binaries if supported.
# symlink appropriate architecture names for universal (fat) binary support.
#
# executables
action ${BUNDLEDIR}/${EXECUTABLE_NAME} ${IOQ3_CLIENT_ARCHS}
action ${BUNDLEDIR}/${DEDICATED_NAME} ${IOQ3_SERVER_ARCHS}
action ${BUNDLEBINDIR}/${EXECUTABLE_NAME} "${IOQ3_CLIENT_ARCHS}"
action ${BUNDLEBINDIR}/${DEDICATED_NAME} "${IOQ3_SERVER_ARCHS}"
# renderers
action ${BUNDLEDIR}/${RENDERER_OPENGL1_NAME} ${IOQ3_RENDERER_GL1_ARCHS}
action ${BUNDLEDIR}/${RENDERER_OPENGL2_NAME} ${IOQ3_RENDERER_GL2_ARCHS}
symlinkArch "${RENDERER_OPENGL}1" "${RENDERER_OPENGL}1" "_" "${BUNDLEDIR}"
symlinkArch "${RENDERER_OPENGL}2" "${RENDERER_OPENGL}2" "_" "${BUNDLEDIR}"
action ${BUNDLEBINDIR}/${RENDERER_OPENGL1_NAME} "${IOQ3_RENDERER_GL1_ARCHS}"
action ${BUNDLEBINDIR}/${RENDERER_OPENGL2_NAME} "${IOQ3_RENDERER_GL2_ARCHS}"
symlinkArch "${RENDERER_OPENGL}1" "${RENDERER_OPENGL}1" "_" "${BUNDLEBINDIR}"
symlinkArch "${RENDERER_OPENGL}2" "${RENDERER_OPENGL}2" "_" "${BUNDLEBINDIR}"
# game
action ${BUNDLEDIR}/${BASEDIR}/${CGAME_NAME} ${IOQ3_CGAME_ARCHS}
action ${BUNDLEDIR}/${BASEDIR}/${GAME_NAME} ${IOQ3_GAME_ARCHS}
action ${BUNDLEDIR}/${BASEDIR}/${UI_NAME} ${IOQ3_UI_ARCHS}
symlinkArch "cgame" "cgame" "" "${BUNDLEDIR}/${BASEDIR}"
symlinkArch "qagame" "qagame" "" "${BUNDLEDIR}/${BASEDIR}"
symlinkArch "ui" "ui" "" "${BUNDLEDIR}/${BASEDIR}"
action ${BUNDLEBINDIR}/${BASEDIR}/${CGAME_NAME} "${IOQ3_CGAME_ARCHS}"
action ${BUNDLEBINDIR}/${BASEDIR}/${GAME_NAME} "${IOQ3_GAME_ARCHS}"
action ${BUNDLEBINDIR}/${BASEDIR}/${UI_NAME} "${IOQ3_UI_ARCHS}"
symlinkArch "${CGAME}" "${CGAME}" "" "${BUNDLEBINDIR}/${BASEDIR}"
symlinkArch "${GAME}" "${GAME}" "" "${BUNDLEBINDIR}/${BASEDIR}"
symlinkArch "${UI}" "${UI}" "" "${BUNDLEBINDIR}/${BASEDIR}"
# missionpack
action ${BUNDLEDIR}/${MISSIONPACKDIR}/${CGAME_NAME} ${IOQ3_MP_CGAME_ARCHS}
action ${BUNDLEDIR}/${MISSIONPACKDIR}/${GAME_NAME} ${IOQ3_MP_GAME_ARCHS}
action ${BUNDLEDIR}/${MISSIONPACKDIR}/${UI_NAME} ${IOQ3_MP_UI_ARCHS}
symlinkArch "cgame" "cgame" "" "${BUNDLEDIR}/${MISSIONPACKDIR}"
symlinkArch "qagame" "qagame" "" "${BUNDLEDIR}/${MISSIONPACKDIR}"
symlinkArch "ui" "ui" "" "${BUNDLEDIR}/${MISSIONPACKDIR}"
action ${BUNDLEBINDIR}/${MISSIONPACKDIR}/${CGAME_NAME} "${IOQ3_MP_CGAME_ARCHS}"
action ${BUNDLEBINDIR}/${MISSIONPACKDIR}/${GAME_NAME} "${IOQ3_MP_GAME_ARCHS}"
action ${BUNDLEBINDIR}/${MISSIONPACKDIR}/${UI_NAME} "${IOQ3_MP_UI_ARCHS}"
symlinkArch "${CGAME}" "${CGAME}" "" "${BUNDLEBINDIR}/${MISSIONPACKDIR}"
symlinkArch "${GAME}" "${GAME}" "" "${BUNDLEBINDIR}/${MISSIONPACKDIR}"
symlinkArch "${UI}" "${UI}" "" "${BUNDLEBINDIR}/${MISSIONPACKDIR}"

View file

@ -1,54 +1,6 @@
#!/bin/sh
#!/bin/bash
CC=gcc-4.0
APPBUNDLE=ioquake3.app
BINARY=ioquake3.ub
DEDBIN=ioq3ded.ub
PKGINFO=APPLIOQ3
ICNS=misc/quake3.icns
DESTDIR=build/release-darwin-ub
BASEDIR=baseq3
MPACKDIR=missionpack
BIN_OBJ="
build/release-darwin-x86_64/ioquake3.x86_64
build/release-darwin-x86/ioquake3.x86
build/release-darwin-ppc/ioquake3.ppc
"
BIN_DEDOBJ="
build/release-darwin-x86_64/ioq3ded.x86_64
build/release-darwin-x86/ioq3ded.x86
build/release-darwin-ppc/ioq3ded.ppc
"
BASE_OBJ="
build/release-darwin-x86_64/$BASEDIR/cgamex86_64.dylib
build/release-darwin-x86/$BASEDIR/cgamex86.dylib
build/release-darwin-ppc/$BASEDIR/cgameppc.dylib
build/release-darwin-x86_64/$BASEDIR/uix86_64.dylib
build/release-darwin-x86/$BASEDIR/uix86.dylib
build/release-darwin-ppc/$BASEDIR/uippc.dylib
build/release-darwin-x86_64/$BASEDIR/qagamex86_64.dylib
build/release-darwin-x86/$BASEDIR/qagamex86.dylib
build/release-darwin-ppc/$BASEDIR/qagameppc.dylib
"
MPACK_OBJ="
build/release-darwin-x86_64/$MPACKDIR/cgamex86_64.dylib
build/release-darwin-x86/$MPACKDIR/cgamex86.dylib
build/release-darwin-ppc/$MPACKDIR/cgameppc.dylib
build/release-darwin-x86_64/$MPACKDIR/uix86_64.dylib
build/release-darwin-x86/$MPACKDIR/uix86.dylib
build/release-darwin-ppc/$MPACKDIR/uippc.dylib
build/release-darwin-x86_64/$MPACKDIR/qagamex86_64.dylib
build/release-darwin-x86/$MPACKDIR/qagamex86.dylib
build/release-darwin-ppc/$MPACKDIR/qagameppc.dylib
"
RENDER_OBJ="
build/release-darwin-x86_64/renderer_opengl1_x86_64.dylib
build/release-darwin-x86/renderer_opengl1_x86.dylib
build/release-darwin-ppc/renderer_opengl1_ppc.dylib
build/release-darwin-x86_64/renderer_opengl2_x86_64.dylib
build/release-darwin-x86/renderer_opengl2_x86.dylib
build/release-darwin-ppc/renderer_opengl2_ppc.dylib
"
cd `dirname $0`
if [ ! -f Makefile ]; then
@ -100,7 +52,7 @@ if [ -z $X86_64_SDK ] || [ -z $X86_SDK ] || [ -z $PPC_SDK ]; then
ERROR: This script is for building a Universal Binary. You cannot build
for a different architecture unless you have the proper Mac OS X SDKs
installed. If you just want to to compile for your own system run
'make' instead of this script."
'make-macosx.sh' instead of this script."
exit 1
fi
@ -118,92 +70,32 @@ WARNING: in order to build a binary with maximum compatibility you must
sleep 3
fi
if [ ! -d $DESTDIR ]; then
mkdir -p $DESTDIR
fi
# For parallel make on multicore boxes...
NCPU=`sysctl -n hw.ncpu`
# x86_64 client and server
if [ -d build/release-release-x86_64 ]; then
rm -r build/release-darwin-x86_64
fi
#if [ -d build/release-release-x86_64 ]; then
# rm -r build/release-darwin-x86_64
#fi
(ARCH=x86_64 CC=gcc-4.0 CFLAGS=$X86_64_CFLAGS LDFLAGS=$X86_64_LDFLAGS make -j$NCPU) || exit 1;
echo;echo
# x86 client and server
if [ -d build/release-darwin-x86 ]; then
rm -r build/release-darwin-x86
fi
#if [ -d build/release-darwin-x86 ]; then
# rm -r build/release-darwin-x86
#fi
(ARCH=x86 CC=gcc-4.0 CFLAGS=$X86_CFLAGS LDFLAGS=$X86_LDFLAGS make -j$NCPU) || exit 1;
echo;echo
# PPC client and server
if [ -d build/release-darwin-ppc ]; then
rm -r build/release-darwin-ppc
fi
#if [ -d build/release-darwin-ppc ]; then
# rm -r build/release-darwin-ppc
#fi
(ARCH=ppc CC=gcc-4.0 CFLAGS=$PPC_CFLAGS LDFLAGS=$PPC_LDFLAGS make -j$NCPU) || exit 1;
echo;echo
echo "Creating .app bundle $DESTDIR/$APPBUNDLE"
if [ ! -d $DESTDIR/$APPBUNDLE/Contents/MacOS/$BASEDIR ]; then
mkdir -p $DESTDIR/$APPBUNDLE/Contents/MacOS/$BASEDIR || exit 1;
fi
if [ ! -d $DESTDIR/$APPBUNDLE/Contents/MacOS/$MPACKDIR ]; then
mkdir -p $DESTDIR/$APPBUNDLE/Contents/MacOS/$MPACKDIR || exit 1;
fi
if [ ! -d $DESTDIR/$APPBUNDLE/Contents/Resources ]; then
mkdir -p $DESTDIR/$APPBUNDLE/Contents/Resources
fi
cp $ICNS $DESTDIR/$APPBUNDLE/Contents/Resources/ioquake3.icns || exit 1;
echo $PKGINFO > $DESTDIR/$APPBUNDLE/Contents/PkgInfo
echo "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist
PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"
\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>$BINARY</string>
<key>CFBundleGetInfoString</key>
<string>ioquake3 $Q3_VERSION</string>
<key>CFBundleIconFile</key>
<string>ioquake3.icns</string>
<key>CFBundleIdentifier</key>
<string>org.ioquake.ioquake3</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>ioquake3</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$Q3_VERSION</string>
<key>CFBundleSignature</key>
<string>$PKGINFO</string>
<key>CFBundleVersion</key>
<string>$Q3_VERSION</string>
<key>NSExtensions</key>
<dict/>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
" > $DESTDIR/$APPBUNDLE/Contents/Info.plist
# Make UB's from previous builds of x86, x86_64 and ppc binaries
lipo -create -o $DESTDIR/$APPBUNDLE/Contents/MacOS/$BINARY $BIN_OBJ
lipo -create -o $DESTDIR/$APPBUNDLE/Contents/MacOS/$DEDBIN $BIN_DEDOBJ
cp $RENDER_OBJ $DESTDIR/$APPBUNDLE/Contents/MacOS/
cp $BASE_OBJ $DESTDIR/$APPBUNDLE/Contents/MacOS/$BASEDIR/
cp $MPACK_OBJ $DESTDIR/$APPBUNDLE/Contents/MacOS/$MPACKDIR/
cp code/libs/macosx/*.dylib $DESTDIR/$APPBUNDLE/Contents/MacOS/
echo
# use the following shell script to build a universal application bundle
"./make-macosx-app.sh" release

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Let's make the user give us a target build system
@ -30,34 +30,7 @@ if [ -z "$DARWIN_GCC_ARCH" ]; then
fi
CC=gcc-4.0
APPBUNDLE=ioquake3.app
BINARY=ioquake3.${BUILDARCH}
DEDBIN=ioq3ded.${BUILDARCH}
PKGINFO=APPLIOQ3
DESTDIR=build/release-darwin-${BUILDARCH}
BASEDIR=baseq3
MPACKDIR=missionpack
BIN_OBJ="
build/release-darwin-${BUILDARCH}/${BINARY}
"
BIN_DEDOBJ="
build/release-darwin-${BUILDARCH}/${DEDBIN}
"
BASE_OBJ="
build/release-darwin-${BUILDARCH}/$BASEDIR/cgame${BUILDARCH}.dylib
build/release-darwin-${BUILDARCH}/$BASEDIR/ui${BUILDARCH}.dylib
build/release-darwin-${BUILDARCH}/$BASEDIR/qagame${BUILDARCH}.dylib
"
MPACK_OBJ="
build/release-darwin-${BUILDARCH}/$MPACKDIR/cgame${BUILDARCH}.dylib
build/release-darwin-${BUILDARCH}/$MPACKDIR/ui${BUILDARCH}.dylib
build/release-darwin-${BUILDARCH}/$MPACKDIR/qagame${BUILDARCH}.dylib
"
RENDER_OBJ="
build/release-darwin-${BUILDARCH}/renderer_opengl1_${BUILDARCH}.dylib
build/release-darwin-${BUILDARCH}/renderer_opengl2_${BUILDARCH}.dylib
"
cd `dirname $0`
if [ ! -f Makefile ]; then
@ -101,9 +74,9 @@ NCPU=`sysctl -n hw.ncpu`
# intel client and server
if [ -d build/release-darwin-${BUILDARCH} ]; then
rm -r build/release-darwin-${BUILDARCH}
fi
#if [ -d build/release-darwin-${BUILDARCH} ]; then
# rm -r build/release-darwin-${BUILDARCH}
#fi
(ARCH=${BUILDARCH} CFLAGS=$ARCH_CFLAGS LDFLAGS=$ARCH_LDFLAGS make -j$NCPU) || exit 1;
# use the following shell script to build an application bundle