# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

pkgname=doxygen
pkgver=1.8.9.1
pkgrel=1
pkgdesc="A documentation system for C++, C, Java, IDL and PHP"
arch=('i686' 'x86_64')
url="http://www.doxygen.org/"
options=('strip' 'staticlibs' '!makeflags') # 'debug')
license=('GPL')
depends=("gcc-libs" "libsqlite" "libiconv")
makedepends=("gcc" "flex" "python2" "libsqlite-devel" "libiconv-devel")
source=("http://ftp.stack.nl/pub/users/dimitri/${pkgname}-${pkgver}.src.tar.gz"
        '1.7.4-iconv.patch'
        'remove-extra-slashes.patch'
        'msys2-change-debug-flags.patch')
md5sums=('3d1a5c26bef358c10a3894f356a69fbc'
         '838712aecc168be786d95dc7497d5901'
         '5eea3d1fddf646d0944e5b1dd95628d6'
         '7abf53469d1c9123955c81c8284a4a8c')
noextract=(${pkgname}-${pkgver}.src.tar.gz)

prepare() {
  cd ${srcdir}
  [[ -d $srcdir/${pkgname}-${pkgver} ]] || tar -xzvf ${startdir}/${pkgname}-${pkgver}.src.tar.gz -C $srcdir
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p2 -i "${srcdir}"/1.7.4-iconv.patch
  patch -p1 -i "${srcdir}"/remove-extra-slashes.patch
  patch -p1 -i "${srcdir}"/msys2-change-debug-flags.patch
}

build() {
  local -a extra_config
  if check_option "debug" "y"; then
    extra_config+=("--debug")
    CFLAGS="-Og"
  else
    extra_config+=("--release")
  fi

  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --prefix /usr \
    --with-sqlite3 \
    --sqlite3-path /usr \
    --shared \
    --docdir /usr/share/doc/${pkgname} \
    --platform linux-g++ \
    "${extra_config[@]}"
  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}

  #make DESTDIR="${pkgdir}" install
  make INSTALL="${pkgdir}"/usr MAN1DIR=share/man/man1 install
}
