# Maintainer (AUR): Maxime Poulin <maxpoulin64@gmail.com>
# Contributor (AUR): Damian Nowak <damian.nowak@atlashost.eu>
# Contributor (AUR): Kyle Fuller <inbox@kylefuller.co.uk>
# Contributor (AUR): jibi <jibi@paranoici.org>

# parabola changes and rationale:
#  - fixed arch array
#  - removed redundant conflicts and provides

pkgname='inspircd'
pkgver='2.0.24'
pkgrel='1'
pkgdesc='A stable, modern and lightweight IRC daemon'
arch=('x86_64' 'i686' 'armv7h')
url='http://www.inspircd.org/'
license=('GPL2')
depends=('perl')
makedepends=('pkg-config' 'libmariadbclient' 'sqlite3' 'libldap' 'geoip'
             'gnutls' 'openssl' 'libgcrypt')
optdepends=('gnutls: m_ssl_gnutls'
            'libgcrypt: m_ssl_gnutls'
            'openssl: m_ssl_openssl'
            'libmariadbclient: m_mysql'
            'pcre: m_regex_pcre'
            'sqlite3: m_sqlite3'
            'libldap: m_ldapoper and m_ldapauth'
            'geoip: m_geoip')
install='inspircd.install'
source=("https://github.com/inspircd/inspircd/archive/v$pkgver.tar.gz"
        'inspircd.service')
sha512sums=('766ed9b2786a36c6f3765405b5e02d831ea5ae1089c1b646ed0340b08147f9bb8d477ff94e16b0d9ed02dc109c6273f3772e1bed10bc45d1e9e9b409a37d2b6a'
            '5a16a7c237693ffc6a108358f339b6aa2451fb16430561848ae869f890199b38fab6a13640bcc35cf1d07e32d7e5fff405d88668ee05ddaffc2ef61cb42ee832')

build() {
  cd "${srcdir}/inspircd-${pkgver}"

  ./configure \
    --enable-extras=m_geoip.cpp \
    --enable-extras=m_ldapauth.cpp \
    --enable-extras=m_ldapoper.cpp \
    --enable-extras=m_mysql.cpp \
    --enable-extras=m_regex_pcre.cpp \
    --enable-extras=m_regex_posix.cpp \
    --enable-extras=m_sqlite3.cpp

  ./configure \
    --uid=0 \
    --prefix=/usr/lib/inspircd \
    --binary-dir=/usr/bin \
    --module-dir=/usr/lib/inspircd/modules \
    --config-dir=/etc/inspircd \
    --data-dir=/var/lib/inspircd \
    --log-dir=/var/log/inspircd \
    --enable-gnutls \
    --enable-openssl \
    --enable-epoll

  make
}

package() {
  install -Dm644 "${srcdir}"/inspircd.service "${pkgdir}"/usr/lib/systemd/system/inspircd.service
  install -o141 -g141 -dm750 "${pkgdir}/var/log/inspircd" "${pkgdir}/var/lib/inspircd"

  cd "${srcdir}/inspircd-${pkgver}"
  make DESTDIR="$pkgdir" install

  mkdir -p "${pkgdir}"/usr/share/inspircd
  mv "${pkgdir}"/etc/inspircd/examples "${pkgdir}"/usr/share/inspircd/examples

  rm -rf "${pkgdir}"/usr/lib/inspircd/logs
  rm -rf "${pkgdir}"/usr/lib/inspircd/data
}
