source: git/buildmacosx.sh @ 2ed64d4

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since 2ed64d4 was 2ed64d4, checked in by Olly Betts <olly@…>, 6 years ago

Factor out macOS Aven.app creation

Put it into make rule so it can be easily used by the homebrew formula.

  • Property mode set to 100755
File size: 10.4 KB
RevLine 
[6df03c1]1#!/bin/sh
2#
[9d49627]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):
[0580c6a]5#
[9d49627]6#   https://developer.apple.com/xcode/downloads/
[2032841]7#
[9d49627]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:
[cc83ec9]11#
[9d49627]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:
[6df03c1]19#
[2032841]20#   ./buildmacosx.sh
[0580c6a]21#
[1aa20f9]22# This will automatically download and temporarily install wxWidgets,
[f55cbeb]23# PROJ.4 and FFmpeg in subdirectories of the source tree (this script is smart
[1aa20f9]24# enough not to re-download or re-build these if it already has).
[0580c6a]25#
[f55cbeb]26# If you already have wxWidgets, PROJ.4 and/or FFmpeg installed permanently,
[1aa20f9]27# you can disable these by passing one or more extra options - e.g. to build
28# none of them, use:
[0580c6a]29#
[f55cbeb]30#   ./buildmacosx.sh --no-install-wx --no-install-proj --no-install-ffmpeg
[6df03c1]31#
[1324d6c]32# If wxWidgets is installed somewhere such that wx-config isn't on your
[6df03c1]33# PATH you need to indicate where wx-config is by running this script
34# something like this:
35#
[b7510ee]36#   env WX_CONFIG=/path/to/wx-config ./buildmacosx.sh
[b72f4b5]37#
[2032841]38# (If you set WX_CONFIG, there's no need to pass --no-install-wx).
39#
[1324d6c]40# If using a pre-installed wxWidgets, note that it must satisfy the
[b72f4b5]41# following requirements:
[0167e06]42#
[b72f4b5]43#   - It must be built with OpenGL support (--with-opengl).
[0167e06]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).
[9d49627]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.
[c72a344]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
[5e6717d]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).
[c72a344]62#
[5e6717d]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):
[c72a344]71#
72#   ./buildmacosx.sh i386
73#
[5e6717d]74# Or to build for much older machines with a Power PC processor, use (again
75# assuming your compiler supports this):
[c72a344]76#
77#   ./buildmacosx.sh ppc
[6df03c1]78
79set -e
[0580c6a]80
[9d49627]81install_wx=yes
82install_proj=yes
[f55cbeb]83install_ffmpeg=yes
[9d49627]84while [ "$#" != 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      ;;
[f55cbeb]94    --no-install-ffmpeg)
95      install_ffmpeg=no
[1aa20f9]96      shift
97      ;;
[9d49627]98    --help|-h)
[f55cbeb]99      echo "Usage: $0 [--no-install-wx] [--no-install-proj] [--no-install-ffmpeg] [ppc|i386|x86_86]"
[9d49627]100      exit 0
101      ;;
102    -*)
103      echo "Unknown option - try --help" >&2
104      exit 1
105      ;;
106    *)
107      break
108      ;;
109  esac
110done
111
[5e6717d]112arch=$1
113if [ -z "$arch" ] ; then
114  arch=`uname -m`
115fi
116arch_flags="-arch $arch"
[9d49627]117
[0a287d2]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.
121dmg_format=UDBZ
122
[e058372]123WX_VERSION=3.0.3.1
124WX_SHA256=f94d4d2713a7ba2778677e2c26c61ac8f6e4be711bde6f88747662d093d899bc
[b72f4b5]125
[a7dfc9e]126PROJ_VERSION=4.9.3
127PROJ_SHA256=6984542fea333488de5c82eea58d699e4aff4b359200a9971537cd7e047185f7
[fb880024]128
[f55cbeb]129FFMPEG_VERSION=3.1.3
130FFMPEG_SHA256=f8575c071e2a64437aeb70c8c030b385cddbe0b5cde20c9b18a6def840128822
[1aa20f9]131
[9d49627]132if [ -z "${WX_CONFIG+set}" ] && [ "$install_wx" != no ] ; then
[0580c6a]133  if test -x WXINSTALL/bin/wx-config ; then
134    :
135  else
[deb58b87]136    prefix=`pwd`/WXINSTALL
[e058372]137    wxtarball=v$WX_VERSION.tar.gz
[56980d4]138    test -f "$wxtarball" || \
[e058372]139      curl -L -O "https://github.com/wxWidgets/wxWidgets/archive/$wxtarball"
[d752afd]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
[56980d4]146    echo "+++ Extracting $wxtarball"
[e576111]147    test -d "wxWidgets-$WX_VERSION" || tar xf "$wxtarball"
[976a038]148    test -d "wxWidgets-$WX_VERSION/BUILD" || mkdir "wxWidgets-$WX_VERSION/BUILD"
149    cd "wxWidgets-$WX_VERSION/BUILD"
[4df1235]150    # Compilation of wx 3.0.2 fails on OS X 10.10.1 with webview enabled.
[1fce809]151    # A build with liblzma enabled doesn't work on OS X 10.6.8.
152    ../configure --disable-shared --prefix="$prefix" \
[cf9156d]153        --with-opengl --enable-display \
[1fce809]154        --disable-webview --without-liblzma \
155        CC="gcc $arch_flags" CXX="g++ $arch_flags"
[0580c6a]156    make -s
157    make -s install
158    cd ../..
159  fi
[b7510ee]160  WX_CONFIG=`pwd`/WXINSTALL/bin/wx-config
[0580c6a]161fi
162
[1c80bef]163[ -n "${WX_CONFIG}" ] || WX_CONFIG=`which wx-config 2>/dev/null`
164if [ -z "${WX_CONFIG}" ] ; then
165  echo "wx-config not found in PATH."
166  echo
167  echo "If wxWidgets is installed, you can specify its location by setting environment variable WX_CONFIG:"
168  echo
169  echo "WX_CONFIG=/opt/bin/wx-config sh ./buildmacosx.sh"
170  exit 1
171fi
[fb880024]172CC=`$WX_CONFIG --cc`
173CXX=`$WX_CONFIG --cxx`
174
[9d49627]175if [ "$install_proj" != no ] ; then
[fb880024]176  if test -f PROJINSTALL/include/proj_api.h ; then
177    :
178  else
179    prefix=`pwd`/PROJINSTALL
180    projtarball=proj-$PROJ_VERSION.tar.gz
181    test -f "$projtarball" || \
182      curl -O "http://download.osgeo.org/proj/$projtarball"
183    if echo "$PROJ_SHA256  $projtarball" | shasum -a256 -c ; then
184      : # OK
185    else
186      echo "Checksum of downloaded file '$projtarball' is incorrect, aborting."
187      exit 1
188    fi
189    echo "+++ Extracting $projtarball"
[e576111]190    test -d "proj-$PROJ_VERSION" || tar xf "$projtarball"
[976a038]191    test -d "proj-$PROJ_VERSION/BUILD" || mkdir "proj-$PROJ_VERSION/BUILD"
192    cd "proj-$PROJ_VERSION/BUILD"
[fb880024]193    ../configure --disable-shared --prefix="$prefix" CC="$CC" CXX="$CXX"
194    make -s
195    make -s install
196    cd ../..
197  fi
198fi
199
[f55cbeb]200if [ "$install_ffmpeg" != no ] ; then
201  if test -f FFMPEGINSTALL/include/libavcodec/avcodec.h ; then
[1aa20f9]202    :
203  else
[f55cbeb]204    prefix=`pwd`/FFMPEGINSTALL
205    ffmpegtarball=ffmpeg-$FFMPEG_VERSION.tar.xz
206    test -f "$ffmpegtarball" || \
207      curl -O "https://ffmpeg.org/releases/$ffmpegtarball"
208    if echo "$FFMPEG_SHA256  $ffmpegtarball" | shasum -a256 -c ; then
[1aa20f9]209      : # OK
210    else
[f55cbeb]211      echo "Checksum of downloaded file '$ffmpegtarball' is incorrect, aborting."
[1aa20f9]212      exit 1
213    fi
[f55cbeb]214    echo "+++ Extracting $ffmpegtarball"
215    test -d "ffmpeg-$FFMPEG_VERSION" || tar xf "$ffmpegtarball"
216    test -d "ffmpeg-$FFMPEG_VERSION/BUILD" || mkdir "ffmpeg-$FFMPEG_VERSION/BUILD"
217    cd "ffmpeg-$FFMPEG_VERSION/BUILD"
218    FFMPEG_CONFIGURE_OPTS='--disable-shared --disable-programs --disable-network --disable-bsfs --disable-protocols --disable-devices'
[6835e68]219    # We don't need to decode video, but disabling these causes a link failure
220    # when linking aven:
221    # --disable-decoders --disable-demuxers
[82901f0]222    if ! nasm -hf|grep -q macho64 ; then
[1aa20f9]223      # nasm needs to support macho64, at least for x86_64 builds.
[f55cbeb]224      FFMPEG_CONFIGURE_OPTS="$FFMPEG_CONFIGURE_OPTS --disable-yasm"
[1aa20f9]225    fi
[f55cbeb]226    ../configure --prefix="$prefix" --cc="$CC" $FFMPEG_CONFIGURE_OPTS
[1aa20f9]227    make -s
228    make -s install
229    cd ../..
230  fi
231fi
232
[b7510ee]233test -n "$WX_CONFIG" || WX_CONFIG=`which wx-config`
234if test -z "$WX_CONFIG" ; then
235  echo "WX_CONFIG not set and wx-config not on your PATH"
[6df03c1]236  exit 1
237fi
[1324d6c]238# Force static linking so the user doesn't need to install wxWidgets.
[b7510ee]239WX_CONFIG=$WX_CONFIG' --static'
[0580c6a]240rm -rf *.dmg Survex macosxtmp
[52f66de7]241C=`pwd`
242D=$C/Survex
243T=$C/macosxtmp
244PKG_CONFIG_PATH=$C/PROJINSTALL/lib/pkgconfig:$C/FFMPEGINSTALL/lib/pkgconfig
[f678705]245export PKG_CONFIG_PATH
[1aa20f9]246./configure --prefix="$D" --bindir="$D" --mandir="$T" \
[f678705]247    WX_CONFIG="$WX_CONFIG" CC="$CC" CXX="$CXX"
[6df03c1]248make
249make install
250#mv Survex/survex Survex/Survex
251
[b72f4b5]252# Construct the Aven application bundle.
[2ed64d4]253make create-aven-app APP_PATH=Survex/Aven.app
[09dfd18]254mv Survex/share/doc/survex Survex/Docs
255rmdir Survex/share/doc
[47eeb112]256mv Survex/share/survex/images Survex/Aven.app/Contents/Resources/
257mv Survex/share/survex/unifont.pixelfont Survex/Aven.app/Contents/Resources/
258ln Survex/share/survex/*.msg Survex/Aven.app/Contents/Resources/
[b72f4b5]259mv Survex/aven Survex/Aven.app/Contents/MacOS/
[c0a3f6a9]260ln Survex/cavern Survex/extend Survex/Aven.app/Contents/MacOS/
[47eeb112]261rm -rf Survex/share/applications Survex/share/icons Survex/share/mime-info
[278e305]262mkdir Survex/share/survex/proj
263cp -p PROJINSTALL/share/proj/epsg PROJINSTALL/share/proj/esri Survex/share/survex/proj
264mkdir Survex/Aven.app/Contents/Resources/proj
265ln Survex/share/survex/proj/* Survex/Aven.app/Contents/Resources/proj
[b72f4b5]266
[6df03c1]267size=`du -s Survex|sed 's/[^0-9].*//'`
[1aa20f9]268# Allow 1500 extra sectors for various overheads (1000 wasn't enough).
269sectors=`expr 1500 + "$size"`
[6df03c1]270# Partition needs to be at least 4M and sectors are 512 bytes.
[56980d4]271if test "$sectors" -lt 8192 ; then
[6df03c1]272  sectors=8192
273fi
274echo "Creating new blank image survex-macosx.dmg of $sectors sectors"
[0580c6a]275# This creates the diskimage file and initialises it as an HFS+ volume.
[56980d4]276hdiutil create -sectors "$sectors" survex-macosx -layout NONE -fs HFS+ -volname Survex
[6df03c1]277
[b72f4b5]278echo "Presenting image to the filesystems for mounting."
[6df03c1]279# This will mount the image onto the Desktop.
[ab66f3c]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)."
[f04ae51]287#
288# In reality, it seems there are also some spaces before each tab character.
[ab66f3c]289hdid_output=`hdid survex-macosx.dmg|tail -1`
290echo "Last line of hdid output was: $hdid_output"
[f04ae51]291dev=`echo "$hdid_output"|sed 's!/dev/\([^        ]*\).*!\1!'`
[fc4d068]292mount_point=`echo "$hdid_output"|sed 's!.*      !!'`
[ab66f3c]293
294echo "Device $dev mounted on $mount_point, copying files into image."
295ditto -rsrcFork Survex "$mount_point/Survex"
296ditto lib/INSTALL.OSX "$mount_point/INSTALL"
297
[0580c6a]298echo "Detaching image."
[56980d4]299hdiutil detach "$dev"
[6df03c1]300
[d260645]301version=`sed 's/^VERSION *= *//p;d' Makefile`
[56980d4]302file=survex-macosx-$version.dmg
[6df03c1]303echo "Compressing image file survex-macosx.dmg to $file"
[0a287d2]304hdiutil convert survex-macosx.dmg -format "$dmg_format" -o "$file"
[0580c6a]305rm survex-macosx.dmg
[6df03c1]306
307echo "$file created successfully."
Note: See TracBrowser for help on using the repository browser.