From 623da5b3ee66c4923679261fa72884d05212225a Mon Sep 17 00:00:00 2001
From: Friedrich Beckmann <friedrich.beckmann@gmx.de>
Date: Mon, 16 Nov 2020 00:02:07 +0100
Subject: [PATCH] MacOS: wc does not support -L option

The default wc application on MacOS does not support the -L option. I added
autotools support to search for GNU wc and use that instead. This assumes
that the application name is gwc which is the case whan using macports.

The tex tests use wc with the -L option. These regression tests fail on MacOS if the default wc application is used.
---
 configure.ac        |  2 ++
 tests/atlocal.in    |  1 +
 tests/output/tex.at | 10 +++++-----
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4b72f7f771..28ae3e4efd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,8 @@ PSPP_PERL
 PSPP_PYTHON
 AC_CHECK_PROGS([TEX], [tex], [no])
 AC_SUBST([TEX])
+AC_CHECK_PROGS([GWC], [gwc wc], [no])
+AC_SUBST([GWC])
 
 # This suppresses an error in gl/careadlinkat.c that otherwise can't be
 # avoided in GCC 10.x:
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 162b832dfd..5ba794cdd0 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -23,6 +23,7 @@ EXEEXT='@EXEEXT@'
 PERL='@PERL@'
 PYTHON='@PYTHON@'
 TEX='@TEX@'
+GWC='@GWC@'
 WITH_PERL_MODULE='@WITH_PERL_MODULE@'
 host='@host@'
 PACKAGE_STRING='@PACKAGE_STRING@'
diff --git a/tests/output/tex.at b/tests/output/tex.at
index bec2804f7a..456ce59757 100644
--- a/tests/output/tex.at
+++ b/tests/output/tex.at
@@ -181,7 +181,7 @@ descriptives /score.
 
 
 AT_CHECK([pspp -O format=tex simple.sps], [0], [])
-AT_CHECK([test $(wc -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
+AT_CHECK([test $($GWC -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
 
 AT_SKIP_IF([test "$TEX" = no])
 AT_CHECK([$TEX --halt-on-error pspp.tex], [0], [ignore])
@@ -200,7 +200,7 @@ AT_CLEANUP
 AT_SETUP([tex another example])
 
 AT_CHECK([pspp -O format=tex $abs_top_srcdir/examples/regress.sps], [0], [])
-AT_CHECK([test $(wc -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
+AT_CHECK([test $($GWC -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
 
 AT_SKIP_IF([test "$TEX" = no])
 AT_CHECK([$TEX --halt-on-error pspp.tex], [0], [ignore])
@@ -234,7 +234,7 @@ correlations
 ])
 
 AT_CHECK([pspp -O format=tex footnote.sps], [0], [])
-AT_CHECK([test $(wc -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
+AT_CHECK([test $($GWC -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
 
 AT_SKIP_IF([test "$TEX" = no])
 AT_CHECK([$TEX --halt-on-error pspp.tex], [0], [ignore])
@@ -275,7 +275,7 @@ frequencies items.
 ])
 
 AT_CHECK([LC_ALL=C.UTF-8 pspp -O format=tex utf8.sps], [0], [])
-AT_CHECK([test $(wc -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
+AT_CHECK([test $($GWC -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
 
 dnl The string "??" should not be present in pspp.tex
 AT_CHECK([grep -F '??' pspp.tex], [1])
@@ -315,7 +315,7 @@ t-test /variables=score /group=group("this", "that").
 ])
 
 AT_CHECK([pspp -O format=tex t-test.sps], [0], [])
-AT_CHECK([test $(wc -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
+AT_CHECK([test $($GWC -L pspp.tex | awk '{print $1}') -le 80], [0], [ignore])
 
 AT_SKIP_IF([test "$TEX" = no])
 AT_CHECK([$TEX --halt-on-error pspp.tex], [0], [ignore])
-- 
2.30.2