Merge 'remotes/trunk'
[0ad.git] / build / workspaces / build-osx-bundle.sh
blob296c6c7f962554cbd18511d4e89c5a58495ac8d0
1 #!/bin/sh
3 # This script will build an OS X app bundle for 0 A.D.
5 # App bundles are intended to be self-contained and portable.
6 # An SDK is required, usually included with Xcode. The SDK ensures
7 # that only those system libraries are used which are available on
8 # the chosen target and compatible systems.
10 # Steps to build a 0 A.D. bundle are:
11 # 1. confirm ARCH is set to desired target architecture
12 # 2. confirm SYSROOT points to the correct target SDK
13 # 3. confirm MIN_OSX_VERSION matches the target OS X version
14 # 4. update BUNDLE_VERSION to match current 0 A.D. version
15 # 5. run this script
18 # Force build architecture, as sometimes environment is broken.
19 # For a universal fat binary, the approach would be to build every
20 # library with both archs and combine them with lipo, then do the
21 # same thing with the game itself.
22 # Choices are "x86_64" or "i386" (ppc and ppc64 not supported)
23 export ARCH=${ARCH:="x86_64"}
25 OSX_VERSION=`sw_vers -productVersion | grep -Eo "^\d+.\d+"`
26 # Set SDK and mimimum required OS X version
27 export SYSROOT=${SYSROOT:="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk"}
28 export MIN_OSX_VERSION=${MIN_OSX_VERSION:="10.7"}
30 # 0 A.D. release version, e.g. Alpha 21 is 0.0.21
31 BUNDLE_VERSION=${BUNDLE_VERSION:="0.0.X"}
33 # Define compiler as "clang", this is all Mavericks supports.
34 # gcc symlinks may still exist, but they are simply clang with
35 # slightly different config, which confuses build scripts.
36 # llvm-gcc and gcc 4.2 are no longer supported by SpiderMonkey.
37 export CC=${CC:="clang"} CXX=${CXX:="clang++"}
39 # Unique identifier string for this bundle (reverse-DNS style)
40 BUNDLE_IDENTIFIER=${BUNDLE_IDENTIFIER:="com.wildfiregames.0ad"}
41 # Minimum version of OS X on which the bundle will run
42 BUNDLE_MIN_OSX_VERSION="${MIN_OSX_VERSION}.0"
44 die()
46 echo ERROR: $*
47 exit 1
50 # Check that we're actually on OS X
51 if [ "`uname -s`" != "Darwin" ]; then
52 die "This script is intended for OS X only"
55 # Check SDK exists
56 if [ ! -d "$SYSROOT" ]; then
57 die "$SYSROOT does not exist! You probably need to install Xcode"
60 cd "$(dirname $0)"
61 # Now in build/workspaces/ (where we assume this script resides)
63 JOBS=${JOBS:="-j5"}
64 build_release=false
65 build_path="$HOME/0ad-export"
66 # TODO: proper logging of all output, but show errors in terminal too
67 build_log="$(pwd)/bundle-build.log"
69 # Parse command-line options:
70 for i in "$@"
72 case $i in
73 -j* ) JOBS=$i ;;
74 --release ) build_release=true ;;
75 esac
76 done
78 rm -f $build_log
80 # For release, export an SVN copy
81 if [ "$build_release" = "true" ]; then
82 echo "\nExporting SVN and preparing release\n"
84 BUNDLE_OUTPUT="$build_path/0ad.app"
85 SVN_REV=`svnversion -n ../..`
86 rm -rf $build_path
87 svn export ../.. $build_path >> $build_log 2>&1 || die "Error exporting SVN working directory"
88 cd $build_path
89 rm -f binaries/data/config/dev.cfg
90 # Only include translations for a subset of languages
91 . source/tools/dist/remove-incomplete-translations.sh $build_path/binaries/data || die "Error excluding translations"
92 echo L\"${SVN_REV}-release\" > build/svn_revision/svn_revision.txt
93 cd build/workspaces
96 BUNDLE_OUTPUT=${BUNDLE_OUTPUT:="$(pwd)/0ad.app"}
97 BUNDLE_CONTENTS=$BUNDLE_OUTPUT/Contents
98 BUNDLE_BIN=$BUNDLE_CONTENTS/MacOS
99 BUNDLE_RESOURCES=$BUNDLE_CONTENTS/Resources
100 BUNDLE_FRAMEWORKS=$BUNDLE_CONTENTS/Frameworks
101 BUNDLE_PLUGINS=$BUNDLE_CONTENTS/PlugIns
102 BUNDLE_SHAREDSUPPORT=$BUNDLE_CONTENTS/SharedSupport
104 # TODO: Do we really want to regenerate everything? (consider if one task fails)
106 # Build libraries against SDK
107 echo "\nBuilding libraries\n"
108 pushd ../../libraries/osx > /dev/null
109 ./build-osx-libs.sh $JOBS --force-rebuild >> $build_log 2>&1 || die "Libraries build script failed"
110 popd > /dev/null
112 # Clean and update workspaces
113 echo "\nGenerating workspaces\n"
115 # Pass OS X options through to Premake
116 (./clean-workspaces.sh && SYSROOT="$SYSROOT" MIN_OSX_VERSION="$MIN_OSX_VERSION" ./update-workspaces.sh --macosx-bundle="$BUNDLE_IDENTIFIER" --sysroot="$SYSROOT" --macosx-version-min="$MIN_OSX_VERSION") >> $build_log 2>&1 || die "update-workspaces.sh failed!"
118 pushd gcc > /dev/null
119 echo "\nBuilding game\n"
120 (make clean && CC="$CC -arch $ARCH" CXX="$CXX -arch $ARCH" make ${JOBS}) >> $build_log 2>&1 || die "Game build failed!"
121 popd > /dev/null
123 # Run test to confirm all is OK
124 # TODO: tests are currently broken on OS X (see http://trac.wildfiregames.com/ticket/2780)
125 #pushd ../../binaries/system > /dev/null
126 #echo "\nRunning tests\n"
127 #./test || die "Post-build testing failed!"
128 #popd > /dev/null
130 # Create bundle structure
131 echo "\nCreating bundle directories\n"
132 rm -rf ${BUNDLE_OUTPUT}
133 mkdir -p ${BUNDLE_BIN}
134 mkdir -p ${BUNDLE_FRAMEWORKS}
135 mkdir -p ${BUNDLE_PLUGINS}
136 mkdir -p ${BUNDLE_RESOURCES}
137 mkdir -p ${BUNDLE_SHAREDSUPPORT}
139 # Build archive(s) - don't archive the _test.* mods
140 pushd ../../binaries/data/mods > /dev/null
141 archives=""
142 for modname in [a-zA-Z0-9]*
144 archives="${archives} ${modname}"
145 done
146 popd > /dev/null
148 pushd ../../binaries/system > /dev/null
150 for modname in $archives
152 echo "\nBuilding archive for '${modname}'\n"
153 ARCHIVEBUILD_INPUT="$(pwd)/../data/mods/${modname}"
154 ARCHIVEBUILD_OUTPUT="${BUNDLE_RESOURCES}/data/mods/${modname}"
156 # For some reason the output directory has to exist?
157 mkdir -p ${ARCHIVEBUILD_OUTPUT}
159 (./pyrogenesis -archivebuild=${ARCHIVEBUILD_INPUT} -archivebuild-output=${ARCHIVEBUILD_OUTPUT}/${modname}.zip) >> $build_log 2>&1 || die "Archive build for '${modname}' failed!"
160 done
162 # Copy binaries
163 echo "\nCopying binaries\n"
164 # Only pyrogenesis for now, until we find a way to load
165 # multiple binaries from one app bundle
166 # TODO: Would be nicer if we could set this path in premake
167 cp pyrogenesis ${BUNDLE_BIN}
169 # Copy libs
170 echo "\nCopying libs\n"
171 # TODO: Would be nicer if we could set this path in premake
172 cp -v libAtlasUI.dylib ${BUNDLE_FRAMEWORKS}
173 cp -v libCollada.dylib ${BUNDLE_FRAMEWORKS}
175 popd > /dev/null
177 # Copy data
178 echo "\nCopying non-archived game data\n"
179 pushd ../../binaries/data > /dev/null
180 if [ "$build_release" = "false" ]; then
181 mv config/dev.cfg config/dev.bak
183 cp -R -v config ${BUNDLE_RESOURCES}/data/
184 cp -R -v l10n ${BUNDLE_RESOURCES}/data/
185 cp -R -v tools ${BUNDLE_RESOURCES}/data/
186 if [ "$build_release" = "false" ]; then
187 mv config/dev.bak config/dev.cfg
189 popd > /dev/null
190 cp -v ../resources/0ad.icns ${BUNDLE_RESOURCES}
192 # Copy license/readmes
193 # TODO: Also want copies in the DMG - decide on layout
194 echo "\nCopying readmes\n"
195 cp -v ../../*.txt ${BUNDLE_RESOURCES}
196 cp -v ../../libraries/LICENSE.txt ${BUNDLE_RESOURCES}/LIB_LICENSE.txt
198 # Create Info.plist
199 echo "\nCreating Info.plist\n"
200 alias PlistBuddy=/usr/libexec/PlistBuddy
201 INFO_PLIST="${BUNDLE_CONTENTS}/Info.plist"
203 PlistBuddy -c "Add :CFBundleName string 0 A.D." ${INFO_PLIST}
204 PlistBuddy -c "Add :CFBundleIdentifier string ${BUNDLE_IDENTIFIER}" ${INFO_PLIST}
205 PlistBuddy -c "Add :CFBundleVersion string ${BUNDLE_VERSION}" ${INFO_PLIST}
206 PlistBuddy -c "Add :CFBundlePackageType string APPL" ${INFO_PLIST}
207 PlistBuddy -c "Add :CFBundleSignature string none" ${INFO_PLIST}
208 PlistBuddy -c "Add :CFBundleExecutable string pyrogenesis" ${INFO_PLIST}
209 PlistBuddy -c "Add :CFBundleShortVersionString string ${BUNDLE_VERSION}" ${INFO_PLIST}
210 PlistBuddy -c "Add :CFBundleDevelopmentRegion string English" ${INFO_PLIST}
211 PlistBuddy -c "Add :CFBundleInfoDictionaryVersion string 6.0" ${INFO_PLIST}
212 PlistBuddy -c "Add :CFBundleIconFile string 0ad" ${INFO_PLIST}
213 PlistBuddy -c "Add :LSMinimumSystemVersion string ${BUNDLE_MIN_OSX_VERSION}" ${INFO_PLIST}
214 PlistBuddy -c "Add :NSHumanReadableCopyright string Copyright © 2015 Wildfire Games" ${INFO_PLIST}
216 # TODO: Automatically create compressed DMG with hdiutil?
217 # (this is a bit complicated so I do it manually for now)
218 # (also we need to have good icon placement, background image, etc)
220 echo "\nBundle complete! Located in ${BUNDLE_OUTPUT}"