# $Id$
# Maintainer: kevin <kevin@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Kritoke <kritoke@gamebox.net>
# Contributor: Luca Roccia <little_rock@users.sourceforge.net>

pkgbase=boost
pkgname=('boost-libs' 'boost')
pkgver=1.49.0
_boostver=${pkgver//./_}
pkgrel=1
arch=('i686' 'x86_64')
url="http://www.boost.org/"
makedepends=('icu' 'python2' 'bzip2' 'zlib' 'openmpi')
source=(http://downloads.sourceforge.net/sourceforge/${pkgbase}/${pkgbase}_${_boostver}.tar.gz
        exceptions.patch)
license=('custom')

_stagedir="${srcdir}/stagedir"

build() {
  # set python path for bjam
  cd "${srcdir}/${pkgbase}_${_boostver}/tools"
  echo "using python : 2.6 : /usr/bin/python2 ;" >> build/v2/user-config.jam
  #echo "using python : 3.2 : /usr/bin/python : /usr/include/python3.2mu : /usr/lib ;" >> build/v2/user-config.jam
  echo "using mpi ;" >> build/v2/user-config.jam

  cd "${srcdir}"/${pkgbase}_${_boostver}
  # https://svn.boost.org/trac/boost/ticket/5731
  patch -p0 -i "${srcdir}/exceptions.patch"

  # build bjam
  cd "${srcdir}/${pkgbase}_${_boostver}/tools/build/v2/engine"
  ./build.sh cc

  _bindir="bin.linuxx86"
  [ "${CARCH}" = "x86_64" ] && _bindir="bin.linuxx86_64"

  install -d "${_stagedir}"/usr/bin
  install ${_bindir}/bjam "${_stagedir}"/usr/bin/bjam

  # build tools
  cd "${srcdir}/${pkgbase}_${_boostver}/tools/"
  "${_stagedir}"/usr/bin/bjam --toolset=gcc

  # copy the tools
  cd "${srcdir}/${pkgbase}_${_boostver}/dist/bin"
  for i in *;do
      install -m755 "${i}" "${_stagedir}/usr/bin/${i}"
  done

  #boostbook needed by quickbook
  cd "${srcdir}/${pkgbase}_${_boostver}/dist/"
  cp -r share "${_stagedir}"

  # build libs
  cd "${srcdir}/${pkgbase}_${_boostver}"

  # default "minimal" install: "release link=shared,static
  # runtime-link=shared threading=single,multi"
  # --layout=tagged will add the "-mt" suffix for multithreaded libraries
  # and installs includes in /usr/include/boost.
  # --layout=system no longer adds the -mt suffix for multi-threaded libs.
  # install to ${_stagedir} in preparation for split packaging

  "${_stagedir}"/usr/bin/bjam \
      release debug-symbols=off threading=multi \
      runtime-link=shared link=shared,static \
      cflags=-fno-strict-aliasing \
      toolset=gcc \
      --prefix="${_stagedir}" \
      -sTOOLS=gcc \
      --layout=system \
      ${MAKEFLAGS} \
      install
}

package_boost() {
    pkgdesc="Free peer-reviewed portable C++ source libraries - Development"
    depends=("boost-libs=${pkgver}")
    optdepends=('python2: for python2 bindings')

    install -d "${pkgdir}"/usr/{include,lib,share}
    # headers/source files
    cp -r "${_stagedir}"/include/ "${pkgdir}"/usr/

    # static libs
    cp -r "${_stagedir}"/lib/*.a "${pkgdir}"/usr/lib/

    # utilities (bjam, bcp, pyste)
    cp -r "${_stagedir}"/usr/* "${pkgdir}"/usr/

    #boostbook
    cp -r "${_stagedir}"/share/* "${pkgdir}"/usr/share

    # license
    install -D -m644 "${srcdir}/${pkgbase}_${_boostver}/LICENSE_1_0.txt" \
        "${pkgdir}"/usr/share/licenses/boost/LICENSE_1_0.txt
}

package_boost-libs() {
    pkgdesc="Free peer-reviewed portable C++ source libraries - Runtime"
    depends=('gcc-libs' 'bzip2' 'zlib' 'icu')
    optdepends=('openmpi: for mpi support')

    install -d "${pkgdir}/usr/lib"
    #shared libs
    cp -r "${_stagedir}"/lib/*.so{,.*} "${pkgdir}/usr/lib/"

    # license
    install -D -m644 "${srcdir}/${pkgbase}_${_boostver}/LICENSE_1_0.txt" \
        "${pkgdir}"/usr/share/licenses/boost-libs/LICENSE_1_0.txt
}
md5sums=('e0defc8c818e4f1c5bbb29d0292b76ca'
         'bedd276510b6ad1ff2b4d143de21373e')