1dnl -*- shell-script -*-
2dnl
3dnl Copyright (c) 2004-2009 The Trustees of Indiana University and Indiana
4dnl                         University Research and Technology
5dnl                         Corporation.  All rights reserved.
6dnl Copyright (c) 2004-2005 The University of Tennessee and The University
7dnl                         of Tennessee Research Foundation.  All rights
8dnl                         reserved.
9dnl Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
10dnl                         University of Stuttgart.  All rights reserved.
11dnl Copyright (c) 2004-2005 The Regents of the University of California.
12dnl                         All rights reserved.
13dnl Copyright (c) 2006-2019 Cisco Systems, Inc.  All rights reserved.
14dnl Copyright (c) 2006-2009 Sun Microsystems, Inc.  All rights reserved.
15dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC.  All rights
16dnl                         reserved.
17dnl Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
18dnl Copyright (c) 2015      Research Organization for Information Science
19dnl                         and Technology (RIST). All rights reserved.
20dnl $COPYRIGHT$
21dnl
22dnl Additional copyrights may follow
23dnl
24dnl $HEADER$
25dnl
26
27dnl Check to see if specific CFLAGS work
28dnl $1: compiler flags to check
29dnl $2: Action if the flags work
30dnl $3: Action if the flags do not work
31AC_DEFUN([_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS],[
32    OPAL_VAR_SCOPE_PUSH([ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save])
33
34    ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save=$CFLAGS
35    AC_MSG_CHECKING([if $1 compiler flag works])
36    CFLAGS="$CFLAGS $1"
37    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[int i = 3;])],
38        [ORTE_SETUP_DEBUGGER_FLAGS_HAPPY=yes],
39        [ORTE_SETUP_DEBUGGER_FLAGS_HAPPY=no])
40    AC_MSG_RESULT([$ORTE_SETUP_DEBUGGER_FLAGS_HAPPY])
41    CFLAGS=$ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save
42
43    OPAL_VAR_SCOPE_POP
44
45    AS_IF([test $ORTE_SETUP_DEBUGGER_FLAGS_HAPPY = yes],
46          [$2], [$3])
47])
48
49AC_DEFUN([ORTE_SETUP_DEBUGGER_FLAGS],[
50    #
51    # Do a final process of the CFLAGS to make a WITHOUT_OPTFLAGS
52    # version.  We need this so that we can guarantee to build the
53    # debugger-sensitive files with -g and nothing else.
54    #
55
56    OPAL_STRIP_OPTFLAGS($CFLAGS)
57    CFLAGS_WITHOUT_OPTFLAGS="$s_result"
58    # Tweak the compiler flags passed to orterun for Sun Studio SPARC
59    # https://svn.open-mpi.org/trac/ompi/ticket/1448
60    if test "x$opal_cv_c_compiler_vendor" = "xsun" && test -n "`echo $host | $GREP sparc`"; then
61        DEBUGGER_CFLAGS="-g -xO0"
62    else
63        # Tweak the compiler flags passed for intel
64        # to stop its aggressive inlining of functions
65        if test "x$opal_cv_c_compiler_vendor" = "xintel"; then
66            DEBUGGER_CFLAGS="-g -O0"
67        else
68            DEBUGGER_CFLAGS="-g"
69        fi
70    fi
71    AC_MSG_CHECKING([which of CFLAGS are ok for debugger modules])
72    AC_MSG_RESULT([$CFLAGS_WITHOUT_OPTFLAGS])
73    AC_MSG_CHECKING([for debugger extra CFLAGS])
74    AC_MSG_RESULT([$DEBUGGER_CFLAGS])
75
76    AC_SUBST(CFLAGS_WITHOUT_OPTFLAGS)
77    AC_SUBST(DEBUGGER_CFLAGS)
78
79    # Check for compiler specific flag to add in unwind information.
80    # This is needed when attaching using MPIR to unwind back to the
81    # user's main function. Certain optimisations can prevent GDB from
82    # producing a stack when explicit unwind information is unavailable.
83    # This is implied by -g, but we want to save space and don't need
84    # full debug symbols.
85    _ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS([-fasynchronous-unwind-tables],
86        [MPIR_UNWIND_CFLAGS="-fasynchronous-unwind-tables"],
87        [_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS([-Meh_frame -Mframe],
88            [MPIR_UNWIND_CFLAGS="-Meh_frame -Mframe"],
89            [MPIR_UNWIND_CFLAGS=-g])
90        ])
91
92    AC_MSG_CHECKING([for final compiler unwind flags])
93    AC_MSG_RESULT([$MPIR_UNWIND_CFLAGS])
94
95    AC_SUBST(MPIR_UNWIND_CFLAGS)
96])
97