]> git.saurik.com Git - wxWidgets.git/blob - wxPython/distrib/mac/wxPythonOSX/build
Be able to build with Pythons other than the System version.
[wxWidgets.git] / wxPython / distrib / mac / wxPythonOSX / build
1 #!/bin/sh -e
2 #----------------------------------------------------------------------
3 # Build wxMac and wxPythonOSX from the tarball and then make an
4 # Installer package out of it.
5
6 spectemplate=distrib/wxPythonFull.spec.in
7
8 if [ ! -d wxPython -o ! -e ${spectemplate} ]; then
9 echo "Please run this script from the root wxPython directory."
10 exit 1
11 fi
12
13 if [ "$UID" != "0" ]; then
14 echo "-------------------------------------------------------"
15 echo " WARNING: I will be unable to change ownership of files"
16 echo " unless this script is run as root or via sudo"
17 echo "-------------------------------------------------------"
18 fi
19
20 #----------------------------------------------------------------------
21 # Check Parameters
22
23 function usage {
24 echo ""
25 echo "Usage: $0 PYVER [jaguar|panther] [command flags...]"
26 echo ""
27 echo " PYVER Python version to use to do the build"
28 echo ""
29 echo " panther Build for Apple's python in /usr/bin, such as on Panther"
30 echo " jaguar Build for a python in /usr/local/bin, such as on Jaguar"
31 echo ""
32 echo "optional command flags:"
33 echo " skiptar Don't unpack the tarball"
34 echo " inplace Don't use the tarball, build from the CVS tree instead"
35 echo " (The Docs and Demo tarballs are still required for a full build.)"
36 echo " unicode Make a unicode build"
37 echo " skipconfig Don't run configure"
38 echo " skipbuild Don't build wxWidgets or wxPython"
39 echo " skipinstall Don't do the installation step"
40 echo " skipdmg Don't make the package or diskimage"
41 echo " skipclean Don't do the cleanup at the end"
42 echo ""
43 }
44
45
46 if [ $# -lt 1 ]; then
47 usage
48 exit 1
49 fi
50
51 PYVER=$1
52 if which python$PYVER && which pythonw$PYVER; then
53 PYTHON=`which python$PYVER`
54 PYTHONW=`which pythonw$PYVER`
55 else
56 usage;
57 exit 1
58 fi
59
60 KIND=$2
61 case $KIND in
62 panther) TAG=macosx10.3 ;;
63 jaguar) TAG=macosx10.2 ;;
64 *) usage; exit 1 ;;
65 esac
66
67 shift;shift
68
69 skiptar=no
70 skipconfig=no
71 skipbuild=no
72 skipinstall=no
73 skipdmg=no
74 skipclean=no
75 inplace=no
76 unicode=no
77
78 for flag in $*; do
79 case ${flag} in
80 skiptar) skiptar=yes ;;
81 skipconfig) skipconfig=yes; skiptar=yes ;;
82 skipbuild) skipbuild=yes; skipconfig=yes; skiptar=yes ;;
83 skipinstall) skipinstall=yes ;;
84 skipdmg) skipdmg=yes ;;
85 skipclean) skipclean=yes ;;
86 inplace) inplace=yes; skiptar=yes ;;
87 unicode) unicode=yes ;;
88
89 *) echo "Unknown flag \"${flag}\""
90 usage
91 exit 1
92 esac
93 done
94
95
96 VERSION=`$PYTHON -c "import setup;print setup.VERSION"`
97 SHORTVER=`echo $VERSION | cut -c 1,2,3`
98 PYPREFIX=`$PYTHON -c "import sys; print sys.exec_prefix"`
99 PYLIB=$PYPREFIX/lib/python$PYVER
100 SITEPACKAGES=$PYLIB/site-packages
101
102 if [ $unicode == yes ]; then
103 CHARTYPE=unicode
104 UNICODEOPT=--enable-unicode
105 PYUNICODEOPT=1
106 else
107 CHARTYPE=ansi
108 UNICODEOPT=--disable-unicode
109 PYUNICODEOPT=0
110 fi
111
112
113 # Test if the python we are using is the System installed framework
114 # or one that was installed by the user. This changes where the
115 # site-packages (or its alias) is located in the installer tree.
116 APPLE_PYTHON=no
117 if [ -e /Library/Python/$PYVER ] && [ `dirname $PYTHON` == "/usr/bin" ]; then
118 APPLE_PYTHON=yes
119 fi
120
121
122
123 if [ -z "$TARBALLDIR" ]; then
124 # this is a spot on my fileserver where the tarballs go, adjust
125 # as needed for where you put the wxPython tarball, or set
126 # TARBALLDIR before invoking this script...
127 TARBALLDIR=/stuff/Development/wxPython/dist/$VERSION
128 fi
129 TARBALL=$TARBALLDIR/wxPython-src-$VERSION.tar.gz
130
131 if [ ! -e $TARBALLDIR/wxPython-demo-$VERSION.tar.gz ]; then
132 echo "-------------------------------------------------------"
133 echo " WARNING: Demo tarball not found, will skip building "
134 echo " the Demo app bundle and etc."
135 echo " $TARBALLDIR/wxPython-demo-$VERSION.tar.gz"
136 echo "-------------------------------------------------------"
137 fi
138
139 if [ ! -e $TARBALLDIR/wxPython-docs-$VERSION.tar.gz ]; then
140 echo "-------------------------------------------------------"
141 echo " WARNING: Docs tarball not found, will skip building "
142 echo " the the wxDocsViewer app bundle and etc."
143 echo " $TARBALLDIR/wxPython-docs-$VERSION.tar.gz"
144 echo "-------------------------------------------------------"
145 fi
146
147
148
149
150 PREFIX=/usr/local/lib/wxPython-$CHARTYPE-$VERSION
151 BINPREFIX=/usr/local/bin
152
153 WXROOT=`dirname $PWD`
154 PROGDIR="`dirname \"$0\"`"
155 TMPDIR=$PWD/_build_dmg
156
157 BUILDROOT=$TMPDIR/build
158
159 INSTALLROOT=$TMPDIR/install-root
160 INSTALLAPPS=$TMPDIR/install-apps
161
162 DMGDIR=$TMPDIR/dmg
163 DMGROOT=$DMGDIR/root
164 DMGAPPS=$DMGDIR/apps
165
166 RESOURCEDIR=$PROGDIR/resources
167 DESTDIR=$PWD/dist
168 SRCROOT=$BUILDROOT/wxPython-src-$VERSION
169
170
171 #----------------------------------------------------------------------
172 # Setup builddirs
173
174 mkdir -p $BUILDROOT
175 mkdir -p $INSTALLROOT
176 mkdir -p $INSTALLAPPS
177
178 rm -rf $DMGDIR
179 mkdir -p $DMGROOT
180 mkdir -p $DMGAPPS/Docs
181 mkdir -p $DMGAPPS/Samples
182
183
184 pushd $BUILDROOT
185
186
187 #----------------------------------------------------------------------
188 # Unpack the tarball
189
190 if [ $skiptar != yes ]; then
191 echo Unarchiving tarball...
192 tar xzf $TARBALL
193 fi
194
195 if [ $inplace = no ]; then
196 # make a build dir and cd to it.
197 cd wxPython-src-$VERSION
198 WXDIR=`pwd`
199 mkdir -p $WXDIR/bld
200 cd $WXDIR/bld
201 WXBLD=$WXDIR/bld
202 else
203
204 # If building "inplace" then our build dir will be off of the
205 # WXROOT like normal, adjust the variables to find things that
206 # way.
207 WXBLD=$WXROOT/build-$CHARTYPE
208 mkdir -p $WXBLD
209 cd $WXBLD
210 WXDIR=..
211 SRCROOT=$WXROOT
212 fi
213
214 echo "Using wx root dir: $WXROOT"
215 echo "Using build dir: $WXBLD"
216 echo "Using source tree: $WXDIR"
217
218 #----------------------------------------------------------------------
219
220 if [ $KIND = panther ]; then
221 OTHER_CFG_OPTS=--enable-mediactrl
222 fi
223
224 # Configure wxWidgets
225 if [ $skipconfig != yes ]; then
226 $WXDIR/configure \
227 --prefix=$PREFIX \
228 --with-mac \
229 --enable-monolithic \
230 --with-opengl \
231 --enable-sound \
232 --enable-display \
233 --enable-geometry \
234 --enable-debug_flag \
235 --enable-precomp=no \
236 --enable-optimise \
237 --disable-debugreport \
238 $UNICODEOPT $OTHER_CFG_OPTS
239
240 fi
241
242 # Build wxWidgets and wxPython
243 if [ $skipbuild != yes ]; then
244
245 # Make wxWidgets and some contribs
246
247 # For some reason Rez and DeRez have started locking up if run via
248 # an ssh terminal. Figure out why, but in the meantime...
249 if [ "$CHARTYPE" = "ansi" ]; then
250 echo cp /projects/wx2.5/bld/lib/libwx_macd-2.5.?.r* lib
251 cp /projects/wx2.5/bld/lib/libwx_macd-2.5.?.r* lib
252 else
253 echo cp /projects/wx2.5/bld-unicode/lib/libwx_macud-2.5.?.r* lib
254 cp /projects/wx2.5/bld-unicode/lib/libwx_macud-2.5.?.r* lib
255 fi
256 touch lib/libwx*.r*
257
258 make $MAKEJOBS
259 make $MAKEJOBS -C contrib/src/gizmos
260 make $MAKEJOBS -C contrib/src/ogl CXXFLAGS="-DwxUSE_DEPRECATED=0"
261 make $MAKEJOBS -C contrib/src/stc
262
263 # Build wxPython
264 cd $WXROOT/wxPython
265 $PYTHON setup.py \
266 UNICODE=$PYUNICODEOPT \
267 NO_SCRIPTS=1 \
268 EP_ADD_OPTS=1 \
269 WX_CONFIG="$WXBLD/wx-config --inplace" \
270 BUILD_BASE=$WXBLD/wxPython \
271 build
272 fi
273
274 #----------------------------------------------------------------------
275
276 if [ $skipinstall != yes ]; then
277 # Install wxWidgets
278 cd $WXBLD
279 make prefix=$INSTALLROOT$PREFIX install
280 make -C contrib/src/gizmos prefix=$INSTALLROOT$PREFIX install
281 make -C contrib/src/ogl CXXFLAGS="-DwxUSE_DEPRECATED=0" prefix=$INSTALLROOT/$PREFIX install
282 make -C contrib/src/stc prefix=$INSTALLROOT$PREFIX install
283
284
285 # relink wx-config with a relative link
286 cd $INSTALLROOT$PREFIX/bin
287 rm wx-config
288 ln -s ../lib/wx/config/* wx-config
289
290 # and wxPython
291 cd $WXROOT/wxPython
292 $PYTHON setup.py \
293 UNICODE=$PYUNICODEOPT \
294 NO_SCRIPTS=1 \
295 EP_ADD_OPTS=1 \
296 WX_CONFIG="$INSTALLROOT/$PREFIX/bin/wx-config --prefix=$INSTALLROOT/$PREFIX" \
297 BUILD_BASE=$WXBLD/wxPython \
298 install \
299 --root=$INSTALLROOT
300
301
302 # Apple's Python Framework (such as what comes with Panther)
303 # sym-links the site-packages dir in the framework to
304 # /Library/Python/$PYVER so we need to move the files so they are
305 # installed in the physical location, not the virtual one.
306 if [ $APPLE_PYTHON == yes ]; then
307 if [ -e $INSTALLROOT/Library/Python/$PYVER ]; then
308 rm -r $INSTALLROOT/Library/Python/$PYVER
309 fi
310 mkdir -p $INSTALLROOT/Library/Python/$PYVER
311 mv $INSTALLROOT/$SITEPACKAGES/* $INSTALLROOT/Library/Python/$PYVER
312 rm -r $INSTALLROOT/System
313 SITEPACKAGES=/Library/Python/$PYVER
314 fi
315
316 # install wxPython's tool scripts
317 mkdir -p $INSTALLROOT$BINPREFIX
318 cd $WXROOT/wxPython/scripts
319 python$PYVER CreateMacScripts.py $INSTALLROOT $BINPREFIX
320
321
322 # Remove the .pyc/.pyo files they just take up space and can be recreated
323 # during the install.
324 pushd $WXROOT/wxPython
325 $PYTHON $PROGDIR/../zappycfiles.py $INSTALLROOT > /dev/null
326 popd
327
328 # Set premissions for files in $INSTALLROOT
329 if [ "$UID" = "0" ]; then
330 chown -R root:admin $INSTALLROOT
331 chmod -R g+w $INSTALLROOT
332 fi
333 fi
334
335 if [ $APPLE_PYTHON == yes ]; then
336 SITEPACKAGES=/Library/Python/$PYVER
337 fi
338 PKGDIR=`cat $INSTALLROOT$SITEPACKAGES/wx.pth`
339
340 popd
341
342 #----------------------------------------------------------------------
343
344 # Make the Installer packages and disk image
345 if [ $skipdmg != yes ]; then
346
347 #-----------------------------------------------
348 # The main runtime installer package
349
350 # Make the welcome message
351 case $KIND in
352 panther) W_MSG="the Panther (OS X 10.3.x) version of" ;;
353 jaguar) W_MSG="the Jaguar (OS X 10.2.x) version of" ;;
354 esac
355
356
357 cat > $RESOURCEDIR/Welcome.txt <<EOF
358 Welcome!
359
360 This Installer package will install the wxPython $CHARTYPE runtime $VERSION for $W_MSG MacPython-OSX $PYVER. This includes:
361
362 * The wxPython packages and modules
363 * The wxWidgets shared libraries and headers
364 * Some command line tool scripts, installed to /usr/local/bin.
365
366 You must install onto your current boot disk, eventhough the installer does not enforce this, otherwise things will not work.
367
368 You can install more than one version of the wxPython runtime if you desire. The most recently installed version will be the default wxPython, but you can choose another by setting the PYTHONPATH or by using the wxversion module. See http://wiki.wxpython.org/index.cgi/MultiVersionInstalls for more details.
369
370 Build date: `date`
371 EOF
372
373 # make the preflight script
374 cat > $RESOURCEDIR/preflight <<EOF
375 #!/bin/sh
376 # Cleanup any old install of the wxPython package
377 rm -rf \$2$SITEPACKAGES/wxPython
378 rm -rf \$2$SITEPACKAGES/wx
379 rm -rf \$2$SITEPACKAGES/$PKGDIR
380 exit 0
381 EOF
382 chmod +x $RESOURCEDIR/preflight
383
384 # make the postflight script
385 cat > $RESOURCEDIR/postflight <<EOF
386 #!/bin/sh -e
387 # Compile the .py files in the wxPython pacakge
388 $PYTHON \$2$PYLIB/compileall.py \$2$SITEPACKAGES/$PKGDIR
389 $PYTHON -O \$2$PYLIB/compileall.py \$2$SITEPACKAGES/$PKGDIR
390
391 # and all of the wxPython pacakge should be group writable
392 chgrp -R admin \$2$SITEPACKAGES/$PKGDIR
393 chmod -R g+w \$2$SITEPACKAGES/$PKGDIR
394
395 exit 0
396 EOF
397 chmod +x $RESOURCEDIR/postflight
398
399
400
401 # Build the main Installer Package...
402 rm -rf wxPython${SHORTVER}-osx-$CHARTYPE-$KIND.pkg
403 python $PROGDIR/../buildpkg.py \
404 --Title=wxPython${SHORTVER}-osx-$CHARTYPE-$KIND \
405 --Version=$VERSION \
406 --Description="wxPython $CHARTYPE runtime $VERSION for $W_MSG MacPython-OSX $PYVER" \
407 --NeedsAuthorization="YES" \
408 --Relocatable="NO" \
409 --InstallOnly="YES" \
410 $INSTALLROOT \
411 $RESOURCEDIR
412
413 mv wxPython${SHORTVER}-osx-$CHARTYPE-$KIND.pkg $DMGROOT
414
415 rm $RESOURCEDIR/postflight
416 rm $RESOURCEDIR/preflight
417 rm $RESOURCEDIR/Welcome.txt
418
419
420 #-----------------------------------------------
421 # Make a README to go on the disk image
422 cat > "$DMGROOT/README 1st.txt" <<EOF
423 Welcome to wxPython!
424
425 This disk image contains the following items:
426
427 wxPython${SHORTVER}-osx-$CHARTYPE-$VERSION-$KIND
428
429 This Installer contains the wxPython runtime, compiled on a
430 $KIND OS X system, using the $CHARTYPE build of the wxWidgets
431 library. It includes the Python modules and extension
432 modules, as well as the wxWidgets libraries.
433
434 It is possible to have more than one version of the runtime
435 installed at once if you wish. The most recently installed
436 version will be the default wxPython, but you can choose
437 another by setting the PYTHONPATH or by using the wxversion
438 module. For more details see:
439 http://wiki.wxpython.org/index.cgi/MultiVersionInstalls
440
441
442 uninstall_wxPython.py
443
444 A simple tool to help you manage your installed versions of
445 wxPython. It will allow you to choose from the currently
446 installed wxPython packages and to select one for
447 uninstallation. It is a text-mode tool so you can either run
448 it from a Terminal command line, or you can open it with
449 PythonLauncher and let it create a Terminal to run it in.
450
451 NOTE: If you have versions prior to 2.5.3.1 installed, please
452 do run this uninstall tool to remove the older version.
453
454 EOF
455
456
457
458 cp $PROGDIR/../uninstall_wxPython.py $DMGROOT
459
460
461 #-----------------------------------------------
462 # Make a disk image to hold these files
463 dmgname=wxPython${SHORTVER}-osx-$CHARTYPE-$VERSION-$TAG-py$PYVER
464 $PROGDIR/../makedmg $DMGROOT $DMGDIR $dmgname
465
466 echo Moving $DMGDIR/$dmgname.dmg to $DESTDIR
467 mv $DMGDIR/$dmgname.dmg $DESTDIR
468
469
470 #---------------------------------------------------------------------------
471 # Now create app bundles for the demo, docs, and tools and make another
472 # disk image to hold it all.
473 #---------------------------------------------------------------------------
474
475 cat > "$DMGAPPS/README 1st.txt" <<EOF
476 Welcome to wxPython!
477
478 On this disk image you will find Demo, Tools, Docs, and etc. for
479 wxPython $VERSION. Everything here is optional and you can drag them
480 out of the disk image and drop them wherever you want. You will need
481 to have an installed wxPython runtime to be able to use any of them.
482
483
484 wxPython Demo An application bundle version of the demo.
485 (This has it's own copy of the demo sources
486 within the bundle.)
487
488 XRCed An application for editing wxPython resource
489 files (XRC files.)
490
491 PyCrust An application that provides an interactive
492 Python shell and also namespace inspectors.
493
494
495
496 Docs/wxDocsViewer An application that allows you to view the
497 wxWidgets documentation.
498
499 Docs/licence License files.
500
501 Docs/other A few readmes, change log, etc.
502
503
504 Samples/samples Several small sample applications that
505 demonstrate how to use wxPython.
506
507 Samples/demo A copy of the wxPython demo source code,
508 just open the folder and run demo.pyw.
509
510 Happy Hacking!
511 EOF
512
513 # PyAlaMode An extension of PyCrust that includes source
514 # file editing capabilities.
515
516
517 # wxDocs
518 if [ ! -e $TARBALLDIR/wxPython-docs-$VERSION.tar.gz ]; then
519 cat > "$DMGAPPS/Docs/Build ERROR.txt" <<EOF
520
521 The wxPython-docs tarball was not found when building this disk image!
522
523 EOF
524
525 else
526 pushd $BUILDROOT
527 tar xzvf $TARBALLDIR/wxPython-docs-$VERSION.tar.gz
528 popd
529
530 # Make an app to launch viewdocs.py
531 $PYTHONW $PROGDIR/../buildapp.py \
532 --builddir=$DMGAPPS/Docs \
533 --name=wxDocsViewer \
534 --mainprogram=$BUILDROOT/wxPython-$VERSION/docs/viewdocs.py \
535 --iconfile=$PROGDIR/Info.icns \
536 build
537
538 cp $BUILDROOT/wxPython-$VERSION/docs/*.zip $DMGAPPS/Docs/wxDocsViewer.app/Contents/Resources
539
540 cat > "$DMGAPPS/Docs/README 1st.txt" <<EOF
541
542 The wxDocsViewer application needs to be copied to your Desktop (or
543 someplace else you have write access to) before you can run it, so it
544 can cache some indexes within its bundle.
545
546 EOF
547
548 fi
549
550 # license files, docs, etc.
551 pushd $DMGAPPS/Docs
552 cp -pR $SRCROOT/wxPython/licence .
553 cp -pR $SRCROOT/wxPython/docs .
554 rm -rf docs/bin
555 rm -rf docs/xml-raw
556 mv docs other
557 popd
558
559
560 if [ ! -e $TARBALLDIR/wxPython-demo-$VERSION.tar.gz ]; then
561 cat > "$DMGAPPS/Samples/Build ERROR.txt" <<EOF
562
563 The wxPython-demo tarball was not found when building this disk image!
564
565 EOF
566 cp "$DMGAPPS/Samples/Build ERROR.txt" $DMGAPPS
567
568 else
569
570 # Copy the demo and samples to the disk image from the tarball
571 pushd $DMGAPPS/Samples
572 tar xzvf $TARBALLDIR/wxPython-demo-$VERSION.tar.gz
573 mv wxPython-$VERSION/* .
574 rm -rf wxPython-$VERSION
575 rm demo/b demo/.setup.sh
576 mv demo/demo.py demo/demo.pyw
577 popd
578
579 # Make an app bundle to run the demo
580 $PYTHONW $PROGDIR/../buildapp.py \
581 --builddir=$DMGAPPS \
582 --name="wxPython Demo" \
583 --mainprogram=$DMGAPPS/Samples/demo/demo.pyw \
584 --iconfile=$PROGDIR/RunDemo.icns \
585 build
586 cp -pR $DMGAPPS/Samples/demo/* "$DMGAPPS/wxPython Demo.app/Contents/Resources"
587 fi
588
589
590 # Make an app bundle to launch PyCrust
591 $PYTHONW $PROGDIR/../buildapp.py \
592 --builddir=$DMGAPPS \
593 --name=PyCrust \
594 --mainprogram=$INSTALLROOT$BINPREFIX/pycrust.py \
595 --iconfile=$PROGDIR/PieShell.icns \
596 build
597
598 ## TODO: PyAlaMode needs tweaked to be able to run from a bundle. It
599 ## needs to know to ignore command line parameters and etc...
600 # # and PyAlaMode
601 # $PYTHONW $PROGDIR/../buildapp.py \
602 # --builddir=$DMGAPPS \
603 # --name=PyAlaMode \
604 # --mainprogram=$INSTALLROOT$BINPREFIX/pyalamode.py \
605 # --iconfile=$PROGDIR/PieShell.icns \
606 # build
607
608 # Make an app to launch XRCed
609 $PYTHONW $PROGDIR/../buildapp.py \
610 --builddir=$DMGAPPS \
611 --name=XRCed \
612 --mainprogram=$INSTALLROOT$BINPREFIX/xrced.py \
613 --iconfile=$PROGDIR/XRCed.icns \
614 build
615
616
617
618 # and then finally make a disk image containing everything
619 dmgname=wxPython${SHORTVER}-osx-docs-demos-$VERSION-$TAG
620 $PROGDIR/../makedmg $DMGAPPS $DMGDIR $dmgname
621
622 echo Moving $DMGDIR/$dmgname.dmg to $DESTDIR
623 mv $DMGDIR/$dmgname.dmg $DESTDIR
624 fi
625
626
627 # Cleanup build/install dirs
628 if [ $skipclean != yes ]; then
629 echo "Cleaning up..."
630 rm -rf $TMPDIR
631 else
632 echo "Cleanup is disabled. You should remove $TMPDIR when finished"
633 fi
634