################################################################################
#
# qt3.cygclass - functions for building Qt3-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/qt3.cygclass
#  SYNOPSIS
#  inherit qt3
#  DESCRIPTION
#  Qt is a C++ cross-platform application framework for writing desktop GUI
#  applications.  Qt is the underlying toolkit used by the KDE desktop
#  environment.
#
#  This cygclass provides definitions and install functions which can be used
#  by all Qt3-based packages, regardless of the build system being used.
#  NOTES
#  * Packages based on the newer 4.x or 5.x versions of Qt must use
#    qt4.cygclass or qt5.cygclass, respectively.
#  * The 3.x version of Qt is deprecated.  Support for Qt3 may be dropped in
#    the near future.
#  INHERITED BY
#  qt3-qmake.cygclass
#****

#****d* qt3.cygclass/QTDIR
#  DESCRIPTION
#  Root directory of the Qt3 installation.  This variable is exported to the
#  build environment.
#****
#****d* qt3.cygclass/QT3_BINDIR
#  DESCRIPTION
#  Directory containing the Qt3 development tools.
#****
#****d* qt3.cygclass/QT3_INCLUDEDIR
#  DESCRIPTION
#  Directory containing the Qt3 library headers.
#****
#****d* qt3.cygclass/QT3_LIBDIR
#  DESCRIPTION
#  Directory containing the Qt3 link libraries.
#****
#****d* qt3.cygclass/QT3_PLUGINSDIR
#  DESCRIPTION
#  Installation path for Qt3 plugins.
#****
#****d* qt3.cygclass/QT3_DATADIR
#  DESCRIPTION
#  Directory containing the Qt3 documentation and translation data.
#****

if inherited cross
then
	export QTDIR=${CROSS_PREFIX}
	QT3_BINDIR=${CROSS_BINDIR}
	QT3_INCLUDEDIR=${CROSS_INCLUDEDIR}/qt3
	QT3_LIBDIR=${CROSS_LIBDIR}
	QT3_PLUGINSDIR=${CROSS_LIBDIR}/qt3/plugins
	QT3_DATADIR=${CROSS_DATADIR}/qt3
else
	export QTDIR=/usr/lib/qt3
	QT3_BINDIR=${QTDIR}/bin
	QT3_INCLUDEDIR=/usr/include/qt3
	QT3_LIBDIR=/usr/lib
	QT3_PLUGINSDIR=${QTDIR}/plugins
	QT3_DATADIR=/usr/share/qt3
fi

#****d* qt3.cygclass/QT3_QMAKE
#  DESCRIPTION
#  Absolute path to the Qt3 project and Makefile generator.
#****
QT3_QMAKE=/usr/lib/qt3/bin/qmake

#****d* qt3.cygclass/QT3_MOC
#  DESCRIPTION
#  Absolute path to the Qt3 Meta-Object Compiler.
#****
QT3_MOC=/usr/lib/qt3/bin/moc

#****d* qt3.cygclass/QT3_UIC
#  DESCRIPTION
#  Absolute path to the Qt3 User Interface Compiler.
#****
QT3_UIC=/usr/lib/qt3/bin/uic

__qt3_qmakespec() {
	local spec

	# FIXME: -64 varieties
	case ${CHOST} in
	*-ibm-aix*)        spec="aix-g++" ;;
	*-*-bsdi*)         spec="bsdi-g++" ;;
	*-*-cygwin*)       spec="cygwin-g++" ;;
	*-*-darwin*)       spec="darwin-g++" ;;
	*-*-dgux*)         spec="dgux-g++" ;;
	*-*-freebsd*)      spec="freebsd-g++" ;;
	*-*-hpux)          spec="hpux-g++" ;;
	*-*-irix)          spec="irix-g++" ;;
	*-*-linux*)        spec="linux-g++" ;;
	*-*-lynxos*)       spec="lynxos-g++" ;;
	*-*-netbsd*)       spec="netbsd-g++" ;;
	*-*-openbsd*)      spec="openbsd-g++" ;;
	*-*-qnx*)          spec="qnx-g++" ;;
	*-*-sco*)          spec="sco-g++" ;;
	*-*-solaris*)      spec="solaris-g++" ;;
	*-*-osf*)          spec="tru64-g++" ;;
	*-*-sysv4.2uw*)    spec="unixware-g++" ;;
	*-*-mingw*)        spec="win32-g++" ;;
	# must be last to avoid false positives from *-*-KERNEL-gnu
	*-*-gnu*)          spec="hurd-g++" ;;
	*)	error "Host ${CHOST} is not supported by Qt3" ;;
	esac

	echo -n ${spec}
}

QMAKESPEC=$(__qt3_qmakespec)

export PATH="/usr/lib/qt3/bin:${PATH}"

#****I* qt3.cygclass/doqt3inc
#  SYNOPSIS
#  doqt3inc HEADERS
#  DESCRIPTION
#  Installs headers into QT3_INCLUDEDIR under $D.
#****
doqt3inc() {
	insinto ${QT3_INCLUDEDIR}
	doins ${@}
}

#****I* qt3.cygclass/doqt3lib
#  SYNOPSIS
#  doqt3lib LIBRARIES
#  DESCRIPTION
#  Installs link libraries into QT3_LIBDIR under $D.
#****
doqt3lib() {
	insinto ${QT3_LIBDIR}
	doins ${@}
}

#****I* qt3.cygclass/qt3pluginto
#  SYNOPSIS
#  qt3pluginto SUBDIRECTORY
#  DESCRIPTION
#  Sets the subdirectory of QT3_PLUGINDIR in which doqt3plugin should install.
#  Supported subdirectores include:
#  * crypto: Qt Cryptographic Architecture backends
#  * designer: Qt Designer widgets
#  * imageformats: image format handlers
#  * sqldrivers: SQL datbase backends
#  * styles: GUI style engines
#****
qt3pluginto() {
	if [ -z "${1}" -o -n "${2}" ]
	then
		error "qt3pluginto requires exactly one argument"
	fi

	__QT3_PLUGIN_SUBDIR=${1}
}

#****I* qt3.cygclass/doqt3plugin
#  SYNOPSIS
#  qt3pluginto SUBDIRECTORY
#  doqt3plugin PLUGINS
#  DESCRIPTION
#  Installs the given plugins into the subdirectory of QT3_PLUGINDIR passed
#  to the previous call to qt3pluginto.
#****
doqt3plugin() {
	if ! defined __QT3_PLUGIN_SUBDIR
	then
		error "qt3pluginto must be called before doqt3plugin"
	fi

	exeinto ${QT3_PLUGINSDIR}/${__QT3_PLUGIN_SUBDIR}
	doexe ${@}
}

readonly -f doqt3inc doqt3lib qt3pluginto doqt3plugin
