# Description: Qt Free Edition
# URL: http://www.trolltech.com
# Packager: Johannes Winkelmann, jw at smts dot ch
# Maintainer: Jose V Beneyto, sepen at crux dot nu
# Arch Maintainer: CRUX-ARM System Team, devel at crux-arm dot nu
# Depends on: fontconfig glib libmng libpng mesa3d xorg-libxcursor xorg-libxi xorg-libxinerama xorg-libxrandr dbus

name=qt4
version=4.7.3
release=1
source=(ftp://ftp.trolltech.com/pub/qt/source/qt-everywhere-opensource-src-$version.tar.gz)

build () {
  cd qt-everywhere-opensource-src-$version
  # We avoid thumb instructions over CFLAGS
  export CFLAGS="$(echo $CFLAGS | sed -e 's/\-mthumb//')"
  sed -i -e 's|X11R6/||g' -e "s/\-mthumb//" mkspecs/*/*.conf
  export CXXFLAGS="$CFLAGS"
  sed -i "s|-O2|$CXXFLAGS|" mkspecs/common/g++.conf
  sed -i "s|INSTALLS += translations||" projects.pro
  ./configure -prefix /usr/share/qt4 \
              -bindir /usr/share/qt4/bin \
              -headerdir /usr/share/qt4/include \
              -libdir /usr/share/qt4/lib \
              -plugindir /usr/share/qt4/plugins \
              -platform linux-g++ -release -shared -sm \
              -nis -verbose -qt-gif -system-zlib \
              -system-lib{png,jpeg} -xmlpatterns \
              -no-{cups,fast,nas-sound,phonon} \
              -x{cursor,inerama,kb,randr,render} \
              -nomake demos -nomake examples -nomake docs \
              -no-separate-debug-info -opensource -confirm-license

  make
  make INSTALL_ROOT=$PKG install

  rm -rf `find $PKG/usr/share/qt4/mkspecs/* | \
    grep -v linux-g++ | grep -v common | grep -v pri | grep -v features`
  rm -f $PKG/usr/share/qt4/mkspecs/linux-g++/linux-g++
  rm -rf $PKG/usr/share/qt4/mkspecs/features/{mac,win32}
  rm -rf $PKG/usr/share/qt4/mkspecs/common/mac*
  rm -rf $PKG/usr/share/qt4/phrasebooks

  install -d $PKG/{etc/ld.so.conf.d,usr/{bin,lib,include}}
  echo "/usr/share/qt4/lib" > $PKG/etc/ld.so.conf.d/qt4.conf

  ln -s ../share/qt4/include     $PKG/usr/include/qt4
  ln -s ../share/qt4/lib         $PKG/usr/lib/qt4
  ln -s linux-g++                $PKG/usr/share/qt4/mkspecs/default

  mv $PKG/usr/share/qt4/lib/pkgconfig $PKG/usr/lib

  sed -i -e "s|-L$SRC/qt-everywhere-opensource-src-$version/lib ||g" \
    -e "s|$SRC/qt-everywhere-opensource-src-$version/bin|/usr/share/qt4/bin|g" \
    $PKG/usr/lib/pkgconfig/*.pc

  for f in assistant designer linguist lrelease lupdate moc qmake qtconfig uic \
    pixeltool qdbus qdbuscpp2xml qdbusxml2cpp qt3to4 rcc uic3; do
    ln -s ../share/qt4/bin/$f $PKG/usr/bin/$f
  done
}