#!/bin/sh
#
######################################################
# Build script for TinyCore 2.x                      #
#                                                    #
# See .info for details                              #
#                                                    #
# November 17, 2009                                  #
######################################################

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

SRCNAM=dmidecode-2.10.tar.gz
WRKDIR=dmidecode-2.10
EXTNAM=dmidecode
TMPDIR=/tmp/dmidecode
EXTYPE=""

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

# Remove dirs and files left from previous creation

rm -r -f $WRKDIR

rm -r -f $TMPDIR
rm -r -f $TMPDIR-doc

# Crete temporary directory

mkdir -p $TMPDIR

######################################################
# Compile extension                                  #
######################################################

# Export variables needed for compilation

# Unpack source in current directory

tar -xf $SRCNAM

# Compile

cd $WRKDIR
cp -f ../Makefile .
make

# Install in base temp dir

mkdir -p $TMPDIR/usr/local/sbin
cp biosdecode $TMPDIR/usr/local/sbin
cp dmidecode $TMPDIR/usr/local/sbin
cp ownership $TMPDIR/usr/local/sbin
cp vpddecode $TMPDIR/usr/local/sbin

mkdir -p $TMPDIR-doc/usr/local/man/man8
cp man/* $TMPDIR-doc/usr/local/man/man8

# Delete compilation work directory

cd ..
rm -r -f $WRKDIR

# Adjust directory access rigths

find $TMPDIR/ -type d | xargs chmod -v 755;

# 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$EXTYPE
cd $TMPDIR
find usr -not -type d > $EXTNAM.tcz$EXTYPE.list
mv ../$EXTNAM.tcz$EXTYPE .

# Create md5 file

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

# Cleanup temp directory

rm -r -f usr  

###################################################
# Create doc extension in temp dir                #
###################################################

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

# Create md5 file

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

# Cleanup temp directory

rm -r -f usr  
