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=/sw
54 # Package always has the same name. Version information is stored in
55 # the Info.plist file which is filled in by the configure script.
56 pkg=Inkscape
57 package="$pkg.app"
59 # TODO: Rewrite handling of command line args and make more robust.
61 strip=false
62 if [ "$1" = "-s" ]; then
63 strip=true
64 shift
65 fi
67 binary="$1"
68 if [ ! -x "$binary" ]; then
69 echo "Not executable: $binary" >&2
70 exit 1
71 fi
72 shift
74 plist="$1"
75 if [ ! -f "$plist" ]; then
76 echo "Need plist file" >&2
77 exit 1
78 fi
79 shift
81 resdir=$1
82 if [ ! -d $resdir ]; then
83 echo "Need the macosx packaging directory" >&2
84 exit 1
85 fi
86 shift
88 # Fix a given executable or library to be relocatable
89 fixlib () {
90 if [ ! -d "$1" ]; then
91 echo $1
92 libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
93 for lib in $libs; do
94 echo " $lib"
95 base=`echo $lib | awk -F/ '{print $NF}'`
96 first=`echo $lib | cut -d/ -f1-3`
97 to=@executable_path/../lib/$base
98 if [ $first != /usr/lib -a $first != /usr/X11R6 ]; then
99 /usr/bin/install_name_tool -change $lib $to $1
100 if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
101 /usr/bin/install_name_tool -id $to ../lib/$base
102 for ll in $libs; do
103 base=`echo $ll | awk -F/ '{print $NF}'`
104 first=`echo $ll | cut -d/ -f1-3`
105 to=@executable_path/../lib/$base
106 if [ $first != /usr/lib -a $first != /usr/X11R6 -a "`echo $ll | fgrep libcrypto`" = "" ]; then
107 /usr/bin/install_name_tool -change $ll $to ../lib/$base
108 fi
109 done
110 fi
111 fi
112 done
113 fi
114 }
118 mkdir -p "$package"/Contents/MacOS
119 mkdir -p "$package"/Contents/Resources/bin
120 mkdir -p "$package"/Contents/Resources/lib
121 mkdir -p "$package"/Contents/Resources/locale
123 binname=`basename "$binary"`
124 binpath="$package/Contents/Resources/bin/inkscape-bin"
126 cp "$binary" "$binpath"
129 # Build and add the launcher.
130 (
131 # Build fails if CC happens to be set (to anything other than CompileC)
132 unset CC
134 cd "$resdir/ScriptExec"
135 xcodebuild $XCODEFLAGS clean build
136 )
137 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$package/Contents/MacOS/Inkscape"
139 # Pull down all the share files
140 binary_dir=`dirname "$binary"`
141 rsync -av "$binary_dir/../share/$binname"/* "$package/Contents/Resources/"
142 cp "$plist" "$package/Contents/Info.plist"
143 rsync -av "$binary_dir/../share/locale"/* "$package/Contents/Resources/locale"
145 # PkgInfo must match bundle type and creator code from Info.plist
146 echo "APPLInks" > $package/Contents/PkgInfo
148 # Pull in extra requirements.
149 pkgetc="$package/Contents/Resources/etc"
150 mkdir -p $pkgetc/pango
151 cp $SW/etc/pango/pangox.aliases $pkgetc/pango/
152 # Need to adjust path and quote incase of spaces in path.
153 sed -e "s,$SW,\"\${CWD},g" -e 's,\.so ,.so" ,g' $SW/etc/pango/pango.modules > $pkgetc/pango/pango.modules
154 cat > $pkgetc/pango/pangorc <<END_PANGO
155 [Pango]
156 ModuleFiles = "\${HOME}/.inkscape-etc/pango.modules"
157 [PangoX]
158 AliasFiles = "\${HOME}/.inkscape-etc/pangox.aliases"
159 END_PANGO
161 # We use a modified fonts.conf file so only need the dtd
162 mkdir -p $pkgetc/fonts
163 cp /etc/fonts/fonts.dtd $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
174 pkglib="$package/Contents/Resources/lib"
175 mkdir -p $pkglib/pango/1.4.0/modules
176 cp $SW/lib/pango/1.4.0/modules/*.so $pkglib/pango/1.4.0/modules/
178 mkdir -p $pkglib/gtk-2.0/2.4.0/{engines,immodules,loaders}
179 cp -r $SW/lib/gtk-2.0/2.4.0/engines/* $pkglib/gtk-2.0/2.4.0/engines/
180 cp $SW/lib/gtk-2.0/2.4.0/immodules/*.so $pkglib/gtk-2.0/2.4.0/immodules/
181 cp $SW/lib/gtk-2.0/2.4.0/loaders/*.so $pkglib/gtk-2.0/2.4.0/loaders/
183 mkdir -p $pkglib/gnome-vfs-2.0/modules
184 cp $SW/lib/gnome-vfs-2.0/modules/*.so $pkglib/gnome-vfs-2.0/modules/
186 # Find out libs we need from fink (e.g. $SW) - loop until no changes
187 a=1
188 nfiles=0
189 endl=true
190 while $endl; do
191 echo "Looking for dependencies. Round " $a
192 libs="`otool -L $pkglib/gtk-2.0/2.4.0/loaders/* $pkglib/gtk-2.0/2.4.0/immodules/* $pkglib/gtk-2.0/2.4.0/engines/*.so $pkglib/pango/1.4.0/modules/* $pkglib/gnome-vfs-2.0/modules/* $package/Contents/Resources/lib/* $binary 2>/dev/null | fgrep compatibility | cut -d\( -f1 | grep $SW | sort | uniq`"
193 cp -f $libs $package/Contents/Resources/lib
194 let "a+=1"
195 nnfiles=`ls $package/Contents/Resources/lib | wc -l`
196 if [ $nnfiles = $nfiles ]; then
197 endl=false
198 else
199 nfiles=$nnfiles
200 fi
201 done
203 for libfile in $EXTRALIBS
204 do
205 cp -f $libfile $package/Contents/Resources/lib
206 done
208 if [ "$strip" = "true" ]; then
209 chmod +w "$package"/Contents/Resources/lib/*.dylib
210 strip -x "$package"/Contents/Resources/lib/*.dylib
211 strip -ur "$binpath"
212 fi
214 # NOTE: This works for all the dylibs but causes GTK to crash at startup.
215 # Instead we leave them with their original install_names and set
216 # DYLD_LIBRARY_PATH within the app bundle before running Inkscape.
217 #
218 # Fix package deps
219 #(cd "$package/Contents/MacOS/bin"
220 # for file in *; do
221 # fixlib "$file"
222 # done
223 # cd ../lib
224 # for file in *; do
225 # fixlib "$file"
226 # done)
228 # Get all the icons and the rest of the script framework
229 rsync -av $resdir/Resources/* $package/Contents/Resources/
232 # Make an image
233 #/usr/bin/hdiutil create -srcfolder "$pkg.app" "$pkg.dmg"
234 ( cd macosx && ./osx-dmg.sh )