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