Skip to content

Commit f49caf3

Browse files
committed
configury: revamp the OPAL_CHECK_PACKAGE macro
add the OPAL_DEFINE_PACKAGE helper that define --with-FOO=DIR --with-FOO-cppflags=FLAGS --with-FOO-ldflags=FLAGS --with-FOO-libdir=DIR (deprecated) OPAL_CHECK_PACKAGE2(prefix, header, library, function, extra-libraries, package, [action-if-found], [action-if-not-found], includes) is much easier to use and handle most of the work under the hood. Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
1 parent 7333f12 commit f49caf3

File tree

3 files changed

+280
-112
lines changed

3 files changed

+280
-112
lines changed

config/opal_check_package2.m4

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
dnl University Research and Technology
5+
dnl Corporation. All rights reserved.
6+
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
7+
dnl of Tennessee Research Foundation. All rights
8+
dnl reserved.
9+
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
dnl University of Stuttgart. All rights reserved.
11+
dnl Copyright (c) 2004-2005 The Regents of the University of California.
12+
dnl All rights reserved.
13+
dnl Copyright (c) 2012-2017 Cisco Systems, Inc. All rights reserved.
14+
dnl Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
15+
dnl Copyright (c) 2014 Intel, Inc. All rights reserved.
16+
dnl Copyright (c) 2015-2018 Research Organization for Information Science
17+
dnl and Technology (RIST). All rights reserved.
18+
dnl $COPYRIGHT$
19+
dnl
20+
dnl Additional copyrights may follow
21+
dnl
22+
dnl $HEADER$
23+
dnl
24+
25+
dnl OPAL_DECLARE_PACKAGE(name,[help],[cppflagshelp],[ldflagshelp])
26+
AC_DEFUN([OPAL_DECLARE_PACKAGE],[
27+
AC_ARG_WITH([$1], [AC_HELP_STRING([--with-$1=DIR], [$2])])
28+
AC_ARG_WITH([$1-cppflags], [AC_HELP_STRING([--with-$1-cppflags=FLAGS], [$3])])
29+
AC_ARG_WITH([$1-ldflags], [AC_HELP_STRING([--with-$1-ldflags=FLAGS], [$4])])
30+
AC_ARG_WITH([$1-libdir], [AC_HELP_STRING([--with-$1-libdir=DIR],
31+
[Deprecated, use --with-$1-ldflags instead])])
32+
AS_IF([test -n "$with_$1_libdir"],
33+
[AS_IF([test -n "$with_$1_ldflags"],
34+
[AC_MSG_WARN([It is not possible to use both --with-$1-ldflags and --with-$1-libdir])
35+
AC_MSG_ERROR([Cannot continue])],
36+
[AC_MSG_WARN([--with_$1_libdir=DIR is deprecated, use --with-$1_ldflags=FLAGS instead])
37+
with_$1_ldflags="-L$with_$1_libdir"])])
38+
])
39+
40+
dnl --------------------------------------------------------------------
41+
dnl _OPAL_CHECK_PACKAGE2_HEADER(prefix, header, cppflags,
42+
dnl [action-if-found], [action-if-not-found],
43+
dnl includes)
44+
dnl --------------------------------------------------------------------
45+
AC_DEFUN([_OPAL_CHECK_PACKAGE2_HEADER], [
46+
# This is stolen from autoconf to peek under the covers to get the
47+
# cache variable for the library check. one should not copy this
48+
# code into other places unless you want much pain and suffering
49+
AS_VAR_PUSHDEF([opal_Header], [ac_cv_header_$2])
50+
51+
# so this sucks, but there's no way to get through the progression
52+
# of header includes without killing off the cache variable and trying
53+
# again...
54+
unset opal_Header
55+
56+
# get rid of the trailing slash(es)
57+
opal_check_package_header_happy="no"
58+
AS_IF([test -z "$3"],
59+
[# try as is...
60+
AC_VERBOSE([looking for header])
61+
AC_CHECK_HEADERS([$2], [opal_check_package_header_happy="yes"], [])
62+
AS_IF([test "$opal_check_package_header_happy" = "no"],
63+
[# no go on the as is - reset the cache and try again
64+
unset opal_Header])],
65+
[$1_CPPFLAGS="$$1_CPPFLAGS $3"
66+
CPPFLAGS="$CPPFLAGS $3"
67+
#AC_CHECK_HEADERS([$2], [opal_check_package_header_happy="yes"], [], [$6])])
68+
69+
AS_IF([test "$opal_check_package_header_happy" = "yes"], [$4], [$5])
70+
unset opal_check_package_header_happy
71+
72+
AS_VAR_POPDEF([opal_Header])dnl
73+
])
74+
75+
76+
dnl _OPAL_CHECK_PACKAGE2_LIB(prefix, library, function, extra-libraries,
77+
dnl package,
78+
dnl [action-if-found], [action-if-not-found]])
79+
dnl --------------------------------------------------------------------
80+
AC_DEFUN([_OPAL_CHECK_PACKAGE2_LIB], [
81+
# This is stolen from autoconf to peek under the covers to get the
82+
# cache variable for the library check. one should not copy this
83+
# code into other places unless you want much pain and suffering
84+
AS_VAR_PUSHDEF([opal_Lib], [ac_cv_search_$3])
85+
86+
# see comment above
87+
unset opal_Lib
88+
opal_check_package_lib_happy="no"
89+
AS_IF([test -n "$with_$5_ldflags" || test -z "$with_$5" || test "$with_$5" = "yes"],
90+
[# ldflags was specified - use as is
91+
$1_LDFLAGS="$$1_LDFLAGS $with_$5_ldflags"
92+
LDFLAGS="$LDFLAGS $with_$5_ldflags"
93+
AS_IF([test -z "$with_$5_ldflags"],
94+
[AC_VERBOSE([looking for library without search path])])
95+
AC_SEARCH_LIBS([$3], [$2],
96+
[opal_check_package_lib_happy="yes"],
97+
[opal_check_package_lib_happy="no"], [$4])
98+
AS_IF([test "$opal_check_package_lib_happy" = "no"],
99+
[LDFLAGS="$opal_check_package_$1_save_LDFLAGS"
100+
$1_LDFLAGS="$opal_check_package_$1_orig_LDFLAGS"
101+
unset opal_Lib])],
102+
[AS_IF([test -d "$with_$5/lib"],
103+
[$1_LDFLAGS="$$1_LDFLAGS -L$with_$5/lib"
104+
LDFLAGS="$LDFLAGS -L$with_$5/lib"
105+
AC_VERBOSE([looking for library in lib])
106+
AC_SEARCH_LIBS([$3], [$2],
107+
[opal_check_package_lib_happy="yes"],
108+
[opal_check_package_lib_happy="no"], [$4])
109+
AS_IF([test "$opal_check_package_lib_happy" = "no"],
110+
[# no go on the as is.. see what happens later...
111+
LDFLAGS="$opal_check_package_$1_save_LDFLAGS"
112+
$1_LDFLAGS="$opal_check_package_$1_orig_LDFLAGS"
113+
unset opal_Lib])])
114+
115+
AS_IF([test "$opal_check_package_lib_happy" = "no" && test -d "$with_$5/lib64"],
116+
[$1_LDFLAGS="$$1_LDFLAGS -L$with_$5/lib64"
117+
LDFLAGS="$LDFLAGS -L$with_$5/lib64"
118+
AC_VERBOSE([looking for library in lib64])
119+
AC_SEARCH_LIBS([$3], [$2],
120+
[opal_check_package_lib_happy="yes"],
121+
[opal_check_package_lib_happy="no"], [$4])
122+
AS_IF([test "$opal_check_package_lib_happy" = "no"],
123+
[# no go on the as is.. see what happens later...
124+
LDFLAGS="$opal_check_package_$1_save_LDFLAGS"
125+
$1_LDFLAGS="$opal_check_package_$1_orig_LDFLAGS"
126+
unset opal_Lib])])])
127+
128+
AS_IF([test "$opal_check_package_lib_happy" = "yes"],
129+
[ # libnl v1 and libnl3 are known to *not* coexist
130+
# harmoniously in the same process. Check to see if this
131+
# new package will introduce such a conflict.
132+
OPAL_LIBNL_SANITY_CHECK([$2], [$3], [$$1_LIBS],
133+
[opal_check_package_libnl_check_ok])
134+
AS_IF([test $opal_check_package_libnl_check_ok -eq 0],
135+
[opal_check_package_lib_happy=no])
136+
])
137+
138+
AS_IF([test "$opal_check_package_lib_happy" = "yes"],
139+
[ # The result of AC SEARCH_LIBS is cached in $ac_cv_search_[function]
140+
AS_IF([test "$ac_cv_search_$3" != "no" &&
141+
test "$ac_cv_search_$3" != "none required"],
142+
[$1_LIBS="$ac_cv_search_$3 $4"],
143+
[$1_LIBS="$4"])
144+
$6],
145+
[$7])
146+
147+
AS_VAR_POPDEF([opal_Lib])dnl
148+
])
149+
150+
151+
dnl OPAL_CHECK_PACKAGE(prefix,
152+
dnl header,
153+
dnl library,
154+
dnl function,
155+
dnl extra-libraries,
156+
dnl package,
157+
dnl [action-if-found], [action-if-not-found],
158+
dnl includes)
159+
dnl -----------------------------------------------------------
160+
dnl Check for package defined by header and libs, and probably
161+
dnl located in dir-prefix, possibly with libs in libdir-prefix.
162+
dnl Both dir-prefix and libdir-prefix can be empty. Will set
163+
dnl prefix_{CPPFLAGS, LDFLAGS, LIBS} as needed.
164+
dnl
165+
dnl The general intent of this macro is to provide finer-grained scoping
166+
dnl of C preprocessor flags, linker flags, and libraries (as opposed to
167+
dnl unconditionally adding to the top-level CPFLAGS, LDFLAGS, and LIBS,
168+
dnl which get used to compile/link *everything*).
169+
dnl
170+
dnl Here is a breakdown of the parameters:
171+
dnl
172+
dnl * prefix: the macro sets $prefix_CPPFLAGS, $prefix_LDFLAGS, and
173+
dnl $prefix_LIBS (and AC_SUBSTs all of them). For example, if a
174+
dnl provider uses this macro to check for a header/library that it
175+
dnl needs, it might well set prefix to be its provider name.
176+
dnl * header_filename: the foo.h file to check for
177+
dnl * library_name / function_name: check for function function_name in
178+
dnl -llibrary_name. Specifically, for library_name, use the "foo" form,
179+
dnl as opposed to "libfoo".
180+
dnl * extra_libraries: if the library_name you are checking for requires
181+
dnl additonal -l arguments to link successfully, list them here.
182+
dnl * dir_prefix: if the header/library is located in a non-standard
183+
dnl location (e.g., /opt/foo as opposed to /usr), list it here
184+
dnl * libdir_prefix: if the library is not under $dir_prefix/lib or
185+
dnl $dir_prefix/lib64, list it here.
186+
dnl * action_if_found: if both the header and library are found and
187+
dnl usable, execute action_if_found
188+
dnl * action_if_not_found: otherwise, execute action_if_not_found
189+
dnl * extra_includes: if including header_filename requires additional
190+
dnl headers to be included first, list them here
191+
dnl
192+
dnl The output _CPPFLAGS, _LDFLAGS, and _LIBS can be used to limit the
193+
dnl scope various flags in Makefiles.
194+
dnl
195+
AC_DEFUN([OPAL_CHECK_PACKAGE2],[
196+
OPAL_VAR_SCOPE_PUSH([opal_check_package2_happy opal_check_package2_cppflags opal_check_package_$1_save_CPPFLAGS opal_check_package_$1_save_LDFLAGS opal_check_package_$1_save_LIBS opal_check_package_$1_orig_CPPFLAGS opal_check_package_$1_orig_LDFLAGS opal_check_package_$1_orig_LIBS])
197+
opal_check_package_$1_save_CPPFLAGS="$CPPFLAGS"
198+
opal_check_package_$1_save_LDFLAGS="$LDFLAGS"
199+
opal_check_package_$1_save_LIBS="$LIBS"
200+
201+
opal_check_package_$1_orig_CPPFLAGS="$$1_CPPFLAGS"
202+
opal_check_package_$1_orig_LDFLAGS="$$1_LDFLAGS"
203+
opal_check_package_$1_orig_LIBS="$$1_LIBS"
204+
205+
AS_IF([test "$with_$6" != "no"],
206+
[AS_IF([test -n "$with_$6_cppflags" || test -z "$with_$6" || test "$with_$6" = "yes"],
207+
[opal_check_package2_cppflags=$with_$6_cppflags],
208+
[AS_IF([test -n "$with_$6"],
209+
[AS_IF([test -r "$with_$6/$2"],
210+
[opal_check_package2_cppflags="-I$with_$6"],
211+
[AS_IF([test -r "$with_$6/include/$2"],
212+
[opal_check_package2_cppflags="-I$with_$6/include"],
213+
[opal_check_package2_happy=no])])])])
214+
215+
AS_IF([test "$opal_check_package2_happy" != "no"],
216+
[_OPAL_CHECK_PACKAGE2_HEADER([$1], [$2], [$opal_check_package2_cppflags],
217+
[_OPAL_CHECK_PACKAGE2_LIB([$1], [$3], [$4], [$5], [$6], [$8],
218+
[opal_check_package2_happy="yes"],
219+
[opal_check_package2_happy="no"])],
220+
[opal_check_package2_happy=no],
221+
[$9])])])
222+
223+
AS_IF([test "$opal_check_package2_happy" = "yes"],
224+
[$7],
225+
[$1_CPPFLAGS="$opal_check_package_$1_orig_CPPFLAGS"
226+
$1_LDFLAGS="$opal_check_package_$1_orig_LDFLAGS"
227+
$1_LIBS="$opal_check_package_$1_orig_LIBS"
228+
AS_IF([test "$with_$6" != "no"],
229+
[$8])])
230+
231+
OPAL_VAR_SCOPE_POP
232+
233+
CPPFLAGS="$opal_check_package_$1_save_CPPFLAGS"
234+
LDFLAGS="$opal_check_package_$1_save_LDFLAGS"
235+
LIBS="$opal_check_package_$1_save_LIBS"
236+
])

config/opal_setup_zlib.m4

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2009-2015 Cisco Systems, Inc. All rights reserved.
44
# Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved.
55
# Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
6-
# Copyright (c) 2017 Research Organization for Information Science
6+
# Copyright (c) 2017-2018 Research Organization for Information Science
77
# and Technology (RIST). All rights reserved.
88
# $COPYRIGHT$
99
#
@@ -15,62 +15,25 @@
1515
# MCA_zlib_CONFIG([action-if-found], [action-if-not-found])
1616
# --------------------------------------------------------------------
1717
AC_DEFUN([OPAL_ZLIB_CONFIG],[
18-
OPAL_VAR_SCOPE_PUSH([opal_zlib_dir opal_zlib_libdir opal_zlib_standard_header_location opal_zlib_standard_lib_location])
1918

20-
AC_ARG_WITH([zlib],
21-
[AC_HELP_STRING([--with-zlib=DIR],
22-
[Search for zlib headers and libraries in DIR ])])
23-
24-
AC_ARG_WITH([zlib-libdir],
25-
[AC_HELP_STRING([--with-zlib-libdir=DIR],
26-
[Search for zlib libraries in DIR ])])
27-
28-
opal_zlib_support=0
29-
if test "$with_zlib" != "no"; then
30-
AC_MSG_CHECKING([for zlib in])
31-
if test ! -z "$with_zlib" && test "$with_zlib" != "yes"; then
32-
opal_zlib_dir=$with_zlib
33-
opal_zlib_standard_header_location=no
34-
opal_zlib_standard_lib_location=no
35-
AS_IF([test -z "$with_zlib_libdir" || test "$with_zlib_libdir" = "yes"],
36-
[if test -d $with_zlib/lib; then
37-
opal_zlib_libdir=$with_zlib/lib
38-
elif test -d $with_zlib/lib64; then
39-
opal_zlib_libdir=$with_zlib/lib64
40-
else
41-
AC_MSG_RESULT([Could not find $with_zlib/lib or $with_zlib/lib64])
42-
AC_MSG_ERROR([Can not continue])
43-
fi
44-
AC_MSG_RESULT([$opal_zlib_dir and $opal_zlib_libdir])],
45-
[AC_MSG_RESULT([$with_zlib_libdir])])
46-
else
47-
AC_MSG_RESULT([(default search paths)])
48-
opal_zlib_standard_header_location=yes
49-
opal_zlib_standard_lib_location=yes
50-
fi
51-
AS_IF([test ! -z "$with_zlib_libdir" && test "$with_zlib_libdir" != "yes"],
52-
[opal_zlib_libdir="$with_zlib_libdir"
53-
opal_zlib_standard_lib_location=no])
54-
55-
OPAL_CHECK_PACKAGE([opal_zlib],
56-
[zlib.h],
57-
[z],
58-
[deflate],
59-
[-lz],
60-
[$opal_zlib_dir],
61-
[$opal_zlib_libdir],
62-
[opal_zlib_support=1],
63-
[opal_zlib_support=0])
64-
if test $opal_zlib_support = "1"; then
65-
LIBS="$LIBS -lz"
66-
if test "$opal_zlib_standard_header_location" != "yes"; then
67-
CPPFLAGS="$CPPFLAGS $opal_zlib_CPPFLAGS"
68-
fi
69-
if test "$opal_zlib_standard_lib_location" != "yes"; then
70-
LDFLAGS="$LDFLAGS $opal_zlib_LDFLAGS"
71-
fi
72-
fi
73-
fi
19+
OPAL_DECLARE_PACKAGE([zlib],
20+
[Search for zlib headers and libraries in DIR],
21+
[Search for zlib headers with these CPPFLAGS],
22+
[Search for zlib library with these LDFLAGS])
23+
24+
OPAL_CHECK_PACKAGE2([opal_zlib],
25+
[zlib.h],
26+
[z],
27+
[deflate],
28+
[-lz],
29+
[zlib],
30+
[opal_zlib_support=1],
31+
[opal_zlib_support=0])
32+
33+
AS_IF([test $opal_zlib_support -eq 1],
34+
[LIBS="$LIBS -lz"
35+
CPPFLAGS="$CPPFLAGS $opal_zlib_CPPFLAGS"
36+
LDFLAGS="$LDFLAGS $opal_zlib_LDFLAGS"])
7437

7538
if test ! -z "$with_zlib" && test "$with_zlib" != "no" && test "$opal_zlib_support" != "1"; then
7639
AC_MSG_WARN([ZLIB SUPPORT REQUESTED AND NOT FOUND])
@@ -86,5 +49,5 @@ AC_DEFUN([OPAL_ZLIB_CONFIG],[
8649

8750
AC_DEFINE_UNQUOTED([OPAL_HAVE_ZLIB], [$opal_zlib_support],
8851
[Whether or not we have zlib support])
89-
OPAL_VAR_SCOPE_POP
52+
9053
])dnl

0 commit comments

Comments
 (0)