1dnl -*- shell-script -*-
2dnl
3dnl Copyright (c) 2004-2005 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-2005 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) 2007-2016 Cisco Systems, Inc.  All rights reserved.
14dnl Copyright (c) 2015      Research Organization for Information Science
15dnl                         and Technology (RIST). All rights reserved.
16dnl Copyright (c) 2016      Los Alamos National Security, LLC. All rights
17dnl                         reserved.
18dnl Copyright (c) 2017-2021 IBM Corporation.  All rights reserved.
19dnl $COPYRIGHT$
20dnl
21dnl Additional copyrights may follow
22dnl
23dnl $HEADER$
24dnl
25
26# check for lsf
27# ORTE_CHECK_LSF(prefix, [action-if-found], [action-if-not-found])
28# --------------------------------------------------------
29AC_DEFUN([ORTE_CHECK_LSF],[
30    AS_IF([test -z "$orte_check_lsf_happy"],[
31       AC_ARG_WITH([lsf],
32               [AC_HELP_STRING([--with-lsf(=DIR)],
33                       [Build LSF support])])
34       OPAL_CHECK_WITHDIR([lsf], [$with_lsf], [include/lsf/lsbatch.h])
35       AC_ARG_WITH([lsf-libdir],
36               [AC_HELP_STRING([--with-lsf-libdir=DIR],
37                       [Search for LSF libraries in DIR])])
38       OPAL_CHECK_WITHDIR([lsf-libdir], [$with_lsf_libdir], [libbat.*])
39
40       AS_IF([test "$with_lsf" != "no"],[
41          # Defaults
42          orte_check_lsf_dir_msg="compiler default"
43          orte_check_lsf_libdir_msg="linker default"
44
45          # Save directory names if supplied
46          AS_IF([test ! -z "$with_lsf" && test "$with_lsf" != "yes"],
47                    [orte_check_lsf_dir="$with_lsf"
48                     orte_check_lsf_dir_msg="$orte_check_lsf_dir (from --with-lsf)"])
49          AS_IF([test ! -z "$with_lsf_libdir" && test "$with_lsf_libdir" != "yes"],
50                    [orte_check_lsf_libdir="$with_lsf_libdir"
51                     orte_check_lsf_libdir_msg="$orte_check_lsf_libdir (from --with-lsf-libdir)"])
52
53          # If no directories were specified, look for LSF_LIBDIR,
54          # LSF_INCLUDEDIR, and/or LSF_ENVDIR.
55          AS_IF([test -z "$orte_check_lsf_dir" && test -z "$orte_check_lsf_libdir"],
56                    [AS_IF([test ! -z "$LSF_ENVDIR" && test -z "$LSF_LIBDIR" && test -f "$LSF_ENVDIR/lsf.conf"],
57                           [LSF_LIBDIR=`egrep ^LSF_LIBDIR= $LSF_ENVDIR/lsf.conf | cut -d= -f2-`])
58                     AS_IF([test ! -z "$LSF_ENVDIR" && test -z "$LSF_INCLUDEDIR" && test -f "$LSF_ENVDIR/lsf.conf"],
59                           [LSF_INCLUDEDIR=`egrep ^LSF_INCLUDEDIR= $LSF_ENVDIR/lsf.conf | cut -d= -f2-`])
60                     AS_IF([test ! -z "$LSF_LIBDIR"],
61                           [orte_check_lsf_libdir=$LSF_LIBDIR
62                            orte_check_lsf_libdir_msg="$LSF_LIBDIR (from \$LSF_LIBDIR)"])
63                     AS_IF([test ! -z "$LSF_INCLUDEDIR"],
64                           [orte_check_lsf_dir=`dirname $LSF_INCLUDEDIR`
65                            orte_check_lsf_dir_msg="$orte_check_lsf_dir (from \$LSF_INCLUDEDIR)"])])
66
67          AS_IF([test "$with_lsf" = "no"],
68                    [orte_check_lsf_happy="no"],
69                    [orte_check_lsf_happy="yes"])
70
71          orte_check_lsf_$1_save_CPPFLAGS="$CPPFLAGS"
72          orte_check_lsf_$1_save_LDFLAGS="$LDFLAGS"
73          orte_check_lsf_$1_save_LIBS="$LIBS"
74
75          # liblsf requires yp_all, yp_get_default_domain, and ypprot_err
76          # on Linux, Solaris, NEC, and Sony NEWSs these are found in libnsl
77          # on AIX it should be in libbsd
78          # on HP-UX it should be in libBSD
79          # on IRIX < 6 it should be in libsun (IRIX 6 and later it is in libc)
80          AS_IF([test "$orte_check_lsf_happy" = "yes"],
81                [OPAL_SEARCH_LIBS_COMPONENT([yp_all_nsl], [yp_all], [nsl bsd BSD sun],
82                              [orte_check_lsf_happy="yes"],
83                              [orte_check_lsf_happy="no"])])
84
85          # liblsf requires shm_open, shm_unlink, which are in librt
86          AS_IF([test "$orte_check_lsf_happy" = "yes"],
87                [OPAL_SEARCH_LIBS_COMPONENT([shm_open_rt], [shm_open], [rt],
88                              [orte_check_lsf_happy="yes"],
89                              [orte_check_lsf_happy="no"])])
90
91          # liblsb requires liblsf - using ls_info as a test for liblsf presence
92          AS_IF([test "$orte_check_lsf_happy" = "yes"],
93                [OPAL_CHECK_PACKAGE([ls_info_lsf],
94                           [lsf/lsf.h],
95                           [lsf],
96                           [ls_info],
97                           [$yp_all_nsl_LIBS $shm_open_rt_LIBS],
98                           [$orte_check_lsf_dir],
99                           [$orte_check_lsf_libdir],
100                           [orte_check_lsf_happy="yes"],
101                           [orte_check_lsf_happy="no"])])
102
103          # test function of liblsb LSF package
104          AS_IF([test "$orte_check_lsf_happy" = "yes"],
105                    [AC_MSG_CHECKING([for LSF dir])
106                     AC_MSG_RESULT([$orte_check_lsf_dir_msg])
107                     AC_MSG_CHECKING([for LSF library dir])
108                     AC_MSG_RESULT([$orte_check_lsf_libdir_msg])
109                     OPAL_CHECK_PACKAGE([orte_check_lsf],
110                        [lsf/lsbatch.h],
111                        [bat],
112                        [lsb_launch],
113                        [$ls_info_lsf_LIBS $yp_all_nsl_LIBS $shm_open_rt_LIBS],
114                        [$orte_check_lsf_dir],
115                        [$orte_check_lsf_libdir],
116                        [orte_check_lsf_happy="yes"],
117                        [orte_check_lsf_happy="no"])])
118
119
120          # Some versions of LSF ship with a libevent.so in their library path.
121          # This is _not_ a copy of Libevent, but something specific to their project.
122          # The Open MPI components should not need to link against LSF's libevent.so
123          # However, the presence of it in the linker search path can cause a problem
124          # if there is a system installed Libevent and Open MPI chooses the 'external'
125          # event component prior to this stage.
126          #
127          # Add a check here to see if we are in a scenario where the two are conflicting.
128          # In which case the earlier checks for successful compile of an LSF program will
129          # have failed with messages like:
130          #   lib64/libevent_pthreads.so: undefined reference to `evthread_set_condition_callbacks'
131          #   lib64/libevent_pthreads.so: undefined reference to `event_mm_malloc_'
132          #   lib64/libevent_pthreads.so: undefined reference to `event_mm_free_'
133          #   lib64/libevent_pthreads.so: undefined reference to `evthread_set_id_callback'
134          #   lib64/libevent_pthreads.so: undefined reference to `evthread_set_lock_callbacks'
135          # Because it picked up -levent from LSF, but -levent_pthreads from Libevent.
136          #
137          # So look for a function that libevent_pthreads is looking for from libevent.so.
138          # If it does appears then we have the correct libevent.so, otherwise then we picked
139          # up the LSF version and a conflict has been detected.
140          # If the external libevent component used 'event_core' instead of 'event'
141          orte_check_lsf_event_conflict=na
142          # Split libs into an array, see if -levent is in that list
143          orte_check_lsf_libevent_present=`echo "$LIBS" | awk '{split([$]0, a, " "); {for (k in a) {if (a[[k]] == "-levent") {print a[[k]]}}}}' | wc -l | tr -d '[[:space:]]'`
144          # (1) LSF check must have failed above. We need to know why...
145          AS_IF([test "$orte_check_lsf_happy" = "no"],
146                [# (2) If there is a -levent in the $LIBS then that might be the problem
147                 AS_IF([test "$opal_event_external_support" = "yes" && test "$orte_check_lsf_libevent_present" != "0"],
148                       [AS_IF([test "$orte_check_lsf_libdir" = "" ],
149                              [],
150                              [LDFLAGS="$LDFLAGS -L$orte_check_lsf_libdir"])
151                        # Note that we do not want to set LIBS here to include -llsf since
152                        # the check is not for an LSF library, but for the conflict with
153                        # LDFLAGS.
154                        # (3) Check to see if the -levent is from Libevent (check for a symbol it has)
155                        AC_CHECK_LIB([event], [evthread_set_condition_callbacks],
156                                     [AC_MSG_CHECKING([for libevent conflict])
157                                      AC_MSG_RESULT([No. The correct libevent.so was linked.])
158                                      orte_check_lsf_event_conflict=no],
159                                     [# (4) The libevent.so is not from Libevent. Warn the user.
160                                      AC_MSG_CHECKING([for libevent conflict])
161                                      AC_MSG_RESULT([Yes. Detected a libevent.so that is not from Libevent.])
162                                      orte_check_lsf_event_conflict=yes])
163                       ],
164                       [AC_MSG_CHECKING([for libevent conflict])
165                        AC_MSG_RESULT([No. Internal Libevent or libevent_core is being used.])
166                        orte_check_lsf_event_conflict=na])],
167                [AC_MSG_CHECKING([for libevent conflict])
168                 AC_MSG_RESULT([No. LSF checks passed.])
169                 orte_check_lsf_event_conflict=na])
170
171          AS_IF([test "$orte_check_lsf_event_conflict" = "yes"],
172                [AC_MSG_WARN([===================================================================])
173                 AC_MSG_WARN([Conflicting libevent.so libraries detected on the system.])
174                 AC_MSG_WARN([])
175                 AC_MSG_WARN([A system-installed Libevent library was detected and the Open MPI])
176                 AC_MSG_WARN([build system chose to use the 'external' component expecting to])
177                 AC_MSG_WARN([link against the Libevent in the linker search path.])
178                 AC_MSG_WARN([If LSF is present on the system and in the default search path then])
179                 AC_MSG_WARN([it _may be_ the source of the conflict.])
180                 AC_MSG_WARN([LSF provides a libevent.so that is not from Libevent in its])
181                 AC_MSG_WARN([library path. At this point the linker is attempting to resolve])
182                 AC_MSG_WARN([Libevent symbols using the LSF library because of the lack of])
183                 AC_MSG_WARN([an explicit linker path pointing to the system-installed Libevent.])
184                 AC_MSG_WARN([])
185                 AC_MSG_WARN([To resolve this issue either (A) explicitly pass the Libevent])
186                 AC_MSG_WARN([library path on the configure line (--with-libevent-libdir), or])
187                 AC_MSG_WARN([(B) use the internal libevent by requesting it from configure ])
188                 AC_MSG_WARN([with the --with-libevent=internal option.])
189                 AC_MSG_WARN([===================================================================])
190                ])
191
192          CPPFLAGS="$orte_check_lsf_$1_save_CPPFLAGS"
193          LDFLAGS="$orte_check_lsf_$1_save_LDFLAGS"
194          LIBS="$orte_check_lsf_$1_save_LIBS"
195
196       ],[orte_check_lsf_happy=no])
197
198       OPAL_SUMMARY_ADD([[Resource Managers]],[[LSF]],[$1],[$orte_check_lsf_happy])
199    ])
200
201    AS_IF([test "$orte_check_lsf_happy" = "yes"],
202          [$1_LIBS="[$]$1_LIBS $orte_check_lsf_LIBS"
203           $1_LDFLAGS="[$]$1_LDFLAGS $orte_check_lsf_LDFLAGS"
204           $1_CPPFLAGS="[$]$1_CPPFLAGS $orte_check_lsf_CPPFLAGS"
205           # add the LSF libraries to static builds as they are required
206           $1_WRAPPER_EXTRA_LDFLAGS=[$]$1_LDFLAGS
207           $1_WRAPPER_EXTRA_LIBS=[$]$1_LIBS
208           $2],
209          [AS_IF([test ! -z "$with_lsf" && test "$with_lsf" != "no"],
210                 [AC_MSG_WARN([LSF support requested (via --with-lsf) but not found.])
211                  AC_MSG_ERROR([Aborting.])])
212           $3])
213])
214