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