From 305a81e596388d9dfed532b1a24509c825dca52d Mon Sep 17 00:00:00 2001
From: Darshit Shah
Date: Fri, 24 Jan 2020 21:38:43 +0100
Subject: [PATCH] Require gawk at configure time
* m4/ax_check_awk_gensub.m4: New file
* m4/ax_try_awk_expout.m4: Same
* m4/ax_need_awk.m4: Same
* configure.ac: Call AX_CHECK_AWK_GENSUB to ensure that the version of
awk supports gensub()
* src/Makefile.am: Use $(AWK) when calling ras
* src/ras: Change the shebang line to not force a path on location of
awk
---
configure.ac | 3 ++
m4/ax_check_awk_gensub.m4 | 35 +++++++++++++++++++++++
m4/ax_need_awk.m4 | 36 ++++++++++++++++++++++++
m4/ax_try_awk_expout.m4 | 59 +++++++++++++++++++++++++++++++++++++++
src/Makefile.am | 2 +-
src/ras | 2 +-
6 files changed, 135 insertions(+), 2 deletions(-)
create mode 100644 m4/ax_check_awk_gensub.m4
create mode 100644 m4/ax_need_awk.m4
create mode 100644 m4/ax_try_awk_expout.m4
diff --git a/configure.ac b/configure.ac
index 0c652ebf..04242fa0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,9 @@ dnl i18n with gettext
AM_GNU_GETTEXT_VERSION([0.19.8])
AM_GNU_GETTEXT([external])
+# Poke requires a version of awk that supports gensub()
+AX_CHECK_AWK_GENSUB([], AC_MSG_ERROR([$AWK does not support gensub.]))
+
dnl The Boehm-Weiser garbage collector
PKG_PROG_PKG_CONFIG
diff --git a/m4/ax_check_awk_gensub.m4 b/m4/ax_check_awk_gensub.m4
new file mode 100644
index 00000000..cd613272
--- /dev/null
+++ b/m4/ax_check_awk_gensub.m4
@@ -0,0 +1,35 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_check_awk_gensub.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CHECK_AWK_GENSUB([ACTION-IF-SUCCESS],[ACTION-IF-FAILURE])
+#
+# DESCRIPTION
+#
+# Check if AWK supports gensub() function. If successful execute
+# ACTION-IF-SUCCESS otherwise ACTION-IF-FAILURE.
+#
+# This work is heavily based upon testawk.sh script by Heiner Steven. You
+# should find his script (and related works) at
+# . Thanks to
+# Alessandro Massignan for his suggestions and extensive nawk tests on
+# FreeBSD.
+#
+# LICENSE
+#
+# Copyright (c) 2009 Francesco Salvestrini
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 9
+
+AC_DEFUN([AX_CHECK_AWK_GENSUB], [
+ AX_TRY_AWK_EXPOUT([gensub()],
+ [],[ print gensub(/u/, "x", "g", "uu") ],[xx],
+ [$1],[$2])
+])
diff --git a/m4/ax_need_awk.m4 b/m4/ax_need_awk.m4
new file mode 100644
index 00000000..ad053531
--- /dev/null
+++ b/m4/ax_need_awk.m4
@@ -0,0 +1,36 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_need_awk.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_NEED_AWK
+#
+# DESCRIPTION
+#
+# Check if an awk implementation is available. Bail-out if not found.
+#
+# This work is heavily based upon testawk.sh script by Heiner Steven. You
+# should find his script (and related works) at
+# . Thanks to
+# Alessandro Massignan for his suggestions and extensive nawk tests on
+# FreeBSD.
+#
+# LICENSE
+#
+# Copyright (c) 2009 Francesco Salvestrini
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 9
+
+AC_DEFUN([AX_NEED_AWK],[
+ AC_REQUIRE([AC_PROG_AWK])
+
+ AS_IF([test "x$AWK" = "x"],[
+ AC_MSG_ERROR([cannot find awk, bailing out])
+ ])
+])
diff --git a/m4/ax_try_awk_expout.m4 b/m4/ax_try_awk_expout.m4
new file mode 100644
index 00000000..683b9eb3
--- /dev/null
+++ b/m4/ax_try_awk_expout.m4
@@ -0,0 +1,59 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_try_awk_expout.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_TRY_AWK_EXPOUT(NAME,TEST-INPUT,TEST-BODY,EXPECTED-OUTPUT,[ACTION-IF-SUCCESS],[ACTION-IF-FAILURE])
+#
+# DESCRIPTION
+#
+# Run a test using the awk program found on AWK variable. The test being
+# run has TEST-BODY as body and is feeded with TEST-INPUT. Check if the
+# test gives the expected output. If successful execute ACTION-IF-SUCCESS
+# otherwise ACTION-IF-FAILURE.
+#
+# This work is heavily based upon testawk.sh script by Heiner Steven. You
+# should find his script (and related works) at
+# . Thanks to
+# Alessandro Massignan for his suggestions and extensive nawk tests on
+# FreeBSD.
+#
+# LICENSE
+#
+# Copyright (c) 2009 Francesco Salvestrini
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 9
+
+AC_DEFUN([AX_TRY_AWK_EXPOUT], [
+ AC_REQUIRE([AX_NEED_AWK])
+
+ AC_MSG_CHECKING([if $AWK supports $1])
+
+ cat < conftest.out
+$2
+EOF
+
+ ax_try_awk_output=`$AWK '{ [$3] ; }' conftest.out 2> /dev/null`
+ ax_try_awk_result=$?
+
+ rm -f conftest.out
+
+ AS_IF([test $ax_try_awk_result -eq 0],[
+ AS_IF([test "X$ax_try_awk_output" = "X[$4]"],[
+ AC_MSG_RESULT([yes])
+ $5
+ ],[
+ AC_MSG_RESULT([no])
+ $6
+ ])
+ ],[
+ AC_MSG_RESULT([no])
+ $6
+ ])
+])
diff --git a/src/Makefile.am b/src/Makefile.am
index 28795a7d..25c04209 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,7 +54,7 @@ poke_SOURCES = poke.c poke.h \
.pks.pkc:
- srcdir=$(srcdir) $(srcdir)/ras $< > $@
+ srcdir=$(srcdir) $(AWK) -f $(srcdir)/ras $< > $@
# XXX this shouldn't be necessary?
EXTRA_DIST = pkl-lex.h
diff --git a/src/ras b/src/ras
index 65bddecf..8667a688 100755
--- a/src/ras
+++ b/src/ras
@@ -1,4 +1,4 @@
-#!/usr/bin/awk -f
+#!/usr/bin/env awk -f
# ras - The Retarded Poke Assembler
#
--
2.25.0