Skip to content

Commit 8e655d4

Browse files
committed
build: Cache build mode for components
Create cache variables for component build mode (dso vs. static). We have a use case for components knowing how other components are built (specifically, components that depend on a common component), and this is a generic way of exposing that. At the same time, slowly start trying to be more safe about variable usage in the macros, using the Autoconf polymorphic variable functions where possible. Signed-off-by: Brian Barrett <[email protected]>
1 parent edcf4ca commit 8e655d4

File tree

1 file changed

+58
-15
lines changed

1 file changed

+58
-15
lines changed

config/opal_mca.m4

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ dnl Copyright (c) 2004-2005 The Regents of the University of California.
1212
dnl All rights reserved.
1313
dnl Copyright (c) 2010-2021 Cisco Systems, Inc. All rights reserved
1414
dnl Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
15-
dnl Copyright (c) 2018-2021 Amazon.com, Inc. or its affiliates.
16-
dnl All Rights reserved.
15+
dnl Copyright (c) 2018-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
1716
dnl Copyright (c) 2021 Triad National Security, LLC. All rights
1817
dnl reserved.
1918
dnl $COPYRIGHT$
@@ -604,9 +603,7 @@ AC_DEFUN([MCA_CONFIGURE_M4_CONFIG_COMPONENT],[
604603
MCA_COMPONENT_BUILD_CHECK($1, $2, $3, [should_build=$8], [should_build=0])
605604
# Allow the component to override the build mode if it really wants to.
606605
# It is, of course, free to end up calling MCA_COMPONENT_COMPILE_MODE
607-
m4_ifdef([MCA_$1_$2_$3_COMPILE_MODE],
608-
[MCA_$1_$2_$3_COMPILE_MODE($1, $2, $3, compile_mode)],
609-
[MCA_COMPONENT_COMPILE_MODE($1, $2, $3, compile_mode)])
606+
MCA_COMPONENT_COMPILE_MODE([$1], [$2], [$3], [compile_mode])
610607
611608
# try to configure the component
612609
m4_ifdef([MCA_$1_$2_$3_CONFIG],
@@ -706,10 +703,52 @@ AC_DEFUN([MCA_CONFIGURE_ALL_CONFIG_COMPONENTS],[
706703
# MCA_COMPONENT_COMPILE_MODE(project_name (1), framework_name (2),
707704
# component_name (3), compile_mode_variable (4))
708705
# -------------------------------------------------------------------------
709-
# set compile_mode_variable to the compile mode for the given component
706+
# set compile_mode_variable to the compile mode for the given component.
707+
# this macro will only evaluate the build mode once per configure, returning
708+
# the cached value for subsequent tests. The string is not stored in a cache
709+
# variable (ie .*_cv_.*) because cache variables would not be invalidated
710+
# based on changes to --enable-mca-dso or --enable-mca-static.
710711
#
711712
# NOTE: component_name may not be determined until runtime....
712713
AC_DEFUN([MCA_COMPONENT_COMPILE_MODE],[
714+
OAC_ASSERT_LITERAL([$1], [1])dnl
715+
OAC_ASSERT_LITERAL([$2], [2])dnl
716+
717+
AS_VAR_PUSHDEF([compile_mode_cv], [$1_$2_$3_compile_mode])dnl
718+
AS_VAR_SET_IF([compile_mode_cv],
719+
[],
720+
[AS_LITERAL_IF([$3],
721+
[m4_ifdef([MCA_$1_$2_$3_COMPILE_MODE],
722+
[dnl We introduced caching of this check after setting the compile
723+
dnl mode by the substitute macro was common, and there was not a
724+
dnl polymorphic variable assumption in all those macros, so we use
725+
dnl a temporary with a fixed name.
726+
OPAL_VAR_SCOPE_PUSH([component_compile_mode_tmp])
727+
MCA_$1_$2_$3_COMPILE_MODE([$1], [$2], [$3], [component_compile_mode_tmp])
728+
AS_VAR_COPY([compile_mode_cv], [$component_compile_mode_tmp])
729+
OPAL_VAR_SCOPE_POP],
730+
[MCA_COMPONENT_COMPILE_MODE_INTERNAL([$1], [$2], [$3], [compile_mode_cv])])],
731+
[MCA_COMPONENT_COMPILE_MODE_INTERNAL([$1], [$2], [$3], [compile_mode_cv])])])
732+
AS_VAR_COPY([$4], [compile_mode_cv])
733+
AS_VAR_POPDEF([compile_mode_cv])dnl
734+
])
735+
736+
# MCA_COMPONENT_COMPILE_MODE_INTERNAL(project_name (1), framework_name (2),
737+
# component_name (3), compile_mode_variable (4))
738+
# -------------------------------------------------------------------------
739+
# Determine compile mode of the given component. Prefer a static
740+
# build by default. Users can customize build mode by influencing the
741+
# component, framework, or all-up build flags. This function starts
742+
# at the most specific (component) and works its way out, looking for
743+
# a set option.
744+
#
745+
# Components can avoid calling this function by defining a macro
746+
# MCA_<project>_<framework>_<component>_COMPILE_MODE.
747+
#
748+
# NOTE: component_name may not be determined until runtime....
749+
AC_DEFUN([MCA_COMPONENT_COMPILE_MODE_INTERNAL], [
750+
OPAL_VAR_SCOPE_PUSH([compile_mode_internal_tmp SHARED_FRAMEWORK SHARED_COMPONENT STATIC_FRAMEWORK STATIC_COMPONENT])
751+
713752
SHARED_FRAMEWORK="$DSO_$2"
714753
AS_VAR_COPY([SHARED_COMPONENT], [DSO_$2_$3])
715754
@@ -720,27 +759,31 @@ AC_DEFUN([MCA_COMPONENT_COMPILE_MODE],[
720759
# there is a tie (either neither or both specified), prefer
721760
# static.
722761
if test "$STATIC_COMPONENT" = "1"; then
723-
$4=static
762+
compile_mode_internal_tmp=static
724763
elif test "$SHARED_COMPONENT" = "1"; then
725-
$4=dso
764+
compile_mode_internal_tmp=dso
726765
elif test "$STATIC_FRAMEWORK" = "1"; then
727-
$4=static
766+
compile_mode_internal_tmp=static
728767
elif test "$SHARED_FRAMEWORK" = "1"; then
729-
$4=dso
768+
compile_mode_internal_tmp=dso
730769
elif test "$STATIC_all" = "1"; then
731-
$4=static
770+
compile_mode_internal_tmp=static
732771
elif test "$DSO_all" = "1"; then
733-
$4=dso
772+
compile_mode_internal_tmp=dso
734773
else
735-
$4=static
774+
compile_mode_internal_tmp=static
736775
fi
737776
777+
AS_VAR_SET([$4], [$compile_mode_internal_tmp])
778+
738779
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
739780
if test "$DIRECT_$2" = "$3" ; then
740-
AC_MSG_RESULT([$$4 - direct])
781+
AC_MSG_RESULT([$compile_mode_internal_tmp - direct])
741782
else
742-
AC_MSG_RESULT([$$4])
783+
AC_MSG_RESULT([$compile_mode_internal_tmp])
743784
fi
785+
786+
OPAL_VAR_SCOPE_POP
744787
])
745788

746789
# OPAL_MCA_STRIP_LAFILES(output_variable(1),

0 commit comments

Comments
 (0)