source: git/buildmacosx.sh @ 9699215

Last change on this file since 9699215 was 9699215, checked in by Olly Betts <olly@…>, 5 months ago

Update PROJ project name and website

The name is now "PROJ" (all caps and no ".4" suffix) and the website
is: https://proj.org/

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