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