macosx: Hardcode the Qt version to 5.5 for now.
[sigrok-util.git] / cross-compile / macosx / create_dmg
1 #!/bin/sh
2 ##
3 ## This file is part of the sigrok-util project.
4 ##
5 ## Copyright (C) 2017 Uwe Hermann <uwe@hermann-uwe.de>
6 ##
7 ## This program is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ##
20
21 set -e
22
23 # The path where the installed sigrok libraries/binaries are located.
24 PREFIX=$HOME/sr_macosx
25
26 # The path where to download files to and where to build packages.
27 BUILDDIR=./build_app
28
29 # We use Qt 5.5 in order to remain compatible with more versions of Mac OS X.
30 QTVER=qt@5.5
31
32 # Path to Qt5 binaries.
33 QTBINDIR=`brew list $QTVER | grep bin | head -n 1 | xargs dirname`
34
35 # Path to boost libraries.
36 BOOSTLIBDIR=`brew list boost | grep libboost_system | head -n 1 | xargs dirname`
37
38 # Path to Python 3 framework.
39 PYTHONFRAMEWORKDIR=`brew list python3 | grep Python.framework | head -n 1 | xargs dirname`/../../../..
40
41 PYVER="3.7"
42
43 # You usually don't need to change anything below this line.
44
45 # -----------------------------------------------------------------------------
46
47 # Remove build directory contents (if any) and create a new build dir.
48 rm -rf $BUILDDIR
49 mkdir $BUILDDIR
50 cd $BUILDDIR
51
52 APPNAME="PulseView"
53 APPNAME_BINARY="pulseview"
54 APPVER="nightly"
55
56 CONTENTSDIR="$APPNAME.app/Contents"
57 MACOSDIR="$CONTENTSDIR/MacOS"
58 FRAMEWORKSDIR="$CONTENTSDIR/Frameworks"
59 SHARE_DIR="$CONTENTSDIR/share"
60 PYDIR="$FRAMEWORKSDIR/Python.framework/Versions/$PYVER"
61
62 mkdir -p $MACOSDIR $FRAMEWORKSDIR $SHARE_DIR
63
64 cp $PREFIX/bin/$APPNAME_BINARY $MACOSDIR
65 cp -R $PREFIX/share/libsigrokdecode $SHARE_DIR
66 rm -rf $SHARE_DIR/libsigrokdecode/decoders/**/__pycache__
67 rm -rf $SHARE_DIR/libsigrokdecode/decoders/common/**/__pycache__
68 cp -R $PREFIX/share/sigrok-firmware $SHARE_DIR
69
70 # Manually copy some boost libs that "macdeployqt" won't copy.
71 cp $BOOSTLIBDIR/libboost_timer-mt.dylib $FRAMEWORKSDIR
72 cp $BOOSTLIBDIR/libboost_chrono-mt.dylib $FRAMEWORKSDIR
73 chmod 644 $FRAMEWORKSDIR/*boost*
74
75 $QTBINDIR/macdeployqt $APPNAME.app
76
77 # Copy Python framework and fix it up.
78 cp -R $PYTHONFRAMEWORKDIR $FRAMEWORKSDIR
79 chmod 644 $PYDIR/lib/libpython*.dylib
80 rm -rf $PYDIR/Headers
81 rm -rf $PYDIR/bin
82 rm -rf $PYDIR/include
83 rm -rf $PYDIR/share
84 rm -rf $PYDIR/lib/pkgconfig
85 rm -rf $PYDIR/lib/python$PYVER/lib2to3
86 rm -rf $PYDIR/lib/python$PYVER/distutils
87 rm -rf $PYDIR/lib/python$PYVER/idlelib
88 rm -rf $PYDIR/lib/python$PYVER/test
89 rm -rf $PYDIR/lib/python$PYVER/**/test
90 rm -rf $PYDIR/lib/python$PYVER/tkinter
91 rm -rf $PYDIR/lib/python$PYVER/turtledemo
92 rm -rf $PYDIR/lib/python$PYVER/unittest
93 rm -rf $PYDIR/lib/python$PYVER/__pycache__
94 rm -rf $PYDIR/lib/python$PYVER/**/__pycache__
95 rm -rf $PYDIR/lib/python$PYVER/**/**/__pycache__
96 rm -rf $PYDIR/Resources
97 install_name_tool -change \
98         /usr/local/opt/python/Frameworks/Python.framework/Versions/$PYVER/Python \
99         @executable_path/../Frameworks/Python.framework/Versions/$PYVER/Python \
100         $FRAMEWORKSDIR/libsigrokdecode.*.dylib
101
102 # Add PulseView wrapper (sets PYTHONHOME/SIGROK_FIRMWARE_DIR/SIGROKDECODE_DIR).
103 mv $MACOSDIR/$APPNAME_BINARY $MACOSDIR/$APPNAME_BINARY.real
104 cp ../contrib/pulseview $MACOSDIR
105 chmod 755 $MACOSDIR/$APPNAME_BINARY
106
107 cp ../contrib/Info.plist $CONTENTSDIR
108 cp ../contrib/pulseview.icns $CONTENTSDIR/Resources
109
110 hdiutil create "${APPNAME}_${APPVER}.dmg" -volname "$APPNAME $APPVER" \
111         -fs HFS+ -srcfolder "$APPNAME.app"