# $Id: PKGBUILD 172119 2012-11-29 17:17:54Z andrea $
# Maintainer: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgbase=qt
pkgname=('qt')
pkgname=('qtbase'
    qtdeclarative
    qtgraphicaleffects
    qtimageformats
    qtmultimedia
    qtquick1
    qtscript
    qtsvg
    qttools
    qttranslations
    qtxmlpatterns)
pkgver=5.0.0
pkgrel=1
arch=('i686' 'x86_64')
url='http://qt-project.org/'
license=('GPL3' 'LGPL')
makedepends=('libxcb' 'xcb-proto' 'xcb-util' 'xcb-util-image' 'xcb-util-wm' 'xcb-util-keysyms'
            'mesa' 'libgl' 'at-spi2-core' 'alsa-lib' 'gstreamer0.10-base-plugins'
            'libjpeg-turbo' 'cups' 'libpulse' 'hicolor-icon-theme' 'desktop-file-utils'
            'postgresql-libs' 'libmysqlclient' 'sqlite' 'unixodbc' 'libfbclient'
            'qtwebkit')
_pkgfqn="${pkgbase}-everywhere-opensource-src-${pkgver}"
source=("http://releases.qt-project.org/qt5/${pkgver}/single/${_pkgfqn}.tar.xz"
        'assistant.desktop' 'designer.desktop' 'linguist.desktop'
        'qtconfig.desktop')
md5sums=('6b4f2f3f1e6252fbce3a57ac5165baff'
         'f1837a03fd0ebbd2da58975845f278e3'
         '480fea1ed076992b688373c8db274be0'
         '5595c24d5bb942c21e3a4d299e6d0bf1'
         '824a3b77a25e98567f640e0441ccdebc')

build() {
  cd ${_pkgfqn}

  export QTDIR="${srcdir}"/${_pkgfqn}
  export LD_LIBRARY_PATH=${QTDIR}/lib:${LD_LIBRARY_PATH}
  export PATH=${QTDIR}/qtbase/bin:$PATH
  
  # Workaround for the deeply messy python management in webkit

  mv /usr/bin/python /usr/bin/python.backup
  ln -sf /usr/bin/python2 /usr/bin/python

  sed -i "s|-O2|${CXXFLAGS}|" qtbase/mkspecs/common/{g++,gcc}-base.conf
  sed -i "/^QMAKE_LFLAGS_RPATH/s| -Wl,-rpath,||g" qtbase/mkspecs/common/gcc-base-unix.conf
  sed -i "/^QMAKE_LFLAGS\s/s|+=|+= ${LDFLAGS}|g" qtbase/mkspecs/common/gcc-base.conf

  ./configure -confirm-license -opensource \
    -release \
    -prefix /usr \
    -docdir /usr/share/doc/qt \
    -plugindir /usr/lib/qt/plugins \
    -importdir /usr/lib/qt/imports \
    -datadir /usr/share/qt \
    -translationdir /usr/share/qt/translations \
    -sysconfdir /etc/xdg \
    -examplesdir /usr/share/doc/qt/examples \
    -plugin-sql-{psql,mysql,sqlite,odbc,ibase} \
    -system-sqlite \
    -openssl-linked \
    -nomake demos \
    -nomake examples \
    -nomake docs \
    -no-rpath \
    -optimized-qmake \
    -dbus-linked \
    -reduce-relocations

  # see the Makefile for the arrangement
  cd qtbase
  make
  cd ../

  cd qtsvg
  qmake
  make
  cd ../

  cd qtxmlpatterns
  qmake
  make
  cd ../

  cd qtscript
  ../qtbase/bin/qmake
  make
  cd ../

  cd qtjsbackend
  qmake
  make
  cd ../

  cd qtdeclarative
  qmake
  make
  cd ../

  cd qtwebkit
  qmake
  make
  cd ../

  cd qttools
  qmake
  make
  cd ../

  cd qttranslations
  qmake
  make
  cd ../

  cd qtdoc
  qmake
  make
  cd ../

  cd qtactiveqt
  qmake
  make
  cd ../

  cd qtmultimedia
  qmake
  make
  cd ../
  
  cd qtimageformats
  qmake
  make
  cd ../

  cd qtquick1
  qmake
  make
  cd ../

  cd qtgraphicaleffects
  qmake
  make
  cd ../

  # Restore the original python symlink that was changed for working around the
  # webkit limitations

  mv /usr/bin/python.backup /usr/bin/python
}

package_qtbase() {
  cd ${_pkgfqn}/qtbase
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtjsbackend() {
  cd ${_pkgfqn}/qtjsbackend
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtdeclarative() {
  cd ${_pkgfqn}/qtdeclarative
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtwebkit() {
  cd ${_pkgfqn}/qtwebkit
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtgraphicaleffects() {
  cd ${_pkgfqn}/qtgraphicaleffects
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtimageformats() {
  cd ${_pkgfqn}/qtimageformats
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtmultimedia() {
  cd ${_pkgfqn}/qtmultimedia
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtquick1() {
  cd ${_pkgfqn}/qtquick1
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtscript() {
  cd ${_pkgfqn}/qtscript
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtsvg() {
  cd ${_pkgfqn}/qtsvg
  make INSTALL_ROOT="${pkgdir}" install
}

package_qttools() {
  cd ${_pkgfqn}/qttools
  make INSTALL_ROOT="${pkgdir}" install
}

package_qttranslations() {
  cd ${_pkgfqn}/qttranslations
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtdoc() {
  cd ${_pkgfqn}/qtdoc
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtactiveqt() {
  cd ${_pkgfqn}/qtactiveqt
  make INSTALL_ROOT="${pkgdir}" install
}

package_qtxmlpatterns() {
  cd ${_pkgfqn}/qtxmlpatterns
  make INSTALL_ROOT="${pkgdir}" install
}

package_qt() {
    pkgdesc='A cross-platform application and UI framework'
    depends=()
    install='qt.install'

    cd ${_pkgfqn}
   # make INSTALL_ROOT="${pkgdir}" install

    # install missing icons and desktop files
    #for icon in tools/linguist/linguist/images/icons/linguist-*-32.png ; do
    #  size=$(echo $(basename ${icon}) | cut -d- -f2)
    #  install -p -D -m644 ${icon} \
    #    "${pkgdir}/usr/share/icons/hicolor/${size}x${size}/apps/linguist.png"
    #done
   # #install -p -D -m644 src/gui/dialogs/images/qtlogo-64.png \
   #   "${pkgdir}/usr/share/icons/hicolor/64x64/apps/qtlogo.png"
   # install -p -D -m644 tools/assistant/tools/assistant/images/assistant.png \
   #   "${pkgdir}/usr/share/icons/hicolor/32x32/apps/assistant.png"
   # install -p -D -m644 tools/designer/src/designer/images/designer.png \
   #   "${pkgdir}/usr/share/icons/hicolor/128x128/apps/designer.png"
   # install -d "${pkgdir}/usr/share/applications"
   # install -m644 "${srcdir}"/{linguist,designer,assistant,qtconfig}.desktop \
   #   "${pkgdir}/usr/share/applications/"

    # install license addition
   # install -D -m644 LGPL_EXCEPTION.txt \
   #   ${pkgdir}/usr/share/licenses/qt/LGPL_EXCEPTION.txt

    # Fix wrong path in pkgconfig files
   # find "${pkgdir}/usr/lib/pkgconfig" -type f -name '*.pc' \
   #   -exec perl -pi -e "s, -L${srcdir}/?\S+,,g" {} \;

    # Fix wrong path in prl files
   # find "${pkgdir}/usr/lib" -type f -name '*.prl' \
   #   -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d;s/\(QMAKE_PRL_LIBS =\).*/\1/' {} \;
}

package_qt-private-headers(){
    pkgdesc="Qt private headers for development"
    depends=("qt=${pkgver}")

    install -d "${pkgdir}"/usr/include/{QtCore,QtDeclarative,QtGui,QtScript}
    install -d "${pkgdir}"/usr/src/{corelib,declarative,gui,script}
    
    for i in QtCore QtDeclarative QtGui QtScript; do
      cp -r ${_pkgfqn}/include/${i}/private/ \
        "${pkgdir}"/usr/include/${i}/
    done

    for i in corelib declarative gui script; do
      cp -r ${_pkgfqn}/src/${i} "${pkgdir}"/usr/src/
    done
}