Code

made it callable by other extensions. the workaround is sorta ugly, but it should...
[inkscape.git] / packaging / osx-app.sh
1 #! /bin/bash
2 # Copyright 2005, Kees Cook <kees@outflux.net>
3 # Licensed under GNU General Public License
4 #
5 # Usage: osx-app [-s] /path/to/bin/inkscape Info.plist /path/to/packaging/macosx
6 #
7 # This attempts to build an Inkscape.app package for OSX, resolving
8 # Dynamic libraries, etc.  Strips the executable and libraries if
9 # '-s' is given.
10 #
11 # Thanks to GNUnet's "build_app" script for help with library dep resolution.
12 # https://gnunet.org/svn/GNUnet/contrib/OSX/build_app
13
14 # Fixes and modifications to use Gimp.app style launcher:
15 #   Michael Wybrow <mjwybrow@users.sourceforge.net>
16 #
17 #
18 # Notes:
19 # The Info.plist file can be found in the base inkscape directory once
20 # configure has been run.
21 # The macosx directory is in the inkscape/packaging directory.
22 #
23 # When packaging Inkscape for OS X, configure should be run with the 
24 # "--enable-osxapp" option which sets the correct paths for support
25 # files inside the app bundle.
26
27 # Thus, the usual use of this file would be to run it from the within the
28 # inkscape/packaging directory, substituting in the inkscape binary path:
29 #       ./osx-app.sh /path/to/bin/inkscape ../Info.plist macosx
33 # Handle some version specific details.
34 VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
35 if [ "$VERSION" -ge "4" ]; then
36   # We're on Tiger (10.4) or later.
37   # XCode behaves a little differently in Tiger and later.
38   XCODEFLAGS="-configuration Deployment"
39   SCRIPTEXECDIR="ScriptExec/build/Deployment/ScriptExec.app/Contents/MacOS"
40   # libXinerama.1.dylib is not installed as part of X11 on Panther but
41   # is introduced as a dependency if Inkscape is compiled on Tiger or
42   # later.  Thus, add the library to the bundle for Panther users
43   EXTRALIBS="/usr/X11R6/lib/libXinerama.1.dylib"
44 else
45   # Panther (10.3) or earlier.
46   XCODEFLAGS="-buildstyle Deployment"
47   SCRIPTEXECDIR="ScriptExec/build/ScriptExec.app/Contents/MacOS"
48   EXTRALIBS=""
49 fi
52 SW="$HOME/ws-fat"
54 pangover=1.5.0
55 gtkver=2.10.0
58 # Package always has the same name.  Version information is stored in
59 # the Info.plist file which is filled in by the configure script.
60 pkg=Inkscape
61 package="$pkg.app"
63 # TODO: Rewrite handling of command line args and make more robust.
65 strip=false
66 if [ "$1" = "-s" ]; then
67         strip=true
68         shift
69 fi
71 binary="$1"
72 if [ ! -x "$binary" ]; then
73         echo "Not executable: $binary" >&2
74         exit 1
75 fi
76 shift
78 plist="$1"
79 if [ ! -f "$plist" ]; then
80         echo "Need plist file" >&2
81         exit 1
82 fi
83 shift
85 resdir=$1
86 if [ ! -d $resdir ]; then
87         echo "Need the macosx packaging directory" >&2
88         exit 1
89 fi
90 shift
92 # Fix a given executable or library to be relocatable
93 fixlib () {
94 if [ ! -d "$1" ]; then
95   echo $1
96   libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
97   for lib in $libs; do
98     echo "  $lib"
99     base=`echo $lib | awk -F/ '{print $NF}'`
100     first=`echo $lib | cut -d/ -f1-3`
101     to=@executable_path/../lib/$base
102     if [ $first != /usr/lib -a $first != /usr/X11R6 ]; then
103       /usr/bin/install_name_tool -change $lib $to $1
104       if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
105         /usr/bin/install_name_tool -id $to ../lib/$base
106         for ll in $libs; do
107           base=`echo $ll | awk -F/ '{print $NF}'`
108           first=`echo $ll | cut -d/ -f1-3`
109           to=@executable_path/../lib/$base
110           if [ $first != /usr/lib -a $first != /usr/X11R6 -a "`echo $ll | fgrep libcrypto`" = "" ]; then
111             /usr/bin/install_name_tool -change $ll $to ../lib/$base
112           fi
113         done
114       fi
115     fi
116   done
117 fi
122 mkdir -p "$package"/Contents/MacOS
123 mkdir -p "$package"/Contents/Resources/bin
124 mkdir -p "$package"/Contents/Resources/lib
125 mkdir -p "$package"/Contents/Resources/locale
127 binname=`basename "$binary"`
128 binpath="$package/Contents/Resources/bin/inkscape-bin"
130 cp "$binary" "$binpath"
133 # Build and add the launcher.
135   # Build fails if CC happens to be set (to anything other than CompileC)
136   unset CC
137   
138   cd "$resdir/ScriptExec"
139   xcodebuild $XCODEFLAGS clean build
141 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$package/Contents/MacOS/Inkscape"
143 # Pull down all the share files
144 binary_dir=`dirname "$binary"`
145 rsync -av "$binary_dir/../share/$binname"/* "$package/Contents/Resources/"
146 cp "$plist" "$package/Contents/Info.plist"
147 rsync -av "$binary_dir/../share/locale"/* "$package/Contents/Resources/locale"
149 # PkgInfo must match bundle type and creator code from Info.plist
150 echo "APPLInks" > $package/Contents/PkgInfo
152 # Pull in extra requirements.
153 pkgetc="$package/Contents/Resources/etc"
154 mkdir -p $pkgetc/pango
155 cp $SW/etc/pango/pangox.aliases $pkgetc/pango/
156 # Need to adjust path and quote incase of spaces in path.
157 sed -e "s,$SW,\"\${CWD},g" -e 's,\.so ,.so" ,g' $SW/etc/pango/pango.modules > $pkgetc/pango/pango.modules
158 cat > $pkgetc/pango/pangorc <<END_PANGO
159 [Pango]
160 ModuleFiles=\${HOME}/.inkscape-etc/pango.modules
161 [PangoX]
162 AliasFiles=\${HOME}/.inkscape-etc/pangox.aliases
163 END_PANGO
165 # We use a modified fonts.conf file so only need the dtd
166 mkdir -p $pkgetc/fonts
167 cp $SW/etc/fonts/fonts.dtd $pkgetc/fonts/
168 cp -r $SW/etc/fonts/conf.avail $pkgetc/fonts/
169 cp -r $SW/etc/fonts/conf.d $pkgetc/fonts/
171 mkdir -p $pkgetc/gtk-2.0
172 sed -e "s,$SW,\${CWD},g" $SW/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
173 sed -e "s,$SW,\${CWD},g" $SW/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
175 for item in gnome-vfs-mime-magic gnome-vfs-2.0
176 do
177   cp -r $SW/etc/$item $pkgetc/
178 done
181 pkglib="$package/Contents/Resources/lib"
182 mkdir -p $pkglib/pango/$pangover/modules
183 cp $SW/lib/pango/$pangover/modules/*.so $pkglib/pango/$pangover/modules/
186 mkdir -p $pkglib/gtk-2.0/$gtkver/{engines,immodules,loaders}
187 cp -r $SW/lib/gtk-2.0/$gtkver/engines/* $pkglib/gtk-2.0/$gtkver/engines/
188 cp $SW/lib/gtk-2.0/$gtkver/immodules/*.so $pkglib/gtk-2.0/$gtkver/immodules/
189 cp $SW/lib/gtk-2.0/$gtkver/loaders/*.so $pkglib/gtk-2.0/$gtkver/loaders/
191 mkdir -p $pkglib/gnome-vfs-2.0/modules
192 cp $SW/lib/gnome-vfs-2.0/modules/*.so $pkglib/gnome-vfs-2.0/modules/
194 # Find out libs we need from fink (e.g. $SW) - loop until no changes
195 a=1
196 nfiles=0
197 endl=true
198 while $endl; do
199   echo "Looking for dependencies. Round " $a
200   libs="`otool -L $pkglib/gtk-2.0/$gtkver/loaders/* $pkglib/gtk-2.0/$gtkver/immodules/* $pkglib/gtk-2.0/$gtkver/engines/*.so $pkglib/pango/$pangover/modules/* $pkglib/gnome-vfs-2.0/modules/* $package/Contents/Resources/lib/* $binary 2>/dev/null | fgrep compatibility | cut -d\( -f1 | grep $SW | sort | uniq`"
201   cp -f $libs $package/Contents/Resources/lib
202   let "a+=1"  
203   nnfiles=`ls $package/Contents/Resources/lib | wc -l`
204   if [ $nnfiles = $nfiles ]; then
205     endl=false
206   else
207     nfiles=$nnfiles
208   fi
209 done
211 for libfile in $EXTRALIBS
212 do
213   cp -f $libfile $package/Contents/Resources/lib
214 done
216 if [ "$strip" = "true" ]; then
217   chmod +w "$package"/Contents/Resources/lib/*.dylib
218   strip -x "$package"/Contents/Resources/lib/*.dylib
219   strip -ur "$binpath"
220 fi
222 # NOTE: This works for all the dylibs but causes GTK to crash at startup.
223 #       Instead we leave them with their original install_names and set
224 #       DYLD_LIBRARY_PATH within the app bundle before running Inkscape.
226 # Fix package deps
227 #(cd "$package/Contents/MacOS/bin"
228 # for file in *; do
229 #    fixlib "$file"
230 # done
231 # cd ../lib
232 # for file in *; do
233 #    fixlib "$file"
234 # done)
236 # Get all the icons and the rest of the script framework
237 rsync -av $resdir/Resources/* $package/Contents/Resources/
240 # Make an image
241 #/usr/bin/hdiutil create -srcfolder "$pkg.app" "$pkg.dmg"
242 ( cd macosx && ./osx-dmg.sh )