]> git.draconx.ca Git - dxcommon.git/blob - m4/join.m4
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[dxcommon.git] / m4 / join.m4
1 dnl Copyright © 2022 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 dnl DX_PROG_JOIN
8 dnl
9 dnl Search PATH for standard POSIX "join" utility.  If found, the JOIN
10 dnl variable (which is substituted by AC_SUBST) is set to the result and
11 dnl the cache variable dx_cv_join_works is set to "yes".  Otherwise,
12 dnl dx_cv_join_works is set to "no" and JOIN is set to an incomplete
13 dnl awk-based implementation.
14 dnl
15 dnl The awk replacement currently has the following limitations:
16 dnl
17 dnl   - Only the -v and -a options are supported.
18 dnl
19 dnl   - Due to limitations of some awk implementations, a filename of "-"
20 dnl     to mean standard input should be avoided for the second file name.
21 dnl     Nevertheless, using "-" for the first filename should be portable.
22
23 AC_DEFUN([DX_PROG_JOIN], [AC_PREREQ([2.62])dnl
24 AC_REQUIRE([AC_PROG_AWK])dnl
25 AC_CACHE_CHECK([for join], [ac_cv_path_JOIN],
26 [dx_cv_join_found=:
27 AC_PATH_PROGS_FEATURE_CHECK([JOIN], [join],
28 [_DX_JOIN_DO_TEST([$ac_path_JOIN],
29 [DX_BASENAME([join_relcmd], ["$ac_path_JOIN"])
30 join_bypath=`{ command -v "$join_relcmd"; } 2>/dev/null` #''
31 ac_cv_path_JOIN=$ac_path_JOIN
32 test x"$join_bypath" = x"$ac_path_JOIN" && ac_cv_path_JOIN=$join_relcmd
33 ac_path_JOIN_found=:
34 dx_cv_join_works=yes])], [ac_cv_path_JOIN=no dx_cv_join_found=false])])
35 AS_IF([$dx_cv_join_found],
36 [JOIN=$ac_cv_path_JOIN
37 AC_SUBST([JOIN])dnl
38 AC_CACHE_CHECK([whether $JOIN works], [dx_cv_join_works],
39 [_DX_JOIN_DO_TEST([$JOIN], [dx_cv_join_works=yes], [dx_cv_join_works=no])])])
40 rm -f conftest.a conftest.b conftest.c
41 AS_IF([test x"$dx_cv_join_works" != x"yes"],
42 [JOIN="$AWK -f m4_do(
43   [m4_pushdef([m4_include], [$][1])],
44   [m4_include(DX_BASEDIR[/scripts/join.awk])],
45   [m4_popdef([m4_include])]) --"])])
46
47 AC_DEFUN([_DX_JOIN_DO_TEST],
48 [AS_IF([test ! -f conftest.b],
49 [cat >conftest.a <<'EOF'
50 1 a
51 3 a1 x
52 3 a2 x
53 5 a
54 7 a
55 9 a1 x
56 9 a2 x
57 EOF
58 cat >conftest.b <<'EOF'
59 2 b
60 2 b
61 3 b y
62 4 b
63 6 b
64 7 b1 y
65 7 b2 y
66 8 b
67 9 b1 y
68 9 b2 y
69 EOF])
70 AS_IF([$1 conftest.a conftest.b >conftest.c 2>&AS_MESSAGE_LOG_FD],
71 [if diff - conftest.c >/dev/null 2>&1 <<'EOF'
72 3 a1 x b y
73 3 a2 x b y
74 7 a b1 y
75 7 a b2 y
76 9 a1 x b1 y
77 9 a1 x b2 y
78 9 a2 x b1 y
79 9 a2 x b2 y
80 EOF
81 then :
82 $2
83 else :
84 $3
85 fi], [$3])])