################################################################################
#
# xfce4.cygclass - functions for building Xfce 4 packages
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2015 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport 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.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/xfce4.cygclass
#  SYNOPSIS
#  inherit xfce4
#  DESCRIPTION
#  Xfce is a desktop environment for X which is lighter and faster than GNOME
#  or KDE but has more features than most lightweight DEs.  The project provides
#  desktop components and some basic applications which are built on a few
#  libraries which are based on GLib and GTK+.
#
#  This cygclass handles the building of Xfce 4.x packages.
#  INHERITS
#  autotools.cygclass
#****

#****o* xfce4.cygclass/HOMEPAGE (xfce4)
#  DEFINITION
HOMEPAGE="http://www.xfce.org/"
#****

ORIG_PN=${ORIG_PN:-${PN}}

#****o* xfce4.cygclass/SRC_URI (xfce4)
#  DESCRIPTION
#  Download location of the release tarball.
#****
#****o* xfce4.cygclass/GIT_URI (xfce4)
#  DESCRIPTION
#  Git repository for the package.
#  NOTE
#  git.cygclass should be inherit()ed last for this to be of use.
#****
case ${ORIG_PN} in
	exo|garcon|gtk-xfce-engine|libxfce4ui|libxfce4util\
	|xfce4-appfinder|xfce4-dev-tools|xfce4-panel\
	|xfce4-session|xfce4-settings|xfconf|xfdesktop|xfwm4)
		uri_subdir="xfce/${ORIG_PN}"
		;;
	libxfce4menu|libxfcegui4|thunar-vfs|xfce-utils)
		uri_subdir="archive/${ORIG_PN}"
		;;
	Thunar)
		uri_subdir="xfce/thunar"
		;;
	Terminal)
		uri_subdir="apps/terminal"
		;;
	xfce4-icon-theme|xfwm4-themes)
		uri_subdir="art/${ORIG_PN}"
		;;
	pyxfce|thunarx-python|xfce4-mm|xfce4-vala)
		uri_subdir="bindings/${ORIG_PN}"
		;;
	thunar-*-plugin)
		uri_subdir="thunar-plugins/${ORIG_PN}"
		;;
	*-plugin)
		uri_subdir="panel-plugins/${ORIG_PN}"
		;;
	*)
		uri_subdir="apps/${ORIG_PN}"
		;;
esac

SRC_URI="mirror://xfce/src/${uri_subdir}/${PV[1]}.${PV[2]}/${ORIG_PN}-${PV}.tar.bz2"
GIT_URI="git://git.xfce.org/${uri_subdir}"

unset uri_subdir

#****C* xfce4.cygclass/xfce4_autoreconf
#  SYNOPSIS
#  cd $S
#  xfce4_autoreconf
#  DESCRIPTION
#  Updates the build system with xdt-autogen.
#  WARNING
#  Skipping this step is strongly discouraged.  Patches to configure.ac, aclocal
#  macros, or Makefile.am files will not take effect until their tools have been
#  regenerated.  Also, Cygwin's libtool package often includes patches which
#  are not yet available in the latest upstream release, so libraries may not
#  be built optimally, or even correctly, without this step having been run.
#  The same applies for some of the other build tools as well.
#  REQUIRES
#  autoconf, automake, gtk-doc, intltool, libglib2.0-devel, libtool,
#  pkg-config, xfce4-dev-tools
#  SEE ALSO
#  cygautoreconf, gnome2_autoreconf
#****
xfce4_autoreconf() {
	local auxdir configure_ac f

	check_prog_req xdt-autogen xfce4-dev-tools

	for f in configure.ac configure.ac.in configure.in configure.in.in
	do
		if [ -e $f ]
		then
			configure_ac=$f
			break
		fi
	done

	if ! defined configure_ac
	then
		error "xfce4: configure.ac or configure.in not found"
	fi

	__config_set with_aclocal 1
	__config_set with_autoconf 1
	__config_set with_autoheader 1
	__config_set with_automake 1
	__config_set with_intltool 1
	__config_set with_libtool 1
	__config_set with_glib_gettext 1

	export WANT_AUTOMAKE

	sed -n -e 's|^AC_CONFIG_MACRO_DIR(\[*\([^]]*\)\]*).*|\1|p' ${configure_ac} | xargs -r mkdir -p

	NOCONFIGURE=1 \
	XDT_PROG_ACLOCAL=aclocal \
	XDT_PROG_AUTOCONF=autoconf \
	XDT_PROG_AUTOHEADER=autoheader \
	XDT_PROG_AUTOMAKE=automake \
	revision=${GIT_REV:0:7} \
	xdt-autogen || error "xdt-autogen failed"

	auxdir="$(grep '^[^\#]*AC_CONFIG_AUX_DIR' ${configure_ac} | sed -e 's!.*AC_CONFIG_AUX_DIR(\[*\(.*\))!\1!g' -e 's!\]*!!g')"
	if [ -f ${auxdir:-.}/config.guess ]
	then
		gnuconfigize ${auxdir:-.}
	fi
}

#****C* xfce4.cygclass/xfce4_compile
#  SYNOPSIS
#  cd $B
#  xfce4_compile [CONFIGURE_FLAGS]
#  DESCRIPTION
#  Calls cygconf with the following options, followed by cygmake:
#  * --disable-visibility: Cygwin does not support ELF visibility attributes
#  All arguments to xfce4_compile are passed to cygconf as configure flags.
#****
xfce4_compile() {
	cygconf \
		--disable-visibility \
		PLATFORM_LDFLAGS=-no-undefined \
		"${@}"

	cygmake
}

KEEP_LA_FILES="none"

#****o* xfce4.cygclass/src_compile (xfce4)
#  DEFINITION
src_compile() {
	cd ${S}
	xfce4_autoreconf
	cd ${B}
	xfce4_compile
}
#****

readonly -f xfce4_autoreconf xfce4_compile
