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-2010
16 # Released under GNU GPL, read the file 'COPYING' for more information
17 #
19 ############################################################
21 # User modifiable parameters
22 #----------------------------------------------------------
23 # Configure flags
24 CONFFLAGS="--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 bzr (run bzr pull)
48 \033[1ma,auto,autogen\033[0m
49 prepare configure script (run autogen.sh). This is only necessary
50 for a fresh bzr 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[1mf,fat,universal\033[0m
67 compile inkscape as a universal binary as both i386 and ppc architectures
68 \033[1mput,upload\033[0m
69 upload the dmg and the associate info file on Modevia server
70 \033[1mall\033[0m
71 do everything (update, configure, build, install, package, distribute)
73 \033[1mEXAMPLES\033[0m
74 \033[1m$0 conf build install\033[0m
75 configure, build and install a dowloaded version of Inkscape in the default
76 directory, keeping debugging information.
77 \033[1m$0 u a c b -p ~ i -s -py ~/site-packages/ p d\033[0m
78 update an bzr checkout, prepare configure script, configure,
79 build and install Inkscape in the user home directory (~).
80 Then package Inkscape without debugging information,
81 with python packages from ~/site-packages/ and prepare
82 a dmg for distribution."
83 }
85 # Parameters
86 #----------------------------------------------------------
87 # Paths
88 HERE=`pwd`
89 SRCROOT=$HERE/../.. # we are currently in packaging/macosx
91 # Defaults
92 if [ "$INSTALLPREFIX" = "" ]
93 then
94 INSTALLPREFIX=$SRCROOT/Build/
95 fi
96 BZRUPDATE="f"
97 AUTOGEN="f"
98 CONFIGURE="f"
99 BUILD="f"
100 INSTALL="f"
101 PACKAGE="f"
102 DISTRIB="f"
103 UPLOAD="f"
104 UNIVERSAL="f"
106 STRIP=""
107 PYTHON_MODULES=""
109 # Parse command line options
110 #----------------------------------------------------------
111 while [ "$1" != "" ]
112 do
113 case $1 in
114 h|help)
115 help
116 exit 1 ;;
117 all)
118 BZRUPDATE="t"
119 CONFIGURE="t"
120 BUILD="t"
121 INSTALL="t"
122 PACKAGE="t"
123 DISTRIB="t" ;;
124 u|up|update)
125 BZRUPDATE="t" ;;
126 a|auto|autogen)
127 AUTOGEN="t" ;;
128 c|conf|configure)
129 CONFIGURE="t" ;;
130 -u|--universal)
131 UNIVERSAL="t" ;;
132 b|build)
133 BUILD="t" ;;
134 i|install)
135 INSTALL="t" ;;
136 p|pack|package)
137 PACKAGE="t" ;;
138 d|dist|distrib)
139 DISTRIB="t" ;;
140 put|upload)
141 UPLOAD="t" ;;
142 -p|--prefix)
143 INSTALLPREFIX=$2
144 shift 1 ;;
145 -s|--strip)
146 STRIP="-s" ;;
147 -py|--with-python)
148 PYTHON_MODULES="$2"
149 shift 1 ;;
150 *)
151 echo "Invalid command line option: $1"
152 exit 2 ;;
153 esac
154 shift 1
155 done
157 OSXMINORVER=`/usr/bin/sw_vers | grep ProductVersion | cut -d' ' -f2 | cut -f1-2 -d.`
159 # Set environment variables
160 # ----------------------------------------------------------
161 export LIBPREFIX
163 # Specific environment variables
164 # automake seach path
165 export CPATH="$LIBPREFIX/include"
166 # configure search path
167 export CPPFLAGS="-I$LIBPREFIX/include"
168 # export CPPFLAGS="-I$LIBPREFIX/include -I /System/Library/Frameworks/Carbon.framework/Versions/Current/Headers"
169 export LDFLAGS="-L$LIBPREFIX/lib"
170 # compiler arguments
171 export CFLAGS="-O3 -Wall"
172 export CXXFLAGS="$CFLAGS"
174 if [[ "$UNIVERSAL" == "t" ]]
175 then
176 MINOSXVER="$OSXMINORVER"
178 export SDK=/Developer/SDKs/MacOSX${MINOSXVER}.sdk
180 export CFLAGS="$CFLAGS -isysroot $SDK -arch ppc -arch i386"
181 export CXXFLAGS="$CFLAGS"
183 export CONFFLAGS="$CONFFLAGS --disable-dependency-tracking"
184 fi
186 # Actions
187 # ----------------------------------------------------------
188 if [[ "$BZRUPDATE" == "t" ]]
189 then
190 cd $SRCROOT
191 bzr pull
192 status=$?
193 if [[ $status -ne 0 ]]; then
194 echo -e "\nBZR update failed"
195 exit $status
196 fi
197 cd $HERE
198 fi
200 # Fetch some information
201 REVISION=`bzr version-info 2>/dev/null | grep revno | cut -d' ' -f2`
202 ARCH=`arch | tr [p,c] [P,C]`
203 OSXVERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -d' ' -f2`
205 if [[ "$OSXMINORVER" == "10.3" ]]; then
206 TARGETNAME="PANTHER"
207 TARGETVERSION="10.3"
208 elif [[ "$OSXMINORVER" == "10.4" ]]; then
209 TARGETNAME="TIGER"
210 TARGETVERSION="10.4"
211 elif [[ "$OSXMINORVER" == "10.5" ]]; then
212 TARGETNAME="LEOPARD+"
213 TARGETVERSION="10.5+"
214 fi
216 TARGETARCH="$ARCH"
217 if [[ "$UNIVERSAL" == "t" ]]; then
218 TARGETARCH="UNIVERSAL"
219 fi
221 NEWNAME="Inkscape-r$REVISION-$TARGETVERSION-$TARGETARCH"
222 DMGFILE="$NEWNAME.dmg"
223 INFOFILE="$NEWNAME-info.txt"
226 if [[ "$UPLOAD" == "t" ]]
227 then
228 # If we are uploading, we are probably building nightlies and don't
229 # need to build a new one if the repository hasn't changed since the
230 # last. Hence, if a dmg for this version already exists, then just
231 # exit here.
232 if [[ -f "$DMGFILE" ]]; then
233 echo -e "\nRepository hasn't changed: $DMGFILE already exists."
234 exit 0
235 fi
236 fi
238 if [[ "$AUTOGEN" == "t" ]]
239 then
240 cd $SRCROOT
241 if [[ "$UNIVERSAL" == "t" ]]
242 then
243 # Universal builds have to be built with the option
244 # --disable-dependency-tracking. So they need to be
245 # started from scratch each time.
246 if [[ -f Makefile ]]; then
247 make distclean
248 fi
249 fi
250 ./autogen.sh
251 status=$?
252 if [[ $status -ne 0 ]]; then
253 echo -e "\nautogen failed"
254 exit $status
255 fi
256 cd $HERE
257 fi
259 if [[ "$CONFIGURE" == "t" ]]
260 then
261 ALLCONFFLAGS=`echo "$CONFFLAGS --prefix=$INSTALLPREFIX"`
262 cd $SRCROOT
263 if [ ! -f configure ]
264 then
265 echo "Configure script not found in $SRCROOT. Run '$0 autogen' first"
266 exit 1
267 fi
268 ./configure $ALLCONFFLAGS
269 status=$?
270 if [[ $status -ne 0 ]]; then
271 echo -e "\nConfigure failed"
272 exit $status
273 fi
274 cd $HERE
275 fi
277 if [[ "$BUILD" == "t" ]]
278 then
279 cd $SRCROOT
280 make
281 status=$?
282 if [[ $status -ne 0 ]]; then
283 echo -e "\nBuild failed"
284 exit $status
285 fi
286 cd $HERE
287 fi
289 if [[ "$INSTALL" == "t" ]]
290 then
291 cd $SRCROOT
292 make install
293 status=$?
294 if [[ $status -ne 0 ]]; then
295 echo -e "\nInstall failed"
296 exit $status
297 fi
298 cd $HERE
299 fi
301 if [[ "$PACKAGE" == "t" ]]
302 then
304 # Test the existence of required files
305 if [ ! -e $INSTALLPREFIX/bin/inkscape ]
306 then
307 echo "The inkscape executable \"$INSTALLPREFIX/bin/inkscape\" cound not be found."
308 exit 1
309 fi
310 if [ ! -e $SRCROOT/Info.plist ]
311 then
312 echo "The file \"$SRCROOT/Info.plist\" could not be found, please re-run configure."
313 exit 1
314 fi
316 # Set python command line option (if PYTHON_MODULES location is not empty, then add the python call to the command line, otherwise, stay empty)
317 if [[ "$PYTHON_MODULES" != "" ]]; then
318 PYTHON_MODULES="-py $PYTHON_MODULES"
319 # TODO: fix this: it does not allow for spaces in the PATH under this form and cannot be quoted
320 fi
322 # Create app bundle
323 ./osx-app.sh $STRIP -b $INSTALLPREFIX/bin/inkscape -p $SRCROOT/Info.plist $PYTHON_MODULES
324 status=$?
325 if [[ $status -ne 0 ]]; then
326 echo -e "\nApplication bundle creation failed"
327 exit $status
328 fi
329 fi
331 function checkversion {
332 DEPVER=`pkg-config --modversion $1 2>/dev/null`
333 if [[ "$?" == "1" ]]; then
334 DEPVER="Not included"
335 fi
336 echo "$DEPVER"
337 }
340 if [[ "$DISTRIB" == "t" ]]
341 then
342 # Create dmg bundle
343 ./osx-dmg.sh -p "Inkscape.app"
344 status=$?
345 if [[ $status -ne 0 ]]; then
346 echo -e "\nDisk image creation failed"
347 exit $status
348 fi
350 mv Inkscape.dmg $DMGFILE
352 # Prepare information file
353 echo "Build information on `date` for `whoami`:
354 For OS X Ver $TARGETNAME ($TARGETVERSION)
355 Architecture $TARGETARCH
356 Build system information:
357 OS X Version $OSXVERSION
358 Architecture $ARCH
359 MacPorts Ver `port version | cut -f2 -d \ `
360 GCC `$CXX --version | grep GCC`
361 Included dependency versions:
362 GTK `checkversion gtk+-2.0`
363 GTKmm `checkversion gtkmm-2.4`
364 Cairo `checkversion cairo`
365 Cairomm `checkversion cairomm-1.0`
366 CairoPDF `checkversion cairo-pdf`
367 Fontconfig `checkversion fontconfig`
368 Pango `checkversion pango`
369 LibXML2 `checkversion libxml-2.0`
370 LibXSLT `checkversion libxslt`
371 LibSigC++ `checkversion sigc++-2.0`
372 LibPNG `checkversion libpng`
373 GSL `checkversion gsl`
374 ImageMagick `checkversion ImageMagick`
375 Poppler `checkversion poppler-cairo`
376 LittleCMS `checkversion lcms`
377 GnomeVFS `checkversion gnome-vfs-2.0`
378 LibWPG `checkversion libwpg-0.1`
379 Configure options:
380 $CONFFLAGS" > $INFOFILE
381 if [[ "$STRIP" == "t" ]]; then
382 echo "Debug info
383 no" >> $INFOFILE
384 else
385 echo "Debug info
386 yes" >> $INFOFILE
387 fi
388 fi
390 if [[ "$UPLOAD" == "t" ]]
391 then
392 # Provide default for user name on modevia
393 if [[ "$MODEVIA_NAME" == "" ]]; then
394 MODEVIA_NAME=$USER
395 fi
396 # Uploasd file
397 scp $DMGFILE $INFOFILE "$MODEVIA_NAME"@inkscape.modevia.com:inkscape/docs/macosx-snap/
398 status=$?
399 if [[ $status -ne 0 ]]; then
400 echo -e "\nUpload failed"
401 exit $status
402 fi
403 fi
405 if [[ "$PACKAGE" == "t" || "$DISTRIB" == "t" ]]; then
406 # open a Finder window here to admire what we just produced
407 open .
408 fi
410 exit 0