1266072Sdes# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
2266072Sdes#
3266072Sdes# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
4266072Sdes# Written by Gary V. Vaughan, 2004
5266072Sdes#
6266072Sdes# This file is free software; the Free Software Foundation gives
7266072Sdes# unlimited permission to copy and/or distribute it, with or without
8266072Sdes# modifications, as long as this notice is preserved.
9266072Sdes
10266072Sdes# serial 6 ltsugar.m4
11266072Sdes
12266072Sdes# This is to help aclocal find these macros, as it can't see m4_define.
13266072SdesAC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
14266072Sdes
15266072Sdes
16266072Sdes# lt_join(SEP, ARG1, [ARG2...])
17266072Sdes# -----------------------------
18266072Sdes# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
19266072Sdes# associated separator.
20266072Sdes# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
21266072Sdes# versions in m4sugar had bugs.
22266072Sdesm4_define([lt_join],
23266072Sdes[m4_if([$#], [1], [],
24266072Sdes       [$#], [2], [[$2]],
25266072Sdes       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
26266072Sdesm4_define([_lt_join],
27266072Sdes[m4_if([$#$2], [2], [],
28266072Sdes       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
29266072Sdes
30266072Sdes
31266072Sdes# lt_car(LIST)
32266072Sdes# lt_cdr(LIST)
33266072Sdes# ------------
34266072Sdes# Manipulate m4 lists.
35266072Sdes# These macros are necessary as long as will still need to support
36266072Sdes# Autoconf-2.59 which quotes differently.
37266072Sdesm4_define([lt_car], [[$1]])
38266072Sdesm4_define([lt_cdr],
39266072Sdes[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
40266072Sdes       [$#], 1, [],
41266072Sdes       [m4_dquote(m4_shift($@))])])
42266072Sdesm4_define([lt_unquote], $1)
43266072Sdes
44266072Sdes
45266072Sdes# lt_append(MACRO-NAME, STRING, [SEPARATOR])
46266072Sdes# ------------------------------------------
47266072Sdes# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
48266072Sdes# Note that neither SEPARATOR nor STRING are expanded; they are appended
49266072Sdes# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
50266072Sdes# No SEPARATOR is output if MACRO-NAME was previously undefined (different
51266072Sdes# than defined and empty).
52266072Sdes#
53266072Sdes# This macro is needed until we can rely on Autoconf 2.62, since earlier
54266072Sdes# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
55266072Sdesm4_define([lt_append],
56266072Sdes[m4_define([$1],
57266072Sdes	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
58266072Sdes
59266072Sdes
60266072Sdes
61266072Sdes# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
62266072Sdes# ----------------------------------------------------------
63266072Sdes# Produce a SEP delimited list of all paired combinations of elements of
64266072Sdes# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
65266072Sdes# has the form PREFIXmINFIXSUFFIXn.
66266072Sdes# Needed until we can rely on m4_combine added in Autoconf 2.62.
67266072Sdesm4_define([lt_combine],
68266072Sdes[m4_if(m4_eval([$# > 3]), [1],
69266072Sdes       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
70266072Sdes[[m4_foreach([_Lt_prefix], [$2],
71266072Sdes	     [m4_foreach([_Lt_suffix],
72266072Sdes		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
73266072Sdes	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
74266072Sdes
75266072Sdes
76266072Sdes# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
77266072Sdes# -----------------------------------------------------------------------
78266072Sdes# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
79266072Sdes# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
80266072Sdesm4_define([lt_if_append_uniq],
81266072Sdes[m4_ifdef([$1],
82266072Sdes	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
83266072Sdes		 [lt_append([$1], [$2], [$3])$4],
84266072Sdes		 [$5])],
85266072Sdes	  [lt_append([$1], [$2], [$3])$4])])
86266072Sdes
87266072Sdes
88266072Sdes# lt_dict_add(DICT, KEY, VALUE)
89266072Sdes# -----------------------------
90266072Sdesm4_define([lt_dict_add],
91266072Sdes[m4_define([$1($2)], [$3])])
92266072Sdes
93266072Sdes
94266072Sdes# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
95266072Sdes# --------------------------------------------
96266072Sdesm4_define([lt_dict_add_subkey],
97266072Sdes[m4_define([$1($2:$3)], [$4])])
98266072Sdes
99266072Sdes
100266072Sdes# lt_dict_fetch(DICT, KEY, [SUBKEY])
101266072Sdes# ----------------------------------
102266072Sdesm4_define([lt_dict_fetch],
103266072Sdes[m4_ifval([$3],
104266072Sdes	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
105266072Sdes    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
106266072Sdes
107266072Sdes
108266072Sdes# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
109266072Sdes# -----------------------------------------------------------------
110266072Sdesm4_define([lt_if_dict_fetch],
111266072Sdes[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
112266072Sdes	[$5],
113266072Sdes    [$6])])
114266072Sdes
115266072Sdes
116266072Sdes# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
117266072Sdes# --------------------------------------------------------------
118266072Sdesm4_define([lt_dict_filter],
119266072Sdes[m4_if([$5], [], [],
120266072Sdes  [lt_join(m4_quote(m4_default([$4], [[, ]])),
121266072Sdes           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
122266072Sdes		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
123266072Sdes])
124