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