# Maintainer: George Rawlinson <george@rawlinson.net.nz>
# Contributor: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

pkgname=nginx-mainline-mod-headers-more
pkgver=0.33
pkgrel=41
pkgdesc="Set and clear input and output headers"
arch=('x86_64')
url="https://github.com/openresty/headers-more-nginx-module"
_modname="${url##*/}"
license=('BSD')
depends=('nginx-mainline')
makedepends=('nginx-mainline-src')
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
b2sums=('fe3097a7700ce5da087058f7bb44c95164b75137031187400473f6833bf0e33e5c4920807225a6ff94174fe7dbd6186cca176a33a629ca0911faab6804bdd12a')

prepare() {
  mkdir -p build
  ln -sf -t build /usr/src/nginx/{auto,src}
}

build() {
  cd build
  /usr/src/nginx/configure --with-compat --add-dynamic-module="$srcdir/$_modname-$pkgver"
  make modules
}

package() {
  # modules
  install -vDm755 -t "$pkgdir/usr/lib/nginx/modules" build/objs/*.so

  cd "$_modname-$pkgver"

  # license
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  sed -n "507,535p" README.markdown > "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"

  # documentation
  install -Dm644 -t "$pkgdir/usr/share/doc/$pkgname" README.markdown
}