| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # You'll need some development tools which aren't installed by default. To |
|---|
| 4 | # get these you can install Xcode (which is a free download from Apple): |
|---|
| 5 | # |
|---|
| 6 | # https://developer.apple.com/xcode/downloads/ |
|---|
| 7 | # |
|---|
| 8 | # To build, open a terminal (Terminal.app in the "Utils" folder in |
|---|
| 9 | # "Applications") and unpack the downloaded survex source code. E.g. for |
|---|
| 10 | # 1.2.17: |
|---|
| 11 | # |
|---|
| 12 | # tar xf survex-1.2.17.tar.gz |
|---|
| 13 | # |
|---|
| 14 | # Then change directory into the unpacked sources: |
|---|
| 15 | # |
|---|
| 16 | # cd survex-1.2.17 |
|---|
| 17 | # |
|---|
| 18 | # And then run this script: |
|---|
| 19 | # |
|---|
| 20 | # ./buildmacosx.sh |
|---|
| 21 | # |
|---|
| 22 | # This will automatically download and temporarily install wxWidgets in |
|---|
| 23 | # a subdirectory of the source tree (this script is smart enough not to |
|---|
| 24 | # download or build it if it already has). |
|---|
| 25 | # |
|---|
| 26 | # If you already have wxWidgets installed permanently, use: |
|---|
| 27 | # |
|---|
| 28 | # ./buildmacosx.sh --no-install-wx |
|---|
| 29 | # |
|---|
| 30 | # If wxWidgets is installed somewhere such that wx-config isn't on your |
|---|
| 31 | # PATH you need to indicate where wx-config is by running this script |
|---|
| 32 | # something like this: |
|---|
| 33 | # |
|---|
| 34 | # env WX_CONFIG=/path/to/wx-config ./buildmacosx.sh |
|---|
| 35 | # |
|---|
| 36 | # (If you set WX_CONFIG, there's no need to pass --no-install-wx). |
|---|
| 37 | # |
|---|
| 38 | # If using a pre-installed wxWidgets, note that it must satisfy the |
|---|
| 39 | # following requirements: |
|---|
| 40 | # - It must be built with OpenGL support (--with-opengl). |
|---|
| 41 | # - If you build with wx < 3, it probably should be a "Unicode" build |
|---|
| 42 | # (--enable-unicode); wx >= 3 dropped support for non-Unicode builds. |
|---|
| 43 | # |
|---|
| 44 | # This script builds diskimages which are known to work at least as far back |
|---|
| 45 | # as OS X 10.6.8. A build of wxWidgets 3.0.2 with the options we pass will |
|---|
| 46 | # default to assuming at least OS X 10.5, but we've not heard from anyone |
|---|
| 47 | # trying with such an old version. |
|---|
| 48 | |
|---|
| 49 | set -e |
|---|
| 50 | |
|---|
| 51 | install_wx=yes |
|---|
| 52 | install_proj=yes |
|---|
| 53 | while [ "$#" != 0 ] ; do |
|---|
| 54 | case $1 in |
|---|
| 55 | --no-install-wx) |
|---|
| 56 | install_wx=no |
|---|
| 57 | shift |
|---|
| 58 | ;; |
|---|
| 59 | --no-install-proj) |
|---|
| 60 | install_proj=no |
|---|
| 61 | shift |
|---|
| 62 | ;; |
|---|
| 63 | --help|-h) |
|---|
| 64 | echo "Usage: $0 [--no-install-wx] [--no-install-proj] [ppc|i386|x86_86]" |
|---|
| 65 | exit 0 |
|---|
| 66 | ;; |
|---|
| 67 | -*) |
|---|
| 68 | echo "Unknown option - try --help" >&2 |
|---|
| 69 | exit 1 |
|---|
| 70 | ;; |
|---|
| 71 | *) |
|---|
| 72 | break |
|---|
| 73 | ;; |
|---|
| 74 | esac |
|---|
| 75 | done |
|---|
| 76 | |
|---|
| 77 | # Mac OS X support "fat" binaries which contain code for more than one |
|---|
| 78 | # processor, but the wxWidgets build system doesn't seem to allow creating |
|---|
| 79 | # these. |
|---|
| 80 | # |
|---|
| 81 | # We default to using -arch x86_64 which produces a build which will only work |
|---|
| 82 | # on # 64-bit Intel Macs, but that's probably all machines modern enough to |
|---|
| 83 | # worry about. |
|---|
| 84 | # |
|---|
| 85 | # If you want a build which also works on 32 bit Intel Macs, then run this |
|---|
| 86 | # script passing i386: |
|---|
| 87 | # |
|---|
| 88 | # ./buildmacosx.sh i386 |
|---|
| 89 | # |
|---|
| 90 | # Or to build for much older machines with a Power PC processor, use: |
|---|
| 91 | # |
|---|
| 92 | # ./buildmacosx.sh ppc |
|---|
| 93 | arch_flags='-arch '${1:-x86_64} |
|---|
| 94 | |
|---|
| 95 | WX_VERSION=3.0.2 |
|---|
| 96 | WX_SHA256=346879dc554f3ab8d6da2704f651ecb504a22e9d31c17ef5449b129ed711585d |
|---|
| 97 | |
|---|
| 98 | PROJ_VERSION=4.8.0 |
|---|
| 99 | PROJ_SHA256=2db2dbf0fece8d9880679154e0d6d1ce7c694dd8e08b4d091028093d87a9d1b5 |
|---|
| 100 | |
|---|
| 101 | if [ -z "${WX_CONFIG+set}" ] && [ "$install_wx" != no ] ; then |
|---|
| 102 | if test -x WXINSTALL/bin/wx-config ; then |
|---|
| 103 | : |
|---|
| 104 | else |
|---|
| 105 | prefix=`pwd`/WXINSTALL |
|---|
| 106 | wxtarball=wxWidgets-$WX_VERSION.tar.bz2 |
|---|
| 107 | test -f "$wxtarball" || \ |
|---|
| 108 | curl -L -O "http://downloads.sourceforge.net/project/wxwindows/$WX_VERSION/$wxtarball" |
|---|
| 109 | if echo "$WX_SHA256 $wxtarball" | shasum -a256 -c ; then |
|---|
| 110 | : # OK |
|---|
| 111 | else |
|---|
| 112 | echo "Checksum of downloaded file '$wxtarball' is incorrect, aborting." |
|---|
| 113 | exit 1 |
|---|
| 114 | fi |
|---|
| 115 | echo "+++ Extracting $wxtarball" |
|---|
| 116 | test -d "wxWidgets-$WX_VERSION" || tar jxf "$wxtarball" |
|---|
| 117 | test -d "wxWidgets-$WX_VERSION/BUILD" || mkdir "wxWidgets-$WX_VERSION/BUILD" |
|---|
| 118 | cd "wxWidgets-$WX_VERSION/BUILD" |
|---|
| 119 | # Compliation of wx 3.0.2 fails on OS X 10.10.1 with webview enabled. |
|---|
| 120 | # A build with liblzma enabled doesn't work on OS X 10.6.8. |
|---|
| 121 | ../configure --disable-shared --prefix="$prefix" \ |
|---|
| 122 | --with-opengl --enable-unicode \ |
|---|
| 123 | --disable-webview --without-liblzma \ |
|---|
| 124 | CC="gcc $arch_flags" CXX="g++ $arch_flags" |
|---|
| 125 | make -s |
|---|
| 126 | make -s install |
|---|
| 127 | cd ../.. |
|---|
| 128 | fi |
|---|
| 129 | WX_CONFIG=`pwd`/WXINSTALL/bin/wx-config |
|---|
| 130 | fi |
|---|
| 131 | |
|---|
| 132 | CC=`$WX_CONFIG --cc` |
|---|
| 133 | CXX=`$WX_CONFIG --cxx` |
|---|
| 134 | |
|---|
| 135 | if [ "$install_proj" != no ] ; then |
|---|
| 136 | if test -f PROJINSTALL/include/proj_api.h ; then |
|---|
| 137 | : |
|---|
| 138 | else |
|---|
| 139 | prefix=`pwd`/PROJINSTALL |
|---|
| 140 | projtarball=proj-$PROJ_VERSION.tar.gz |
|---|
| 141 | test -f "$projtarball" || \ |
|---|
| 142 | curl -O "http://download.osgeo.org/proj/$projtarball" |
|---|
| 143 | if echo "$PROJ_SHA256 $projtarball" | shasum -a256 -c ; then |
|---|
| 144 | : # OK |
|---|
| 145 | else |
|---|
| 146 | echo "Checksum of downloaded file '$projtarball' is incorrect, aborting." |
|---|
| 147 | exit 1 |
|---|
| 148 | fi |
|---|
| 149 | echo "+++ Extracting $projtarball" |
|---|
| 150 | test -d "proj-$PROJ_VERSION" || tar jxf "$projtarball" |
|---|
| 151 | test -d "proj-$PROJ_VERSION/BUILD" || mkdir "proj-$PROJ_VERSION/BUILD" |
|---|
| 152 | cd "proj-$PROJ_VERSION/BUILD" |
|---|
| 153 | ../configure --disable-shared --prefix="$prefix" CC="$CC" CXX="$CXX" |
|---|
| 154 | make -s |
|---|
| 155 | make -s install |
|---|
| 156 | cd ../.. |
|---|
| 157 | fi |
|---|
| 158 | fi |
|---|
| 159 | |
|---|
| 160 | test -n "$WX_CONFIG" || WX_CONFIG=`which wx-config` |
|---|
| 161 | if test -z "$WX_CONFIG" ; then |
|---|
| 162 | echo "WX_CONFIG not set and wx-config not on your PATH" |
|---|
| 163 | exit 1 |
|---|
| 164 | fi |
|---|
| 165 | # Force static linking so the user doesn't need to install wxWidgets. |
|---|
| 166 | WX_CONFIG=$WX_CONFIG' --static' |
|---|
| 167 | rm -rf *.dmg Survex macosxtmp |
|---|
| 168 | D=`pwd`/Survex |
|---|
| 169 | T=`pwd`/macosxtmp |
|---|
| 170 | ./configure --prefix="$D" --bindir="$D" --mandir="$T" WX_CONFIG="$WX_CONFIG" CC="$CC" CXX="$CXX" CPPFLAGS=-I"`pwd`/PROJINSTALL/include" LDFLAGS=-L"`pwd`/PROJINSTALL/lib" |
|---|
| 171 | make |
|---|
| 172 | make install |
|---|
| 173 | #mv Survex/survex Survex/Survex |
|---|
| 174 | |
|---|
| 175 | # Construct the Aven application bundle. |
|---|
| 176 | mkdir -p Survex/Aven.app/Contents/MacOS Survex/Aven.app/Contents/Resources |
|---|
| 177 | cp lib/Info.plist Survex/Aven.app/Contents |
|---|
| 178 | printf APPLAVEN > Survex/Aven.app/Contents/PkgInfo |
|---|
| 179 | cp -r "$D"/share/survex/* Survex/Aven.app/Contents/Resources/ |
|---|
| 180 | rm Survex/Aven.app/Contents/Resources/bcra*.svx |
|---|
| 181 | rm Survex/Aven.app/Contents/Resources/icons/3d.png |
|---|
| 182 | rm Survex/Aven.app/Contents/Resources/icons/err.png |
|---|
| 183 | rm Survex/Aven.app/Contents/Resources/icons/plt.png |
|---|
| 184 | rm Survex/Aven.app/Contents/Resources/icons/pos.png |
|---|
| 185 | rm Survex/Aven.app/Contents/Resources/icons/svx.png |
|---|
| 186 | mv Survex/aven Survex/Aven.app/Contents/MacOS/ |
|---|
| 187 | ln Survex/cavern Survex/Aven.app/Contents/MacOS/ |
|---|
| 188 | mv Survex/share/doc/survex Survex/Docs |
|---|
| 189 | rmdir Survex/share/doc |
|---|
| 190 | rm -f Survex/share/survex/unifont.pixelfont |
|---|
| 191 | rm -rf Survex/share/survex/icons |
|---|
| 192 | rm -rf Survex/share/applications Survex/share/mime-info Survex/share/pixmaps |
|---|
| 193 | |
|---|
| 194 | # Create .icns files in the bundle's "Resources" directory. |
|---|
| 195 | for i in Aven svxedit 3d err plt pos svx ; do |
|---|
| 196 | unzip -d Survex/Aven.app/Contents/Resources "lib/icons/$i.iconset.zip" |
|---|
| 197 | iconutil --convert icns "Survex/Aven.app/Contents/Resources/$i.iconset" |
|---|
| 198 | rm -rf "Survex/Aven.app/Contents/Resources/$i.iconset" |
|---|
| 199 | done |
|---|
| 200 | |
|---|
| 201 | # Construct the svxedit application bundle. |
|---|
| 202 | mkdir -p Survex/svxedit.App/Contents/MacOS Survex/svxedit.App/Contents/Resources |
|---|
| 203 | cp lib/svxedit_Info.plist Survex/svxedit.App/Contents/Info.plist |
|---|
| 204 | printf APPLSVXE > Survex/svxedit.App/Contents/PkgInfo |
|---|
| 205 | mv Survex/svxedit Survex/svxedit_wrap Survex/svxedit.App/Contents/MacOS/ |
|---|
| 206 | |
|---|
| 207 | mv Survex/Aven.app/Contents/Resources/svxedit.icns \ |
|---|
| 208 | Survex/svxedit.App/Contents/Resources |
|---|
| 209 | ln Survex/Aven.app/Contents/Resources/svx.icns \ |
|---|
| 210 | Survex/svxedit.App/Contents/Resources |
|---|
| 211 | |
|---|
| 212 | size=`du -s Survex|sed 's/[^0-9].*//'` |
|---|
| 213 | # Allow 1000 extra sectors for various overheads (500 wasn't enough). |
|---|
| 214 | sectors=`expr 1000 + "$size"` |
|---|
| 215 | # Partition needs to be at least 4M and sectors are 512 bytes. |
|---|
| 216 | if test "$sectors" -lt 8192 ; then |
|---|
| 217 | sectors=8192 |
|---|
| 218 | fi |
|---|
| 219 | echo "Creating new blank image survex-macosx.dmg of $sectors sectors" |
|---|
| 220 | # This creates the diskimage file and initialises it as an HFS+ volume. |
|---|
| 221 | hdiutil create -sectors "$sectors" survex-macosx -layout NONE -fs HFS+ -volname Survex |
|---|
| 222 | |
|---|
| 223 | echo "Presenting image to the filesystems for mounting." |
|---|
| 224 | # This will mount the image onto the Desktop. |
|---|
| 225 | # Get the name of the device it is mounted on and the mount point. |
|---|
| 226 | |
|---|
| 227 | # man hdiutil says: |
|---|
| 228 | # "The output of [hdiutil] attach has been stable since OS X 10.0 (though it |
|---|
| 229 | # was called hdid(8) then) and is intended to be program-readable. It consists |
|---|
| 230 | # of the /dev node, a tab, a content hint (if applicable), another tab, and a |
|---|
| 231 | # mount point (if any filesystems were mounted)." |
|---|
| 232 | # |
|---|
| 233 | # In reality, it seems there are also some spaces before each tab character. |
|---|
| 234 | hdid_output=`hdid survex-macosx.dmg|tail -1` |
|---|
| 235 | echo "Last line of hdid output was: $hdid_output" |
|---|
| 236 | dev=`echo "$hdid_output"|sed 's!/dev/\([^ ]*\).*!\1!'` |
|---|
| 237 | mount_point=`echo "$hdid_output"|sed 's!.* !!'` |
|---|
| 238 | |
|---|
| 239 | echo "Device $dev mounted on $mount_point, copying files into image." |
|---|
| 240 | ditto -rsrcFork Survex "$mount_point/Survex" |
|---|
| 241 | ditto lib/INSTALL.OSX "$mount_point/INSTALL" |
|---|
| 242 | |
|---|
| 243 | echo "Detaching image." |
|---|
| 244 | hdiutil detach "$dev" |
|---|
| 245 | |
|---|
| 246 | version=`sed 's/^VERSION *= *//p;d' Makefile` |
|---|
| 247 | file=survex-macosx-$version.dmg |
|---|
| 248 | echo "Compressing image file survex-macosx.dmg to $file" |
|---|
| 249 | # UDBZ means the resultant disk image will only open on OS X 10.4 or above. |
|---|
| 250 | # UDZO works on 10.1 and later, but is larger, UDCO works on 10.0 as well. |
|---|
| 251 | hdiutil convert survex-macosx.dmg -format UDBZ -o "$file" |
|---|
| 252 | rm survex-macosx.dmg |
|---|
| 253 | |
|---|
| 254 | echo "$file created successfully." |
|---|