adding osx application bundler scripts
[pspp] / utilities / osxbundler / makeosxbundle.sh
1 #!/bin/sh -e
2
3 # Create a MacOS application bundle for pspp
4 # This will install all required dependencies via macports
5 # With option --git it will build pspp from a source tree
6 # The default is to install also pspp from macports
7 # Requires XCode Commandline Tools installed and ready for macports
8
9 # Copyright (C) 2016 Free Software Foundation, Inc.
10 # Released under GNU General Public License, either version 3
11 # or any later option
12
13 # The source tree for pspp is here. This is only required if you
14 # build with option --git
15 psppsource=`pwd`/../..
16
17 # Check if we are on MacOS
18 if ! test `uname` = "Darwin"; then
19     echo "This only works on MacOS"
20     exit
21 fi
22
23 # Check if XCode is installed - Assume clang indicates xcode.
24 if ! test -f /usr/bin/clang; then
25     echo "/usr/bin/clang not found - please install XCode CLT"
26     exit
27 fi
28
29 # Check the required configuration files
30 if ! test -f ./pspp.bundle; then
31     echo "pspp.bundle is missing"
32     exit
33 fi
34
35 if ! test -f ./Info-pspp.plist; then
36     echo "Info-pspp.plist is missing"
37     exit
38 fi
39
40 buildfromsource=false
41 if test $# = 1 && test $1 = "--git"; then
42     echo "Trying to build from source"
43     if test -f $psppsource/configure; then
44         buildfromsource=true
45     else
46         echo "Could not find pspp source in: $psppsource"
47         exit
48     fi
49 fi
50
51 # This is the installation directory which will be used as macports prefix
52 # and as pspp configure prefix.
53 bundleinstall=`pwd`/install
54
55 export PATH=$bundleinstall/bin:$bundleinstall/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
56
57 # Target macports install directory for the pspp bundle
58 if test -d $bundleinstall; then
59     echo "Found existing macports directory $bundleinstall"
60     echo "Updating macports packages"
61     port uninstall pspp
62     port uninstall gtk-mac-bundler
63 else
64     echo "Creating Macports installation in $bundleinstall"
65     mkdir $bundleinstall
66     # Install macports
67     rm -rf /tmp/macports
68     mkdir /tmp/macports
69     pushd /tmp/macports
70     curl https://distfiles.macports.org/MacPorts/MacPorts-2.3.4.tar.gz -O
71     tar xvzf Macports-2.3.4.tar.gz
72     cd Macports-2.3.4
73     ./configure --prefix=$bundleinstall \
74                 --with-applications-dir=$bundleinstall/Applications \
75                 --with-no-root-privileges
76     make
77     make install
78     popd
79     rm -rf /tmp/macports
80     # Modify the default variants to use quartz
81     echo "-x11 +no_x11 +quartz" > $bundleinstall/etc/macports/variants.conf
82 fi
83
84 # Install the packages for pspp
85 port -v selfupdate
86 port upgrade outdated || true
87 if test $buildfromsource = "true"; then
88     # Install the build dependencies for pspp
89     port install pkgconfig texinfo makeicns cairo fontconfig freetype \
90      gettext glib2 gsl libiconv libxml2 ncurses pango readline zlib atk \
91      gdk-pixbuf2 gtksourceview3 adwaita-icon-theme
92 # Configure and build pspp
93     rm -rf ./build
94     mkdir ./build
95     pushd build
96     $psppsource/configure --prefix=$bundleinstall \
97                          LDFLAGS=-L$bundleinstalll/lib \
98                          CPPFLAGS=-I$bundleinstall/include \
99                          --enable-relocatable
100     make
101     make install
102     popd
103 else
104     # Install the pspp package from macports
105     # This is a custom package for the moment as this requires the relocatable variant
106     echo "Installing pspp from macports package"
107     pushd ./macports-custom-packages/pspp
108     port install +reloc
109     popd
110 fi
111
112 # install the mac gtk-mac-bundler
113 # Custom package for the moment...
114 pushd ./macports-custom-packages/gtk-mac-bundler
115 port install
116 popd
117
118 # Create the icns file
119 makeicns -256 $bundleinstall/share/icons/hicolor/256x256/apps/pspp.png \
120          -32  $bundleinstall/share/icons/hicolor/32x32/apps/pspp.png \
121          -16  $bundleinstall/share/icons/hicolor/16x16/apps/pspp.png \
122          -out pspp.icns
123
124 # produce the pspp.app bundle in Desktop
125 export PSPPINSTALL=$bundleinstall
126 gtk-mac-bundler pspp.bundle
127
128 # Fix the link issue for the relocatable binary in the app bundle
129 # MacOS/pspp - the wrapper from gtk-mac-bundler calling
130 # MacOS/pspp-bin - the wrapper from glibc relocatable calling pspp-bin.bin
131 # but that is in the Resource directory
132 pushd pspp.app/Contents/MacOS
133 ln -s ../Resources/bin/psppire.bin ./pspp-bin.bin
134 popd
135
136 # Create the DMG for distribution
137 rm -rf /tmp/psppbundle
138 mkdir /tmp/psppbundle
139 mv ./pspp.app /tmp/psppbundle
140 rm -rf pspp.dmg
141 hdiutil create -fs HFS+ -srcfolder /tmp/psppbundle -volname pspp pspp.dmg
142 rm -rf /tmp/psppbundle
143
144 echo "Done! Your dmg file is pspp.dmg"
145 echo "You can remove the install directory: $bundleinstall"