]> git.draconx.ca Git - dxcommon.git/blob - m4/join.m4
2f25ce80d9b535c89cbac8c7a7534a9dac3b89ae
[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 which supports no options.
14
15 AC_DEFUN([DX_PROG_JOIN], [AC_PREREQ([2.62])dnl
16 AC_REQUIRE([AC_PROG_AWK])dnl
17 AC_CACHE_CHECK([for join], [ac_cv_path_JOIN],
18 [dx_cv_join_found=:
19 AC_PATH_PROGS_FEATURE_CHECK([JOIN], [join],
20 [_DX_JOIN_DO_TEST([$ac_path_JOIN],
21 [DX_BASENAME([join_relcmd], ["$ac_path_JOIN"])
22 join_bypath=`{ command -v "$join_relcmd"; } 2>/dev/null` #''
23 ac_cv_path_JOIN=$ac_path_JOIN
24 test x"$join_bypath" = x"$ac_path_JOIN" && ac_cv_path_JOIN=$join_relcmd
25 ac_path_JOIN_found=:
26 dx_cv_join_works=yes])], [ac_cv_path_JOIN=no dx_cv_join_found=false])])
27 AS_IF([$dx_cv_join_found],
28 [JOIN=$ac_cv_path_JOIN
29 AC_SUBST([JOIN])dnl
30 AC_CACHE_CHECK([whether $JOIN works], [dx_cv_join_works],
31 [_DX_JOIN_DO_TEST([$JOIN], [dx_cv_join_works=yes], [dx_cv_join_works=no])])])
32 rm -f conftest.a conftest.b conftest.c
33 AS_IF([test x"$dx_cv_join_works" != x"yes"],
34 [JOIN="$AWK -f m4_do(
35   [m4_pushdef([m4_include], [$][1])],
36   [m4_include(DX_BASEDIR[/scripts/join.awk])],
37   [m4_popdef([m4_include])])"])])
38
39 AC_DEFUN([_DX_JOIN_DO_TEST],
40 [AS_IF([test ! -f conftest.b],
41 [cat >conftest.a <<'EOF'
42 1 a
43 3 a1 x
44 3 a2 x
45 5 a
46 7 a
47 9 a1 x
48 9 a2 x
49 EOF
50 cat >conftest.b <<'EOF'
51 2 b
52 2 b
53 3 b y
54 4 b
55 6 b
56 7 b1 y
57 7 b2 y
58 8 b
59 9 b1 y
60 9 b2 y
61 EOF])
62 AS_IF([$1 conftest.a conftest.b >conftest.c 2>&AS_MESSAGE_LOG_FD],
63 [if diff - conftest.c >/dev/null 2>&1 <<'EOF'
64 3 a1 x b y
65 3 a2 x b y
66 7 a b1 y
67 7 a b2 y
68 9 a1 x b1 y
69 9 a1 x b2 y
70 9 a2 x b1 y
71 9 a2 x b2 y
72 EOF
73 then :
74 $2
75 else :
76 $3
77 fi], [$3])])