### this file is sourced not run
PKGVER=5.15.8
PKGBUILD=1
PKGARCH=x86_64

# source: BLFS 11.3
TARBALL=qt-everywhere-opensource-src-$PKGVER.tar.xz
MD5SUM=86b7b496735df3973a390b0d515c1a0f
SRC_URL=https://download.qt.io/archive/qt/5.15/$PKGVER/single/$TARBALL
BUNDLE=

SLACKREQ='libX11 alsa-lib mesa dbus glib libjpeg-turbo libpng libtiff
openssl sqlite3 cups gtk2 libinput gstreamer2 gst2-plugins-base' 
SLACKDESC="qt5: qt $PKGVER (Qt GUI framework)  
qt5:  
qt5: Qt is a cross-platform application framework that is widely used for 
qt5: developing application software with a graphical user interface (GUI) (in 
qt5: which cases Qt is classified as a widget toolkit), and also used for 
qt5: developing non-GUI programs such as command-line tools and consoles for 
qt5: servers. One of the major users of Qt is KDE.  
qt5: 
qt5: This package installs in /opt/qt5
qt5: 
qt5: 
"

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/qt* &&
	
	# BLFS 11.3 accumulated patch.
	patch -Np1 -i ../pkg/qt-everywhere-opensource-src-5.15.8-kf5-1.patch &&
	mkdir -pv qtbase/.git # this is need to make the patch above works
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/qt*

	export QT5DIR=/opt/qt5
	mkdir -pv /opt/qt-$PKGVER    &&
	ln -sfvn qt-$PKGVER /opt/qt5 &&

	./configure -prefix  $QT5DIR  \
			-libdir      $QT5DIR/$LIBDIR \
			-archdatadir $QT5DIR/$LIBDIR \
			-sysconfdir /etc/xdg \
			-confirm-license     \
			-opensource          \
            -dbus-linked         \
            -openssl-linked      \
            -system-harfbuzz     \
            -system-sqlite       \
            -nomake examples     \
            -no-rpath            \
            -syslog              \
            -skip qtwebengine    \
			-reduce-relocations  \
            -optimized-qmake     \
    &&
    #       -static              \
    #       -shared              \
	make $MAKEFLAGS &&
	make install    &&
	
	# BLFS 11.3 remove build directory from library dependency
	find $QT5PREFIX/ -name \*.prl \
	   -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d' {} \; &&

<< "EOF" && # the old way of doing it
	find $QT5DIR/$LIBDIR/pkgconfig -name "*.pc" -exec perl -pi -e "s, -L$PWD/?\S+,,g" {} \; &&
	find $QT5DIR -name qt_lib_bootstrap_private.pri \
	   -exec sed -i -e "s:$PWD/qtbase:/$QT5PREFIX/$LIBDIR/:g" {} \; &&
	find $QT5DIR -name \*.prl \
	   -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d' {} \; &&
EOF

	# add desktop icons
	install -v -dm755 /usr/share/pixmaps/                  &&
	install -v -Dm644 qttools/src/assistant/assistant/images/assistant-128.png \
					  /usr/share/pixmaps/assistant-qt5.png &&
	install -v -Dm644 qttools/src/designer/src/designer/images/designer.png \
					  /usr/share/pixmaps/designer-qt5.png  &&
	install -v -Dm644 qttools/src/linguist/linguist/images/icons/linguist-128-32.png \
					  /usr/share/pixmaps/linguist-qt5.png  &&
	install -v -Dm644 qttools/src/qdbus/qdbusviewer/images/qdbusviewer-128.png \
					  /usr/share/pixmaps/qdbusviewer-qt5.png &&

	# add desktop files
	install -dm755 /usr/share/applications &&
	install -m644 /tmp/pkg/assistant-qt5.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/designer-qt5.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/linguist-qt5.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/qdbusviewer-qt5.desktop /usr/share/applications &&

	# add profile
	mkdir -p /etc/profile.d &&
	install -m755 /tmp/pkg/qt5.sh /etc/profile.d &&

	# some apps (e.g vlc) looks for certain executables with a -qt5 suffix.
	#for file in moc uic rcc qmake lconvert lrelease lupdate; do
	#  ln -sfrvn $QT5BINDIR/$file /usr/bin/$file-qt5
	#done
	
	# this is the old way of doing it - create the symlinks inside Qt5 prefix, not in /usr
	for file in moc uic rcc qmake lconvert lrelease lupdate; do
		ln -sfrvn $QT5DIR/bin/$file $QT5DIR/bin/$file-qt5
		ln -sfrvn $QT5DIR/bin/$file $QT5DIR/bin/$file-qt5-64 # multilib
	done &&
	
	pkg_build_slackdesc &&
	
	# multilib
	if [ -e /usr/bin/multiarch_wrapper ]; then
		cp -v /usr/bin/multiarch_wrapper $QT5DIR/bin && # wrapper has to be in QT5DIR
		for file in moc uic rcc qmake lconvert lrelease lupdate; do
			ln -sfrvn $QT5DIR/bin/$file-64 $QT5DIR/bin/$file-qt5-64 &&
			mv -v $QT5DIR/bin/${file}{,-64} &&
			ln -sfv multiarch_wrapper $QT5DIR/bin/$file || return 1
		done &&

		mv -v $QT5DIR/include/QtCore/qconfig{,-64}.h              &&
		cp -v /tmp/pkg/qconfig.h $QT5DIR/include/QtCore/qconfig.h &&
		true
	fi
}


