# Tanım: Qt ücretsiz sürümü, sürüm 5.x
# URL: http://qt-project.org/
# Paketçi: milisarge
# Gerekler: hunspell xorg-proto xorg-libxkbfile xorg-xtrans xorg-libx11 xorg-libxext xorg-libfs xorg-libice xorg-libsm xorg-libxscrnsaver xorg-libxt xorg-libxmu xorg-libxpm xorg-libxaw xorg-libxfixes xorg-libxcomposite xorg-libxrender xorg-libxcursor xorg-libxdamage xorg-libfontenc xorg-libxfont xorg-libxft xorg-libxi xorg-libxinerama xorg-libxrandr xorg-libxres xorg-libxtst xorg-libxv xorg-libxvmc xorg-libxxf86dga xorg-libxxf86vm xorg-libdmx xorg-libpciaccess xorg-libxkbfile xorg-libxshmfence  xcb-proto xcb-util-image xcb-util-keysyms xcb-util-renderutil xcb-util-wm alsa-lib ca-certificates cups dbus glib gstreamer-plugins-base icu jasper libproxy libinput libjpeg-turbo libmng libpng libtiff libwebp xorg-mesa mtdev openssl pcre sqlite ruby gstreamer1-plugins-base geoclue gtk2 harfbuzz postgresql pulseaudio unixodbc libxkbcommon mariadb
# Grup: geliştirme sistem

isim=qt5
surum=5.9.1
devir=1

_isim=qt-everywhere-opensource-src-${surum}

kaynak=(http://download.qt.io/official_releases/qt/${surum%.*}/$surum/single/qt-everywhere-opensource-src-$surum.tar.xz
	    qt5-logo.png)

derle() {

cd ${_name}*
	# Respect system CXX
	[ "$CXX" ] || CXX=g++
	sed -i "/^QMAKE_CXX\s/s|=.*|= $CXX|" qtbase/mkspecs/common/g++-base.conf

	# Remove obsolete xorg path
	sed -i 's|X11R6/||g' qtbase/mkspecs/*/*.conf

	# Respect system CXXFLAGS
	sed -i "s|^\(QMAKE_CFLAGS_RELEASE.*\)|\1 ${CXXFLAGS}|" qtbase/mkspecs/common/gcc-base.conf

	# Respect system LDFLAGS
	sed -i "s|^\(QMAKE_LFLAGS_RELEASE.*\)|\1 ${LDFLAGS}|" qtbase/mkspecs/common/g++-unix.conf

	export QTDIR="$PWD"
	export LD_LIBRARY_PATH="$QTDIR/qtbase/lib:$QTDIR/qttools/lib:$LD_LIBRARY_PATH"
	export QT_PLUGIN_PATH="$QTDIR/qtbase/plugins"

	./configure \
		-prefix /usr/ \
		-archdatadir /usr/lib/qt5 \
		-bindir /usr/lib/qt5/bin \
		-datadir /usr/share/qt5 \
		-docdir /usr/share/doc/qt5-$surum \
		-examplesdir /usr/share/doc/qt5-$surum/examples \
		-headerdir /usr/include/qt5 \
		-libdir /usr/lib \
		-sysconfdir /usr/etc/xdg \
		-confirm-license \
		-dbus-linked \
		-no-egl \
		-nomake examples \
		-no-pch \
		-no-rpath \
		-no-separate-debug-info \
		-no-strip \
		-opengl desktop \
		-opensource \
		-openssl-linked \
		-optimized-qmake \
		-reduce-relocations \
		-release \
		-shared \
		-skip qtwebengine

	make
	make -j1 INSTALL_ROOT=$PKG install
    
	# Fix paths
	find $PKG/usr/lib/ -type f -name '*.prl' \
		-exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d;s/\(QMAKE_PRL_LIBS =\).*/\1/' {} \;
        
	sed -e "s|$PWD/qtbase|/usr/lib/qt5|g" \
		-i $PKG/usr/lib/qt5/mkspecs/modules/qt_lib_bootstrap_private.pri

	rm -r $PKG/usr/share/doc

	# Install useful symlinks
	install -d $PKG/usr/bin
	for file in $PKG/usr/lib/qt5/bin/*; do
		ln -s ../lib/qt5/bin/$(basename $file) $PKG/usr/bin/$(basename $file)-qt5
	done

	# Add menu entries for all those hidden but great Qt applications:
	# # Qt5 logo:
	install -d $PKG/usr/share/icons/hicolor/48x48/apps

	install -m 0644 $SRC/qt5-logo.png $PKG/usr/share/icons/hicolor/48x48/apps/qt5-logo.png

	# Assistant icons
	install -m 0644 -D qttools/src/assistant/assistant/images/assistant.png $PKG/usr/share/icons/hicolor/32x32/apps/qt5-assistant.png
	install -m 0644 -D qttools/src/assistant/assistant/images/assistant-128.png $PKG/usr/share/icons/hicolor/128x128/apps/qt5-assistant.png

	# Designer icon
	install -m 0644 -D qttools/src/designer/src/designer/images/designer.png $PKG/usr/share/icons/hicolor/128x128/apps/qt5-designer.png

	# QDbusViewer icons
	install -m 0644 qttools/src/qdbus/qdbusviewer/images/qdbusviewer.png $PKG/usr/share/icons/hicolor/32x32/apps/qt5-qdbusviewer.png
	install -m 0644 qttools/src/qdbus/qdbusviewer/images/qdbusviewer-128.png $PKG/usr/share/icons/hicolor/128x128/apps/qt5-qdbusviewer.png

	# Linguist icons
	for icon in qttools/src/linguist/linguist/images/icons/linguist-*-32.png ; do
		size=$(echo $(basename ${icon}) | cut -d- -f2)
		install -m 0644 -D ${icon} $PKG/usr/share/icons/hicolor/${size}x${size}/apps/qt5-linguist.png
	done

	# And the .desktop files too:
	install -d $PKG/usr/share/applications
	cat <<EOF > $PKG/usr/share/applications/qt5-designer.desktop
[Desktop Entry]
Name=Qt5 Designer
GenericName=Arayüz tasarımı
Comment=Qt5 uygulamaları için arayüz tasarımı
Exec=designer-qt5 -qt=5
Icon=qt5-designer
MimeType=application/x-designer;
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;
EOF
	cat <<EOF > $PKG/usr/share/applications/qt5-assistant.desktop
[Desktop Entry]
Name=Qt5 Asistan
Comment=Qt5 belgelerini ve örneklerini gösterir
Exec=assistant-qt5 -qt=5
Icon=qt5-assistant
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;Documentation;
EOF
	cat <<EOF > $PKG/usr/share/applications/qt5-linguist.desktop
[Desktop Entry]
Name=Qt5 Linguist
Comment=Qt5 uygulamalarına dil ekleme
Exec=linguist-qt5 -qt=5
Icon=qt5-linguist
MimeType=text/vnd.trolltech.linguist;application/x-linguist;
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;
EOF
	cat <<EOF > $PKG/usr/share/applications/qt5-qdbusviewer.desktop
[Desktop Entry]
Name=Qt5 QDbusViewer
GenericName=Qt5 D-Bus Debugger
Comment=D-Bus uygulamalarında hata ayıklama
Exec=qdbusviewer-qt5
Icon=qt5-qdbusviewer
Terminal=false
Type=Application
Categories=Qt;Development;Debugger;
EOF
}
