#!/bin/sh
# Build Qt
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-qt
HTMLDOCS=$TMP/package-qt-htmldocs
EXAMPLES=$TMP/package-qt-examples
BUILD=2
VERSION=4.3.3
ARCH=alpha

rm -rf $PKG
mkdir -p $PKG
# Trust me, we avoid a lot of problems building in the target location. :-)
( cd $TMP
# NOTE THIS NUKES THE EXISTING QT
rm -rf qt*
tar xzf $CWD/qt-x11-opensource-src-$VERSION.tar.gz
cd qt-x11-opensource-src-$VERSION

# Fix file perms:
chown -R root:root .
find . -perm 2775 -exec chmod 755 {} \;
find . -perm 2755 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

export CFLAGS="-mcpu=ev6 -mtune=ev67"
export CXXFLAGS="-mcpu=ev6 -mtune=ev67"
export OPENSOURCE_CXXFLAGS="-mcpu=ev6 -mtune=ev67"

# And here's what we are currently using.  The "yes" agrees to the GPL, so don't run this script if you
# don't agree.  :-)
echo "yes" | ./configure \
 -prefix /usr/lib/qt-$VERSION \
 -release \
 -nomake examples \
 -nomake demos

# We're using '-i' to work around a bug where the build tries to strip html files.
# Build the important stuff:
make

# Half the time this doesn't work for squat, so don't write to tell me I should be
# using "make install".  The methods used here are more likely to continue to work.
#make INSTALL_ROOT=$PKG moc-install src-install tools-install qmake-install plugins-install  
make install INSTALL_ROOT=$PKG

mkdir -p $PKG/usr/bin
( cd $PKG/usr/bin
  for file in assistant designer linguist lrelease lupdate moc pixeltool qdbus qdbuscpp2xml qdbusviewer qdbusxml2cpp qmake qt3to4 qtconfig rcc uic uic3 ; do
    ln -sf /usr/lib/qt-$VERSION/bin/$file ${file}-qt4 ;
  done
)

# Then, package things up in $PKG:
mkdir -p $PKG/usr/lib
( cd $PKG/usr/lib ; ln -sf qt-$VERSION qt )
( cd $PKG/usr/lib/qt/bin
  cp qmake qmake.bin
  rm qmake
  mv qmake.bin qmake 
  strip * 2> /dev/null )

( cd $PKG/usr/lib/qt/lib ; strip --strip-unneeded *.so 2> /dev/null )
( cd $PKG/usr/lib/qt/plugins
  strip --strip-unneeded */*.so 2> /dev/null
  cd ..
  find . -type d -name .obj -exec rm -r {} \;
  find . -type d -name .moc -exec rm -r {} \; )

( cd $PKG/usr/lib/qt ; rm -rf  translations )

mkdir -p $PKG/usr/lib/pkgconfig
( cd $PKG/usr/lib/pkgconfig
  ln -sf /usr/lib/qt-${VERSION}/lib/qt-mt.pc .
)

mkdir -p $PKG/etc/profile.d
cat $CWD/profile.d/qt.sh > $PKG/etc/profile.d/qt.sh
cat $CWD/profile.d/qt.csh > $PKG/etc/profile.d/qt.csh
chmod 755 $PKG/etc/profile.d/*

mkdir -p $PKG/install
zcat $CWD/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n --prepend $TMP/qt-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/qt.build.log
