From: Nick Bowler Date: Sun, 30 Jan 2022 01:48:17 +0000 (-0500) Subject: Add "join" detection macro. X-Git-Url: https://git.draconx.ca/gitweb/dxcommon.git/commitdiff_plain/5865ffc2d8b828aa78235fbdcf9dfe18a8799980 Add "join" detection macro. It seems that unconditional use of "join" is not portable. Alpine Linux, for example, does not include it. Add a macro which detects whether join exists and works, with a fallback to an (incomplete) awk implementation of the tool. --- diff --git a/m4/join.m4 b/m4/join.m4 new file mode 100644 index 0000000..2f25ce8 --- /dev/null +++ b/m4/join.m4 @@ -0,0 +1,77 @@ +dnl Copyright © 2022 Nick Bowler +dnl +dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. +dnl This is free software: you are free to do what the fuck you want to. +dnl There is NO WARRANTY, to the extent permitted by law. + +dnl DX_PROG_JOIN +dnl +dnl Search PATH for standard POSIX "join" utility. If found, the JOIN +dnl variable (which is substituted by AC_SUBST) is set to the result and +dnl the cache variable dx_cv_join_works is set to "yes". Otherwise, +dnl dx_cv_join_works is set to "no" and JOIN is set to an incomplete +dnl awk-based implementation which supports no options. + +AC_DEFUN([DX_PROG_JOIN], [AC_PREREQ([2.62])dnl +AC_REQUIRE([AC_PROG_AWK])dnl +AC_CACHE_CHECK([for join], [ac_cv_path_JOIN], +[dx_cv_join_found=: +AC_PATH_PROGS_FEATURE_CHECK([JOIN], [join], +[_DX_JOIN_DO_TEST([$ac_path_JOIN], +[DX_BASENAME([join_relcmd], ["$ac_path_JOIN"]) +join_bypath=`{ command -v "$join_relcmd"; } 2>/dev/null` #'' +ac_cv_path_JOIN=$ac_path_JOIN +test x"$join_bypath" = x"$ac_path_JOIN" && ac_cv_path_JOIN=$join_relcmd +ac_path_JOIN_found=: +dx_cv_join_works=yes])], [ac_cv_path_JOIN=no dx_cv_join_found=false])]) +AS_IF([$dx_cv_join_found], +[JOIN=$ac_cv_path_JOIN +AC_SUBST([JOIN])dnl +AC_CACHE_CHECK([whether $JOIN works], [dx_cv_join_works], +[_DX_JOIN_DO_TEST([$JOIN], [dx_cv_join_works=yes], [dx_cv_join_works=no])])]) +rm -f conftest.a conftest.b conftest.c +AS_IF([test x"$dx_cv_join_works" != x"yes"], +[JOIN="$AWK -f m4_do( + [m4_pushdef([m4_include], [$][1])], + [m4_include(DX_BASEDIR[/scripts/join.awk])], + [m4_popdef([m4_include])])"])]) + +AC_DEFUN([_DX_JOIN_DO_TEST], +[AS_IF([test ! -f conftest.b], +[cat >conftest.a <<'EOF' +1 a +3 a1 x +3 a2 x +5 a +7 a +9 a1 x +9 a2 x +EOF +cat >conftest.b <<'EOF' +2 b +2 b +3 b y +4 b +6 b +7 b1 y +7 b2 y +8 b +9 b1 y +9 b2 y +EOF]) +AS_IF([$1 conftest.a conftest.b >conftest.c 2>&AS_MESSAGE_LOG_FD], +[if diff - conftest.c >/dev/null 2>&1 <<'EOF' +3 a1 x b y +3 a2 x b y +7 a b1 y +7 a b2 y +9 a1 x b1 y +9 a1 x b2 y +9 a2 x b1 y +9 a2 x b2 y +EOF +then : +$2 +else : +$3 +fi], [$3])]) diff --git a/m4/linguas.m4 b/m4/linguas.m4 index eb6701e..fce4e0c 100644 --- a/m4/linguas.m4 +++ b/m4/linguas.m4 @@ -1,4 +1,4 @@ -dnl Copyright © 2011, 2021 Nick Bowler +dnl Copyright © 2011, 2021-2022 Nick Bowler dnl dnl Computes the set of .po and .mo files based on the LINGUAS environment dnl variable. The variable POFILES is set to the complete list of .po files, @@ -12,6 +12,7 @@ dnl There is NO WARRANTY, to the extent permitted by law. AC_DEFUN([DX_LINGUAS], [AC_REQUIRE([AM_GNU_GETTEXT])dnl +AC_REQUIRE([DX_PROG_JOIN])dnl POFILES= MOFILES= @@ -21,7 +22,7 @@ if test -f "$srcdir/po/LINGUAS"; then for (i = 1; i <= NF; i++) { print $(i) } - }' "$srcdir/po/LINGUAS" | sort -u >conftest.all + }' "$srcdir/po/LINGUAS" | LC_ALL=C sort -u >conftest.all : "${LINGUAS=all}" if test x"$LINGUAS" = x"all"; then @@ -40,7 +41,7 @@ if test -f "$srcdir/po/LINGUAS"; then ;; esac done - } | sort -u >conftest.ena + } | LC_ALL=C sort -u >conftest.ena fi exec 3conftest.out + LC_ALL=C $JOIN conftest.ena conftest.all >conftest.out exec 3 rhs[1]) { + if (advance_rhs() == 0) + exit(0); + } +} + +$1 == rhs[1] { + lhs_prev = $1 = $1; + do { + print_match(); + advance_rhs(); + } while ($1 == rhs[1]); +} + +function advance_rhs(raw, rc) +{ + rc = getline raw < file2; + if (rc < 0) + exit(1); + + split(raw, rhs); + return rc; +} + +function print_match(i) +{ + printf "%s", $0 + for (i = 2; i in rhs; i++) { + printf " %s", rhs[i]; + } + print "" +} diff --git a/tests/macros.at b/tests/macros.at index f746e54..3f39fbd 100644 --- a/tests/macros.at +++ b/tests/macros.at @@ -1,4 +1,4 @@ -dnl Copyright © 2014-2015, 2018-2019, 2021 Nick Bowler +dnl Copyright © 2014-2015, 2018-2019, 2021-2022 Nick Bowler dnl dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. dnl This is free software: you are free to do what the fuck you want to. @@ -236,6 +236,56 @@ MOFILES = @&t@ AT_CLEANUP +AT_SETUP([DX_LINGUAS with broken "join" utility]) +AT_KEYWORDS([DX_LINGUAS macro]) + +echo : >config.rpath +chmod +x config.rpath + +mkdir bin +cat >bin/join <