1a33c354dSmrg# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
2a33c354dSmrg#
3a33c354dSmrg# Copyright (C) 2004-2005, 2007-2008, 2011-2019, 2021-2022 Free Software
4a33c354dSmrg# Foundation, Inc.
5a33c354dSmrg# Written by Gary V. Vaughan, 2004
6a33c354dSmrg#
7a33c354dSmrg# This file is free software; the Free Software Foundation gives
8a33c354dSmrg# unlimited permission to copy and/or distribute it, with or without
9a33c354dSmrg# modifications, as long as this notice is preserved.
10a33c354dSmrg
11a33c354dSmrg# serial 6 ltsugar.m4
12a33c354dSmrg
13a33c354dSmrg# This is to help aclocal find these macros, as it can't see m4_define.
14a33c354dSmrgAC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
15a33c354dSmrg
16a33c354dSmrg
17a33c354dSmrg# lt_join(SEP, ARG1, [ARG2...])
18a33c354dSmrg# -----------------------------
19a33c354dSmrg# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
20a33c354dSmrg# associated separator.
21a33c354dSmrg# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
22a33c354dSmrg# versions in m4sugar had bugs.
23a33c354dSmrgm4_define([lt_join],
24a33c354dSmrg[m4_if([$#], [1], [],
25a33c354dSmrg       [$#], [2], [[$2]],
26a33c354dSmrg       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
27a33c354dSmrgm4_define([_lt_join],
28a33c354dSmrg[m4_if([$#$2], [2], [],
29a33c354dSmrg       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
30a33c354dSmrg
31a33c354dSmrg
32a33c354dSmrg# lt_car(LIST)
33a33c354dSmrg# lt_cdr(LIST)
34a33c354dSmrg# ------------
35a33c354dSmrg# Manipulate m4 lists.
36a33c354dSmrg# These macros are necessary as long as will still need to support
37a33c354dSmrg# Autoconf-2.59, which quotes differently.
38a33c354dSmrgm4_define([lt_car], [[$1]])
39a33c354dSmrgm4_define([lt_cdr],
40a33c354dSmrg[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
41a33c354dSmrg       [$#], 1, [],
42a33c354dSmrg       [m4_dquote(m4_shift($@))])])
43a33c354dSmrgm4_define([lt_unquote], $1)
44a33c354dSmrg
45a33c354dSmrg
46a33c354dSmrg# lt_append(MACRO-NAME, STRING, [SEPARATOR])
47a33c354dSmrg# ------------------------------------------
48a33c354dSmrg# Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'.
49a33c354dSmrg# Note that neither SEPARATOR nor STRING are expanded; they are appended
50a33c354dSmrg# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
51a33c354dSmrg# No SEPARATOR is output if MACRO-NAME was previously undefined (different
52a33c354dSmrg# than defined and empty).
53a33c354dSmrg#
54a33c354dSmrg# This macro is needed until we can rely on Autoconf 2.62, since earlier
55a33c354dSmrg# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
56a33c354dSmrgm4_define([lt_append],
57a33c354dSmrg[m4_define([$1],
58a33c354dSmrg	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
59a33c354dSmrg
60a33c354dSmrg
61a33c354dSmrg
62a33c354dSmrg# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
63a33c354dSmrg# ----------------------------------------------------------
64a33c354dSmrg# Produce a SEP delimited list of all paired combinations of elements of
65a33c354dSmrg# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
66a33c354dSmrg# has the form PREFIXmINFIXSUFFIXn.
67a33c354dSmrg# Needed until we can rely on m4_combine added in Autoconf 2.62.
68a33c354dSmrgm4_define([lt_combine],
69a33c354dSmrg[m4_if(m4_eval([$# > 3]), [1],
70a33c354dSmrg       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
71a33c354dSmrg[[m4_foreach([_Lt_prefix], [$2],
72a33c354dSmrg	     [m4_foreach([_Lt_suffix],
73a33c354dSmrg		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
74a33c354dSmrg	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
75a33c354dSmrg
76a33c354dSmrg
77a33c354dSmrg# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
78a33c354dSmrg# -----------------------------------------------------------------------
79a33c354dSmrg# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
80a33c354dSmrg# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
81a33c354dSmrgm4_define([lt_if_append_uniq],
82a33c354dSmrg[m4_ifdef([$1],
83a33c354dSmrg	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
84a33c354dSmrg		 [lt_append([$1], [$2], [$3])$4],
85a33c354dSmrg		 [$5])],
86a33c354dSmrg	  [lt_append([$1], [$2], [$3])$4])])
87a33c354dSmrg
88a33c354dSmrg
89a33c354dSmrg# lt_dict_add(DICT, KEY, VALUE)
90a33c354dSmrg# -----------------------------
91a33c354dSmrgm4_define([lt_dict_add],
92a33c354dSmrg[m4_define([$1($2)], [$3])])
93a33c354dSmrg
94a33c354dSmrg
95a33c354dSmrg# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
96a33c354dSmrg# --------------------------------------------
97a33c354dSmrgm4_define([lt_dict_add_subkey],
98a33c354dSmrg[m4_define([$1($2:$3)], [$4])])
99a33c354dSmrg
100a33c354dSmrg
101a33c354dSmrg# lt_dict_fetch(DICT, KEY, [SUBKEY])
102a33c354dSmrg# ----------------------------------
103a33c354dSmrgm4_define([lt_dict_fetch],
104a33c354dSmrg[m4_ifval([$3],
105a33c354dSmrg	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
106a33c354dSmrg    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
107a33c354dSmrg
108a33c354dSmrg
109a33c354dSmrg# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
110a33c354dSmrg# -----------------------------------------------------------------
111a33c354dSmrgm4_define([lt_if_dict_fetch],
112a33c354dSmrg[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
113a33c354dSmrg	[$5],
114a33c354dSmrg    [$6])])
115a33c354dSmrg
116a33c354dSmrg
117a33c354dSmrg# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
118a33c354dSmrg# --------------------------------------------------------------
119a33c354dSmrgm4_define([lt_dict_filter],
120a33c354dSmrg[m4_if([$5], [], [],
121a33c354dSmrg  [lt_join(m4_quote(m4_default([$4], [[, ]])),
122a33c354dSmrg           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
123a33c354dSmrg		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
124a33c354dSmrg])
125