#!/bin/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=ncmpc
PKGVERSION=0.34
PKGREVISION=1
PKGLICENSE="GPLv20"
PKGSUMMARY="curses client for the Music Player Daemon"
PKGDOWNLOAD="https://www.musicpd.org/download/ncmpc/0/$PKGNAME-$PKGVERSION.tar.xz"
PKGDEPENDS="meson:build ncurses"
PKGOPTIONS="COLORS LOCALE MOUSE NLS REGEX"

: ${CC:=clang}
: ${CFLAGS:=-O2}
: ${CXX:=clang++}
: ${CXXFLAGS:=-O2}
: ${LDFLAGS:=}
: ${COLORS:=yes}
: ${LOCALE:=yes}
: ${MOUSE:=yes}
: ${NLS:=yes}
: ${REGEX:=yes}         # Note: regex support through pcre.

if [ "$COLORS" = "yes" ]; then
	with_colors="-D colors=true"
else
	with_colors="-D colors=false"
fi

if [ "$LOCALE" = "yes" ]; then
	with_locale="-D locale=enabled"
else
	with_locale="-D locale=disabled"
fi

if [ "$MOUSE" = "yes" ]; then
	with_mouse="-D mouse=enabled"
else
	with_mouse="-D mouse=disabled"
fi

if [ "$NLS" = "yes" ]; then
	PKGDEPENDS="gettext $PKGDEPENDS"
	with_nls="-D nls=enabled"
else
	with_nls="-D nls=disabled"
fi

if [ "$REGEX" = "yes" ]; then
	PKGDEPENDS="pcre $PKGDEPENDS"
	with_regex="-D regex=enabled"
else
	with_regex="-D regex=disabled"
fi

build()
{
	rm -rf $PKGNAME-$PKGVERSION
	tar xvf $PKGNAME-$PKGVERSION.tar.xz
	cd $PKGNAME-$PKGVERSION

	CC="$CC" \
	CFLAGS="$CFLAGS" \
	CXX="$CXX" \
	CXXFLAGS="$CXXFLAGS" \
	LDFLAGS="$LDFLAGS" \
	meson . build \
		--prefix / \
		--buildtype release \
		--default-library shared \
		$with_colors \
		$with_locale \
		$with_mouse \
		$with_nls \
		$with_regex
	ninja -C build
	DESTDIR=$DESTDIR ninja -C build install

	cd ..
	rm -rf $PKGNAME-$PKGVERSION
}
