Skip to content

Commit d16bc6f

Browse files
committed
Port of existing macros to new repo
Copy the OAC_CHECK_PACKAGE and OAC_ASSERT_LITERAL macros from Open MPI / OpenPMIx into the oac repository. Bring along the macros necessary to fill the dependency tree (logging, list manipulation, and scope management). Signed-off-by: Brian Barrett <[email protected]>
1 parent 7f06f90 commit d16bc6f

File tree

6 files changed

+1124
-0
lines changed

6 files changed

+1124
-0
lines changed

oac_check_package.m4

+677
Large diffs are not rendered by default.

oac_linker.m4

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
dnl -*- autoconf -*-
2+
dnl
3+
dnl Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
4+
dnl $COPYRIGHT$
5+
dnl
6+
dnl Additional copyrights may follow
7+
dnl
8+
dnl $HEADER$
9+
10+
11+
dnl OAC_LINKER_STATIC_CHECK: Check if a linker or compiler flag will force
12+
dnl static linking
13+
dnl
14+
dnl 1 -> action if static linking
15+
dnl 2 -> action if not static linking
16+
AC_DEFUN([OAC_LINKER_STATIC_CHECK], [
17+
OAC_VAR_SCOPE_PUSH([oac_linker_arg])
18+
AC_CACHE_CHECK([if static link flag supplied],
19+
[oac_cv_linker_found_static_linker_flag],
20+
[oac_cv_linker_found_static_linker_flag="no"
21+
for oac_linker_arg in ${CFLAGS} ${LDFLAGS} ; do
22+
AS_IF([test "${oac_linker_arg}" = "-static" -o \
23+
"${oac_linker_arg}" = "--static" -o \
24+
"${oac_linker_arg}" = "-Bstatic" -o \
25+
"${oac_linker_arg}" = "-Wl,-static" -o \
26+
"${oac_linker_arg}" = "-Wl,--static" -o \
27+
"${oac_linker_arg}" = "-Wl,-Bstatic"],
28+
[oac_cv_linker_found_static_linker_flag="yes"])
29+
done])
30+
AS_IF([test "${oac_cv_linker_found_static_linker_flag}" = "yes"], [$1], [$2])
31+
OAC_VAR_SCOPE_POP
32+
])

oac_list.m4

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

oac_literal.m4

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
dnl -*- autoconf -*-
2+
dnl
3+
dnl Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
4+
dnl $COPYRIGHT$
5+
dnl
6+
dnl Additional copyrights may follow
7+
8+
dnl OAC_ASSERT_LITERAL: Assert if first argument is not an Autoconf literal
9+
dnl
10+
dnl 1 -> Variable which must be a literal
11+
dnl 2 -> Argument reference string (usually an integer argument number)
12+
dnl
13+
dnl Assert that the first argument is a literal (in the Autoconf sense
14+
dnl of the word) Second argument is the argument number (ie, a bare
15+
dnl number) to make the error message easier to parse.
16+
AC_DEFUN([OAC_ASSERT_LITERAL],
17+
[AS_LITERAL_IF([$1], [], [m4_fatal([argument $2 ($1) must be a literal])])])dnl

oac_log.m4

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
dnl -*- autoconf -*-
2+
dnl
3+
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
dnl University Research and Technology
5+
dnl Corporation. All rights reserved.
6+
dnl Copyright (c) 2004-2018 The University of Tennessee and The University
7+
dnl of Tennessee Research Foundation. All rights
8+
dnl reserved.
9+
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
dnl University of Stuttgart. All rights reserved.
11+
dnl Copyright (c) 2004-2005 The Regents of the University of California.
12+
dnl All rights reserved.
13+
dnl Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
14+
dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
15+
dnl Copyright (c) 2009-2020 Cisco Systems, Inc. All rights reserved.
16+
dnl Copyright (c) 2014 Intel, Inc. All rights reserved.
17+
dnl Copyright (c) 2015-2017 Research Organization for Information Science
18+
dnl and Technology (RIST). All rights reserved.
19+
dnl Copyright (c) 2021-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
20+
dnl
21+
dnl $COPYRIGHT$
22+
dnl
23+
dnl Additional copyrights may follow
24+
dnl
25+
dnl $HEADER$
26+
27+
28+
dnl OAC_LOG_MSG: Log message in config.log, including prefix
29+
dnl giving line number
30+
dnl
31+
dnl 1 -> the message to log
32+
AC_DEFUN([OAC_LOG_MSG],
33+
[AS_ECHO(["configure:__oline__: $1"]) >&AS_MESSAGE_LOG_FD])dnl
34+
35+
36+
dnl OAC_LOG_MSG_NOPREFIX: Log message in config.log, with no prefix
37+
dnl
38+
dnl 1 -> the message to log
39+
AC_DEFUN([OAC_LOG_MSG_NOPREFIX],
40+
[AS_ECHO([$1]) >&AS_MESSAGE_LOG_FD])dnl
41+
42+
43+
dnl OAC_LOG_FILE: Dump the specified file into config.log
44+
dnl
45+
dnl 1 -> filename of file to dump into config.log
46+
AC_DEFUN([OAC_LOG_FILE],
47+
[AS_IF([test -n "$1" && test -f "$1"], [cat $1 >&AS_MESSAGE_LOG_FD])])dnl
48+
49+
50+
dnl OAC_LOG_COMMAND: Run command, logging output, and checking status
51+
dnl
52+
dnl 1 -> command to execute
53+
dnl 2 -> action if successful
54+
dnl 3 -> action if if fail
55+
AC_DEFUN([OAC_LOG_COMMAND],[
56+
OAC_LOG_MSG([$1])
57+
$1 1>&AS_MESSAGE_LOG_FD 2>&1
58+
oac_log_command_status=$?
59+
OAC_LOG_MSG([\$? = $oac_log_command_status])
60+
AS_IF([test $oac_log_command_status -eq 0],
61+
[$2], [$3])
62+
AS_UNSET([oac_log_command_status])])

0 commit comments

Comments
 (0)