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