# Template file for 'wxWidgets'
pkgname=wxWidgets
version=3.0.4
revision=9
configure_args="--enable-unicode --with-opengl --with-sdl --with-libmspack
 --with-libnotify --enable-mediactrl --with-gtk=2 --disable-webview"
build_style=gnu-configure
hostmakedepends="pkg-config"
makedepends="gtk+-devel libjpeg-turbo-devel tiff-devel libSM-devel libnotify-devel
 libXinerama-devel libmspack-devel SDL2-devel glu-devel
 gstreamer1-devel gst-plugins-base1-devel"
depends="wxWidgets-common>=${version}"
short_desc="The wxWidgets GUI toolkit library (version 3)"
maintainer="Martin Riese <grauehaare@gmx.de>"
license="wxWindows"
homepage="https://www.wxwidgets.org/"
distfiles="https://github.com/wxWidgets/wxWidgets/releases/download/v${version}/wxWidgets-${version}.tar.bz2"
checksum=96157f988d261b7368e5340afa1a0cad943768f35929c22841f62c25b17bf7f0

post_install() {
	# remove files that are already in wxWidgets-common
	rm -f ${DESTDIR}/usr/lib/libwx_baseu*
	rm -rf ${DESTDIR}/usr/bin/wxrc*
	rm -rf ${DESTDIR}/usr/share
	find ${DESTDIR}/usr/include -type f -not -name tabartgtk.h \
		-not -name fontdlgg.h -not -name notifmsg.h -exec rm -f {} \;
	for f in "" generic gtk; do
		rm ${DESTDIR}/usr/include/wx-3.0/wx/$f/notifmsg.h
	done
}

wxWidgets-devel_package() {
	depends="${sourcepkg}>=${version}_${revision} ${sourcepkg}-common-devel>=${version}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/bin
		vmove "usr/lib/*.so"
		vmove usr/lib/wx

		ln -sf wx-config-3.0 ${PKGDESTDIR}/usr/bin/wx-config

		# remove all occurrences of $XBPS_CROSS_TRIPLET
		# wx-config:
		#   - mark this build as native build
		#   - ignore --host option; breaks configure scripts when
		#     cross compiling (isn’t necessary in our case anyway)
		if [ -n "$CROSS_BUILD" ]; then
			local _config="gtk2-unicode-3.0"
			mv ${PKGDESTDIR}/usr/lib/wx/include/{${XBPS_CROSS_TRIPLET}-${_config},${_config}}

			rename "${XBPS_CROSS_TRIPLET}-" "" ${PKGDESTDIR}/usr/lib/wx/config/*
			rename -- "-${XBPS_CROSS_TRIPLET}" "" ${PKGDESTDIR}/usr/lib/*

			sed -i -e "s/${XBPS_CROSS_TRIPLET}-//g" \
			 -e "s/-${XBPS_CROSS_TRIPLET}//g" \
			 -e 's/is_cross()  { \[ "xyes" = "xyes" \]; }/is_cross()  { \[ "xno" = "xyes" \]; }/g' \
			 -e 's/--\*=\*)/--host=\*) continue;;\n\n    --\*=\*)/' \
			 ${PKGDESTDIR}/usr/lib/wx/config/${_config}

			ln -sf ../lib/wx/config/${_config} ${PKGDESTDIR}/usr/bin/wx-config-3.0
		fi
	}
}
