Skip to content

Commit 24000aa

Browse files
author
rhc54
authored
Merge pull request #2638 from rhc54/topic/pmixcflags
Avoid mangling user-provided CFLAGS by using the new PMIX_FLAGS_UNIQ autoconf script in place of PMIX_UNIQ
2 parents 791f4f1 + d3aa377 commit 24000aa

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-4
lines changed

opal/mca/pmix/pmix2x/pmix/config/pmix_functions.m4

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,103 @@ dnl #######################################################################
326326
dnl #######################################################################
327327
dnl #######################################################################
328328

329+
# Remove all duplicate -I, -L, and -l flags from the variable named $1
330+
AC_DEFUN([PMIX_FLAGS_UNIQ],[
331+
# 1 is the variable name to be uniq-ized
332+
pmix_name=$1
333+
334+
# Go through each item in the variable and only keep the unique ones
335+
336+
pmix_count=0
337+
for val in ${$1}; do
338+
pmix_done=0
339+
pmix_i=1
340+
pmix_found=0
341+
342+
# Loop over every token we've seen so far
343+
344+
pmix_done="`expr $pmix_i \> $pmix_count`"
345+
while test "$pmix_found" = "0" && test "$pmix_done" = "0"; do
346+
347+
# Have we seen this token already? Prefix the comparison
348+
# with "x" so that "-Lfoo" values won't be cause an error.
349+
350+
pmix_eval="expr x$val = x\$pmix_array_$pmix_i"
351+
pmix_found=`eval $pmix_eval`
352+
353+
# Check the ending condition
354+
355+
pmix_done="`expr $pmix_i \>= $pmix_count`"
356+
357+
# Increment the counter
358+
359+
pmix_i="`expr $pmix_i + 1`"
360+
done
361+
362+
# Check for special cases where we do want to allow repeated
363+
# arguments (per
364+
# http://www.open-mpi.org/community/lists/devel/2012/08/11362.php
365+
# and
366+
# https://github.com/open-mpi/ompi/issues/324).
367+
368+
case $val in
369+
-Xclang)
370+
pmix_found=0
371+
pmix_i=`expr $pmix_count + 1`
372+
;;
373+
-framework)
374+
pmix_found=0
375+
pmix_i=`expr $pmix_count + 1`
376+
;;
377+
--param)
378+
pmix_found=0
379+
pmix_i=`expr $pmix_count + 1`
380+
;;
381+
esac
382+
383+
# If we didn't find the token, add it to the "array"
384+
385+
if test "$pmix_found" = "0"; then
386+
pmix_eval="pmix_array_$pmix_i=$val"
387+
eval $pmix_eval
388+
pmix_count="`expr $pmix_count + 1`"
389+
else
390+
pmix_i="`expr $pmix_i - 1`"
391+
fi
392+
done
393+
394+
# Take all the items in the "array" and assemble them back into a
395+
# single variable
396+
397+
pmix_i=1
398+
pmix_done="`expr $pmix_i \> $pmix_count`"
399+
pmix_newval=
400+
while test "$pmix_done" = "0"; do
401+
pmix_eval="pmix_newval=\"$pmix_newval \$pmix_array_$pmix_i\""
402+
eval $pmix_eval
403+
404+
pmix_eval="unset pmix_array_$pmix_i"
405+
eval $pmix_eval
406+
407+
pmix_done="`expr $pmix_i \>= $pmix_count`"
408+
pmix_i="`expr $pmix_i + 1`"
409+
done
410+
411+
# Done; do the assignment
412+
413+
pmix_newval="`echo $pmix_newval`"
414+
pmix_eval="$pmix_name=\"$pmix_newval\""
415+
eval $pmix_eval
416+
417+
# Clean up
418+
419+
unset pmix_name pmix_i pmix_done pmix_newval pmix_eval pmix_count
420+
])dnl
421+
422+
dnl #######################################################################
423+
dnl #######################################################################
424+
dnl #######################################################################
425+
329426
# PMIX_APPEND_UNIQ(variable, new_argument)
330427
# ----------------------------------------
331428
# Append new_argument to variable if not already in variable. This assumes a

opal/mca/pmix/pmix2x/pmix/config/pmix_setup_cc.m4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ AC_DEFUN([PMIX_SETUP_CC],[
7272
if test "$WANT_DEBUG" = "1" && test "$enable_debug_symbols" != "no" ; then
7373
CFLAGS="$CFLAGS -g"
7474

75-
PMIX_UNIQ(CFLAGS)
75+
PMIX_FLAGS_UNIQ(CFLAGS)
7676
AC_MSG_WARN([-g has been added to CFLAGS (--enable-debug)])
7777
fi
7878

@@ -138,7 +138,7 @@ AC_DEFUN([PMIX_SETUP_CC],[
138138
fi
139139

140140
CFLAGS="$CFLAGS_orig $add"
141-
PMIX_UNIQ(CFLAGS)
141+
PMIX_FLAGS_UNIQ(CFLAGS)
142142
AC_MSG_WARN([$add has been added to CFLAGS (--enable-picky)])
143143
unset add
144144
fi
@@ -188,7 +188,7 @@ AC_DEFUN([PMIX_SETUP_CC],[
188188
fi
189189
CFLAGS="$CFLAGS_orig$add"
190190

191-
PMIX_UNIQ(CFLAGS)
191+
PMIX_FLAGS_UNIQ(CFLAGS)
192192
AC_MSG_WARN([$add has been added to CFLAGS])
193193
unset add
194194
fi
@@ -217,7 +217,7 @@ AC_DEFUN([PMIX_SETUP_CC],[
217217
fi
218218

219219
CFLAGS="${CFLAGS_orig}${add}"
220-
PMIX_UNIQ([CFLAGS])
220+
PMIX_FLAGS_UNIQ([CFLAGS])
221221
if test "$add" != "" ; then
222222
AC_MSG_WARN([$add has been added to CFLAGS])
223223
fi

0 commit comments

Comments
 (0)