# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# T2 SDE: package/.../qt/qt.conf
# Copyright (C) 2004 - 2007 The T2 SDE Project
# Copyright (C) 1998 - 2004 ROCK Linux Project
# 
# More information can be found in the files COPYING and README.
# 
# This program 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; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- T2-COPYRIGHT-NOTE-END ---

prefix="${SDECFG_PKG_QT_PREFIX:-opt/qt33}"
set_confopt

qt_preconf() {
	QTDIR=$PWD
	var_insert LD_LIBRARY_PATH ':' "$QTDIR/lib"
	var_insert PATH ':' "$QTDIR/bin"
	export QTDIR LD_LIBRARY_PATH PATH

	# an optimization crashes g++ during the Makefile generator build :-(
	echo "yes" | ( CXX_WRAPPER_BYPASS=1 ; ./configure $confopt )
}
hook_add preconf 5 qt_preconf

# Qt only supports some selected options ...
confopt="-prefix $root/$prefix -bindir $root/$bindir -libdir $root/$libdir \
	 -thread -qt-gif -system-zlib \
         -system-libpng -system-libjpeg -xft -xrender"

pkginstalled libmng ' ' 'system-libmng'

[[ $libdir = *lib64* ]] && var_append confopt ' ' '-platform linux-g++-64'

[ "$SDECFG_PKG_QT_EXCEPTION" = "0" ] &&
	var_append confopt " " "-no-g++-exceptions"
[ "$SDECFG_PKG_QT_STL" = "0" ] &&
	var_append confopt " " "-no-stl"

if pkginstalled mysql; then
	pkgprefix -t mysql
	var_append confopt " " "-plugin-sql-mysql"
	for x in CXX GCC; do
		var_append ${x}_WRAPPER_APPEND ' ' "-L$( pkgprefix libdir mysql)/mysql"
	done
	for x in CXX GCC CPP; do
		var_append ${x}_WRAPPER_APPEND ' ' "-I$( pkgprefix includedir mysql )/mysql"
		var_append ${x}_WRAPPER_APPEND ' ' "-I$( pkgprefix includedir mysql )/mysql"
	done
fi

if pkginstalled postgresql; then
	pkgprefix -t postgresql
	var_append confopt " " "-plugin-sql-psql"

	for x in CXX GCC; do
		var_append ${x}_WRAPPER_APPEND ' ' "-L$( pkgprefix libdir postgresql)"
		var_append ${x}_WRAPPER_APPEND ' ' "-L$( pkgprefix libdir postgresql)"
	done

	for x in CXX GCC CPP; do
		var_append ${x}_WRAPPER_APPEND ' ' "-I$( pkgprefix includedir postgresql )/server"
		var_append ${x}_WRAPPER_APPEND ' ' "-I$( pkgprefix includedir postgresql )"
	done
fi

qt_postmake() {
	# create compatibility links ...
	(cd ${root}$libdir/ ; for x in libqt-mt.so* ; do
		ln -svf $x ${x/-mt}
	done)
	
        echo "Copy some documentation ..."
	# to be done in another package: examples extensions tutorial tools ...
	cp -r ch* doc/html tutorial $docdir/
	
	find $docdir -name '*.o' | xargs rm -vf
	
	cat > $root/etc/profile.d/qt3 <<-EOT
QT33DIR=/$prefix
QTDIR=/$prefix
export QT33DIR QTDIR
EOT
}
hook_add postmake 5 qt_postmake

runconf=0
createdocs=0

# we do not want running applications crash due cp'ing the new shared object over the old one
var_append makeinstopt ' ' 'INSTALL_FILE=install'