################################################################################
#
# fox.cygclass - functions for building FOX-toolkit-dependent 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/fox.cygclass
#  SYNOPSIS
#  FOX_VERSION="X.Y"
#  inherit fox
#  DESCRIPTION
#  The FOX toolkit is a cross-platform, C++ GUI toolkit.  The API changes with
#  each major.minor version, each of which is parallel-installable.  Packages
#  which depend on the FOX toolkit will only build against one or two branches
#  at any given time.
#
#  This cygclass selects the fox-config script for the desired version of the
#  FOX toolkit.
#  REQUIRES
#  libFOX1.*-devel
#****

#****v* fox.cygclass/FOX_VERSION
#  DESCRIPTION
#  The desired major.minor branch of the FOX toolkit.  This variable must be
#  set before inherit()ing the fox.cygclass.
#  NOTE
#  Even minor version numbers represent stable branches; versions 1.2, 1.4,
#  and 1.6 are supported.  Unstable branches (with odd minor versions) are
#  currently not supported.
#****

_fox_find_config() {
	local fc fox_config

	case ${FOX_VERSION} in
		'')	error "FOX_VERSION must be defined" ;;
		*.*.*)	error "FOX_VERSION must be only a major-minor branch" ;;
		1.[01]) error "FOX ${FOX_VERSION} is not supported" ;;
		1.*)
			for fc in fox-config-${FOX_VERSION} fox-${FOX_VERSION}-config fox-config
			do
				if [ -f $(__host_prefix)/bin/$fc ]
				then
					fox_config=$(__host_prefix)/bin/$fc
					break
				fi
			done
			;;
		*) error "FOX ${FOX_VERSION} is not yet supported" ;;
	esac

	if [ ! -f ${fox_config} ]
	then
		error "libFOX${FOX_VERSION}-devel is not installed"
	fi

	case $(${fox_config} --version) in
		${FOX_VERSION}.*) ;;
		*) error "version mismatch: ${FOX_VERSION} requested but not found" ;;
	esac

	echo -n ${fox_config}
}

#****d* fox.cygclass/FOX_CONFIG
#  DESCRIPTION
#  Absolute path to the fox-config script for the given FOX_VERSION.  This definition
#  is exported to the build environment.
#****
export FOX_CONFIG="$(_fox_find_config)"

#****d* fox.cygclass/FOX_CFLAGS
#  DESCRIPTION
#  Compile flags for the specified version of the FOX toolkit.  This
#  is equivalent to `$FOX_CONFIG --cflags`.
#****
FOX_CFLAGS="$(${FOX_CONFIG} --cflags)"

#****d* fox.cygclass/FOX_LIBS
#  DESCRIPTION
#  Link flags for the specified version of the FOX toolkit.  This
#  is equivalent to `$FOX_CONFIG --libs`.
#****
FOX_LIBS="$(${FOX_CONFIG} --libs)"

#****f* fox.cygclass/fox-config
#  DESCRIPTION
#  Wrapper function for calling FOX_CONFIG.
#****
fox-config() {
	${FOX_CONFIG} ${@}
}

readonly -f _fox_find_config fox-config
