# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# Filename: package/.../qt3/qt3.conf
# Copyright (C) 2006 - 2007 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2004 Clifford Wolf
# 
# 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.
# --- SDE-COPYRIGHT-NOTE-END ---

prefix="${SDECFG_PKG_QT3_PREFIX:-usr}"
set_confopt

if [ "$prefix" = "usr" ]; then
	includedir=$includedir/$pkg
	datadir=$datadir/$pkg
fi

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 \
		 -headerdir $root/$includedir \
		 -libdir $root/$libdir \
		 -plugindir $root/$libdir/$pkg/plugins \
		 -datadir $root/$datadir \
		 -docdir $root/$docdir \
		 -translationdir $root/$datadir/translations \
		 -thread -qt-gif -system-zlib \
		 -system-libmng -system-libpng -system-libjpeg -xft -xrender"

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

	[ "$SDECFG_PKG_QT3_EXCEPTION_STL" = "0" ] &&
	  var_append confopt " " "-no-g++-exceptions -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
	find $docdir -type f -perm +111 | xargs strip -v || true
	
	cat > $root/etc/profile.d/qt3 <<-EOT
QT33DIR=/$prefix
QTDIR=/$prefix
QTLIB=$libdir
export QT33DIR QTDIR QTLIB
EOT
}
hook_add postmake 5 qt_postmake

runconf=0
createdocs=0