# vim: set ts=2 sw=2 et:
# $Id: PKGBUILD 150148 2012-02-13 14:49:35Z dreisner $
# Maintainer: Dan McGee <dan@archlinux.org>
# Maintainer: Dave Reisner <dave@archlinux.org>

_pkgname=parabola-pacman
pkgname=pacman-lukeshu
_pkgver=f8fc16f
pkgver=4.0.3
pkgrel=3.2

provides=(pacman=$pkgver)
conflicts=(pacman)

pkgdesc="A library-based package manager with dependency support, with vcsget"
arch=('i686' 'x86_64' 'mips64el')
url="http://www.archlinux.org/pacman/"
license=('GPL')
groups=('base')
depends=('bash' 'glibc>=2.15' 'libarchive>=3.0.2' 'curl>=7.19.4'
         'gpgme' 'pacman-mirrorlist' 'archlinux-keyring' 'parabola-keyring')
makedepends=('asciidoc')
optdepends=('fakeroot: for makepkg usage as normal user')
backup=(etc/pacman.conf etc/makepkg.conf)
install=pacman.install
options=(!libtool)
source=(${_pkgname}-${_pkgver}.tar.gz::https://gitorious.org/parabola/pacman/archive-tarball/${_pkgver}
        pacman.conf
        pacman.conf.x86_64
        pacman.conf.mips64el)

build() {
  cd $srcdir/$_pkgname

  ./autogen.sh

  ./configure --prefix=/usr --sysconfdir=/etc \
    --localstatedir=/var --enable-doc
  make
  make -C contrib
}

check() {
  make -C "$srcdir/$_pkgname" check
}

package() {
  cd $srcdir/$_pkgname
  make DESTDIR=$pkgdir install

  # install Arch specific stuff
  mkdir -p $pkgdir/etc
  case "$CARCH" in
    i686)
      install -m644 $srcdir/pacman.conf $pkgdir/etc/pacman.conf
      mycarch="i686"
      mychost="i686-pc-linux-gnu"
      myflags="-march=i686 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
      myldflags="-Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu"
      ;;
    x86_64)
      install -m644 $srcdir/pacman.conf.x86_64 $pkgdir/etc/pacman.conf
      mycarch="x86_64"
      mychost="x86_64-unknown-linux-gnu"
      myflags="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
      myldflags="-Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu"
      ;;
    mips64el)
      install -m644 $srcdir/pacman.conf.mips64el $pkgdir/etc/pacman.conf
      mycarch="mips64el"
      mychost="mips64el-unknown-linux-gnu"
      myflags="-O2 -march=loongson2f -mabi=n32 -pipe -mplt -Wa,-mfix-loongson2f-nop -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
      myldflags="-Wl,-O1,--sort-common,--as-needed,-z,relro"
      ;;
  esac
  #install -m644 $srcdir/makepkg.conf $pkgdir/etc/
  # set things correctly in the default conf file
  sed -i $pkgdir/etc/makepkg.conf \
    -e "s|@CARCH[@]|$mycarch|g" \
    -e "s|@CHOST[@]|$mychost|g" \
    -e "s|@LDFLAGS[@]|$myldflags|g" \
    -e "s|@CARCHFLAGS[@]|$myflags|g"

  # install completion files
  install -Dm644 contrib/bash_completion "$pkgdir/usr/share/bash-completion/completions/pacman"
  for f in makepkg pacman-key; do
    ln -s pacman "$pkgdir/usr/share/bash-completion/completions/$f"
  done

  install -Dm644 contrib/zsh_completion $pkgdir/usr/share/zsh/site-functions/_pacman
}

md5sums=('49cec981a8cdc8e8b61843a8747e4f1d'
         '080d9f76f56e135cc62205874636aa0f'
         'ce9943fc8086d491890565e91ea1a0d8'
         'eb8dba9bd0b315230fbf0e5dc0a7335b')