# Maintainer: Fincer <fincer89 at hotmail dot com>

pkgname=openra-bleed-tibsunra2
pkgver=r22244.c12cfbc
pkgrel=1
pkgdesc="An open-source implementation of the Red Alert engine using .NET/mono and OpenGL (git version)"
arch=("any")
url="http://openra.net"
license=("GPL3")
depends=("mono" "ttf-dejavu" "openal" "libgl" "freetype2" "sdl2" "lua51" "hicolor-icon-theme" "desktop-file-utils" "xdg-utils")
optdepends=('zenity')
makedepends=("git")
provides=("openra")
conflicts=("openra-git" "openra")
install=openra-bleed-tibsunra2.install
source=("$pkgname-src::git+https://github.com/OpenRA/OpenRA.git#branch=bleed"
"git://github.com/OpenRA/ra2.git"
sha1sums=('SKIP'
          'SKIP'
          'SKIP'
          '5d73aedf0b3f6736981c727646c122d3c75ea27b'
          'af97ff3908959e60f44949ee874d9035999c9fc3'
          '7e87cb67e8ade6397129e45203e67504d572abf6'
          '07930220fbd876492085d82ec33001316b6862f9'
          '9846854381f099e734d41dafe8eaa9457e27250b')

pkgver() {
    cd "$srcdir/$pkgname-src"
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
    
build() {

# Move Red Alert 2 Github files to the right place:
    cd "$srcdir/ra2"
    mv ./OpenRA.Mods.RA2 "$srcdir/$pkgname-src/"
    mkdir -p "$srcdir/$pkgname-src/mods/ra2/"
    mv ./* "$srcdir/$pkgname-src/mods/ra2/"

# Patch OpenRA core files for Tiberian Sun & Red Alert 2
    cd "$srcdir/$pkgname-src"
    for i in $srcdir/*.patch; do patch -Np1 < $i; done

    mkdir $srcdir/$pkgname-src/mods/ra2/bits/{vehicles,themes}

# Get Red Alert 2 GIT version number for files
    ra2_version=git-$(git ls-remote https://github.com/OpenRA/ra2.git | head -1 | sed "s/HEAD//" | sed 's/^\(.\{7\}\).*/\1/')
    sed -i "s/Version: {DEV_VERSION}/Version: $ra2_version/g" $srcdir/$pkgname-src/mods/ra2/mod.yaml
    sed -i "s/maps\/ra2\/{DEV_VERSION}/maps\/ra2\/$ra2_version/g" $srcdir/$pkgname-src/mods/ra2/mod.yaml
    
    cd "$srcdir/$pkgname-src"
    make version
    make dependencies
    make all [DEBUG=false]
}

package() {
    cd "$srcdir/$pkgname-src"
    make prefix=/usr DESTDIR="$pkgdir" install-all
    make prefix=/usr DESTDIR="$pkgdir" install-linux-shortcuts

    rm $pkgdir/usr/lib/openra/mods/cnc/OpenRA.Mods.Cnc.dll.mdb
    rm $pkgdir/usr/lib/openra/mods/common/OpenRA.Mods.Common.dll.mdb
    rm $pkgdir/usr/lib/openra/mods/d2k/OpenRA.Mods.D2k.dll.mdb
    rm $pkgdir/usr/lib/openra/mods/ra/OpenRA.Mods.RA.dll.mdb

    rm $pkgdir/usr/lib/openra/mods/ra2/{build.cake,OpenRA.Mods.RA2.dll.mdb,make.cmd,make.ps1,makefile}
    rm $pkgdir/usr/lib/openra/mods/ts/OpenRA.Mods.TS.dll.mdb
}
