# Contributor: Michael Hanson <hansonorders@verizon.net>
# Maintainer: Michael Hanson <hansonorders@verizon.net>
pkgname=mythtv-contrib
pkgver=0.24
pkgrel=1
pkgdesc="User contributed scripts and utilities for mythtv."
arch=('i686' 'x86_64')
url="http://mythtv.org"
license=('GPL')
groups=('mythtv-extras')
depends=('perl' 'mythtv>=0.24')
makedepends=('gcc' 'git' 'help2man' 'libavc1394' 'libraw1394' 'libiec61883')
install='mythtv-contrib.install'
source=('http://www.pdp8.net/directv/directv.pl' \
        'http://stb-command.googlecode.com/files/stb-command1.2.tar.gz' \
        'http://mythtv.mlaronson.com/myth-xbmc-connect/downloads/xbmc_mythlink.tgz' \
        'mythchanger.10f.beta.tar' '6200ch.tar.gz' 'dct-channel_make.patch' \
        'mythchanger_make.patch')

_gitroot="git://github.com/MythTV/mythtv.git"
_gitname="contrib"

build() {
        if [ -d ${srcdir}/mythtv ] ; then
          rm -fr ${srcdir}/mythtv
        fi
        cd ${srcdir}
        msg "Updating from GIT..."
        git clone -b fixes/0.24 ${_gitroot}
        #git pull
        msg "The local files are updated."

	# build and install
        echo "Building 6200ch..."
        cd ${srcdir}
        tar zxf 6200ch.tar.gz
        cd ${srcdir}/6200ch
        gcc -std=gnu99 -o 6200ch 6200ch.c -lavc1394 -lrom1394 -lraw1394 || return 1
        install -D -m755 6200ch ${pkgdir}/usr/bin/6200ch || return 1
        install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.6200ch || return 1

       # echo "Building change-channel-lirc..."
       # cd ${srcdir}/mythtv/mythtv/contrib/channel_changers/change-channel-lirc || return 1
       # install -D -m755 *{.pl,.sh} ${pkgdir}/usr/bin || return 1

       # echo "Building d10control..."
       # cd ${srcdir}/mythtv/mythtv/contrib/channel_changers/d10control || return 1
       # install -D -m755 d10control.pl ${pkgdir}/usr/bin/d10control.pl  || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.d10control

        echo "Building dct-channel..."
        cd ${srcdir}/mythtv/mythtv/contrib/channel_changers/dct-channel
        patch -p4 <$startdir/dct-channel_make.patch || return 1
        make
        install -D -m755 channel ${pkgdir}/usr/bin || return 1
        install -D -m644 channel.1 ${pkgdir}/usr/man/man1/channel.1 || return 1
        install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.dct-channel
        install -D -m644 COPYING ${pkgdir}/usr/share/licenses/mythtv-contrib/COPYING.dct-channel

       # echo "Building dct2000serial..."
       # cd ${srcdir}/mythtv/mythtv/contrib/channel_changers/dct2000serial || return 1
       # install -D -m755 *.py ${pkgdir}/usr/bin || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.dct2000serial

       # echo "Building redeye..."
       # cd ${srcdir}/mythtv/mythtv/contrib/channel_changers/red_eye || return 1
       # gcc -Wall -o red_eye red_eye.c || return 1
       # install -D -m755 red_eye ${pkgdir}/usr/bin/red_eye || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.red_eye

       # echo "Building sa3250ch..."
       # cd ${srcdir}/mythtv/mythtv/contrib/channel_changers/sa3250ch || return 1
       # gcc -Wall -o sa3250ch sa3250ch.c -lrom1394 -lavc1394 -lraw1394 || return 1
       # install -D -m755 sa3250ch ${pkgdir}/usr/bin/sa3250ch || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.sa3250ch

       # echo "Building firewire_tester..."
       # cd ${srcdir}/mythtv/mythtv/contrib/development/firewire_tester || return 1
       # gcc -Wall -o firewire_tester firewire_tester.c -liec61883 -lraw1394 || return 1
       # install -D -m755 firewire_tester ${pkgdir}/usr/bin || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.firewire_tester

        echo "Building development..."
        cd ${srcdir}/mythtv/mythtv/contrib/development || return 1
        install -D -m755 mkdummyts.sh ${pkgdir}/usr/bin || return 1
        cd ${srcdir}/mythtv/mythtv/contrib/development/tsc-calibrate || return 1
        gcc -o tsc-calibrate tsc-calibrate.c || return 1
        install -D -m755 tsc-calibrate ${pkgdir}/usr/bin || return 1

       # echo "Building mythname..."
       # cd ${srcdir}/mythtv/mythtv/contrib/info/mythname || return 1
       # install -D -m755 mythname.pl ${pkgdir}/usr/bin || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.mythname

       # echo "Building misc_status_info..."
       # cd ${srcdir}/mythtv/mythtv/contrib/info/misc_status_info || return 1
       # install -D -m755 *{.sh,.pl} ${pkgdir}/usr/bin || return 1
       # install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.misc_status_info

        echo "Building imports..."
        cd ${srcdir}/mythtv/mythtv/contrib/imports/mirobridge || return 1
        install -D -m755 mirobridge.py ${pkgdir}/usr/bin/mirobridge.py || return 1
        mkdir -p ${pkgdir}/usr/share/doc/mythtv-contrib/mirobridge || return 1
        cd ${srcdir}/mythtv/mythtv/contrib/imports/mirobridge/mirobridge || return 1
        install -D -m755 *.{py,conf} ${pkgdir}/usr/share/doc/mythtv-contrib/mirobridge/ || return 1
        cd ${srcdir}/mythtv/mythtv/contrib/imports/mirobridge || return 1
        install -D -m644 mirobridge.README ${pkgdir}/usr/share/doc/mythtv-contrib/README.mirobridge || return 1

        echo "Building maintenance..."
        cd ${srcdir}/mythtv/mythtv/contrib/maintenance || return 1
        install -D -m755 *.pl ${pkgdir}/usr/bin || return 1

       # echo "Building mythmail..."
       # cd ${srcdir}/mythtv/mythtv/contrib/mythmail || return 1
       # install -D -m755 *.pl ${pkgdir}/usr/bin || return 1

       # echo "Building recovery..."
       # cd ${srcdir}/mythtv/mythtv/contrib/recovery || return 1
       # install -D -m755 *.pl ${pkgdir}/usr/bin || return 1

        echo "Building user_jobs..."
        cd ${srcdir}/mythtv/mythtv/contrib/user_jobs || return 1
        install -D -m755 *.pl ${pkgdir}/usr/bin || return 1
       # install -D -m755 setbookmark ${pkgdir}/usr/bin/setbookmark.pl || return 1

       # echo "Building directv.pl..."
       # cd ${srcdir} || return 1
       # install -D -m755 directv.pl ${pkgdir}/usr/bin || return 1

        echo "Building stb-command..."
        cd ${srcdir}
        tar zxf stb-command1.2.tar.gz || return 1
        cd ${srcdir}/stb-command
        make || return 1
	install -D -m755 stb-command ${pkgdir}/usr/bin || return 1
        install -D -m755 sa3250_ch_guid  ${pkgdir}/usr/bin || return 1
        install -D -m755 stb_cmd_guid  ${pkgdir}/usr/bin || return 1
        install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.stb-command || return 1

        echo "Building mythchanger..."
        cd ${srcdir}
        tar xf mythchanger.10f.beta.tar || return 1
        cd ${srcdir}/mythchanger.10f.beta
        patch -p1 <$startdir/mythchanger_make.patch || return 1
        make || return 1
        install -D -m755 mythchanger $pkgdir/usr/bin || return 1
        install -D -m644 README ${pkgdir}/usr/share/doc/mythtv-contrib/README.mythchanger

        echo "Building xbmc mythlink..."
        cd ${srcdir}
        tar zxf xbmc_mythlink.tgz || return 1
        install -D -m755 xbmc_mythlink_helper.sh ${pkgdir}/usr/bin || return 1
        install -D -m755 xbmc_mythlink.py ${pkgdir}/usr/bin || return 1
}
md5sums=('35b8533f96ec915bf049711f931d5e11'
         '8067175170add2c4d8aa333e43c9387c'
         '2ee7eafc3804f0bd48ede0ad05e718f1'
         '34d148795f832f12973a08d59e9a0ef3'
         '40d3b9e719b3e779b6d6f9565bbf9b22'
         'ecb201556b0ffe9fdeed1494a9bb556e'
         'c5996437bef4448acbee300bd6659dad')