#!/bin/sh

[ `id -u` = 0 ] || { echo "must be root"; exit 1; }

export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"
export CPPFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig

TODAY=`date +%Y/%m/%d`
MIRROR="http://www.acpica.org/download/"
PACKAGE="iasl"
SEP="-"
VERSION="20090903"
EXT="tcz"
DESCRIPTION="ASL compiler/decompiler     (TESTING)"
AUTHORS="Intel Corp"
HOMEPAGE="www.acpica.org"
LICENSE="GPL"
ME="Kingdomcome"
DEPS=""
BUILDDEPS=""
FLAGS="--prefix=/usr/local"
DOCS=""

TCUSER=`cat /etc/sysconfig/tcuser`
SRC="acpica-unix${SEP}${VERSION}.tar.gz"
THISDIR=`pwd`
PKGDIR="${THISDIR}/${PACKAGE}"
SRCDIR="${PKGDIR}/acpica-unix${SEP}${VERSION}/compiler"

environment(){
   for each in compiletc.tcz squashfs-tools-4.0.tcz ${DEPS} ${BUILDDEPS}; do
      sudo -u ${TCUSER} tce-load -w -i ${each}
   done
   [ -d "${PKGDIR}" ] && rm -rf ${PKGDIR}
   mkdir -p ${PKGDIR}/tmp
   cd ${PKGDIR} && wget ${MIRROR}${SRC}
   tar xzf ${SRC}
}

buildit(){
   cd ${SRCDIR}
   make
   install -D -m 0755 iasl ${PKGDIR}/tmp/usr/local/bin/iasl
}

workit(){
   cd ${PKGDIR}/tmp

   find usr/ | xargs file | grep "executable" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

#mkdir -p usr/local/tce.installed
#cat <<EOF> usr/local/tce.install/${PACKAGE}
#!/bin/sh

#EOF
#chmod 755 usr/local/tce.installed/${PACKAGE}

#mkdir -p usr/local/tce.menu
#cat <<EOF> usr/local/tce.menu/${PACKAGE}
#<JWM>
#  <Program label=" "></Program>
#</JWM>
#EOF

#mkdir -p usr/local/tce.icons
#cat <<EOF> usr/local/tce.icons/${PACKAGE}
#i:
#t:
#c:
#EOF

#package specific stuff

}

packageit(){
   cd ${PKGDIR}/tmp
   for dir in `ls -A`; do
      find ${dir} -not -type d | sort >> ../${PACKAGE}.${EXT}.list
   done
   mksquashfs . ../${PACKAGE}.${EXT}
   cd ${PKGDIR}
   md5sum ${PACKAGE}.${EXT} > ${PACKAGE}.${EXT}.md5.txt
   [ -f "${PACKAGE}.${EXT}.dep" ] && rm -f ${PACKAGE}.${EXT}.dep
   for each in ${DEPS}; do echo ${each} >> ${PACKAGE}.${EXT}.dep; done
size=`du -h ${PACKAGE}.${EXT} | cut -f 1`
cat <<EOF> ${PACKAGE}.${EXT}.info
Title:		${PACKAGE}.${EXT}
Description:	${DESCRIPTION}
Version:	${VERSION}
Author:		${AUTHORS}
Original-site:	${HOMEPAGE}
Copying-policy:	${LICENSE}
Size:		${size}
Extension_by:	${ME}
Comments:	Compiler/Decompiler for ASL (ACPI Source Language)
		and ASM (ACPI Machine Language)
		
		
		This extension is PPI compatible
Change-log:	----
Current:	${TODAY} First Version
EOF
}

#here we go

environment
buildit
workit
packageit
