Code

Some more quotes around /Users/jiho to allow spaces
[inkscape.git] / packaging / macosx / osx-build.sh
1 #!/bin/bash
2 #
3 #  Inkscape compilation and packaging script for Mac OS X
4 #
5 # Please see
6 #  http://wiki.inkscape.org/wiki/index.php?title=CompilingMacOsX
7 # for more complete information
8 #
9 # Author:
10 #       Jean-Olivier Irisson <jo.irisson@gmail.com>
11 # with information from
12 #       Kees Cook
13 #       Michael Wybrow
14 #
15 # Copyright (C) 2006-2007
16 # Released under GNU GPL, read the file 'COPYING' for more information
17 #
19 ############################################################
21 # User modifiable parameters
22 #----------------------------------------------------------
23 # Configure flags
24 CONFFLAGS="--disable-static --enable-shared --enable-osxapp"
25 # Libraries prefix (Warning: NO trailing slash)
26 LIBPREFIX="/opt/local"
27 # User name on Modevia
28 MODEVIA_NAME=""
30 ############################################################
32 # Help message
33 #----------------------------------------------------------
34 help()
35 {
37 echo -e "
38 Compilation script for Inkscape on Mac OS X.
40 \033[1mUSAGE\033[0m
41   $0 [options] action[s]
43 \033[1mACTIONS & OPTIONS\033[0m
44   \033[1mh,help\033[0m  
45     display this help message
46   \033[1mu,up,update\033[0m
47     update an existing checkout from svn (run svn up)
48   \033[1ma,auto,autogen\033[0m
49     prepare configure script (run autogen.sh). This is only necessary
50     for a fresh svn checkout or after make distclean.
51   \033[1mc,conf,configure\033[0m
52     configure the build (run configure). Edit your configuration
53     options in $0
54     \033[1m-p,--prefix\033[0m   specify install prefix (configure step only)
55   \033[1mb,build\033[0m
56     build Inkscape (run make)
57   \033[1mi,install\033[0m
58     install the build products locally, inside the source
59     directory (run make install)
60   \033[1mp,pack,package\033[0m
61     package Inkscape in a double clickable .app bundle 
62     \033[1m-s,--strip\033[0m    remove debugging information in Inkscape package
63     \033[1m-py,--with-python\033[0m     specify python modules path for inclusion into the app bundle
64   \033[1md,dist,distrib\033[0m
65     store Inkscape.app in a disk image (dmg) for distribution
66   \033[1mput,upload\033[0m
67     upload the dmg and the associate info file on Modevia server
68   \033[1mall\033[0m
69     do everything (update, configure, build, install, package, distribute)
71 \033[1mEXAMPLES\033[0m
72   \033[1m$0 conf build install\033[0m
73     configure, build and install a dowloaded version of Inkscape in the default
74     directory, keeping debugging information.   
75   \033[1m$0 u a c b -p ~ i -s -py ~/site-packages/ p d\033[0m
76     update an svn checkout, prepare configure script, configure,
77     build and install Inkscape in the user home directory (~).  
78     Then package Inkscape without debugging information,
79     with python packages from ~/site-packages/ and prepare 
80     a dmg for distribution."
81 }
83 # Parameters
84 #----------------------------------------------------------
85 # Paths
86 HERE=`pwd`
87 SRCROOT=$HERE/../..             # we are currently in packaging/macosx
89 # Defaults
90 if [ "$INSTALLPREFIX" = "" ]
91 then
92         INSTALLPREFIX=$SRCROOT/Build/
93 fi
94 SVNUPDATE="f"
95 AUTOGEN="f"
96 CONFIGURE="f"
97 BUILD="f"
98 INSTALL="f"
99 PACKAGE="f"
100 DISTRIB="f"
101 UPLOAD="f"
103 STRIP=""
104 PYTHON_MODULES=""
106 # Parse command line options
107 #----------------------------------------------------------
108 while [ "$1" != "" ]
109 do
110         case $1 in
111         h|help)
112                 help 
113                 exit 1 ;;
114         all)            
115                 SVNUPDATE="t"
116                 CONFIGURE="t"
117                 BUILD="t" 
118                 INSTALL="t"
119                 PACKAGE="t"
120                 DISTRIB="t" ;;
121    u|up|update)
122                 SVNUPDATE="t" ;;
123    a|auto|autogen)
124                 AUTOGEN="t" ;;
125         c|conf|configure)
126                 CONFIGURE="t" ;;
127         b|build)
128                 BUILD="t" ;;
129         i|install)
130                 INSTALL="t" ;;
131         p|pack|package)
132                 PACKAGE="t" ;;
133         d|dist|distrib)
134                 DISTRIB="t" ;;
135         put|upload)
136                 UPLOAD="t" ;;
137         -p|--prefix)
138                 INSTALLPREFIX=$2
139                 shift 1 ;;
140         -s|--strip)
141                 STRIP="-s" ;;
142         -py|--with-python)
143                 PYTHON_MODULES="$2"
144                 shift 1 ;;
145         *)
146                 echo "Invalid command line option: $1" 
147                 exit 2 ;;
148         esac
149         shift 1
150 done
153 # Set environment variables
154 # ----------------------------------------------------------
155 export LIBPREFIX
157 # Specific environment variables
158 #  automake seach path
159 export CPATH="$LIBPREFIX/include"
160 #  configure search path
161 export CPPFLAGS="-I$LIBPREFIX/include"
162 # export CPPFLAGS="-I$LIBPREFIX/include -I /System/Library/Frameworks/Carbon.framework/Versions/Current/Headers"
163 export LDFLAGS="-L$LIBPREFIX/lib"
164 #  compiler arguments
165 export CFLAGS="-O3 -Wall"
166 export CXXFLAGS="$CFLAGS"
169 # Actions
170 # ----------------------------------------------------------
171 if [[ "$SVNUPDATE" == "t" ]]
172 then
173         cd $SRCROOT
174         svn up
175         status=$?
176         if [[ $status -ne 0 ]]; then
177                 echo -e "\nSVN update failed"
178                 exit $status
179         fi
180         cd $HERE
181 fi
183 if [[ "$AUTOGEN" == "t" ]]
184 then
185         cd $SRCROOT
186         ./autogen.sh
187         status=$?
188         if [[ $status -ne 0 ]]; then
189                 echo -e "\nautogen failed"
190                 exit $status
191         fi
192         cd $HERE
193 fi
195 if [[ "$CONFIGURE" == "t" ]]
196 then
197         ALLCONFFLAGS=`echo "$CONFFLAGS --prefix=$INSTALLPREFIX"`
198         cd $SRCROOT
199         if [ ! -f configure ]
200         then
201                 echo "Configure script not found in $SRCROOT. Run '$0 autogen' first"
202                 exit 1
203         fi
204         ./configure $ALLCONFFLAGS
205         status=$?
206         if [[ $status -ne 0 ]]; then
207                 echo -e "\nConfigure failed"
208                 exit $status
209         fi
210         cd $HERE
211 fi
213 if [[ "$BUILD" == "t" ]]
214 then
215         cd $SRCROOT
216         make
217         status=$?
218         if [[ $status -ne 0 ]]; then
219                 echo -e "\nBuild failed"
220                 exit $status
221         fi
222         cd $HERE
223 fi
225 if [[ "$INSTALL" == "t" ]] 
226 then
227         cd $SRCROOT
228         make install
229         status=$?
230         if [[ $status -ne 0 ]]; then
231                 echo -e "\nInstall failed"
232                 exit $status
233         fi
234         cd $HERE
235 fi
237 if [[ "$PACKAGE" == "t" ]]
238 then
239         
240         # Test the existence of required files
241         if [ ! -e $INSTALLPREFIX/bin/inkscape ]
242         then
243                 echo "The inkscape executable \"$INSTALLPREFIX/bin/inkscape\" cound not be found."
244                 exit 1
245         fi
246         if [ ! -e $SRCROOT/Info.plist ]
247         then
248                 echo "The file \"$SRCROOT/Info.plist\" could not be found, please re-run configure."
249                 exit 1
250         fi
251         
252         # Set python command line option (if PYTHON_MODULES location is not empty, then add the python call to the command line, otherwise, stay empty)
253         if [[ "$PYTHON_MODULES" != "" ]]; then
254                 PYTHON_MODULES="-py $PYTHON_MODULES"
255                 # TODO: fix this: it does not allow for spaces in the PATH under this form and cannot be quoted
256         fi
258         # Create app bundle
259         ./osx-app.sh $STRIP -b $INSTALLPREFIX/bin/inkscape -p $SRCROOT/Info.plist $PYTHON_MODULES
260         status=$?
261         if [[ $status -ne 0 ]]; then
262                 echo -e "\nApplication bundle creation failed"
263                 exit $status
264         fi
265 fi
267 # Fetch some information
268 REVISION=`head -n 4 ../../.svn/entries | tail -n 1`
269 ARCH=`arch | tr [p,c] [P,C]`
270 MINORVERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d \.`
271 NEWNAME="Inkscape-$REVISION-10.$MINORVERSION-$ARCH"
272 DMGFILE="$NEWNAME.dmg"
273 INFOFILE="$NEWNAME-info.txt"
275 if [[ "$DISTRIB" == "t" ]]
276 then
277         # Create dmg bundle
278         ./osx-dmg.sh -p "Inkscape.app"
279         status=$?
280         if [[ $status -ne 0 ]]; then
281                 echo -e "\nDisk image creation failed"
282                 exit $status
283         fi
285         mv Inkscape.dmg $DMGFILE
286         
287         # Prepare information file
288         echo "Version information on $DATE for `whoami`:
289         OS X       `/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d \:`
290         Architecture $ARCH
291         DarwinPorts  `port version | cut -f2 -d \ `
292         GCC          `gcc --version | grep GCC`
293         GTK          `pkg-config --modversion gtk+-2.0`
294         GTKmm        `pkg-config --modversion gtkmm-2.4`
295         Cairo        `pkg-config --modversion cairo`
296         Cairomm      `pkg-config --modversion cairomm-1.0`
297         CairoPDF     `pkg-config --modversion cairo-pdf`
298         Pango        `pkg-config --modversion pango`
299 Configure options:
300         $CONFFLAGS" > $INFOFILE
301         if [[ "$STRIP" == "t" ]]; then
302                 echo "Debug info
303         no" >> $INFOFILE
304         else
305                 echo "Debug info
306         yes" >> $INFOFILE
307         fi      
308 fi
310 if [[ "$UPLOAD" == "t" ]]
311 then
312         # Provide default for user name on modevia
313         if [[ "$MODEVIA_NAME" == "" ]]; then
314                 MODEVIA_NAME=$USER
315         fi
316         # Uploasd file
317         scp $DMGFILE $INFOFILE "$MODEVIA_NAME"@inkscape.modevia.com:inkscape/docs/macosx-snap/
318         status=$?
319         if [[ $status -ne 0 ]]; then
320                 echo -e "\nUpload failed"
321                 exit $status
322         fi
323 fi
325 if [[ "$PACKAGE" == "t" || "$DISTRIB" == "t" ]]; then
326         # open a Finder window here to admire what we just produced
327         open .
328 fi
330 exit 0