# Maintainer: Andreas Radke <andyrtr@archlinux.org>

pkgname=xorg-xdm
pkgver=1.1.14
pkgrel=1
pkgdesc="X Display Manager"
arch=('x86_64')
url="https://xorg.freedesktop.org/"
license=('custom')
depends=('pam' 'libxaw' 'libxinerama' 'xorg-xrdb' 'xorg-sessreg' 'libxft' 'systemd' 'libxcrypt')
makedepends=('xorg-util-macros' 'xtrans')
backup=(etc/X11/xdm/Xaccess etc/X11/xdm/Xresources etc/X11/xdm/Xservers etc/X11/xdm/xdm-config etc/pam.d/xdm etc/X11/xdm/Xsetup_0 etc/X11/xdm/Xsession)
source=(${url}/releases/individual/app/xdm-${pkgver}.tar.xz{,.sig}
        Xsession-loginshell.patch
        Xsession-xsm.patch
        xdm-1.0.5-sessreg-utmp-fix-bug177890.patch
        xdm.pam
        nolisten.patch)
sha512sums=('8ed1d2c946916c24cb4b2de9326f65629c97e53b145312c9cb9c6e4308d8b47d67d3981319fbd4feac9b3ed436b9dfb24a1c905d37d7bcf07b49c18a68c7a6e4'
            'SKIP'
            'cf79d5ced77568f346e0955d955438ce27dae99cca21fdd80df779c97cfc03b3b15b561d483f8a8206e1db0785434b816b3474d6cc20c5adb8072c0985254c69'
            '9ba9b515d18c595cec402c7d4f2a8c4b9b10d99ee1bb0a86f2c72c813962a325c3c6e85ea5387f11819f8c046761494d6e54df0cb33bb4ab1e87ef354dc61c5b'
            '698d401899660708dc17eaa84bd2323426afa4c3c094ff8d4a8d9c54e26e073f40dafed67636855bb230f351523a88f1f1ed1ec443d77d92ef65646b5a6976d5'
            'cb912013a294f0801b357a43f3e5313ffa9ac5fcc493b2318843983388eb0b839c84060a97c355e12ca03f3b056644aa4a2bb8a74ed73a0f2405816b8d6efdc0'
            '36136bdec96dbe034d93b68f14dbd34663e3423520eb8674a5760c7e6379006b32e42c43691cf6d91f9d683bee07e117c7ffc326c50b9e24f7515495e12cd89b')
validpgpkeys=('4A193C06D35E7C670FA4EF0BA2FB9E081F2D130E') # Alan Coopersmith <alan.coopersmith@oracle.com>

prepare() {
  cd xdm-${pkgver}
  patch -Np0 -i "${srcdir}/Xsession-loginshell.patch"
  patch -Np1 -i "${srcdir}/Xsession-xsm.patch"
  patch -Np0 -i "${srcdir}/xdm-1.0.5-sessreg-utmp-fix-bug177890.patch"
  patch -Np1 -i ../nolisten.patch
  autoreconf -vfi
}

build() {
  cd xdm-${pkgver}

  # FS#63867 XDM's default userPath / systemPath hide /usr/local 
  unset DEF_USER_PATH

  ./configure --prefix=/usr \
      --disable-xdm-auth \
      --disable-static \
      --with-xdmconfigdir=/etc/X11/xdm \
      --with-xdmscriptdir=/etc/X11/xdm \
      --with-pixmapdir=/usr/share/xdm/pixmaps \
      DEF_USER_PATH="/usr/local/bin:/usr/bin:/bin" \
      DEF_SYSTEM_PATH="/usr/local/bin:/usr/bin:/bin"

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

check() {
  cd xdm-${pkgver}
  make check
}

package() {
  cd xdm-${pkgver}
  make DESTDIR="${pkgdir}" install
  install -m755 -d "${pkgdir}/var/lib/xdm"
  install -m755 -d "${pkgdir}/etc/pam.d"
  install -m644 "${srcdir}/xdm.pam" "${pkgdir}/etc/pam.d/xdm"
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/"

  sed -i -e 's/\/X11R6//g' "${pkgdir}"/etc/X11/xdm/*

  sed -i 's|^Alias=.*|Alias=display-manager.service|' \
    "$pkgdir/usr/lib/systemd/system/xdm.service"
}
