xref: /freebsd/contrib/ntp/sntp/libevent/m4/ltsugar.m4 (revision f0574f5cf69e168cc4ea71ebbe5fdec9ec9a3dfe)
12b15cb3dSCy Schubert# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
22b15cb3dSCy Schubert#
3*f0574f5cSXin LI# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software
4*f0574f5cSXin LI# Foundation, Inc.
52b15cb3dSCy Schubert# Written by Gary V. Vaughan, 2004
62b15cb3dSCy Schubert#
72b15cb3dSCy Schubert# This file is free software; the Free Software Foundation gives
82b15cb3dSCy Schubert# unlimited permission to copy and/or distribute it, with or without
92b15cb3dSCy Schubert# modifications, as long as this notice is preserved.
102b15cb3dSCy Schubert
112b15cb3dSCy Schubert# serial 6 ltsugar.m4
122b15cb3dSCy Schubert
132b15cb3dSCy Schubert# This is to help aclocal find these macros, as it can't see m4_define.
142b15cb3dSCy SchubertAC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
152b15cb3dSCy Schubert
162b15cb3dSCy Schubert
172b15cb3dSCy Schubert# lt_join(SEP, ARG1, [ARG2...])
182b15cb3dSCy Schubert# -----------------------------
192b15cb3dSCy Schubert# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
202b15cb3dSCy Schubert# associated separator.
212b15cb3dSCy Schubert# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
222b15cb3dSCy Schubert# versions in m4sugar had bugs.
232b15cb3dSCy Schubertm4_define([lt_join],
242b15cb3dSCy Schubert[m4_if([$#], [1], [],
252b15cb3dSCy Schubert       [$#], [2], [[$2]],
262b15cb3dSCy Schubert       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
272b15cb3dSCy Schubertm4_define([_lt_join],
282b15cb3dSCy Schubert[m4_if([$#$2], [2], [],
292b15cb3dSCy Schubert       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
302b15cb3dSCy Schubert
312b15cb3dSCy Schubert
322b15cb3dSCy Schubert# lt_car(LIST)
332b15cb3dSCy Schubert# lt_cdr(LIST)
342b15cb3dSCy Schubert# ------------
352b15cb3dSCy Schubert# Manipulate m4 lists.
362b15cb3dSCy Schubert# These macros are necessary as long as will still need to support
37*f0574f5cSXin LI# Autoconf-2.59, which quotes differently.
382b15cb3dSCy Schubertm4_define([lt_car], [[$1]])
392b15cb3dSCy Schubertm4_define([lt_cdr],
402b15cb3dSCy Schubert[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
412b15cb3dSCy Schubert       [$#], 1, [],
422b15cb3dSCy Schubert       [m4_dquote(m4_shift($@))])])
432b15cb3dSCy Schubertm4_define([lt_unquote], $1)
442b15cb3dSCy Schubert
452b15cb3dSCy Schubert
462b15cb3dSCy Schubert# lt_append(MACRO-NAME, STRING, [SEPARATOR])
472b15cb3dSCy Schubert# ------------------------------------------
48*f0574f5cSXin LI# Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'.
492b15cb3dSCy Schubert# Note that neither SEPARATOR nor STRING are expanded; they are appended
502b15cb3dSCy Schubert# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
512b15cb3dSCy Schubert# No SEPARATOR is output if MACRO-NAME was previously undefined (different
522b15cb3dSCy Schubert# than defined and empty).
532b15cb3dSCy Schubert#
542b15cb3dSCy Schubert# This macro is needed until we can rely on Autoconf 2.62, since earlier
552b15cb3dSCy Schubert# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
562b15cb3dSCy Schubertm4_define([lt_append],
572b15cb3dSCy Schubert[m4_define([$1],
582b15cb3dSCy Schubert	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
592b15cb3dSCy Schubert
602b15cb3dSCy Schubert
612b15cb3dSCy Schubert
622b15cb3dSCy Schubert# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
632b15cb3dSCy Schubert# ----------------------------------------------------------
642b15cb3dSCy Schubert# Produce a SEP delimited list of all paired combinations of elements of
652b15cb3dSCy Schubert# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
662b15cb3dSCy Schubert# has the form PREFIXmINFIXSUFFIXn.
672b15cb3dSCy Schubert# Needed until we can rely on m4_combine added in Autoconf 2.62.
682b15cb3dSCy Schubertm4_define([lt_combine],
692b15cb3dSCy Schubert[m4_if(m4_eval([$# > 3]), [1],
702b15cb3dSCy Schubert       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
712b15cb3dSCy Schubert[[m4_foreach([_Lt_prefix], [$2],
722b15cb3dSCy Schubert	     [m4_foreach([_Lt_suffix],
732b15cb3dSCy Schubert		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
742b15cb3dSCy Schubert	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
752b15cb3dSCy Schubert
762b15cb3dSCy Schubert
772b15cb3dSCy Schubert# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
782b15cb3dSCy Schubert# -----------------------------------------------------------------------
792b15cb3dSCy Schubert# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
802b15cb3dSCy Schubert# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
812b15cb3dSCy Schubertm4_define([lt_if_append_uniq],
822b15cb3dSCy Schubert[m4_ifdef([$1],
832b15cb3dSCy Schubert	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
842b15cb3dSCy Schubert		 [lt_append([$1], [$2], [$3])$4],
852b15cb3dSCy Schubert		 [$5])],
862b15cb3dSCy Schubert	  [lt_append([$1], [$2], [$3])$4])])
872b15cb3dSCy Schubert
882b15cb3dSCy Schubert
892b15cb3dSCy Schubert# lt_dict_add(DICT, KEY, VALUE)
902b15cb3dSCy Schubert# -----------------------------
912b15cb3dSCy Schubertm4_define([lt_dict_add],
922b15cb3dSCy Schubert[m4_define([$1($2)], [$3])])
932b15cb3dSCy Schubert
942b15cb3dSCy Schubert
952b15cb3dSCy Schubert# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
962b15cb3dSCy Schubert# --------------------------------------------
972b15cb3dSCy Schubertm4_define([lt_dict_add_subkey],
982b15cb3dSCy Schubert[m4_define([$1($2:$3)], [$4])])
992b15cb3dSCy Schubert
1002b15cb3dSCy Schubert
1012b15cb3dSCy Schubert# lt_dict_fetch(DICT, KEY, [SUBKEY])
1022b15cb3dSCy Schubert# ----------------------------------
1032b15cb3dSCy Schubertm4_define([lt_dict_fetch],
1042b15cb3dSCy Schubert[m4_ifval([$3],
1052b15cb3dSCy Schubert	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
1062b15cb3dSCy Schubert    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
1072b15cb3dSCy Schubert
1082b15cb3dSCy Schubert
1092b15cb3dSCy Schubert# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
1102b15cb3dSCy Schubert# -----------------------------------------------------------------
1112b15cb3dSCy Schubertm4_define([lt_if_dict_fetch],
1122b15cb3dSCy Schubert[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
1132b15cb3dSCy Schubert	[$5],
1142b15cb3dSCy Schubert    [$6])])
1152b15cb3dSCy Schubert
1162b15cb3dSCy Schubert
1172b15cb3dSCy Schubert# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
1182b15cb3dSCy Schubert# --------------------------------------------------------------
1192b15cb3dSCy Schubertm4_define([lt_dict_filter],
1202b15cb3dSCy Schubert[m4_if([$5], [], [],
1212b15cb3dSCy Schubert  [lt_join(m4_quote(m4_default([$4], [[, ]])),
1222b15cb3dSCy Schubert           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
1232b15cb3dSCy Schubert		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
1242b15cb3dSCy Schubert])
125