-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoac_list.m4
235 lines (211 loc) · 8.07 KB
/
oac_list.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
dnl -*- autoconf -*-
dnl
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
dnl University Research and Technology
dnl Corporation. All rights reserved.
dnl Copyright (c) 2004-2018 The University of Tennessee and The University
dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl All rights reserved.
dnl Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
dnl Copyright (c) 2009-2023 Cisco Systems, Inc. All rights reserved.
dnl Copyright (c) 2014 Intel, Inc. All rights reserved.
dnl Copyright (c) 2015-2017 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl Copyright (c) 2021-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl OAC_UNIQ: Uniqify the string-separated words in the input variable
dnl
dnl 1 -> variable name to be uniq-ized
AC_DEFUN([OAC_UNIQ],[
OAC_VAR_SCOPE_PUSH([oac_uniq_name oac_uniq_done oac_uniq_i oac_uniq_found oac_uniq_count oac_uniq_newval oac_uniq_val])
oac_uniq_name=$1
# Go through each item in the variable and only keep the unique ones
oac_uniq_count=0
for oac_uniq_val in ${$1}; do
oac_uniq_done=0
oac_uniq_i=1
oac_uniq_found=0
# Loop over every token we've seen so far
oac_uniq_done="`expr ${oac_uniq_i} \> ${oac_uniq_count}`"
while test ${oac_uniq_found} -eq 0 && test ${oac_uniq_done} -eq 0; do
# Have we seen this token already? Prefix the comparison with
# "x" so that "-Lfoo" values won't be cause an error.
oac_uniq_eval="expr x${oac_uniq_val} = x\${oac_uniq_array_$oac_uniq_i}"
oac_uniq_found=`eval ${oac_uniq_eval}`
# Check the ending condition
oac_uniq_done="`expr ${oac_uniq_i} \>= ${oac_uniq_count}`"
# Increment the counter
oac_uniq_i="`expr ${oac_uniq_i} + 1`"
done
# If we didn't find the token, add it to the "array"
if test ${oac_uniq_found} -eq 0; then
oac_uniq_eval="oac_uniq_array_${oac_uniq}_i=${oac_uniq_val}"
eval ${oac_uniq_eval}
oac_uniq_count="`expr ${oac_uniq_count} + 1`"
else
oac_uniq_i="`expr ${oac_uniq_i} - 1`"
fi
done
# Take all the items in the "array" and assemble them back into a
# single variable
oac_uniq_i=1
oac_uniq_done="`expr ${oac_uniq_i} \> ${oac_uniq_count}`"
oac_uniq_newval=
while test ${oac_uniq_done} -eq 0; do
oac_uniq_eval="oac_uniq_newval=\"${oac_uniq_newval} \${oac_uniq_array_$oac_uniq_i}\""
eval ${oac_uniq_eval}
oac_uniq_eval="unset oac_uniq_array_${oac_uniq_i}"
eval ${oac_uniq_eval}
oac_uniq_done="`expr ${oac_uniq_i} \>= ${oac_uniq_count}`"
oac_uniq_i="`expr ${oac_uniq_i} + 1`"
done
# Done; do the assignment
oac_uniq_newval="`echo ${oac_uniq_newval}`"
oac_uniq_eval="${oac_uniq_name}=\"${oac_uniq_newval}\""
eval ${oac_uniq_eval}
OAC_VAR_SCOPE_POP
])dnl
dnl OAC_APPEND: Append argument to list
dnl
dnl 1 -> variable name to append to
dnl 2 -> string to append
dnl
dnl Append the given argument ($2) to the variable name passed as $1.
dnl The list is assumed to be space separated, and $1 must be a string
dnl literal (ie, no indirection is supported).
AC_DEFUN([OAC_APPEND],
[OAC_ASSERT_LITERAL([$1])
AS_IF([test -z "${$1}"], [$1="$2"], [$1="${$1} $2"])
])dnl
dnl OAC_APPEND_UNIQ: Append argument to list if not already there
dnl
dnl 1 -> variable name to append to
dnl 2 -> string to append
dnl
dnl uniquely append arguments to a space separated list. $1 is a
dnl string literal variable name into which the arguments are
dnl inserted. $2 is a space separated list of arguments to add, each
dnl of which is individually unique-checked before insertion.
dnl
dnl This could probably be made more efficient :(.
AC_DEFUN([OAC_APPEND_UNIQ],
[OAC_ASSERT_LITERAL([$1])
OAC_VAR_SCOPE_PUSH([oac_list_arg oac_list_found oac_list_val])
for oac_list_arg in $2; do
oac_list_found=0;
for oac_list_val in ${$1}; do
AS_IF([test "x${oac_list_val}" = "x${oac_list_arg}"],
[oac_list_found=1
break])
done
AS_IF([test "${oac_list_found}" = "0"],
[OAC_APPEND([$1], [${oac_list_arg}])])
done
OAC_VAR_SCOPE_POP
])dnl
dnl OAC_FLAGS_APPEND_UNIQ: Uniquely append argument to list
dnl
dnl 1 -> variable name to append to
dnl 2 -> string to append
dnl
dnl Append new_argument to variable if:
dnl
dnl - the argument does not begin with -I, -L, or -l, or
dnl - the argument begins with -I, -L, or -l, and it's not already in variable
dnl
dnl This macro assumes a space separated list.
AC_DEFUN([OAC_FLAGS_APPEND_UNIQ],
[OAC_ASSERT_LITERAL([$1])
OAC_VAR_SCOPE_PUSH([oac_list_prefix oac_list_append oac_list_arg oac_list_val])
for oac_list_arg in $2; do
oac_list_append=1
AS_CASE([${oac_list_arg}],
[-I*|-L*|-l*],
[for oac_list_val in ${$1}; do
AS_IF([test "x${oal_list_val}" = "x${oac_list_arg}"],
[oac_list_append=0])
done])
AS_IF([test ${oac_list_append} -eq 1],
[OAC_APPEND([$1], [$oac_list_arg])])
done
OAC_VAR_SCOPE_POP
])dnl
dnl OAC_FLAGS_PREPEND_UNIQ: Uniquely prepend argument to list
dnl
dnl 1 -> variable name to prepend to
dnl 2 -> string to append
dnl
dnl Prepend new_argument to variable if:
dnl
dnl - the argument does not begin with -I, -L, or -l, or
dnl - the argument begins with -I, -L, or -l, and it's not already in variable
dnl
dnl This macro assumes a space separated list.
AC_DEFUN([OAC_FLAGS_PREPEND_UNIQ],
[OAC_ASSERT_LITERAL([$1])
OAC_VAR_SCOPE_PUSH([oac_list_prefix oac_list_prepend oac_list_arg oac_list_val])
for oac_list_arg in $2; do
oac_list_prepend=1
AS_CASE([${oac_list_arg}],
[-I*|-L*|-l*],
[for oac_list_val in ${$1}; do
AS_IF([test "x${oal_list_val}" = "x${oac_list_arg}"],
[oac_list_prepend=0])
done])
AS_IF([test ${oac_list_prepend} -eq 1],
[AS_IF([test -z "${$1}"], [$1="$2"], [$1="$2 ${$1}"])])
done
OAC_VAR_SCOPE_POP
])dnl
dnl OAC_FLAGS_APPEND_MOVE: Uniquely add libraries to list
dnl
dnl 1 -> variable name to append to
dnl 2 -> string to append
dnl
dnl add new_arguments to the end of variable.
dnl
dnl If an argument in new_arguments does not begin with -I, -L, or -l OR
dnl the argument begins with -I, -L, or -l and it is not already in
dnl variable, it is appended to variable.
dnl
dnl If an argument in new_argument begins with a -l and is already in
dnl variable, the existing occurrences of the argument are removed from
dnl variable and the argument is appended to variable. This behavior
dnl is most useful in LIBS, where ordering matters and being rightmost
dnl is usually the right behavior.
dnl
dnl This macro assumes a space separated list.
AC_DEFUN([OAC_FLAGS_APPEND_MOVE],
[OAC_ASSERT_LITERAL([$1])
OAC_VAR_SCOPE_PUSH([oac_list_arg oac_list_append oac_list_val oac_list_tmp_variable])
for oac_list_arg in $2; do
AS_CASE([${oac_list_arg}],
[-I*|-L*],
[oac_list_append=1
for oac_list_val in ${$1} ; do
AS_IF([test "x${oac_list_val}" = "x${oac_list_arg}"],
[oac_list_append=0])
done
AS_IF([test ${oac_list_append} -eq 1],
[OAC_APPEND([$1], [${oac_list_arg}])])],
[-l*],
[oac_list_tmp_variable=
for oac_list_val in ${$1}; do
AS_IF([test "x${oac_list_val}" != "x${oac_list_arg}"],
[OAC_APPEND([oac_list_tmp_variable], [${oac_list_val}])])
done
OAC_APPEND([oac_list_tmp_variable], [${oac_list_arg}])
$1="${oac_list_tmp_variable}"],
[OAC_APPEND([$1], [${oac_list_arg}])])
done
OAC_VAR_SCOPE_POP
])dnl