Code

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