cdd4359cc47a521a7ad41fde071ba607ada3eb97
1 #! /bin/bash
2 #
3 # Usage: osx-app [-s] /path/to/bin/inkscape Info.plist
4 #
5 # This script attempts to build an Inkscape.app package for OS X, resolving
6 # dynamic libraries, etc. It strips the executable and libraries if
7 # '-s' is given.
8 #
9 #
10 # Authors:
11 # Kees Cook <kees@outflux.net>
12 # Michael Wybrow <mjwybrow@users.sourceforge.net>
13 # Jean-Olivier Irisson <jo.irisson@gmail.com>
14 #
15 # Copyright (C) 2005 Kees Cook
16 # Copyright (C) 2005-2007 Michael Wybrow
17 # Copyright (C) 2007 Jean-Olivier Irisson
18 #
19 #
20 # Released under GNU GPL, read the file 'COPYING' for more information
21 #
22 # Thanks to GNUnet's "build_app" script for help with library dep resolution.
23 # https://gnunet.org/svn/GNUnet/contrib/OSX/build_app
24 #
25 #
26 # Notes:
27 # The Info.plist file can be found in the base inkscape directory once
28 # configure has been run.
29 #
30 # When packaging Inkscape for OS X, configure should be run with the
31 # "--enable-osxapp" option which sets the correct paths for support
32 # files inside the app bundle.
33 #
34 # Thus, the usual use of this file would be to run it from the within the
35 # inkscape/packaging/macosx directory, substituting in the inkscape binary path:
36 # ./osx-app.sh /path/to/bin/inkscape ../../Info.plist
40 # Handle some version specific details.
41 VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
42 if [ "$VERSION" -ge "4" ]; then
43 # We're on Tiger (10.4) or later.
44 # XCode behaves a little differently in Tiger and later.
45 XCODEFLAGS="-configuration Deployment"
46 SCRIPTEXECDIR="ScriptExec/build/Deployment/ScriptExec.app/Contents/MacOS"
47 # libXinerama.1.dylib is not installed as part of X11 on Panther but
48 # is introduced as a dependency if Inkscape is compiled on Tiger or
49 # later. Thus, add the library to the bundle for Panther users
50 # Building on Tiger gives app bundles incompatible with Panther anyway
51 # so we do not need to add this now
52 # EXTRALIBS="/usr/X11R6/lib/libXinerama.1.dylib"
53 EXTRALIBS=""
54 else
55 # Panther (10.3) or earlier.
56 XCODEFLAGS="-buildstyle Deployment"
57 SCRIPTEXECDIR="ScriptExec/build/ScriptExec.app/Contents/MacOS"
58 EXTRALIBS=""
59 fi
61 # set LIBPREFIX only if it has not been set before
62 # (by osx-build.sh for example)
63 if [ -z $LIBPREFIX ]
64 then
65 export LIBPREFIX="$HOME/ws-fat"
66 fi
69 # Package always has the same name. Version information is stored in
70 # the Info.plist file which is filled in by the configure script.
71 pkg=Inkscape
72 package="$pkg.app"
74 # TODO: Rewrite handling of command line args and make more robust.
76 strip=false
77 if [ "$1" = "-s" ]; then
78 strip=true
79 shift
80 fi
82 binary="$1"
83 if [ ! -x "$binary" ]; then
84 echo "Not executable: $binary" >&2
85 exit 1
86 fi
87 shift
89 plist="$1"
90 if [ ! -f "$plist" ]; then
91 echo "Need plist file" >&2
92 exit 1
93 fi
94 shift
96 # Set the 'macosx' directory, usually the current directory.
97 resdir=`pwd`
99 # Fix a given executable or library to be relocatable
100 fixlib () {
101 if [ ! -d "$1" ]; then
102 echo $1
103 libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
104 for lib in $libs; do
105 echo " $lib"
106 base=`echo $lib | awk -F/ '{print $NF}'`
107 first=`echo $lib | cut -d/ -f1-3`
108 to=@executable_path/../lib/$base
109 if [ $first != /usr/lib -a $first != /usr/X11R6 ]; then
110 /usr/bin/install_name_tool -change $lib $to $1
111 if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
112 /usr/bin/install_name_tool -id $to ../lib/$base
113 for ll in $libs; do
114 base=`echo $ll | awk -F/ '{print $NF}'`
115 first=`echo $ll | cut -d/ -f1-3`
116 to=@executable_path/../lib/$base
117 if [ $first != /usr/lib -a $first != /usr/X11R6 -a "`echo $ll | fgrep libcrypto`" = "" ]; then
118 /usr/bin/install_name_tool -change $ll $to ../lib/$base
119 fi
120 done
121 fi
122 fi
123 done
124 fi
125 }
129 mkdir -p "$package"/Contents/MacOS
130 mkdir -p "$package"/Contents/Resources/bin
131 mkdir -p "$package"/Contents/Resources/lib
132 mkdir -p "$package"/Contents/Resources/locale
134 binname=`basename "$binary"`
135 binpath="$package/Contents/Resources/bin/inkscape-bin"
137 cp "$binary" "$binpath"
140 # Build and add the launcher.
141 (
142 # Build fails if CC happens to be set (to anything other than CompileC)
143 unset CC
145 cd "$resdir/ScriptExec"
146 xcodebuild $XCODEFLAGS clean build
147 )
148 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$package/Contents/MacOS/Inkscape"
150 # Pull down all the share files
151 binary_dir=`dirname "$binary"`
152 rsync -av "$binary_dir/../share/$binname"/* "$package/Contents/Resources/"
153 cp "$plist" "$package/Contents/Info.plist"
154 rsync -av "$binary_dir/../share/locale"/* "$package/Contents/Resources/locale"
156 # PkgInfo must match bundle type and creator code from Info.plist
157 echo "APPLInks" > $package/Contents/PkgInfo
159 # Pull in extra requirements.
160 pkgetc="$package/Contents/Resources/etc"
161 mkdir -p $pkgetc/pango
162 cp $LIBPREFIX/etc/pango/pangox.aliases $pkgetc/pango/
163 # Need to adjust path and quote incase of spaces in path.
164 sed -e "s,$LIBPREFIX,\"\${CWD},g" -e 's,\.so ,.so" ,g' $LIBPREFIX/etc/pango/pango.modules > $pkgetc/pango/pango.modules
165 cat > $pkgetc/pango/pangorc <<END_PANGO
166 [Pango]
167 ModuleFiles=\${HOME}/.inkscape-etc/pango.modules
168 [PangoX]
169 AliasFiles=\${HOME}/.inkscape-etc/pangox.aliases
170 END_PANGO
172 # We use a modified fonts.conf file so only need the dtd
173 mkdir -p $pkgetc/fonts
174 cp $LIBPREFIX/etc/fonts/fonts.dtd $pkgetc/fonts/
175 cp -r $LIBPREFIX/etc/fonts/conf.avail $pkgetc/fonts/
176 cp -r $LIBPREFIX/etc/fonts/conf.d $pkgetc/fonts/
178 mkdir -p $pkgetc/gtk-2.0
179 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
180 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
182 for item in gnome-vfs-mime-magic gnome-vfs-2.0
183 do
184 cp -r $LIBPREFIX/etc/$item $pkgetc/
185 done
188 pkglib="$package/Contents/Resources/lib"
189 pangover=`ls $LIBPREFIX/lib/pango/`
190 mkdir -p $pkglib/pango/$pangover/modules
191 cp $LIBPREFIX/lib/pango/$pangover/modules/*.so $pkglib/pango/$pangover/modules/
193 gtkver=`ls $LIBPREFIX/lib/gtk-2.0/ | grep "2\."`
194 mkdir -p $pkglib/gtk-2.0/$gtkver/{engines,immodules,loaders}
195 cp -r $LIBPREFIX/lib/gtk-2.0/$gtkver/engines/* $pkglib/gtk-2.0/$gtkver/engines/
196 cp $LIBPREFIX/lib/gtk-2.0/$gtkver/immodules/*.so $pkglib/gtk-2.0/$gtkver/immodules/
197 cp $LIBPREFIX/lib/gtk-2.0/$gtkver/loaders/*.so $pkglib/gtk-2.0/$gtkver/loaders/
199 mkdir -p $pkglib/gnome-vfs-2.0/modules
200 cp $LIBPREFIX/lib/gnome-vfs-2.0/modules/*.so $pkglib/gnome-vfs-2.0/modules/
202 # Find out libs we need from fink, darwinports, or from a custom install
203 # (e.g. $LIBPREFIX), then loop until no changes.
204 a=1
205 nfiles=0
206 endl=true
207 while $endl; do
208 echo "Looking for dependencies. Round " $a
209 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 $LIBPREFIX | sort | uniq`"
210 cp -f $libs $package/Contents/Resources/lib
211 let "a+=1"
212 nnfiles=`ls $package/Contents/Resources/lib | wc -l`
213 if [ $nnfiles = $nfiles ]; then
214 endl=false
215 else
216 nfiles=$nnfiles
217 fi
218 done
220 for libfile in $EXTRALIBS
221 do
222 cp -f $libfile $package/Contents/Resources/lib
223 done
225 if [ "$strip" = "true" ]; then
226 chmod +w "$package"/Contents/Resources/lib/*.dylib
227 strip -x "$package"/Contents/Resources/lib/*.dylib
228 strip -ur "$binpath"
229 fi
231 # NOTE: This works for all the dylibs but causes GTK to crash at startup.
232 # Instead we leave them with their original install_names and set
233 # DYLD_LIBRARY_PATH within the app bundle before running Inkscape.
234 #
235 # Fix package deps
236 #(cd "$package/Contents/MacOS/bin"
237 # for file in *; do
238 # fixlib "$file"
239 # done
240 # cd ../lib
241 # for file in *; do
242 # fixlib "$file"
243 # done)
245 # Get all the icons and the rest of the script framework
246 rsync -av $resdir/Resources/* $package/Contents/Resources/
248 # Make an image
249 #/usr/bin/hdiutil create -srcfolder "$pkg.app" "$pkg.dmg"
250 # ./osx-dmg.sh