################################################################################
#
# qt4-qmake.cygclass - functions for building QMake-based Qt4 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/qt4-qmake.cygclass
#  SYNOPSIS
#  inherit qt4-qmake
#  DESCRIPTION
#  This cygclass builds Qt4-based packages which use the qmake build system.
#  INHERITS
#  qt4.cygclass
#  INHERITED BY
#  qt4-qconf.cygclass
#****

inherit qt4

#****C* qt4-qmake.cygclass/cygqmake4
#  SYNOPSIS
#  cd $B
#  cygqmake4
#  DESCRIPTION
#  Generates Makefiles from the package's qmake project files.
#****
cygqmake4() {
	if [ ! -x ${QT4_QMAKE} ]
	then
		error "libQtCore4-devel is required to build this package"
	fi

	${QT4_QMAKE} -recursive \
		QMAKE_CFLAGS_RELEASE="${CFLAGS}" \
		QMAKE_CXXFLAGS_RELEASE="${CXXFLAGS}" \
		QMAKE_LFLAGS="${LDFLAGS}" \
		QMAKE_LFLAGS_RPATH= \
		QMAKE_STRIP=: \
		QMAKE_PROJECT_DEPTH=0 \
		${CYGQMAKE4_ARGS} "${@}" \
		|| error "qmake failed"
}

#****C* qt4-qmake.cygclass/qt4_qmake_compile
#  DEFINITION
qt4_qmake_compile() {
	cygqmake4
	cygmake
}
#****

#****I* qt4-qmake.cygclass/qt4_qmake_install
#  SYNOPSIS
#  cd $B
#  qt4_qmake_install
#  DESCRIPTION
#  Installs the package into $D and fixes some common installation issues.
#  WARNING
#  Many qmake projects do not define correct install rules, if any at all.
#  qt4_qmake_install is of no use in such cases; you must use manual
#  installation commands instead.
#****
qt4_qmake_install() {
	local dll pc

	make install INSTALL_ROOT=${D} || error "make install failed"

	for dll in $(find ${D}$(__host_prefix)/lib/ -maxdepth 1 -name '*.dll' 2> /dev/null)
	do
		dodir $(__host_prefix)/bin
		mv ${dll} ${D}$(__host_prefix)/bin/
	done
}

#****o* qt4-qmake.cygclass/src_compile (qt4-qmake)
#  DEFINITION
src_compile() {
	lndirs
	cd ${B}
	qt4_qmake_compile
}
#****

#****o* qt4-qmake.cygclass/src_install (qt4-qmake)
#  DEFINITION
src_install() {
	cd ${B}
	qt4_qmake_install
}
#****

readonly -f cygqmake4 qt4_qmake_compile qt4_qmake_install
