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

name=qt4
version=4.8.7
release=1
source=(http://download.qt-project.org/official_releases/qt/${version%.*}/$version/qt-everywhere-opensource-src-$version.tar.gz)

build () {
    cd qt-everywhere-opensource-src-$version

    sed -i 's|X11R6/||g' mkspecs/*/*.conf

    sed -i "s|-O2|$CXXFLAGS|" mkspecs/common/g++-unix.conf
    sed -i "s|INSTALLS += translations||" projects.pro
    sed -i 's|"$COMPILER" -c|$COMPILER -c|' config.tests/unix/fvisibility.test

    ./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 -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

    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/lib" 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
}
