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