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
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 #
22 # When packaging Inkscape for OS X, configure should be run with the
23 # "--enable-osxapp" option which sets the correct paths for support
24 # files inside the app bundle.
25 #
26 # Thus, the usual use of this file would be to run it from the within the
27 # inkscape/packaging directory, substituting in the inkscape binary path:
28 # ./osx-app.sh /path/to/bin/inkscape ../Info.plist
32 # Handle some version specific details.
33 VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
34 if [ "$VERSION" -ge "4" ]; then
35 # We're on Tiger (10.4) or later.
36 # XCode behaves a little differently in Tiger and later.
37 XCODEFLAGS="-configuration Deployment"
38 SCRIPTEXECDIR="ScriptExec/build/Deployment/ScriptExec.app/Contents/MacOS"
39 # libXinerama.1.dylib is not installed as part of X11 on Panther but
40 # is introduced as a dependency if Inkscape is compiled on Tiger or
41 # later. Thus, add the library to the bundle for Panther users
42 EXTRALIBS="/usr/X11R6/lib/libXinerama.1.dylib"
43 else
44 # Panther (10.3) or earlier.
45 XCODEFLAGS="-buildstyle Deployment"
46 SCRIPTEXECDIR="ScriptExec/build/ScriptExec.app/Contents/MacOS"
47 EXTRALIBS=""
48 fi
51 SW="$HOME/ws-fat"
53 pangover=1.5.0
54 gtkver=2.10.0
57 # Package always has the same name. Version information is stored in
58 # the Info.plist file which is filled in by the configure script.
59 pkg=Inkscape
60 package="$pkg.app"
62 # TODO: Rewrite handling of command line args and make more robust.
64 strip=false
65 if [ "$1" = "-s" ]; then
66 strip=true
67 shift
68 fi
70 binary="$1"
71 if [ ! -x "$binary" ]; then
72 echo "Not executable: $binary" >&2
73 exit 1
74 fi
75 shift
77 plist="$1"
78 if [ ! -f "$plist" ]; then
79 echo "Need plist file" >&2
80 exit 1
81 fi
82 shift
84 resdir=`pwd`
86 # Fix a given executable or library to be relocatable
87 fixlib () {
88 if [ ! -d "$1" ]; then
89 echo $1
90 libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
91 for lib in $libs; do
92 echo " $lib"
93 base=`echo $lib | awk -F/ '{print $NF}'`
94 first=`echo $lib | cut -d/ -f1-3`
95 to=@executable_path/../lib/$base
96 if [ $first != /usr/lib -a $first != /usr/X11R6 ]; then
97 /usr/bin/install_name_tool -change $lib $to $1
98 if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
99 /usr/bin/install_name_tool -id $to ../lib/$base
100 for ll in $libs; do
101 base=`echo $ll | awk -F/ '{print $NF}'`
102 first=`echo $ll | cut -d/ -f1-3`
103 to=@executable_path/../lib/$base
104 if [ $first != /usr/lib -a $first != /usr/X11R6 -a "`echo $ll | fgrep libcrypto`" = "" ]; then
105 /usr/bin/install_name_tool -change $ll $to ../lib/$base
106 fi
107 done
108 fi
109 fi
110 done
111 fi
112 }
116 mkdir -p "$package"/Contents/MacOS
117 mkdir -p "$package"/Contents/Resources/bin
118 mkdir -p "$package"/Contents/Resources/lib
119 mkdir -p "$package"/Contents/Resources/locale
121 binname=`basename "$binary"`
122 binpath="$package/Contents/Resources/bin/inkscape-bin"
124 cp "$binary" "$binpath"
127 # Build and add the launcher.
128 (
129 # Build fails if CC happens to be set (to anything other than CompileC)
130 unset CC
132 cd "$resdir/ScriptExec"
133 xcodebuild $XCODEFLAGS clean build
134 )
135 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$package/Contents/MacOS/Inkscape"
137 # Pull down all the share files
138 binary_dir=`dirname "$binary"`
139 rsync -av "$binary_dir/../share/$binname"/* "$package/Contents/Resources/"
140 cp "$plist" "$package/Contents/Info.plist"
141 rsync -av "$binary_dir/../share/locale"/* "$package/Contents/Resources/locale"
143 # PkgInfo must match bundle type and creator code from Info.plist
144 echo "APPLInks" > $package/Contents/PkgInfo
146 # Pull in extra requirements.
147 pkgetc="$package/Contents/Resources/etc"
148 mkdir -p $pkgetc/pango
149 cp $SW/etc/pango/pangox.aliases $pkgetc/pango/
150 # Need to adjust path and quote incase of spaces in path.
151 sed -e "s,$SW,\"\${CWD},g" -e 's,\.so ,.so" ,g' $SW/etc/pango/pango.modules > $pkgetc/pango/pango.modules
152 cat > $pkgetc/pango/pangorc <<END_PANGO
153 [Pango]
154 ModuleFiles=\${HOME}/.inkscape-etc/pango.modules
155 [PangoX]
156 AliasFiles=\${HOME}/.inkscape-etc/pangox.aliases
157 END_PANGO
159 # We use a modified fonts.conf file so only need the dtd
160 mkdir -p $pkgetc/fonts
161 cp $SW/etc/fonts/fonts.dtd $pkgetc/fonts/
162 cp -r $SW/etc/fonts/conf.avail $pkgetc/fonts/
163 cp -r $SW/etc/fonts/conf.d $pkgetc/fonts/
165 mkdir -p $pkgetc/gtk-2.0
166 sed -e "s,$SW,\${CWD},g" $SW/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
167 sed -e "s,$SW,\${CWD},g" $SW/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
169 for item in gnome-vfs-mime-magic gnome-vfs-2.0
170 do
171 cp -r $SW/etc/$item $pkgetc/
172 done
175 pkglib="$package/Contents/Resources/lib"
176 mkdir -p $pkglib/pango/$pangover/modules
177 cp $SW/lib/pango/$pangover/modules/*.so $pkglib/pango/$pangover/modules/
180 mkdir -p $pkglib/gtk-2.0/$gtkver/{engines,immodules,loaders}
181 cp -r $SW/lib/gtk-2.0/$gtkver/engines/* $pkglib/gtk-2.0/$gtkver/engines/
182 cp $SW/lib/gtk-2.0/$gtkver/immodules/*.so $pkglib/gtk-2.0/$gtkver/immodules/
183 cp $SW/lib/gtk-2.0/$gtkver/loaders/*.so $pkglib/gtk-2.0/$gtkver/loaders/
185 mkdir -p $pkglib/gnome-vfs-2.0/modules
186 cp $SW/lib/gnome-vfs-2.0/modules/*.so $pkglib/gnome-vfs-2.0/modules/
188 # Find out libs we need from fink (e.g. $SW) - loop until no changes
189 a=1
190 nfiles=0
191 endl=true
192 while $endl; do
193 echo "Looking for dependencies. Round " $a
194 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`"
195 cp -f $libs $package/Contents/Resources/lib
196 let "a+=1"
197 nnfiles=`ls $package/Contents/Resources/lib | wc -l`
198 if [ $nnfiles = $nfiles ]; then
199 endl=false
200 else
201 nfiles=$nnfiles
202 fi
203 done
205 for libfile in $EXTRALIBS
206 do
207 cp -f $libfile $package/Contents/Resources/lib
208 done
210 if [ "$strip" = "true" ]; then
211 chmod +w "$package"/Contents/Resources/lib/*.dylib
212 strip -x "$package"/Contents/Resources/lib/*.dylib
213 strip -ur "$binpath"
214 fi
216 # NOTE: This works for all the dylibs but causes GTK to crash at startup.
217 # Instead we leave them with their original install_names and set
218 # DYLD_LIBRARY_PATH within the app bundle before running Inkscape.
219 #
220 # Fix package deps
221 #(cd "$package/Contents/MacOS/bin"
222 # for file in *; do
223 # fixlib "$file"
224 # done
225 # cd ../lib
226 # for file in *; do
227 # fixlib "$file"
228 # done)
230 # Get all the icons and the rest of the script framework
231 rsync -av $resdir/Resources/* $package/Contents/Resources/
234 # Make an image
235 #/usr/bin/hdiutil create -srcfolder "$pkg.app" "$pkg.dmg"
236 ./osx-dmg.sh