# Contributer: Sebastian Sareyko <public@nooms.de>
#
# It is possible to choose the idct implementation
# Available are:
# 
# none               use ProjectX Java implementation
# idct               the C implementation of the source from ProjectX
# idct-ffmpeg        taken from the ffmpeg Project
# idct-mjpeg         taken from MJPEGTOOLS 1.8.0
# idct-mjpeg-mmx     taken from MJPEGTOOLS 1.8.0
#
_idct=idct-mjpeg-mmx

pkgname=projectx
pkgver=0.91.0
pkgrel=5
license=('GPL')
arch=('i686' 'x86_64')
pkgdesc="DVB demux tool for repairing and analyzing different stream types"
makedepends=('java-environment')
depends=('java-runtime')
url="http://sourceforge.net/projects/project-x"
source=(http://downloads.sourceforge.net/sourceforge/project-x/ProjectX_$pkgver.zip \
        IDCTFast.patch
	projectx)

md5sums=('5cf7bb227abe2c16d34e8e9c84915291'
         '364022b37a55643fd8ec8d042827c3c9'
         '0bb5dfb7683babb91f7fc996f5de7f2d')
build() {
    cd ${srcdir}
    cd Project-X_0.91.0/
    if [ ${_idct} != "none" ]; then
       patch -p1 < ${srcdir}/IDCTFast.patch
       unzip lib/Linux/ProjectX_Source_0.90.4-portable.zip
       cp ProjectX_Source_0.90.4/src/net/sourceforge/dvb/projectx/video/IDCTFast.java src/net/sourceforge/dvb/projectx/video/
    fi
    sh ./build.sh
    if [ ${_idct} != "none" ]; then
       cd ProjectX_Source_0.90.4/lib/PORTABLE/
       make clean
       make PROJECTX_HOME=${srcdir}/Project-X_0.91.0 IDCT=${_idct} CPLAT="$CFLAGS -fPIC"
       cd ${srcdir}/Project-X_0.91.0
    fi
    install -D -m0755 $startdir/projectx $startdir/pkg/usr/bin/projectx
    install -D -m0644 ProjectX.jar $startdir/pkg/opt/projectx/ProjectX.jar
    if [ ${_idct} != "none" ]; then
       install -D -m0644 ProjectX_Source_0.90.4/lib/PORTABLE/libidctfast.so \
            $startdir/pkg/opt/projectx/lib/libidctfast.so
    fi
    install -D -m0644 lib/commons-net-1.3.0.jar \
             $startdir/pkg/opt/projectx/lib/commons-net-1.3.0.jar
    install -D -m0644 lib/jakarta-oro-2.0.8.jar \
             $startdir/pkg/opt/projectx/lib/jakarta-oro-2.0.8.jar
    sed -i -e 's#Exec=java -jar /usr/share/projectx/ProjectX.jar#Exec=/usr/bin/projectx#' projectx.desktop
    install -D -m0644 projectx.desktop $startdir/pkg/usr/share/applications/projectx.desktop
}