]> git.draconx.ca Git - dxcommon.git/blob - m4/am-compat.m4
Add some backwards-compatibility helpers for silent-rules.
[dxcommon.git] / m4 / am-compat.m4
1 dnl Copyright © 2012 Nick Bowler
2 dnl
3 dnl Definitions to help maintain compatibility with older versions of Automake.
4 dnl
5 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 dnl This is free software: you are free to do what the fuck you want to.
7 dnl There is NO WARRANTY, to the extent permitted by law.
8
9 dnl DX_AUTOMAKE_COMPAT
10 dnl
11 dnl Provides definitions to help maintain compatibility with older versions of
12 dnl Automake.  Currently, this means:
13 dnl
14 dnl  - AM_V and AM_DEFAULT_V (new in Automake 1.12) are defined and AC_SUBSTed
15 dnl    if Automake did not already, in a manner compatible with silent-rules
16 dnl    support from previous versions.
17 dnl
18 dnl  - A make variable DX_ALIGN_V is defined which contain printf alignment
19 dnl    flags for silent-rules output, since the alignment changed between
20 dnl    Automake 1.11 and 1.12.  It is intended to be used like this:
21 dnl
22 dnl      MYGEN_V   = $(MYGEN_V@AM_V@)
23 dnl      MYGEN_V_  = $(MYGEN_V_@AM_DEFAULT_V)
24 dnl      MYGEN_V_0 = @printf '  %$(DX_ALIGN_V)s %s\n' 'MYGEN   ' $@
25 dnl
26 dnl    The spacing after MYGEN should be defined so that the silent-rules
27 dnl    alignment is correct for the latest version of Automake if DX_ALIGN_V
28 dnl    is empty (that way, this definition provides only backwards
29 dnl    compatibility).  However, it is irrelevant when DX_ALIGN_V is defined
30 dnl    by this macro, as the spacing will always be correct.  This feature
31 dnl    maintains alignment by truncating the argument, so it will only work
32 dnl    properly if your string can actually be aligned in all versions of
33 dnl    Automake being targeted (this means you are limited to 6 characters
34 dnl    in Automake 1.11).
35
36 AC_DEFUN_ONCE([DX_AUTOMAKE_COMPAT], [dnl
37 AC_REQUIRE([DX_INIT])
38
39 AC_CONFIG_COMMANDS_PRE([dnl
40         AS_VAR_SET_IF([AM_V], [], [AC_SUBST([AM_V], ['$(V)'])])
41         AS_VAR_SET_IF([AM_DEFAULT_V], [],
42                 [AC_SUBST([AM_DEFAULT_V], ['$(AM_DEFAULT_VERBOSITY)'])])])
43
44 # This will only work if there is a Makefile.in generated at the top srcdir.
45 AC_CACHE_CHECK([for alignment of silent-rules output], [dx_cv_align_v], [dnl
46 cat >conftest.sed <<'EOF'
47 /^am__v_GEN_0 *=/{
48         s/@<:@^"@:>@*"  \(GEN *\).*/\1/
49         s/ /x/g
50         p
51 }
52 EOF
53 if sed -nf conftest.sed Makefile.in >conftest.out 2>/dev/null; then
54         read dx_genline <conftest.out
55         dx_cv_align_v=`expr "$dx_genline" : '.*'`
56         test $dx_cv_align_v -eq 0 && dx_cv_align_v=unknown
57 fi
58 : "${dx_cv_align_v:=unknown}"
59 rm -f conftest*
60 ])
61
62 AS_IF([test x"$dx_cv_align_v" != x"unknown"],
63         [AC_SUBST([DX_ALIGN_V], [-$dx_cv_align_v.$dx_cv_align_v])])
64 ])