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