# $Id: PKGBUILD 104106 2014-01-15 18:44:35Z bpiotrowski $
# Maintainer:  Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Chris Brannon <cmbrannon79@gmail.com>
# Contributor: Geoffroy Carrier <geoffroy@archlinux.org>

pkgbase=luarocks
pkgname=('luarocks' 'luarocks5.1')
pkgver=2.1.2
pkgrel=1
arch=('any')
url='http://luarocks.org/'
license=('custom')
depends=('unzip' 'zip' 'curl')
makedepends=('lua' 'lua51')
optdepends=('cvs: for fetching sources from CVS repositories'
            'git: for fetching sources from git repositories'
            'mercurial: for fetching sources from mercurial repositories'
            'cmake: for building rocks that use the cmake build system')
options=('!makeflags')
source=(http://luarocks.org/releases/$pkgname-$pkgver.tar.gz)
md5sums=('0afc5fd6ee6ec6128fccda1bc559f41e')

prepare() {
  cp -r $pkgbase-$pkgver ${pkgbase}5.1-$pkgver
}

build() {

  cd $pkgbase-$pkgver
  LUA_VERSION= ./configure --prefix=/usr \
    --sysconfdir=/etc/luarocks \
    --lua-version=5.2 \
    --with-lua-include=/usr/include \
    --with-downloader=curl \
    --versioned-rocks-dir
  make

  cd ../${pkgbase}5.1-$pkgver
  ./configure --prefix=/usr \
    --sysconfdir=/etc/luarocks \
    --lua-version=5.1 \
    --with-lua-include=/usr/include/lua5.1 \
    --with-downloader=curl \
    --versioned-rocks-dir
  make
  sed -i 's/env lua/env lua5.1/' src/bin/luarocks{,-admin}

}

package_luarocks() {
  pkgdesc='Deployment and management system for Lua 5.2 modules'
  backup=('etc/luarocks/config-5.2.lua')
  depends+=('lua')
  optdepends+=('lua-sec: HTTPS support')

  cd $pkgname-$pkgver
  make install DESTDIR="$pkgdir"
  install -D COPYING "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_luarocks5.1() {
  pkgdesc='Deployment and management system for Lua 5.1 modules'
  backup=('etc/luarocks/config-5.1.lua')
  depends+=('lua51')
  optdepends+=('lua51-sec: HTTPS support')

  cd $pkgname-$pkgver
  make install DESTDIR="$pkgdir"
  install -D COPYING "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

  rm "$pkgdir"/usr/bin/luarocks{,-admin}
}
