~jon-hill/spud/macos

« back to all changes in this revision

Viewing changes to diamond/macosx/mac_bundle.sh

  • Committer: Jon Hill
  • Date: 2013-10-23 19:19:57 UTC
  • Revision ID: jon.hill@imperial.ac.uk-20131023191957-chwfec43f28rgalr
New method of packaging up macos versions of PyGTK apps. Basically involved building the whole stack from python upwards. Works though

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
# Package script for Diamond.
4
 
#
5
 
# Thanks: http://stackoverflow.com/questions/1596945/building-osx-app-bundle
6
 
 
7
 
# Instructions:
8
 
#  bzr co lp:spud mac_bundle
9
 
#  cd mac_bundle
10
 
#  ./configure
11
 
#  cd diamond/macosx
12
 
#  ./mac_bundle
13
 
#  *make a coffee or tea*
14
 
#  Done
15
 
#
16
 
 
17
 
 
18
 
# Also fix $INSTALLDIR/MacOS/diamond in case this number changes
19
 
PYVER=2.7
20
 
APP=Diamond.app
21
 
INSTALLDIR=$APP/Contents
22
 
LIBDIR=$INSTALLDIR/lib
23
 
APPDIR=/Applications/$INSTALLDIR
24
 
LOCALDIR=/opt/gtk
25
 
 
26
 
# set up our virtual python environment
27
 
virtualenv --python=python$PYVER --no-site-packages $INSTALLDIR
28
 
 
29
 
cd ../
30
 
# install diamond in it
31
 
sed -i .bak 's/packaging=False/packaging=True/' setup.py
32
 
macosx/$INSTALLDIR/bin/python setup.py install
33
 
 
34
 
# install dxdiff
35
 
cd ../dxdiff;
36
 
../diamond/macosx/$INSTALLDIR/bin/python setup.py install
37
 
 
38
 
cd ../diamond/macosx;
39
 
 
40
 
mkdir $INSTALLDIR/MacOS
41
 
mkdir $INSTALLDIR/Resources
42
 
 
43
 
# Sort out the Resources
44
 
cp PkgInfo $INSTALLDIR/
45
 
cp Info.plist $INSTALLDIR/
46
 
cp pango_rc $INSTALLDIR/Resources/
47
 
cp diamond.icns $INSTALLDIR/Resources/
48
 
cp diamond $INSTALLDIR/MacOS
49
 
 
50
 
# Now we have to play silly buggers with some bits of the diamond file
51
 
# as the Mac app packages adds a command line argument, which we want to ignore
52
 
sed -i .bak 's/sys.argv\[1:\]/sys.argv\[2:\]/' $INSTALLDIR/bin/diamond
53
 
 
54
 
 
55
 
 
56
 
# Let's get the latest fluidity release schema
57
 
# NOTE: UPDATE URL AFTER A RELEASE
58
 
if [ ! -d fluidity ]; then
59
 
        bzr branch lp:fluidity/4.1 fluidity
60
 
else
61
 
        cd fluidity
62
 
        bzr up
63
 
        cd ../
64
 
fi
65
 
# Make the schemata description
66
 
rm -rf $INSTALLDIR/Resources/schemata/fluidity
67
 
mkdir -p $INSTALLDIR/Resources/schemata/fluidity
68
 
cat > $INSTALLDIR/Resources/schemata/flml << EOF
69
 
Fluidity Markup Language
70
 
/Applications/Diamond.app/Contents/Resources/schemata/fluidity/fluidity_options.rng
71
 
EOF
72
 
cp fluidity/schemas/*.rng $INSTALLDIR/Resources/schemata/fluidity/
73
 
cp ../../schema/*.rng $INSTALLDIR/Resources/schemata/fluidity/
74
 
# clean up
75
 
#rm -rf fluidity
76
 
 
77
 
# Do the above for any other schema we want to distribute
78
 
# Don't forget the spud-base!
79
 
 
80
 
 
81
 
 
82
 
# Let's get lxml installed
83
 
$INSTALLDIR/bin/easy_install --allow-hosts=lxml.de,*.python.org lxml
84
 
 
85
 
# Temp. solution - Just manually copy stuff we know we need
86
 
SITEPACKAGES=$LIBDIR/python$PYVER/site-packages
87
 
 
88
 
mkdir -p $SITEPACKAGES
89
 
 
90
 
# This locates pygtk.pyc. We want the source file
91
 
pygtk=`python -c "import pygtk; print pygtk.__file__[:-1]"`
92
 
oldsite=`dirname $pygtk`
93
 
gobject=`python -c "import gobject; print gobject.__file__[:-1]"`
94
 
glib=`python -c "import glib; print glib.__file__[:-1]"`
95
 
 
96
 
# Copy PyGtk and related libraries
97
 
cp $pygtk $SITEPACKAGES
98
 
cp -r `dirname $gobject` $SITEPACKAGES
99
 
cp -r `dirname $glib` $SITEPACKAGES
100
 
cp -r $oldsite/cairo $SITEPACKAGES
101
 
cp -r $oldsite/gtk-2.0 $SITEPACKAGES
102
 
cp $oldsite/pygtk.pth $SITEPACKAGES
103
 
 
104
 
 
105
 
# Modules, config, etc.
106
 
for dir in lib etc/pango etc/gtk-2.0 share/themes; do
107
 
  mkdir -p $INSTALLDIR/$dir
108
 
  cp -r $LOCALDIR/$dir/* $INSTALLDIR/$dir
109
 
done
110
 
 
111
 
# Resources, are processed on startup
112
 
for dir in etc/gtk-2.0 etc/pango lib/gdk-pixbuf-2.0/2.10.0; do
113
 
  mkdir -p $INSTALLDIR/Resources/$dir
114
 
  cp $LOCALDIR/$dir/* $INSTALLDIR/Resources/$dir
115
 
done
116
 
 
117
 
# Somehow files are writen with mode 444
118
 
find $INSTALLDIR -type f -exec chmod u+w {} \;
119
 
 
120
 
function log() {
121
 
  echo $* >&2
122
 
}
123
 
 
124
 
function resolve_deps() {
125
 
  local lib=$1
126
 
  local dep
127
 
  otool -L $lib | grep -e "^.$LOCALDIR/" |\
128
 
      while read dep _; do
129
 
    echo $dep
130
 
  done
131
 
}
132
 
 
133
 
function fix_paths() {
134
 
  local lib=$1
135
 
  log Fixing $lib
136
 
  for dep in `resolve_deps $lib`; do
137
 
    log Fixing `basename $lib`
138
 
    log "|  $dep"
139
 
    install_name_tool -change $dep @executable_path/../lib/`basename $dep` $lib
140
 
  done
141
 
}
142
 
 
143
 
binlibs=`find $INSTALLDIR -type f -name '*.so'`
144
 
 
145
 
for lib in $binlibs; do
146
 
  log Resolving $lib
147
 
  resolve_deps $lib
148
 
  fix_paths $lib
149
 
done | sort -u | while read lib; do
150
 
  log Copying $lib
151
 
  cp $lib $LIBDIR
152
 
  chmod u+w $LIBDIR/`basename $lib`
153
 
  fix_paths $LIBDIR/`basename $lib`
154
 
done
155
 
 
156
 
for lib in $dylibs; do
157
 
  log Resolving $lib
158
 
  resolve_deps $lib
159
 
  fix_paths $lib
160
 
done | sort -u | while read lib; do
161
 
  log Copying $lib
162
 
  cp $lib $LIBDIR
163
 
  chmod u+w $LIBDIR/`basename $lib`
164
 
  fix_paths $LIBDIR/`basename $lib`
165
 
done
166
 
 
167
 
 
168
 
# Fix config files
169
 
sed -i .bak 's#/opt/gtk/#'$APPDIR'/#' $INSTALLDIR/etc/pango/pango.modules 
170
 
sed -i .bak 's#/opt/gtk/#'$APPDIR'/#' $INSTALLDIR/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache
171
 
sed -i .bak 's#/opt/gtk/#'$APPDIR'/#' $INSTALLDIR/Resources/etc/pango/pango.modules 
172
 
sed -i .bak 's#/opt/gtk/#'$APPDIR'/#' $INSTALLDIR/Resources/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache
173
 
 
174
 
 
175
 
 
176
 
# Package!
177
 
VERSION=0.01
178
 
# we now need to fiddle with the Python run path on the diamond script
179
 
# COMMENT THESE OUT IF YOU WANT TO TEST YOUR APP WITHOUT INSTALLING
180
 
# EDIT AS REQUIRED
181
 
sed -i .bak 's|/Users/amcg/Software/spud/mac_port/diamond|/Applications|' $INSTALLDIR/bin/diamond
182
 
sed -i .bak 's|/Users/amcg/Software/spud/mac_port/diamond|/Applications|' $INSTALLDIR/MacOS/diamond
183
 
 
184
 
zip -rq Diamond-$VERSION-osx.zip $APP
185
 
hdiutil create -srcfolder $APP Diamond-$VERSION.dmg
186
 
 
187
 
 
188
 
# To test, temporarily move your /opt/gtk folder
189
 
# Move the Diamond.app folder to /Applications and go
190
 
# open -a Console 
191
 
# helps to debug
 
 
b'\\ No newline at end of file'