#!/bin/sh
#
# buildpy.sh: build a small Python framework
#

#set -x

PREFIX=/opt/py
PREP=1
BUILD=1
INSTALL=1
STRIP=1
ZIPIT=1
RMOBVIOUS=1

if [ "$PREP" = "1" ] ; then
  rm -rf $PREFIX
  make clean
fi
if [ "$BUILD" = "1" ] ; then
  ./configure --prefix=$PREFIX --without-doc-strings #--without-readline --enable-shared
  make
fi
if [ "$INSTALL" = "1" ] ; then
  make altinstall
  size=`du -sh $PREFIX`
  cd $PREFIX
  if [ "$STRIP" = 1 ] ; then
    strip bin/python2.4
    find . -name '*.so' | xargs strip
  fi
  rm -rf bin/idle bin/pydoc bin/smtpd.py include

  # future python-2.4 in tmp
  cd lib
  mkdir tmp
  mv python2.4/site-packages tmp
  mv python2.4/lib-dynload tmp

  # prepare zip
  cd python2.4
  find . -name '*.pyc' -o -name '*.py' | xargs rm
  # unnecessary
  rm -rf aifc.* audiodev.* BaseHTTPServer.* CGIHTTPServer.* cgi.* cgitb.* chunk.* cmd.* commands.* curses difflib.* dis.* distutils doctest.* DocXMLRPCServer.* dummy_threading.* dummy_thread.* getopt.* getpass.* hotshot lib-tk macpath.* macurl2path.* mutex.* netrc.* new.* nturl2path.* os2emxpath.* pdb.* pprint.* pty.* pyclbr.* pydoc.* regsub.* rexec.* rlcompleter.* robotparser.* smtpd.* sndhdr.* statcache.* statvfs.* stringold.* subprocess.* sunaudio.* sunau.* symbol.* symtable.* tabnanny.* tarfile.* telnetlib.* this.* threading.* timeit.* toaiff.* tokenize.* token.* trace.* tty.* unittest.* user.* whrandom.* xdrlib.*
  # wishful
  #rm -rf asynchat.* asyncore.py binhex.* bisect.* bsddb calendar.* colorsys.* compileall.* compiler ConfigParser.* cookielib.* Cookie.py csv.* dbhash.* decimal.* dircache.* dumbdbm.* email encodings filecmp.* fileinput.* fnmatch.* formatter.* fpformat.* ftplib.* __future__.* gettext.* glob.* gopherlib.* gzip.* heapq.* hmac.* htmlentitydefs.* htmllib.* HTMLParser.* ihooks.* imaplib.* imghdr.* imputil.* inspect.* locale.* logging mailbox.* mailcap.* markupbase.* mhlib.* mimetypes.* multifile.* nntplib.* ntpath.* opcode.* optparse.* pickle.* pickletools.* pipes.* pkgutil.* platform.* popen2.* poplib.* posixfile.* posixpath.*   py_compile.* Queue.* random.* reconvert.* regex_syntax.* sched.* sets.* sgmllib.* shelve.* shlex.* smtplib.* SocketServer.* stringprep.* tempfile.* textwrap.* tzparse.* urllib2.* wave.* weakref.* webbrowser.* xml xmllib.* _LWPCookieJar.* _MozillaCookieJar.* __phello__.foo.* _strptime.* _threading_local.*
  
  [ "$RMOBVIOUS" = "1" ] && rm -rf idlelib lib-old config test email/test bsddb/test curses lib-tk  plat-linux2 LICENSE.txt $PREFIX/lib/python2.4/site-packages/README
  if [ "$ZIPIT" = "1" ] ; then
    zip -qr ../python24.zip *
    rm -rf *
  fi
  cd ..
  mv tmp/* python2.4
  rmdir tmp
  cd python2.4/lib-dynload ; rm -rf _codecs*.so _bisect.so _csv.so _curses*.so _heapq.so _hotshot.so _locale.so _multibytecodec.so _testcapi.so _weakref.so audioop.so crypt.so datetime.so dl.so imageop.so linuxaudiodev.so md5.so mmap.so nis.so operator.so ossaudiodev.so parser.so readline.so resource.so rgbimage.so sha.so syslog.so termios.so unicodedata.so strop.so timing.so pwd.so grp.so itertools.so collections.so rgbimg.so
fi
size2=`du -sh $PREFIX`
#echo "- Original size: $size"
#echo "- Final size:  $size2"
