# $Id$
# Maintainer: Jason Plum <jplum@archlinuxarm.org>
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>
# Contributor: Josh Cartwright <joshc@eso.teric.us>
# from https://github.com/WarheadsSE/PKGs/blob/master/distccd-alarm/PKGBUILD
# for  https://archlinuxarm.org/wiki/Distcc_Cross-Compiling

noautobuild=1

_subarchs=(armv5 armv6h armv7h armv8)
pkgbase='distccd-alarm'
pkgname=("${_subarchs[@]/#/$pkgbase-}")
pkgver=6.1.1
pkgrel=1
pkgdesc="An x-tools & distcc services package for Arch Linux ARM"
arch=('x86_64')
license=('GPL' )
url="http://archlinuxarm.org/developers/distcc-cross-compiling"
depends=('distcc')
options=('libtool' 'emptydirs' '!strip')
source=(http://archlinuxarm.org/builder/xtools/x-tools.tar.xz
        http://archlinuxarm.org/builder/xtools/x-tools6h.tar.xz
        http://archlinuxarm.org/builder/xtools/x-tools7h.tar.xz
        http://archlinuxarm.org/builder/xtools/x-tools8.tar.xz
        distccd-armv5.conf
        distccd-armv5.service
        distccd-armv6h.conf
        distccd-armv6h.service
        distccd-armv7h.conf
        distccd-armv7h.service
        distccd-armv8.conf
        distccd-armv8.service
        )
md5sums=('92a5cd5ddde22683bb910261b763b509'
         '2d19d3f941276441999834c4f5fbdd7e'
         '58766cfb988135f761d9f4c2c0d5c4e4'
         '87e0796ac697c9dceb3e83a51b51113c'
         '3706fb6f1c891717861f1101233bebbd'
         '41d29c84a9624653040491226cbf287d'
         'c15d726a8b9708eda6d274dbae11783e'
         '0f2ed6569e6f9de9ce63c9550b68a7a7'
         '717a4bc07b1c7ad4461603a633e6a008'
         'e760b78b6d8c4d94ba1540ee0a9e33b9'
         'ca0ab42032060b2ab5da525bab0a46a8'
         '3da954cb728f347c142eb42f65477593'
         )

_package_subarch() {
    # backup configs
    backup=("etc/conf.d/distccd-$1")
    # install symlink to distccd
    install -d "${pkgdir}/usr/bin"
    ln -sf /usr/bin/distccd "${pkgdir}/usr/bin/distccd-$1"
    # copy in toolchain
    install -d "${pkgdir}/usr/local/x-tools-$1"
    cp -ar "${srcdir}/$2" "${pkgdir}/usr/local/x-tools-$1"
    # install services
    install -Dm0644 "${srcdir}/distccd-$1.service" \
       "${pkgdir}/usr/lib/systemd/system/distccd-$1.service"
    # install config
    install -Dm0644 "${srcdir}/distccd-$1.conf" \
       "${pkgdir}/etc/conf.d/distccd-$1"
    
}

for i in "${!_subarchs[@]}"; do   
    _xtoolsdir="${source[i]##*/}"
    _xtoolsdir="${_xtoolsdir%%.*}"
    eval 'package_distccd-alarm-'${_subarchs[i]}'() {
        _package_subarch '${_subarchs[i]}' '${_xtoolsdir}'
    }'
done

