#!/bin/sh

# Copyright © 2015-2022 Jakub Wilk <jwilk@jwilk.net>
#
# This file is part of python-djvulibre.
#
# python-djvulibre is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# python-djvulibre is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.

pkgs_base='
build-essential
libdjvulibre-dev
pkg-config
python-dev
cython
'
pkgs_tests='
python-subprocess32
djvulibre-bin
ghostscript
'
pkgs="$pkgs_base"

usage()
{
    printf 'Usage: %s [--tests] [--py3]\n' "$0"
}

set -e -u

if ! args=$(getopt -n "$0" -o 'h' --long 'help,tests,py3' -- "$@")
then
    usage >&2
    exit 1
fi
opt_tests=
opt_py3=
eval set -- "$args"
while true
do
    case "$1" in
        -h|--help) usage; exit 0;;
        --tests) opt_tests=y; shift;;
        --py3) opt_py3=y; shift;;
        --) shift; break;;
        *) printf '%s: internal error (%s)\n' "$0" "$1" >&2; exit 1;;
    esac
done

[ "$opt_tests" ] && pkgs="$pkgs $pkgs_tests"
if [ "$opt_py3" ]
then
    pkgs=$(printf '%s' "$pkgs" | sed -e '/^python-subprocess32$/d' -e 's/^python-/python3-/' -e 's/^cython$/cython3/')
fi

PS4='# '
(
    set -x
    # shellcheck disable=SC2086
    apt-get install --no-install-recommends $pkgs
)

# vim:ts=4 sts=4 sw=4 et
