xref: /freebsd/contrib/ldns/m4/ltsugar.m4 (revision 986ba33c7a3bc8f5ba13c7a9d6512602f6e32c61)
117d15b25SDag-Erling Smørgrav# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
217d15b25SDag-Erling Smørgrav#
3*986ba33cSDag-Erling Smørgrav# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software
4*986ba33cSDag-Erling Smørgrav# Foundation, Inc.
517d15b25SDag-Erling Smørgrav# Written by Gary V. Vaughan, 2004
617d15b25SDag-Erling Smørgrav#
717d15b25SDag-Erling Smørgrav# This file is free software; the Free Software Foundation gives
817d15b25SDag-Erling Smørgrav# unlimited permission to copy and/or distribute it, with or without
917d15b25SDag-Erling Smørgrav# modifications, as long as this notice is preserved.
1017d15b25SDag-Erling Smørgrav
1117d15b25SDag-Erling Smørgrav# serial 6 ltsugar.m4
1217d15b25SDag-Erling Smørgrav
1317d15b25SDag-Erling Smørgrav# This is to help aclocal find these macros, as it can't see m4_define.
1417d15b25SDag-Erling SmørgravAC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
1517d15b25SDag-Erling Smørgrav
1617d15b25SDag-Erling Smørgrav
1717d15b25SDag-Erling Smørgrav# lt_join(SEP, ARG1, [ARG2...])
1817d15b25SDag-Erling Smørgrav# -----------------------------
1917d15b25SDag-Erling Smørgrav# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
2017d15b25SDag-Erling Smørgrav# associated separator.
2117d15b25SDag-Erling Smørgrav# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
2217d15b25SDag-Erling Smørgrav# versions in m4sugar had bugs.
2317d15b25SDag-Erling Smørgravm4_define([lt_join],
2417d15b25SDag-Erling Smørgrav[m4_if([$#], [1], [],
2517d15b25SDag-Erling Smørgrav       [$#], [2], [[$2]],
2617d15b25SDag-Erling Smørgrav       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
2717d15b25SDag-Erling Smørgravm4_define([_lt_join],
2817d15b25SDag-Erling Smørgrav[m4_if([$#$2], [2], [],
2917d15b25SDag-Erling Smørgrav       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
3017d15b25SDag-Erling Smørgrav
3117d15b25SDag-Erling Smørgrav
3217d15b25SDag-Erling Smørgrav# lt_car(LIST)
3317d15b25SDag-Erling Smørgrav# lt_cdr(LIST)
3417d15b25SDag-Erling Smørgrav# ------------
3517d15b25SDag-Erling Smørgrav# Manipulate m4 lists.
3617d15b25SDag-Erling Smørgrav# These macros are necessary as long as will still need to support
37*986ba33cSDag-Erling Smørgrav# Autoconf-2.59, which quotes differently.
3817d15b25SDag-Erling Smørgravm4_define([lt_car], [[$1]])
3917d15b25SDag-Erling Smørgravm4_define([lt_cdr],
4017d15b25SDag-Erling Smørgrav[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
4117d15b25SDag-Erling Smørgrav       [$#], 1, [],
4217d15b25SDag-Erling Smørgrav       [m4_dquote(m4_shift($@))])])
4317d15b25SDag-Erling Smørgravm4_define([lt_unquote], $1)
4417d15b25SDag-Erling Smørgrav
4517d15b25SDag-Erling Smørgrav
4617d15b25SDag-Erling Smørgrav# lt_append(MACRO-NAME, STRING, [SEPARATOR])
4717d15b25SDag-Erling Smørgrav# ------------------------------------------
48*986ba33cSDag-Erling Smørgrav# Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'.
4917d15b25SDag-Erling Smørgrav# Note that neither SEPARATOR nor STRING are expanded; they are appended
5017d15b25SDag-Erling Smørgrav# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
5117d15b25SDag-Erling Smørgrav# No SEPARATOR is output if MACRO-NAME was previously undefined (different
5217d15b25SDag-Erling Smørgrav# than defined and empty).
5317d15b25SDag-Erling Smørgrav#
5417d15b25SDag-Erling Smørgrav# This macro is needed until we can rely on Autoconf 2.62, since earlier
5517d15b25SDag-Erling Smørgrav# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
5617d15b25SDag-Erling Smørgravm4_define([lt_append],
5717d15b25SDag-Erling Smørgrav[m4_define([$1],
5817d15b25SDag-Erling Smørgrav	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
5917d15b25SDag-Erling Smørgrav
6017d15b25SDag-Erling Smørgrav
6117d15b25SDag-Erling Smørgrav
6217d15b25SDag-Erling Smørgrav# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
6317d15b25SDag-Erling Smørgrav# ----------------------------------------------------------
6417d15b25SDag-Erling Smørgrav# Produce a SEP delimited list of all paired combinations of elements of
6517d15b25SDag-Erling Smørgrav# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
6617d15b25SDag-Erling Smørgrav# has the form PREFIXmINFIXSUFFIXn.
6717d15b25SDag-Erling Smørgrav# Needed until we can rely on m4_combine added in Autoconf 2.62.
6817d15b25SDag-Erling Smørgravm4_define([lt_combine],
6917d15b25SDag-Erling Smørgrav[m4_if(m4_eval([$# > 3]), [1],
7017d15b25SDag-Erling Smørgrav       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
7117d15b25SDag-Erling Smørgrav[[m4_foreach([_Lt_prefix], [$2],
7217d15b25SDag-Erling Smørgrav	     [m4_foreach([_Lt_suffix],
7317d15b25SDag-Erling Smørgrav		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
7417d15b25SDag-Erling Smørgrav	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
7517d15b25SDag-Erling Smørgrav
7617d15b25SDag-Erling Smørgrav
7717d15b25SDag-Erling Smørgrav# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
7817d15b25SDag-Erling Smørgrav# -----------------------------------------------------------------------
7917d15b25SDag-Erling Smørgrav# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
8017d15b25SDag-Erling Smørgrav# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
8117d15b25SDag-Erling Smørgravm4_define([lt_if_append_uniq],
8217d15b25SDag-Erling Smørgrav[m4_ifdef([$1],
8317d15b25SDag-Erling Smørgrav	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
8417d15b25SDag-Erling Smørgrav		 [lt_append([$1], [$2], [$3])$4],
8517d15b25SDag-Erling Smørgrav		 [$5])],
8617d15b25SDag-Erling Smørgrav	  [lt_append([$1], [$2], [$3])$4])])
8717d15b25SDag-Erling Smørgrav
8817d15b25SDag-Erling Smørgrav
8917d15b25SDag-Erling Smørgrav# lt_dict_add(DICT, KEY, VALUE)
9017d15b25SDag-Erling Smørgrav# -----------------------------
9117d15b25SDag-Erling Smørgravm4_define([lt_dict_add],
9217d15b25SDag-Erling Smørgrav[m4_define([$1($2)], [$3])])
9317d15b25SDag-Erling Smørgrav
9417d15b25SDag-Erling Smørgrav
9517d15b25SDag-Erling Smørgrav# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
9617d15b25SDag-Erling Smørgrav# --------------------------------------------
9717d15b25SDag-Erling Smørgravm4_define([lt_dict_add_subkey],
9817d15b25SDag-Erling Smørgrav[m4_define([$1($2:$3)], [$4])])
9917d15b25SDag-Erling Smørgrav
10017d15b25SDag-Erling Smørgrav
10117d15b25SDag-Erling Smørgrav# lt_dict_fetch(DICT, KEY, [SUBKEY])
10217d15b25SDag-Erling Smørgrav# ----------------------------------
10317d15b25SDag-Erling Smørgravm4_define([lt_dict_fetch],
10417d15b25SDag-Erling Smørgrav[m4_ifval([$3],
10517d15b25SDag-Erling Smørgrav	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
10617d15b25SDag-Erling Smørgrav    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
10717d15b25SDag-Erling Smørgrav
10817d15b25SDag-Erling Smørgrav
10917d15b25SDag-Erling Smørgrav# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
11017d15b25SDag-Erling Smørgrav# -----------------------------------------------------------------
11117d15b25SDag-Erling Smørgravm4_define([lt_if_dict_fetch],
11217d15b25SDag-Erling Smørgrav[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
11317d15b25SDag-Erling Smørgrav	[$5],
11417d15b25SDag-Erling Smørgrav    [$6])])
11517d15b25SDag-Erling Smørgrav
11617d15b25SDag-Erling Smørgrav
11717d15b25SDag-Erling Smørgrav# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
11817d15b25SDag-Erling Smørgrav# --------------------------------------------------------------
11917d15b25SDag-Erling Smørgravm4_define([lt_dict_filter],
12017d15b25SDag-Erling Smørgrav[m4_if([$5], [], [],
12117d15b25SDag-Erling Smørgrav  [lt_join(m4_quote(m4_default([$4], [[, ]])),
12217d15b25SDag-Erling Smørgrav           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
12317d15b25SDag-Erling Smørgrav		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
12417d15b25SDag-Erling Smørgrav])
125