Skip to content

Commit b83ed23

Browse files
committed
hwloc201/configure.m4: make it safe when used with hwloc:external
The Autoconf AC_CONFIG_* macros can only be instantiated exacly once for any given file, *and* they must be in a code execution path at run time for the target file to be generated at the end of configure. For example, if you want to generate file ABC at the end of configure, you must invoke the AC_CONFIG_FILES(ABC) macro in a code path that will get executed when configure is run. That's pretty straightforward. What's not straightforward is two corner cases: 1. You cannot invoke the AC_CONFIG_FILES(ABC) macro for the same file more than once. If you do, autoreconf will fail (even before you can run configure). 2. If AC_CONFIG_FILES(ABC) is not in a code path that is executed by configure, the file ABC is not registered properly, and ABC will not be generated at the end of configure. This applies to hwloc because hwloc's HWLOC_SETUP_CORE macro calls both AC_CONFIG_FILES and AC_CONFIG_HEADER to setup its Makefiles (etc.) so that targets like "make distclean" and "make distcheck" will work properly. Hence, we *have* to invoke HWLOC_SETUP_CORE. However, the MCA_opal_hwloc_hwloc201_CONFIG macro has a few side effects. It would be nice to do able to do something like this: ``` if hwloc:extern is going to be used: Invoke minimal HWLOC_SETUP_CORE (with no side effects) else Invoke full HWLOC_SETUP_CORE (with side effects) fi ``` But we can't, because autoreconf will detect that AC_CONFIG_FILES has been invoked on the same files more than once (regardless of whether those code paths will be executed at run time or not). Kaboom. Similarly, we can't do this: ``` if hwloc:extern is not going to be used: Invoke full HWLOC_SETUP_CORE (with side effects) fi ``` Because then hwloc's AC_CONFIG_FILES won't be registered properly when hwloc:external *is* used (i.e., when the HWLOC_SETUP_CORE macro is not in a code path that is executed at run time), and targets like "make distclean" will fail because hwloc's Makefiles won't have been setup. Kaboom. But remember that the hwloc framework is a bit special: there will only ever be 2 comoponents: external and internal. External is guaranteed to be configured first because of its priority. So the internal component (i.e., this component) immediately knows if it is going to be used or not based on whether the external component configuration succeeded or failed. Specifically: regardless of whether the internal component (i.e., this component) is going to be used, we have to invoke HWLOC_SETUP_CORE. But we can manage the side effects: allow the side effects when this/internal component is going to be used, and avoid the side effects when this/internal component is not going to be used. This is a little less clean than I would have liked, but because of Autoconf's oddity about its AC_CONFIG_* macros, this is the only solution I could come up with. Signed-off-by: Jeff Squyres <[email protected]>
1 parent 69aa46e commit b83ed23

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

opal/mca/hwloc/hwloc201/configure.m4

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,23 @@ AC_DEFUN([MCA_opal_hwloc_hwloc201_POST_CONFIG],[
6969
# MCA_hwloc_hwloc201_CONFIG([action-if-found], [action-if-not-found])
7070
# --------------------------------------------------------------------
7171
AC_DEFUN([MCA_opal_hwloc_hwloc201_CONFIG],[
72+
# Hwloc needs to know if we have Verbs support
73+
AC_REQUIRE([OPAL_CHECK_VERBS_DIR])
74+
75+
AC_CONFIG_FILES([opal/mca/hwloc/hwloc201/Makefile])
76+
77+
OPAL_VAR_SCOPE_PUSH([HWLOC_VERSION opal_hwloc_hwloc201_save_CPPFLAGS opal_hwloc_hwloc201_save_LDFLAGS opal_hwloc_hwloc201_save_LIBS opal_hwloc_hwloc201_save_cairo opal_hwloc_hwloc201_save_xml opal_hwloc_hwloc201_save_mode opal_hwloc_hwloc201_basedir opal_hwloc_hwloc201_file opal_hwloc_hwloc201_save_cflags CPPFLAGS_save LIBS_save opal_hwloc_external])
78+
7279
# We know that the external hwloc component will be configured
7380
# before this one because of its priority. This component is only
7481
# needed if the external component was not successful in selecting
75-
# itself.
82+
# itself. Print out a message explaining this.
7683
AC_MSG_CHECKING([if hwloc external component succeeded])
7784
AS_IF([test "$opal_hwloc_external_support" = "yes"],
7885
[AC_MSG_RESULT([yes])
79-
AC_MSG_NOTICE([hwloc:external succeeded, so this component will be skipped])
80-
$2],
86+
AC_MSG_NOTICE([hwloc:external succeeded, so this component will be configured, but then will be skipped])],
8187
[AC_MSG_RESULT([no])
82-
AC_MSG_NOTICE([hwloc:external failed, so this component will be used])
83-
MCA_opal_hwloc_hwloc201_BACKEND_CONFIG($1, $2)])
84-
])
85-
86-
AC_DEFUN([MCA_opal_hwloc_hwloc201_BACKEND_CONFIG],[
87-
# Hwloc needs to know if we have Verbs support
88-
AC_REQUIRE([OPAL_CHECK_VERBS_DIR])
89-
90-
AC_CONFIG_FILES([opal/mca/hwloc/hwloc201/Makefile])
91-
92-
OPAL_VAR_SCOPE_PUSH([HWLOC_VERSION opal_hwloc_hwloc201_save_CPPFLAGS opal_hwloc_hwloc201_save_LDFLAGS opal_hwloc_hwloc201_save_LIBS opal_hwloc_hwloc201_save_cairo opal_hwloc_hwloc201_save_xml opal_hwloc_hwloc201_save_mode opal_hwloc_hwloc201_basedir opal_hwloc_hwloc201_file opal_hwloc_hwloc201_save_cflags CPPFLAGS_save LIBS_save opal_hwloc_external])
88+
AC_MSG_NOTICE([hwloc:external failed, so this component will be used])])
9389

9490
# default to this component not providing support
9591
opal_hwloc_hwloc201_basedir=opal/mca/hwloc/hwloc201
@@ -99,8 +95,6 @@ AC_DEFUN([MCA_opal_hwloc_hwloc201_BACKEND_CONFIG],[
9995
opal_hwloc_hwloc201_save_LDFLAGS=$LDFLAGS
10096
opal_hwloc_hwloc201_save_LIBS=$LIBS
10197

102-
HWLOC_SET_SYMBOL_PREFIX([opal_hwloc201_])
103-
10498
# save XML or graphical options
10599
opal_hwloc_hwloc201_save_cairo=$enable_cairo
106100
opal_hwloc_hwloc201_save_xml=$enable_xml
@@ -143,6 +137,12 @@ AC_DEFUN([MCA_opal_hwloc_hwloc201_BACKEND_CONFIG],[
143137
AS_IF([test -n "$opal_datatype_cuda_CPPFLAGS"],
144138
[CPPFLAGS="$CPPFLAGS $opal_datatype_cuda_CPPFLAGS"])
145139

140+
# Only set the symbol prefix if this component is being used
141+
# (i.e., if the external component is not being used).
142+
AS_IF([test "$opal_hwloc_external_support" = "yes"],
143+
[HWLOC_SET_SYMBOL_PREFIX([opal_hwloc201_])])
144+
145+
# Do the bulk of the hwloc core setup
146146
HWLOC_SETUP_CORE([opal/mca/hwloc/hwloc201/hwloc],
147147
[AC_MSG_CHECKING([whether hwloc configure succeeded])
148148
AC_MSG_RESULT([yes])
@@ -202,8 +202,8 @@ AC_DEFUN([MCA_opal_hwloc_hwloc201_BACKEND_CONFIG],[
202202
# infrastructure is setup properly (e.g., w.r.t. SUBDIRS=hwloc in
203203
# this directory's Makefile.am, we still need the Autotools "make
204204
# distclean" infrastructure to work properly).
205-
AS_IF([test "$opal_hwloc_external" = "yes"],
206-
[AC_MSG_WARN([using an external hwloc; disqualifying this component])
205+
AS_IF([test "$opal_hwloc_external_support" = "yes"],
206+
[AC_MSG_NOTICE([using an external hwloc; disqualifying this component])
207207
opal_hwloc_hwloc201_support=no],
208208
[AC_DEFINE([HAVE_DECL_HWLOC_OBJ_OSDEV_COPROC], [1])
209209
AC_DEFINE([HAVE_HWLOC_TOPOLOGY_DUP], [1])])

0 commit comments

Comments
 (0)