# Template file for 'dmenu'
pkgname=dmenu
version=4.5
revision=10
makedepends="libXinerama-devel $(vopt_if xft 'libXft-devel freetype-devel')"
short_desc="A generic menu for X"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="MIT"
homepage="http://tools.suckless.org/dmenu/"
distfiles="http://dl.suckless.org/tools/${pkgname}-${version}.tar.gz"
checksum="082cd698d82125ca0b3989006fb84ac4675c2a5585bf5bb8af0ea09cfb95a850"

build_options="xft fuzzymatch monarg mouse"
desc_option_xft="Enable Xft font support"
desc_option_fuzzymatch="Enable Fuzzymatch support"
desc_option_monarg="Enable monitor argument support"
desc_option_mouse="Enable mouse support"

if [ "$build_option_xft" ]; then
	distfiles+=" http://tools.suckless.org/dmenu/patches/dmenu-${version}-xft.diff"
	skip_extraction+=" ${pkgname}-${version}-xft.diff"
	checksum+=" efb4095d65e5e86f9dde97294732174409c24f319bdd4824cc22fa1404972b4f"
fi

if [ "$build_option_fuzzymatch" ]; then
	distfiles+=" http://tools.suckless.org/dmenu/patches/${pkgname}-${version}-fuzzymatch.diff"
	skip_extraction+=" ${pkgname}-${version}-fuzzymatch.diff"
	checksum+=" f037978583a16b2dab554058b147c2dbdfc758472d2bc9e1f031b2b9c686c0ff"
fi

if [ "$build_option_monarg" ]; then
	distfiles+=" http://tools.suckless.org/dmenu/patches/${pkgname}-${version}-monarg.diff"
	skip_extraction+=" ${pkgname}-${version}-monarg.diff"
	checksum+=" c30a4acd9202712c019de72f9c2832686e6e25ca0b939757e31c20b9c110008b"
fi

if [ "$build_option_mouse" ]; then
	distfiles+=" http://tools.suckless.org/dmenu/patches/${pkgname}-${version}-mouse-support.diff"
	skip_extraction+=" ${pkgname}-${version}-mouse-support.diff"
	checksum+=" 8ac73e77abb7c5e60080abe892e2b4232c9370bff39e5548cf9a403cffe692c4"
fi

## RIght now mouse && xft are incompatible

pre_build() {
	local srcdir="${XBPS_SRCDISTDIR}/${pkgname}-${version}/"
	if [ "$build_option_fuzzymatch" ]; then
		msg_normal "Applying fuzzymatch patches"
		patch -p2 < "$srcdir/${pkgname}-${version}-fuzzymatch.diff"
		echo '#include "fuzzymatch.c"' >> dmenu.c
	fi
	if [ "$build_option_xft" ]; then
		msg_normal "Applying xft patches"
		patch -p1 < "$srcdir/${pkgname}-${version}-xft.diff"
	fi
	if [ "$build_option_mouse" ]; then
		msg_normal "Applying mouse patches"
		patch -p1 < "$srcdir/${pkgname}-${version}-mouse-support.diff"
	fi
	if [ "$build_option_monarg" ]; then
		msg_normal "Applying monarg patches"
		patch -p1 < "$srcdir/${pkgname}-${version}-monarg.diff"
	fi
}

do_build() {
	sed -i -e "s|^CFLAGS   =|CFLAGS += |g" \
		-e "s|^LDFLAGS  = \-s|LDFLAGS += |g" config.mk

	x11inc=$XBPS_CROSS_BASE/usr/include/X11
	x11lib=$XBPS_CROSS_BASE/usr/lib
	xftinc=-I$XBPS_CROSS_BASE/usr/include/freetype2
	make CC="$CC" ${makejobs} X11INC=$x11inc X11LIB=$x11lib \
		$(vopt_if xft XFTINC=$xftinc)
}

do_install() {
	make PREFIX=/usr DESTDIR=${DESTDIR} install
	vlicense LICENSE
}
