################################################################################
#
# qt4.cygclass - functions for building Qt4-dependent packages
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2020 Cygport authors
# Provided by the Cygwin project <https://cygwin.com/>
#
# 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 <https://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/qt4.cygclass
#  SYNOPSIS
#  inherit qt4
#  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 Qt4-based packages, regardless of the build system being used.
#  NOTES
#  * Packages based on the deprecated 3.x or newer 5.x versions of Qt must
#    use qt3.cygclass or qt5.cygclass, respectively.
#  INHERITED BY
#  kde4.cygclass, qt4-cmake.cygclass, qt4-qmake.cygclass
#****

#****d* qt4.cygclass/QT4_QTDIR
#  DESCRIPTION
#  Root directory for the Qt4 installation.
#****
#****d* qt4.cygclass/QT4_BINDIR
#  DESCRIPTION
#  Directory containing the Qt4 build tools.
#****
#****d* qt4.cygclass/QT4_INCLUDEDIR
#  DESCRIPTION
#  Directory containing the Qt4 library headers.
#****
#****d* qt4.cygclass/QT4_LIBDIR
#  DESCRIPTION
#  Directory containing the Qt4 link libraries.
#****
#****d* qt4.cygclass/QT4_PLUGINSDIR
#  DESCRIPTION
#  Installation path for Qt4 plugins.
#****
#****d* qt4.cygclass/QT4_IMPORTSDIR
#  DESCRIPTION
#  Installation path for Qt4 Quick extensions.
#****
#****d* qt4.cygclass/QT4_DATADIR
#  DESCRIPTION
#  Directory containing Qt4 documentation and translation data.
#****
#****d* qt4.cygclass/QT4_MKSPECSDIR
#  DESCRIPTION
#  Directory containing Qt4 QMake specs files.
#****
#****d* qt4.cygclass/QT4_QMAKE
#  DESCRIPTION
#  Absolute path to the Qt4 project and Makefile generator
#****
#****d* qt4.cygclass/QT4_MOC
#  DESCRIPTION
#  Absolute path to the Qt4 Meta-Object Compiler
#****
#****d* qt4.cygclass/QT4_RCC
#  DESCRIPTION
#  Absolute path to the Qt4 resource compiler
#****
#****d* qt4.cygclass/QT4_UIC
#  DESCRIPTION
#  Absolute path to the Qt4 User Interface Compiler
#****
#****d* qt4.cygclass/QT4_UIC3
#  DESCRIPTION
#  Absolute path to the Qt4 Qt3Support User Interface Compiler
#****
#****d* qt4.cygclass/QT4_LRELEASE
#  DESCRIPTION
#  Absolute path to the Qt4 Linguist translation compiler
#****

if inherited cross
then
	QT4_QTDIR=${CROSS_PREFIX}
	QT4_QMAKE=/usr/bin/${CROSS_HOST}-qmake-qt4
else
	QT4_QTDIR=/usr/lib/qt4
	QT4_QMAKE=/usr/bin/qmake-qt4
fi

QT4_BINDIR=$(dirname $(readlink -f ${QT4_QMAKE}))
QT4_INCLUDEDIR=$(${QT4_QMAKE} -query QT_INSTALL_HEADERS)
QT4_LIBDIR=$(${QT4_QMAKE} -query QT_INSTALL_LIBS)
QT4_PLUGINSDIR=$(${QT4_QMAKE} -query QT_INSTALL_PLUGINS)
QT4_IMPORTSDIR=$(${QT4_QMAKE} -query QT_INSTALL_IMPORTS)
QT4_DATADIR=$(${QT4_QMAKE} -query QT_INSTALL_DATA)
QT4_MKSPECSDIR=$(${QT4_QMAKE} -query QMAKE_MKSPECS)
QT4_MOC=${QT4_BINDIR}/moc
QT4_RCC=${QT4_BINDIR}/rcc
QT4_UIC=${QT4_BINDIR}/uic
QT4_UIC3=${QT4_BINDIR}/uic3
QT4_LRELEASE=${QT4_BINDIR}/lrelease

__qt4_qmakespec() {
	local spec

	# FIXME: -64 varieties, qws/*
	case ${CHOST} in
	*-ibm-aix*)        spec="aix-g++" ;;
	*-*-cygwin*)       spec="cygwin-g++" ;;
	*-*-darwin*)       spec="darwin-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++" ;;
	*-*-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 Qt4" ;;
	esac

	echo -n ${spec}
}

QMAKESPEC=$(__qt4_qmakespec)

export PATH="${QT4_BINDIR}:${PATH}"

#****I* qt4.cygclass/doqt4inc
#  SYNOPSIS
#  doqt4inc HEADERS
#  DESCRIPTION
#  Installs headers into QT4_INCLUDEDIR under $D.
#****
doqt4inc() {
	insinto ${QT4_INCLUDEDIR}
	doins ${@}
}

#****I* qt4.cygclass/doqt4lib
#  SYNOPSIS
#  doqt4lib LIBRARIES
#  DESCRIPTION
#  Installs link libraries into QT4_LIBDIR under $D.
#****
doqt4lib() {
	insinto ${QT4_LIBDIR}
	doins ${@}
}

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

	__QT4_PLUGIN_SUBDIR=${1}
}

#****I* qt4.cygclass/doqt4plugin
#  SYNOPSIS
#  qt4pluginto SUBDIRECTORY
#  doqt4plugin PLUGINS
#  DESCRIPTION
#  Installs the given plugins into the subdirectory of QT4_PLUGINDIR passed
#  to the previous call to qt4pluginto.
#****
doqt4plugin() {
	if ! defined __QT4_PLUGIN_SUBDIR
	then
		error "qt4pluginto must be called before doqt4plugin"
	fi

	exeinto ${QT4_PLUGINSDIR}/${__QT4_PLUGIN_SUBDIR}
	doexe ${@}
}

readonly -f __qt4_qmakespec doqt4inc doqt4lib qt4pluginto doqt4plugin
