|
| 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 |
0 commit comments