#!/bin/sh
#
######################################################
# Build script for TinyCore 3.x                      #
#                                                    #
# See .info for details                              #
#                                                    #
# August 9, 2010                                     #
######################################################

######################################################
# Configure extension creation parameters            #
######################################################

SRCNAM=pyusb-0.4.3.tar.gz
WRKDIR=pyusb-0.4.3
EXTNAM=pyusb
TMPDIR=/tmp/pyusb

######################################################
# Prepare extension creation                         #
######################################################

# Remove dirs and files left from previous creation

rm -r -f $WRKDIR

rm -r -f $TMPDIR

# Crete temporary directory

mkdir -p $TMPDIR/usr/local/lib/python2.6/site-packages

######################################################
# Compile and install module                         #
######################################################

tar -xf $SRCNAM
cd $WRKDIR
python setup.py install

# Delete compilation work directory

cd ..
rm -r -f $WRKDIR

mv /usr/local/lib/python2.6/site-packages/usb.so $TMPDIR/usr/local/lib/python2.6/site-packages
mv /usr/local/lib/python2.6/site-packages/pyusb* $TMPDIR/usr/local/lib/python2.6/site-packages

# Strip executables

find $TMPDIR | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded

###################################################
# Create base extension in temp dir               #
###################################################

cd $TMPDIR
cd ..
mksquashfs $TMPDIR $EXTNAM.tcz
cd $TMPDIR
find usr -not -type d > $EXTNAM.tcz.list
mv ../$EXTNAM.tcz .

# Create md5 file

md5sum $EXTNAM.tcz > $EXTNAM.tcz.md5.txt

# Cleanup temp directory

rm -r -f usr