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, |
---|
23 | # PROJ.4 and libav in subdirectories of the source tree (this script is smart |
---|
24 | # enough not to re-download or re-build these if it already has). |
---|
25 | # |
---|
26 | # If you already have wxWidgets, PROJ.4 and/or libav installed permanently, |
---|
27 | # you can disable these by passing one or more extra options - e.g. to build |
---|
28 | # none of them, use: |
---|
29 | # |
---|
30 | # ./buildmacosx.sh --no-install-wx --no-install-proj --no-install-libav |
---|
31 | # |
---|
32 | # If wxWidgets is installed somewhere such that wx-config isn't on your |
---|
33 | # PATH you need to indicate where wx-config is by running this script |
---|
34 | # something like this: |
---|
35 | # |
---|
36 | # env WX_CONFIG=/path/to/wx-config ./buildmacosx.sh |
---|
37 | # |
---|
38 | # (If you set WX_CONFIG, there's no need to pass --no-install-wx). |
---|
39 | # |
---|
40 | # If using a pre-installed wxWidgets, note that it must satisfy the |
---|
41 | # following requirements: |
---|
42 | # |
---|
43 | # - It must be built with OpenGL support (--with-opengl). |
---|
44 | # |
---|
45 | # We strongly recommend using wxWidgets >= 3.0, but if you want to build with |
---|
46 | # wxWidgets 2.8, it probably should be a "Unicode" build (--enable-unicode); |
---|
47 | # wxWidgets >= 3.0 effectively is always a "Unicode" build, so the |
---|
48 | # --enable-unicode option isn't needed (and is ignored if specified). |
---|
49 | # |
---|
50 | # This script builds diskimages which are known to work at least as far back |
---|
51 | # as OS X 10.6.8. A build of wxWidgets 3.0.2 with the options we pass will |
---|
52 | # default to assuming at least OS X 10.5, but we've not heard from anyone |
---|
53 | # trying with such an old version. |
---|
54 | # |
---|
55 | # Mac OS X support "fat" binaries which contain code for more than one |
---|
56 | # processor, but the wxWidgets build system doesn't seem to allow creating |
---|
57 | # these, so we have to choose what processor family to build for. By default |
---|
58 | # we build for the architecture of the version of OS X the build machine is |
---|
59 | # running, which on a modern Mac will be x86_64, producing a build which will |
---|
60 | # only work on 64-bit Intel Macs (but that's probably all machines modern |
---|
61 | # enough to worry about). |
---|
62 | # |
---|
63 | # You can specify an arch explicitly on the command-line, e.g. to force a |
---|
64 | # build for 64-bit Intel Macs: |
---|
65 | # |
---|
66 | # ./buildmacosx.sh x86_64 |
---|
67 | # |
---|
68 | # Or if you want a build which also works on older 32 bit Intel Macs, then run |
---|
69 | # this script passing i386 on the command line, like so (assuming your compiler |
---|
70 | # supports this): |
---|
71 | # |
---|
72 | # ./buildmacosx.sh i386 |
---|
73 | # |
---|
74 | # Or to build for much older machines with a Power PC processor, use (again |
---|
75 | # assuming your compiler supports this): |
---|
76 | # |
---|
77 | # ./buildmacosx.sh ppc |
---|
78 | |
---|
79 | set -e |
---|
80 | |
---|
81 | install_wx=yes |
---|
82 | install_proj=yes |
---|
83 | install_libav=yes |
---|
84 | while [ "$#" != 0 ] ; do |
---|
85 | case $1 in |
---|
86 | --no-install-wx) |
---|
87 | install_wx=no |
---|
88 | shift |
---|
89 | ;; |
---|
90 | --no-install-proj) |
---|
91 | install_proj=no |
---|
92 | shift |
---|
93 | ;; |
---|
94 | --no-install-libav) |
---|
95 | install_libav=no |
---|
96 | shift |
---|
97 | ;; |
---|
98 | --help|-h) |
---|
99 | echo "Usage: $0 [--no-install-wx] [--no-install-proj] [ppc|i386|x86_86]" |
---|
100 | exit 0 |
---|
101 | ;; |
---|
102 | -*) |
---|
103 | echo "Unknown option - try --help" >&2 |
---|
104 | exit 1 |
---|
105 | ;; |
---|
106 | *) |
---|
107 | break |
---|
108 | ;; |
---|
109 | esac |
---|
110 | done |
---|
111 | |
---|
112 | arch=$1 |
---|
113 | if [ -z "$arch" ] ; then |
---|
114 | arch=`uname -m` |
---|
115 | fi |
---|
116 | arch_flags="-arch $arch" |
---|
117 | |
---|
118 | # UDBZ means the resultant disk image will only open on OS X 10.4 or above. |
---|
119 | # UDZO works on 10.1 and later, but is larger, UDCO works on 10.0 as well, |
---|
120 | # but is larger still. |
---|
121 | dmg_format=UDBZ |
---|
122 | |
---|
123 | WX_VERSION=3.0.2 |
---|
124 | WX_SHA256=346879dc554f3ab8d6da2704f651ecb504a22e9d31c17ef5449b129ed711585d |
---|
125 | |
---|
126 | PROJ_VERSION=4.8.0 |
---|
127 | PROJ_SHA256=2db2dbf0fece8d9880679154e0d6d1ce7c694dd8e08b4d091028093d87a9d1b5 |
---|
128 | |
---|
129 | LIBAV_VERSION=11.4 |
---|
130 | LIBAV_SHA256=0b7dabc2605f3a254ee410bb4b1a857945696aab495fe21b34c3b6544ff5d525 |
---|
131 | |
---|
132 | if [ -z "${WX_CONFIG+set}" ] && [ "$install_wx" != no ] ; then |
---|
133 | if test -x WXINSTALL/bin/wx-config ; then |
---|
134 | : |
---|
135 | else |
---|
136 | prefix=`pwd`/WXINSTALL |
---|
137 | wxtarball=wxWidgets-$WX_VERSION.tar.bz2 |
---|
138 | test -f "$wxtarball" || \ |
---|
139 | curl -L -O "http://downloads.sourceforge.net/project/wxwindows/$WX_VERSION/$wxtarball" |
---|
140 | if echo "$WX_SHA256 $wxtarball" | shasum -a256 -c ; then |
---|
141 | : # OK |
---|
142 | else |
---|
143 | echo "Checksum of downloaded file '$wxtarball' is incorrect, aborting." |
---|
144 | exit 1 |
---|
145 | fi |
---|
146 | echo "+++ Extracting $wxtarball" |
---|
147 | test -d "wxWidgets-$WX_VERSION" || tar xf "$wxtarball" |
---|
148 | test -d "wxWidgets-$WX_VERSION/BUILD" || mkdir "wxWidgets-$WX_VERSION/BUILD" |
---|
149 | cd "wxWidgets-$WX_VERSION/BUILD" |
---|
150 | # Compilation of wx 3.0.2 fails on OS X 10.10.1 with webview enabled. |
---|
151 | # A build with liblzma enabled doesn't work on OS X 10.6.8. |
---|
152 | ../configure --disable-shared --prefix="$prefix" \ |
---|
153 | --with-opengl --enable-display \ |
---|
154 | --disable-webview --without-liblzma \ |
---|
155 | CC="gcc $arch_flags" CXX="g++ $arch_flags" |
---|
156 | make -s |
---|
157 | make -s install |
---|
158 | cd ../.. |
---|
159 | fi |
---|
160 | WX_CONFIG=`pwd`/WXINSTALL/bin/wx-config |
---|
161 | fi |
---|
162 | |
---|
163 | CC=`$WX_CONFIG --cc` |
---|
164 | CXX=`$WX_CONFIG --cxx` |
---|
165 | |
---|
166 | if [ "$install_proj" != no ] ; then |
---|
167 | if test -f PROJINSTALL/include/proj_api.h ; then |
---|
168 | : |
---|
169 | else |
---|
170 | prefix=`pwd`/PROJINSTALL |
---|
171 | projtarball=proj-$PROJ_VERSION.tar.gz |
---|
172 | test -f "$projtarball" || \ |
---|
173 | curl -O "http://download.osgeo.org/proj/$projtarball" |
---|
174 | if echo "$PROJ_SHA256 $projtarball" | shasum -a256 -c ; then |
---|
175 | : # OK |
---|
176 | else |
---|
177 | echo "Checksum of downloaded file '$projtarball' is incorrect, aborting." |
---|
178 | exit 1 |
---|
179 | fi |
---|
180 | echo "+++ Extracting $projtarball" |
---|
181 | test -d "proj-$PROJ_VERSION" || tar xf "$projtarball" |
---|
182 | test -d "proj-$PROJ_VERSION/BUILD" || mkdir "proj-$PROJ_VERSION/BUILD" |
---|
183 | cd "proj-$PROJ_VERSION/BUILD" |
---|
184 | ../configure --disable-shared --prefix="$prefix" CC="$CC" CXX="$CXX" |
---|
185 | make -s |
---|
186 | make -s install |
---|
187 | cd ../.. |
---|
188 | fi |
---|
189 | fi |
---|
190 | |
---|
191 | if [ "$install_libav" != no ] ; then |
---|
192 | if test -f LIBAVINSTALL/include/libavcodec/avcodec.h ; then |
---|
193 | : |
---|
194 | else |
---|
195 | prefix=`pwd`/LIBAVINSTALL |
---|
196 | libavtarball=libav-$LIBAV_VERSION.tar.xz |
---|
197 | test -f "$libavtarball" || \ |
---|
198 | curl -O "http://libav.org/releases/$libavtarball" |
---|
199 | if echo "$LIBAV_SHA256 $libavtarball" | shasum -a256 -c ; then |
---|
200 | : # OK |
---|
201 | else |
---|
202 | echo "Checksum of downloaded file '$libavtarball' is incorrect, aborting." |
---|
203 | exit 1 |
---|
204 | fi |
---|
205 | echo "+++ Extracting $libavtarball" |
---|
206 | test -d "libav-$LIBAV_VERSION" || tar xf "$libavtarball" |
---|
207 | test -d "libav-$LIBAV_VERSION/BUILD" || mkdir "libav-$LIBAV_VERSION/BUILD" |
---|
208 | cd "libav-$LIBAV_VERSION/BUILD" |
---|
209 | LIBAV_CONFIGURE_OPTS='--disable-shared --disable-programs --disable-network --disable-bsfs --disable-protocols --disable-devices' |
---|
210 | # We don't need to decode video, but disabling these causes a link failure |
---|
211 | # when linking aven: |
---|
212 | # --disable-decoders --disable-demuxers |
---|
213 | if ! nasm -hf|grep -q macho64 ; then |
---|
214 | # nasm needs to support macho64, at least for x86_64 builds. |
---|
215 | LIBAV_CONFIGURE_OPTS="$LIBAV_CONFIGURE_OPTS --disable-yasm" |
---|
216 | fi |
---|
217 | ../configure --prefix="$prefix" --cc="$CC" $LIBAV_CONFIGURE_OPTS |
---|
218 | make -s |
---|
219 | make -s install |
---|
220 | cd ../.. |
---|
221 | fi |
---|
222 | fi |
---|
223 | |
---|
224 | test -n "$WX_CONFIG" || WX_CONFIG=`which wx-config` |
---|
225 | if test -z "$WX_CONFIG" ; then |
---|
226 | echo "WX_CONFIG not set and wx-config not on your PATH" |
---|
227 | exit 1 |
---|
228 | fi |
---|
229 | # Force static linking so the user doesn't need to install wxWidgets. |
---|
230 | WX_CONFIG=$WX_CONFIG' --static' |
---|
231 | rm -rf *.dmg Survex macosxtmp |
---|
232 | D=`pwd`/Survex |
---|
233 | T=`pwd`/macosxtmp |
---|
234 | PKG_CONFIG_PATH=`pwd`/PROJINSTALL/lib/pkgconfig:`pwd`/LIBAVINSTALL/lib/pkgconfig |
---|
235 | export PKG_CONFIG_PATH |
---|
236 | ./configure --prefix="$D" --bindir="$D" --mandir="$T" \ |
---|
237 | WX_CONFIG="$WX_CONFIG" CC="$CC" CXX="$CXX" |
---|
238 | make |
---|
239 | make install |
---|
240 | #mv Survex/survex Survex/Survex |
---|
241 | |
---|
242 | # Construct the Aven application bundle. |
---|
243 | mkdir -p Survex/Aven.app/Contents/MacOS Survex/Aven.app/Contents/Resources |
---|
244 | cp lib/Info.plist Survex/Aven.app/Contents |
---|
245 | printf APPLAVEN > Survex/Aven.app/Contents/PkgInfo |
---|
246 | mv Survex/share/doc/survex Survex/Docs |
---|
247 | rmdir Survex/share/doc |
---|
248 | mv Survex/share/survex/images Survex/Aven.app/Contents/Resources/ |
---|
249 | mv Survex/share/survex/unifont.pixelfont Survex/Aven.app/Contents/Resources/ |
---|
250 | ln Survex/share/survex/*.msg Survex/Aven.app/Contents/Resources/ |
---|
251 | mv Survex/aven Survex/Aven.app/Contents/MacOS/ |
---|
252 | ln Survex/cavern Survex/Aven.app/Contents/MacOS/ |
---|
253 | rm -rf Survex/share/applications Survex/share/icons Survex/share/mime-info |
---|
254 | mkdir Survex/share/survex/proj |
---|
255 | cp -p PROJINSTALL/share/proj/epsg PROJINSTALL/share/proj/esri Survex/share/survex/proj |
---|
256 | mkdir Survex/Aven.app/Contents/Resources/proj |
---|
257 | ln Survex/share/survex/proj/* Survex/Aven.app/Contents/Resources/proj |
---|
258 | |
---|
259 | # Create .icns files in the bundle's "Resources" directory. |
---|
260 | for zip in lib/icons/*.iconset.zip ; do |
---|
261 | unzip -d Survex/Aven.app/Contents/Resources "$zip" |
---|
262 | i=`echo "$zip"|sed 's!.*/\(.*\)\.zip$!\1!'` |
---|
263 | iconutil --convert icns "Survex/Aven.app/Contents/Resources/$i" |
---|
264 | rm -rf "Survex/Aven.app/Contents/Resources/$i" |
---|
265 | done |
---|
266 | |
---|
267 | size=`du -s Survex|sed 's/[^0-9].*//'` |
---|
268 | # Allow 1500 extra sectors for various overheads (1000 wasn't enough). |
---|
269 | sectors=`expr 1500 + "$size"` |
---|
270 | # Partition needs to be at least 4M and sectors are 512 bytes. |
---|
271 | if test "$sectors" -lt 8192 ; then |
---|
272 | sectors=8192 |
---|
273 | fi |
---|
274 | echo "Creating new blank image survex-macosx.dmg of $sectors sectors" |
---|
275 | # This creates the diskimage file and initialises it as an HFS+ volume. |
---|
276 | hdiutil create -sectors "$sectors" survex-macosx -layout NONE -fs HFS+ -volname Survex |
---|
277 | |
---|
278 | echo "Presenting image to the filesystems for mounting." |
---|
279 | # This will mount the image onto the Desktop. |
---|
280 | # Get the name of the device it is mounted on and the mount point. |
---|
281 | |
---|
282 | # man hdiutil says: |
---|
283 | # "The output of [hdiutil] attach has been stable since OS X 10.0 (though it |
---|
284 | # was called hdid(8) then) and is intended to be program-readable. It consists |
---|
285 | # of the /dev node, a tab, a content hint (if applicable), another tab, and a |
---|
286 | # mount point (if any filesystems were mounted)." |
---|
287 | # |
---|
288 | # In reality, it seems there are also some spaces before each tab character. |
---|
289 | hdid_output=`hdid survex-macosx.dmg|tail -1` |
---|
290 | echo "Last line of hdid output was: $hdid_output" |
---|
291 | dev=`echo "$hdid_output"|sed 's!/dev/\([^ ]*\).*!\1!'` |
---|
292 | mount_point=`echo "$hdid_output"|sed 's!.* !!'` |
---|
293 | |
---|
294 | echo "Device $dev mounted on $mount_point, copying files into image." |
---|
295 | ditto -rsrcFork Survex "$mount_point/Survex" |
---|
296 | ditto lib/INSTALL.OSX "$mount_point/INSTALL" |
---|
297 | |
---|
298 | echo "Detaching image." |
---|
299 | hdiutil detach "$dev" |
---|
300 | |
---|
301 | version=`sed 's/^VERSION *= *//p;d' Makefile` |
---|
302 | file=survex-macosx-$version.dmg |
---|
303 | echo "Compressing image file survex-macosx.dmg to $file" |
---|
304 | hdiutil convert survex-macosx.dmg -format "$dmg_format" -o "$file" |
---|
305 | rm survex-macosx.dmg |
---|
306 | |
---|
307 | echo "$file created successfully." |
---|