#!/bin/busybox sh
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

PKGNAME=jasper
PKGVERSION=2.0.14
PKGREVISION=1
PKGLICENSE="CUSTOM"
PKGSUMMARY="JasPer Image Processing/Coding Tool Kit"
PKGDOWNLOAD="https://www.ece.uvic.ca/~frodo/jasper/software/$PKGNAME-$PKGVERSION.tar.gz"
PKGDEPENDS="cmake:build"
PKGOPTIONS="JPEG OPENGL"

: ${CC:=clang}
: ${CFLAGS:=-O2}
: ${JPEG:=yes}
: ${OPENGL:=yes}

if [ "$JPEG" = "yes" ]; then
	PKGDEPENDS="libjpeg-turbo $PKGDEPENDS"
	with_jpeg="-DJAS_ENABLE_LIBJPEG=On"
else
	with_jpeg="-DJAS_ENABLE_LIBJPEG=Off"
fi

if [ "$OPENGL" = "yes" ]; then
	PKGDEPENDS="mesa freeglut $PKGDEPENDS"
	with_opengl="-DJAS_ENABLE_OPENGL=On"
else
	with_opengl="-DJAS_ENABLE_OPENGL=Off"
fi

rm -rf $PKGNAME-$PKGVERSION
tar xvf $PKGNAME-$PKGVERSION.tar.gz
cd $PKGNAME-$PKGVERSION

mkdir bld && cd bld
cmake .. \
	-DBUILD_SHARED_LIBS=On \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_C_COMPILER="$CC" \
	-DCMAKE_C_FLAGS="$CFLAGS" \
	-DCMAKE_INSTALL_PREFIX= \
	-DCMAKE_INSTALL_DOCDIR=/share/doc/$PKGNAME \
	$with_jpeg \
	$with_opengl
make VERBOSE=1
make install DESTDIR=$DESTDIR
cd ..

cd ..
rm -rf $PKGNAME-$PKGVERSION
