Code

* packaging/macosx/osx-app.sh: Improve the comand line option processing.
[inkscape.git] / packaging / macosx / osx-app.sh
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"
75 strip=false
76 while getopts 's' flag; do
77         case $flag in
78                 s)  strip=true ;;
79                 \?) echo "Invalid command line option."; exit 1 ;;
80                 *)  echo "Internal error in getopts."; exit 2 ;;
81         esac
82 done
83 shift `expr $OPTIND - 1`;
86 binary="$1"
87 if [ ! -x "$binary" ]; then
88         echo "Not executable: $binary" >&2
89         exit 1
90 fi
92 plist="$2"
93 if [ ! -f "$plist" ]; then
94         echo "Need plist file" >&2
95         exit 1
96 fi
98 # Set the 'macosx' directory, usually the current directory.
99 resdir=`pwd`
101 # Fix a given executable or library to be relocatable
102 fixlib () {
103 if [ ! -d "$1" ]; then
104   echo $1
105   libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
106   for lib in $libs; do
107     echo "  $lib"
108     base=`echo $lib | awk -F/ '{print $NF}'`
109     first=`echo $lib | cut -d/ -f1-3`
110     to=@executable_path/../lib/$base
111     if [ $first != /usr/lib -a $first != /usr/X11R6 ]; then
112       /usr/bin/install_name_tool -change $lib $to $1
113       if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
114         /usr/bin/install_name_tool -id $to ../lib/$base
115         for ll in $libs; do
116           base=`echo $ll | awk -F/ '{print $NF}'`
117           first=`echo $ll | cut -d/ -f1-3`
118           to=@executable_path/../lib/$base
119           if [ $first != /usr/lib -a $first != /usr/X11R6 -a "`echo $ll | fgrep libcrypto`" = "" ]; then
120             /usr/bin/install_name_tool -change $ll $to ../lib/$base
121           fi
122         done
123       fi
124     fi
125   done
126 fi
131 mkdir -p "$package"/Contents/MacOS
132 mkdir -p "$package"/Contents/Resources/bin
133 mkdir -p "$package"/Contents/Resources/lib
134 mkdir -p "$package"/Contents/Resources/locale
136 binname=`basename "$binary"`
137 binpath="$package/Contents/Resources/bin/inkscape-bin"
139 cp "$binary" "$binpath"
142 # Build and add the launcher.
144   # Build fails if CC happens to be set (to anything other than CompileC)
145   unset CC
146   
147   cd "$resdir/ScriptExec"
148   xcodebuild $XCODEFLAGS clean build
150 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$package/Contents/MacOS/Inkscape"
152 # Pull down all the share files
153 binary_dir=`dirname "$binary"`
154 rsync -av "$binary_dir/../share/$binname"/* "$package/Contents/Resources/"
155 cp "$plist" "$package/Contents/Info.plist"
156 rsync -av "$binary_dir/../share/locale"/* "$package/Contents/Resources/locale"
158 # PkgInfo must match bundle type and creator code from Info.plist
159 echo "APPLInks" > $package/Contents/PkgInfo
161 # Pull in extra requirements.
162 pkgetc="$package/Contents/Resources/etc"
163 mkdir -p $pkgetc/pango
164 cp $LIBPREFIX/etc/pango/pangox.aliases $pkgetc/pango/
165 # Need to adjust path and quote incase of spaces in path.
166 sed -e "s,$LIBPREFIX,\"\${CWD},g" -e 's,\.so ,.so" ,g' $LIBPREFIX/etc/pango/pango.modules > $pkgetc/pango/pango.modules
167 cat > $pkgetc/pango/pangorc <<END_PANGO
168 [Pango]
169 ModuleFiles=\${HOME}/.inkscape-etc/pango.modules
170 [PangoX]
171 AliasFiles=\${HOME}/.inkscape-etc/pangox.aliases
172 END_PANGO
174 # We use a modified fonts.conf file so only need the dtd
175 mkdir -p $pkgetc/fonts
176 cp $LIBPREFIX/etc/fonts/fonts.dtd $pkgetc/fonts/
177 cp -r $LIBPREFIX/etc/fonts/conf.avail $pkgetc/fonts/
178 cp -r $LIBPREFIX/etc/fonts/conf.d $pkgetc/fonts/
180 mkdir -p $pkgetc/gtk-2.0
181 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
182 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
184 for item in gnome-vfs-mime-magic gnome-vfs-2.0
185 do
186   cp -r $LIBPREFIX/etc/$item $pkgetc/
187 done
190 pkglib="$package/Contents/Resources/lib"
191 pangover=`ls $LIBPREFIX/lib/pango/`
192 mkdir -p $pkglib/pango/$pangover/modules
193 cp $LIBPREFIX/lib/pango/$pangover/modules/*.so $pkglib/pango/$pangover/modules/
195 gtkver=`ls $LIBPREFIX/lib/gtk-2.0/ | grep "2\."`
196 mkdir -p $pkglib/gtk-2.0/$gtkver/{engines,immodules,loaders}
197 cp -r $LIBPREFIX/lib/gtk-2.0/$gtkver/engines/* $pkglib/gtk-2.0/$gtkver/engines/
198 cp $LIBPREFIX/lib/gtk-2.0/$gtkver/immodules/*.so $pkglib/gtk-2.0/$gtkver/immodules/
199 cp $LIBPREFIX/lib/gtk-2.0/$gtkver/loaders/*.so $pkglib/gtk-2.0/$gtkver/loaders/
201 mkdir -p $pkglib/gnome-vfs-2.0/modules
202 cp $LIBPREFIX/lib/gnome-vfs-2.0/modules/*.so $pkglib/gnome-vfs-2.0/modules/
204 # Find out libs we need from fink, darwinports, or from a custom install
205 # (e.g. $LIBPREFIX), then loop until no changes.
206 a=1
207 nfiles=0
208 endl=true
209 while $endl; do
210   echo "Looking for dependencies. Round " $a
211   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`"
212   cp -f $libs $package/Contents/Resources/lib
213   let "a+=1"  
214   nnfiles=`ls $package/Contents/Resources/lib | wc -l`
215   if [ $nnfiles = $nfiles ]; then
216     endl=false
217   else
218     nfiles=$nnfiles
219   fi
220 done
222 for libfile in $EXTRALIBS
223 do
224   cp -f $libfile $package/Contents/Resources/lib
225 done
227 if [ "$strip" = "true" ]; then
228   chmod +w "$package"/Contents/Resources/lib/*.dylib
229   strip -x "$package"/Contents/Resources/lib/*.dylib
230   strip -ur "$binpath"
231 fi
233 # NOTE: This works for all the dylibs but causes GTK to crash at startup.
234 #       Instead we leave them with their original install_names and set
235 #       DYLD_LIBRARY_PATH within the app bundle before running Inkscape.
237 # Fix package deps
238 #(cd "$package/Contents/MacOS/bin"
239 # for file in *; do
240 #    fixlib "$file"
241 # done
242 # cd ../lib
243 # for file in *; do
244 #    fixlib "$file"
245 # done)
247 # Get all the icons and the rest of the script framework
248 rsync -av $resdir/Resources/* $package/Contents/Resources/
250 # Make an image
251 #/usr/bin/hdiutil create -srcfolder "$pkg.app" "$pkg.dmg"
252 # ./osx-dmg.sh