pkgname=pam
pkgver=1.7.1
pkgdesc="PAM (Pluggable Authentication Modules) library"
arch=('x86_64')
license=('GPL-2.0-only')
homepage="http://linux-pam.org"
_etcfiles=("login"
  "other"
  "passwd"
  "su"
  "system-auth"
  "system-local-login"
  "system-login"
  "system-remote-login"
  "system-services"
)
_etcfile_sums=("91ad33eabae9f7ae7809e81ab3df8672"
  "a1ca1c975faaa52c654151243019379f"
  "5bd5838c81534c4a24a2a112500ba62c"
  "5dfd9fee8f37d44324386e51e78e95a6"
  "ed9690cb2d0b742604cc0ce38abdb75a"
  "76da90222db315e3b0834f82ed6280b8"
  "809604420097ba6d005d82a686bde039"
  "76da90222db315e3b0834f82ed6280b8"
  "ddcb922b0db94547d3f07beb1eb00ee5"
)
sources=("Linux-PAM-${pkgver}.tar.xz"
  ${_etcfiles[@]}
)
urls=("https://github.com/linux-pam/linux-pam/releases/download/v${pkgver}/${sources[0]}"
  ${_etcfiles[@]}
)
md5sums=("92812d7dd414d816fba8d649e84e68ca"
  ${_etcfile_sums[@]}
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  unset BROWSER

  local machine_file="${TMPDIR}/meson.${CHOST}.ini.local"
  cat >> "${machine_file}" << "EOF"
[binaries]
xmlcatalog='true'
xmllint='true'
elinks='true'
w3m='true'
EOF

  local meson_args=(
    --prefix=/usr
    --buildtype=release
    --native-file "${machine_file}"
    -D audit=disabled
    -D examples=true
    -D pam-debug=false
    -D nis=disabled
    -D i18n=enabled
    -D selinux=disabled
    -D isadir='.'
    -D xml-catalog=/etc/xml/catalog
    -D sbindir=/usr/sbin
    -D securedir=/usr/lib/security
    -D docdir=/usr/share/doc/${pkgname}-${pkgver}
    -D htmldir=/usr/share/doc/${pkgname}-${pkgver}/html
    -D pdfdir=/usr/share/doc/${pkgname}-${pkgver}/pdf
    -D docs=disabled
    -D pam_unix=enabled
    -D econf=disabled
    -D logind=enabled
    -D elogind=disabled
    -D pam_lastlog=enabled
  )

  meson setup build "${meson_args[@]}"

  meson compile -C build
}

src_check() {
  meson test -C build
}

src_install() {
  meson install -C build --destdir "${pkgdir}"

  # set unix_chkpwd uid
  chmod +s "${pkgdir}"/usr/sbin/unix_chkpwd

  for _f in ${_etcfiles[@]}; do
    install -vDm644 "${filedir}/${_f}" -t "${pkgdir}/etc/pam.d"
  done
}

# vim:ft=sh syn=sh et sw=2:
