# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

pkgname=scons
pkgver=3.1.2
pkgrel=6
pkgdesc="Extensible Python-based build utility"
arch=('any')
groups=('base-devel')
url="https://scons.org/"
license=('MIT')
depends=('python')
source=("https://downloads.sourceforge.net/sourceforge/${pkgname}/${pkgname}-${pkgver}.tar.gz"
        scons-2.3.4-cyglink-msys2.patch
        scons-2.3.4-msys2-plat-mingw-env.patch
        mingw_w64.py)
sha256sums=('7801f3f62f654528e272df780be10c0e9337e897650b62ddcee9f39fde13f8fb'
            '48e9ac05b18f123c179da0a7398b6a8e777bb309d4125b729855100119644ec4'
            'c024560dc93636d92614c17d7519080dd931f6c1471088616692a443d3cfc064'
            '984c55d0ca18ac594941bb6336fe994efe2f5bba20225e8cb1f5d42c80eaf651')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  cp ../mingw_w64.py engine/SCons/Tool/

  # avoid errors when re-running makepkg
  rm -f engine/SCons/Platform/msys.py engine/SCons/Tool/msyslink.py
  patch -p1 -i ${srcdir}/scons-2.3.4-cyglink-msys2.patch
  patch -p0 -i ${srcdir}/scons-2.3.4-msys2-plat-mingw-env.patch
}

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

  /usr/bin/python setup.py install \
      --standard-lib \
      --prefix=/usr \
      --install-data=/usr/share \
      --optimize=1 \
      --root="${pkgdir}"

  # Fix shebang
  sed -i 's:^#!.*bin/env python:#!/usr/bin/python:' \
    "${pkgdir}"/usr/bin/*

  install -Dm644 LICENSE.txt \
    "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
