From 55a960b7d5d05bfc3f506aa93a441ad14cb52fb2 Mon Sep 17 00:00:00 2001
From: Andy Cobaugh <andrew.cobaugh@gmail.com>
Date: Sat, 18 May 2019 10:15:23 -0400
Subject: [PATCH] New package: wsjtx-2.0.1

---
 srcpkgs/wsjtx/patches/cmake_cross.patch | 42 +++++++++++++++++++++++++
 srcpkgs/wsjtx/template                  | 35 +++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 srcpkgs/wsjtx/patches/cmake_cross.patch
 create mode 100644 srcpkgs/wsjtx/template

diff --git a/srcpkgs/wsjtx/patches/cmake_cross.patch b/srcpkgs/wsjtx/patches/cmake_cross.patch
new file mode 100644
index 00000000000..ad6d59e5cb6
--- /dev/null
+++ b/srcpkgs/wsjtx/patches/cmake_cross.patch
@@ -0,0 +1,42 @@
+--- CMakeLists.txt	2019-02-24 23:11:18.000000000 -0500
++++ CMakeLists.txt	2019-05-24 21:58:42.000000000 -0400
+@@ -79,6 +79,10 @@
+ 
+ include (ExternalProject)
+ 
++if (DEFINED ENV{CROSS_BUILD})
++  get_filename_component(cross_triplet $ENV{XBPS_CROSS_BASE} NAME)
++  set (hamlib_cross "--host=${cross_triplet}")
++endif ()
+ 
+ #
+ # build and install hamlib locally so it can be referenced by the
+@@ -91,7 +95,7 @@
+   URL_HASH MD5=${hamlib_md5sum}
+   UPDATE_COMMAND ./bootstrap
+   PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -N < ${CMAKE_CURRENT_SOURCE_DIR}/hamlib.patch
+-  CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-shared --enable-static --without-cxx-binding ${EXTRA_FLAGS} # LIBUSB_LIBS=${USB_LIBRARY}
++  CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-shared --enable-static --without-cxx-binding ${EXTRA_FLAGS} ${hamlib_cross} # LIBUSB_LIBS=${USB_LIBRARY}
+   BUILD_COMMAND $(MAKE) all V=1 # $(MAKE) is ExternalProject_Add() magic to do recursive make
+   INSTALL_COMMAND $(MAKE) install-strip V=1 DESTDIR=""
+   STEP_TARGETS update install
+@@ -128,6 +132,11 @@
+ # build and optionally install WSJT-X using the hamlib package built
+ # above
+ #
++if (DEFINED ENV{CROSS_BUILD})
++  message(STATUS "Enabling cross-compile toolchain, CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
++  set (wsjtx_cross "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
++endif ()
++
+ ExternalProject_Get_Property (hamlib INSTALL_DIR)
+ ExternalProject_Add (wsjtx
+   GIT_REPOSITORY ${wsjtx_repo}
+@@ -140,6 +149,7 @@
+   -DCMAKE_PREFIX_PATH=${INSTALL_DIR}
+   -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
+   ${WSJTX_EXTRA_CMAKE_OPTIONS}
++  ${wsjtx_cross}
+   INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
+   STEP_TARGETS update configure build install package
+   )
diff --git a/srcpkgs/wsjtx/template b/srcpkgs/wsjtx/template
new file mode 100644
index 00000000000..ecc94077995
--- /dev/null
+++ b/srcpkgs/wsjtx/template
@@ -0,0 +1,35 @@
+# Template file for 'wsjtx'
+pkgname=wsjtx
+version=2.0.1
+revision=1
+build_style=cmake
+hostmakedepends="git autoconf automake libtool gcc-fortran asciidoc ruby-asciidoctor"
+makedepends="fftw fftw-devel qt5-serialport-devel qt5-devel qt5-multimedia-devel libusb-devel libgomp-devel libgomp qt5-plugin-mysql qt5-plugin-odbc qt5-plugin-pgsql qt5-plugin-sqlite qt5-plugin-tds"
+short_desc="WSJT-X weak-signal radio communication program"
+maintainer="Andy Cobaugh <andrew.cobaugh@gmail.com>"
+license="GPL-3.0"
+nocross="https://travis-ci.org/void-linux/void-packages/builds/537982537?utm_source=github_status&utm_medium=notification"
+homepage="http://www.physics.princeton.edu/pulsar/K1JT/wsjtx.html"
+distfiles="http://www.physics.princeton.edu/pulsar/K1JT/wsjtx-${version}.tgz"
+checksum=18f18f93f7e0ecc631ff5f7e0002521c41b54322ea33e5d6ca3ab5144fe1a0cd
+
+if [ -n "${CROSS_BUILD}" ] ; then
+	hostmakedepents+="qt5-plugin-mysql qt5-plugin-odbc qt5-plugin-pgsql qt5-plugin-sqlite qt5-plugin-tds qt5-qmake qt5-devel"
+fi
+
+post_configure() {
+	# if cross-compiling, make sure cmake can find things local to the project like boost, hamlib, etc
+	# CMAKE_FIND_ROOT_PATH is overriden to $XBPS_CROSS_BASE, so append to the toolchain file a cmake list()
+	# to add the project build dir back in
+	if [ -n "${CROSS_BUILD}" ] ; then
+		builddir=/builddir/$(basename $PWD)/build
+		toolchain_file=${builddir}/cross_$(basename $XBPS_CROSS_BASE).cmake
+		toolchain_file_state=${toolchain_file}.patched
+		if [ ! -f ${toolchain_file_state} ] ; then
+			env | sort
+			pwd
+			echo "list(APPEND CMAKE_FIND_ROOT_PATH $builddir)" >> $toolchain_file
+			touch ${toolchain_file_state}
+		fi
+	fi
+}
