| 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 | WX_VERSION=3.0.2 | 
|---|
| 99 | WX_SHA256=346879dc554f3ab8d6da2704f651ecb504a22e9d31c17ef5449b129ed711585d | 
|---|
| 100 |  | 
|---|
| 101 | PROJ_VERSION=4.8.0 | 
|---|
| 102 | PROJ_SHA256=2db2dbf0fece8d9880679154e0d6d1ce7c694dd8e08b4d091028093d87a9d1b5 | 
|---|
| 103 |  | 
|---|
| 104 | if [ -z "${WX_CONFIG+set}" ] && [ "$install_wx" != no ] ; then | 
|---|
| 105 |   if test -x WXINSTALL/bin/wx-config ; then | 
|---|
| 106 |     : | 
|---|
| 107 |   else | 
|---|
| 108 |     prefix=`pwd`/WXINSTALL | 
|---|
| 109 |     wxtarball=wxWidgets-$WX_VERSION.tar.bz2 | 
|---|
| 110 |     test -f "$wxtarball" || \ | 
|---|
| 111 |       curl -L -O "http://downloads.sourceforge.net/project/wxwindows/$WX_VERSION/$wxtarball" | 
|---|
| 112 |     if echo "$WX_SHA256  $wxtarball" | shasum -a256 -c ; then | 
|---|
| 113 |       : # OK | 
|---|
| 114 |     else | 
|---|
| 115 |       echo "Checksum of downloaded file '$wxtarball' is incorrect, aborting." | 
|---|
| 116 |       exit 1 | 
|---|
| 117 |     fi | 
|---|
| 118 |     echo "+++ Extracting $wxtarball" | 
|---|
| 119 |     test -d "wxWidgets-$WX_VERSION" || tar jxf "$wxtarball" | 
|---|
| 120 |     test -d "wxWidgets-$WX_VERSION/BUILD" || mkdir "wxWidgets-$WX_VERSION/BUILD" | 
|---|
| 121 |     cd "wxWidgets-$WX_VERSION/BUILD" | 
|---|
| 122 |     # Compilation of wx 3.0.2 fails on OS X 10.10.1 with webview enabled. | 
|---|
| 123 |     # A build with liblzma enabled doesn't work on OS X 10.6.8. | 
|---|
| 124 |     ../configure --disable-shared --prefix="$prefix" \ | 
|---|
| 125 |         --with-opengl --enable-display \ | 
|---|
| 126 |         --disable-webview --without-liblzma \ | 
|---|
| 127 |         CC="gcc $arch_flags" CXX="g++ $arch_flags" | 
|---|
| 128 |     make -s | 
|---|
| 129 |     make -s install | 
|---|
| 130 |     cd ../.. | 
|---|
| 131 |   fi | 
|---|
| 132 |   WX_CONFIG=`pwd`/WXINSTALL/bin/wx-config | 
|---|
| 133 | fi | 
|---|
| 134 |  | 
|---|
| 135 | CC=`$WX_CONFIG --cc` | 
|---|
| 136 | CXX=`$WX_CONFIG --cxx` | 
|---|
| 137 |  | 
|---|
| 138 | if [ "$install_proj" != no ] ; then | 
|---|
| 139 |   if test -f PROJINSTALL/include/proj_api.h ; then | 
|---|
| 140 |     : | 
|---|
| 141 |   else | 
|---|
| 142 |     prefix=`pwd`/PROJINSTALL | 
|---|
| 143 |     projtarball=proj-$PROJ_VERSION.tar.gz | 
|---|
| 144 |     test -f "$projtarball" || \ | 
|---|
| 145 |       curl -O "http://download.osgeo.org/proj/$projtarball" | 
|---|
| 146 |     if echo "$PROJ_SHA256  $projtarball" | shasum -a256 -c ; then | 
|---|
| 147 |       : # OK | 
|---|
| 148 |     else | 
|---|
| 149 |       echo "Checksum of downloaded file '$projtarball' is incorrect, aborting." | 
|---|
| 150 |       exit 1 | 
|---|
| 151 |     fi | 
|---|
| 152 |     echo "+++ Extracting $projtarball" | 
|---|
| 153 |     test -d "proj-$PROJ_VERSION" || tar jxf "$projtarball" | 
|---|
| 154 |     test -d "proj-$PROJ_VERSION/BUILD" || mkdir "proj-$PROJ_VERSION/BUILD" | 
|---|
| 155 |     cd "proj-$PROJ_VERSION/BUILD" | 
|---|
| 156 |     ../configure --disable-shared --prefix="$prefix" CC="$CC" CXX="$CXX" | 
|---|
| 157 |     make -s | 
|---|
| 158 |     make -s install | 
|---|
| 159 |     cd ../.. | 
|---|
| 160 |   fi | 
|---|
| 161 | fi | 
|---|
| 162 |  | 
|---|
| 163 | test -n "$WX_CONFIG" || WX_CONFIG=`which wx-config` | 
|---|
| 164 | if test -z "$WX_CONFIG" ; then | 
|---|
| 165 |   echo "WX_CONFIG not set and wx-config not on your PATH" | 
|---|
| 166 |   exit 1 | 
|---|
| 167 | fi | 
|---|
| 168 | # Force static linking so the user doesn't need to install wxWidgets. | 
|---|
| 169 | WX_CONFIG=$WX_CONFIG' --static' | 
|---|
| 170 | rm -rf *.dmg Survex macosxtmp | 
|---|
| 171 | D=`pwd`/Survex | 
|---|
| 172 | T=`pwd`/macosxtmp | 
|---|
| 173 | ./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" | 
|---|
| 174 | make | 
|---|
| 175 | make install | 
|---|
| 176 | #mv Survex/survex Survex/Survex | 
|---|
| 177 |  | 
|---|
| 178 | # Construct the Aven application bundle. | 
|---|
| 179 | mkdir -p Survex/Aven.app/Contents/MacOS Survex/Aven.app/Contents/Resources | 
|---|
| 180 | cp lib/Info.plist Survex/Aven.app/Contents | 
|---|
| 181 | printf APPLAVEN > Survex/Aven.app/Contents/PkgInfo | 
|---|
| 182 | mv Survex/share/doc/survex Survex/Docs | 
|---|
| 183 | rmdir Survex/share/doc | 
|---|
| 184 | rm -rf Survex/share/survex/icons | 
|---|
| 185 | cp -r Survex/share/survex/* Survex/Aven.app/Contents/Resources/ | 
|---|
| 186 | rm Survex/Aven.app/Contents/Resources/bcra*.svx | 
|---|
| 187 | mv Survex/aven Survex/Aven.app/Contents/MacOS/ | 
|---|
| 188 | ln Survex/cavern Survex/Aven.app/Contents/MacOS/ | 
|---|
| 189 | rm -f Survex/share/survex/unifont.pixelfont | 
|---|
| 190 | rm -rf Survex/share/applications Survex/share/mime-info Survex/share/pixmaps | 
|---|
| 191 |  | 
|---|
| 192 | # Create .icns files in the bundle's "Resources" directory. | 
|---|
| 193 | for zip in lib/icons/*.iconset.zip ; do | 
|---|
| 194 |   unzip -d Survex/Aven.app/Contents/Resources "$zip" | 
|---|
| 195 |   i=`echo "$zip"|sed 's!.*/\(.*\)\.zip$!\1!'` | 
|---|
| 196 |   iconutil --convert icns "Survex/Aven.app/Contents/Resources/$i" | 
|---|
| 197 |   rm -rf "Survex/Aven.app/Contents/Resources/$i" | 
|---|
| 198 | done | 
|---|
| 199 |  | 
|---|
| 200 | size=`du -s Survex|sed 's/[^0-9].*//'` | 
|---|
| 201 | # Allow 1000 extra sectors for various overheads (500 wasn't enough). | 
|---|
| 202 | sectors=`expr 1000 + "$size"` | 
|---|
| 203 | # Partition needs to be at least 4M and sectors are 512 bytes. | 
|---|
| 204 | if test "$sectors" -lt 8192 ; then | 
|---|
| 205 |   sectors=8192 | 
|---|
| 206 | fi | 
|---|
| 207 | echo "Creating new blank image survex-macosx.dmg of $sectors sectors" | 
|---|
| 208 | # This creates the diskimage file and initialises it as an HFS+ volume. | 
|---|
| 209 | hdiutil create -sectors "$sectors" survex-macosx -layout NONE -fs HFS+ -volname Survex | 
|---|
| 210 |  | 
|---|
| 211 | echo "Presenting image to the filesystems for mounting." | 
|---|
| 212 | # This will mount the image onto the Desktop. | 
|---|
| 213 | # Get the name of the device it is mounted on and the mount point. | 
|---|
| 214 |  | 
|---|
| 215 | # man hdiutil says: | 
|---|
| 216 | # "The output of [hdiutil] attach has been stable since OS X 10.0 (though it | 
|---|
| 217 | # was called hdid(8) then) and is intended to be program-readable.  It consists | 
|---|
| 218 | # of the /dev node, a tab, a content hint (if applicable), another tab, and a | 
|---|
| 219 | # mount point (if any filesystems were mounted)." | 
|---|
| 220 | # | 
|---|
| 221 | # In reality, it seems there are also some spaces before each tab character. | 
|---|
| 222 | hdid_output=`hdid survex-macosx.dmg|tail -1` | 
|---|
| 223 | echo "Last line of hdid output was: $hdid_output" | 
|---|
| 224 | dev=`echo "$hdid_output"|sed 's!/dev/\([^        ]*\).*!\1!'` | 
|---|
| 225 | mount_point=`echo "$hdid_output"|sed 's!.*      !!'` | 
|---|
| 226 |  | 
|---|
| 227 | echo "Device $dev mounted on $mount_point, copying files into image." | 
|---|
| 228 | ditto -rsrcFork Survex "$mount_point/Survex" | 
|---|
| 229 | ditto lib/INSTALL.OSX "$mount_point/INSTALL" | 
|---|
| 230 |  | 
|---|
| 231 | echo "Detaching image." | 
|---|
| 232 | hdiutil detach "$dev" | 
|---|
| 233 |  | 
|---|
| 234 | version=`sed 's/^VERSION *= *//p;d' Makefile` | 
|---|
| 235 | file=survex-macosx-$version.dmg | 
|---|
| 236 | echo "Compressing image file survex-macosx.dmg to $file" | 
|---|
| 237 | # UDBZ means the resultant disk image will only open on OS X 10.4 or above. | 
|---|
| 238 | # UDZO works on 10.1 and later, but is larger,  UDCO works on 10.0 as well, | 
|---|
| 239 | # but is larger still. | 
|---|
| 240 | hdiutil convert survex-macosx.dmg -format UDBZ -o "$file" | 
|---|
| 241 | rm survex-macosx.dmg | 
|---|
| 242 |  | 
|---|
| 243 | echo "$file created successfully." | 
|---|