Newer
Older
dnl -*- autoconf -*-
# Macros needed to find dumux and dependent libraries. They are called by
# the macros in ${top_src_dir}/dependencies.m4, which is generated by
# "dunecontrol autogen"
# Additional checks needed to build dumux
# This macro should be invoked by every module which depends on dumux, as
# well as by dumux itself
AC_DEFUN([DUMUX_CHECKS])

Andreas Lauser
committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# DUMUX_CHECK_MODULES(NAME, HEADER, SYMBOL)
#
# THIS IS JUST A COPY OF THE DUNE_CHECK_MODULES MACRO WITH THE REQUIREMENT THAT
# THE HEADER RESIDES IN THE 'dune' SUB-DIRECTORY REMOVED!
#
# Generic check for dune modules. This macro should not be used directly, but
# in the modules m4/{module}.m4 in the {MODULE}_CHECK_MODULE macro. The
# {MODULE}_CHECK_MODULE macro knows the parameters to call this
# DUNE_CHECK_MODULES macro with, and it does not take any parameters itself,
# so it may be used with AC_REQUIRE.
#
# NAME Name of the module, lowercase with dashes (like "dune-common"). The
# value must be known when autoconf runs, so shell variables in the
# value are not permissible.
#
# HEADER Header to check for. The check will really be for <{HEADER}>,
# so the header must reside within a directory called "dune".
#
# SYMBOL Symbol to check for in the module's library. If this argument is
# empty or missing, it is assumed that the module does not provide a
# library. The value must be known when autoconf runs, so shell
# variables in the value are not permissible. This value is actually
# handed to AC_TRY_LINK unchanged as the FUNCTION-BODY argument, so it
# may contain more complex stuff than a simple symbol.
#
# The name of the library is assumed to be the same as the module name,
# with any occurance of "-" removed. The path of the library is
# obtained from pkgconfig for installed modules, or assumed to be the
# directory "lib" within the modules root for non-installed modules.
#
# In the following, {module} is {NAME} with any "-" replaced by "_" and
# {MODULE} is the uppercase version of {module}.
#
# configure options:
# --with-{NAME}
#
# configure/shell variables:
# {MODULE}_ROOT, {MODULE}_LIBDIR
# HAVE_{MODULE} (1 or 0)
# with_{module} ("yes" or "no")
# DUNE_CPPFLAGS, DUNE_LDFLAGS, DUNE_LIBS (adds the modules values here,
# substitution done by DUNE_CHECK_ALL)
# ALL_PKG_CPPFLAGS, ALL_PKG_LDFLAGS, ALL_PKG_LIBS (adds the modules values
# here, substitution done by DUNE_CHECK_ALL)
# DUNE_PKG_CPPFLAGS, DUNE_PKG_LDFLAGS, DUNE_PKG_LIBS (deprecated, adds the
# modules values here)
# {MODULE}_VERSION
# {MODULE}_VERSION_MAJOR
# {MODULE}_VERSION_MINOR
# {MODULE}_VERSION_REVISION
#
# configure substitutions/makefile variables:
# {MODULE}_CPPFLAGS, {MODULE}_LDFLAGS, {MODULE}_LIBS
# {MODULE}_ROOT
# {MODULE}_LIBDIR (only if modules provides a library)
#
# preprocessor defines:
# HAVE_{MODULE} (1 or undefined)
# {MODULE}_VERSION
# {MODULE}_VERSION_MAJOR
# {MODULE}_VERSION_MINOR
# {MODULE}_VERSION_REVISION
#
# automake conditionals:
# HAVE_{MODULE}
AC_DEFUN([DUMUX_CHECK_MODULES],[
AC_REQUIRE([AC_PROG_CXX])
AC_REQUIRE([AC_PROG_CXXCPP])
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
AC_REQUIRE([DUNE_DISABLE_LIBCHECK])
AC_REQUIRE([LT_OUTPUT])
# ____DUNE_CHECK_MODULES_____ ($1)
m4_pushdef([_dune_name], [$1])
m4_pushdef([_dune_module], [m4_translit(_dune_name, [-], [_])])
m4_pushdef([_dune_header], [$2])
m4_pushdef([_dune_ldpath], [lib])
m4_pushdef([_dune_lib], [m4_translit(_dune_name, [-], [])])
m4_pushdef([_dune_symbol], [$3])
m4_pushdef([_DUNE_MODULE], [m4_toupper(_dune_module)])
# switch tests to c++
AC_LANG_PUSH([C++])
# the usual option...
AC_ARG_WITH(_dune_name,
AS_HELP_STRING([--with-_dune_name=PATH],[_dune_module directory]))
# backup of flags
ac_save_CPPFLAGS="$CPPFLAGS"
ac_save_LIBS="$LIBS"
ac_save_LDFLAGS="$LDFLAGS"
CPPFLAGS=""
LIBS=""
##
## Where is the module $1?
##
AC_MSG_CHECKING([for $1 installation or source tree])
# is a directory set?
AS_IF([test -z "$with_[]_dune_module"],[
#
# search module $1 via pkg-config
#
with_[]_dune_module="global installation"
AS_IF([test -z "$PKG_CONFIG"],[
AC_MSG_RESULT([failed])
AC_MSG_NOTICE([could not search for module _dune_name])
AC_MSG_ERROR([pkg-config is required for using installed modules])
])
AS_IF(AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]),[
_dune_cm_CPPFLAGS="`$PKG_CONFIG --cflags _dune_name`" 2>/dev/null
_DUNE_MODULE[]_ROOT="`$PKG_CONFIG --variable=prefix _dune_name`" 2>/dev/null
_DUNE_MODULE[]_VERSION="`$PKG_CONFIG --modversion _dune_name`" 2>/dev/null
_dune_cm_LDFLAGS=""
ifelse(_dune_symbol,,
[_DUNE_MODULE[]_LIBDIR=""
_dune_cm_LIBS=""],
[_DUNE_MODULE[]_LIBDIR=`$PKG_CONFIG --variable=libdir _dune_name 2>/dev/null`
_dune_cm_LIBS="-L$_DUNE_MODULE[]_LIBDIR -l[]_dune_lib"])
HAVE_[]_DUNE_MODULE=1
AC_MSG_RESULT([global installation in $_DUNE_MODULE[]_ROOT])
],[
HAVE_[]_DUNE_MODULE=0
AC_MSG_RESULT([not found])
])
],[
#
# path for module $1 is specified via command line
#
AS_IF([test -d "$with_[]_dune_module"],[
# expand tilde / other stuff
_DUNE_MODULE[]_ROOT=`cd $with_[]_dune_module && pwd`
# expand search path (otherwise empty CPPFLAGS)
AS_IF([test -d "$_DUNE_MODULE[]_ROOT/include/dune"],[
# Dune was installed into directory given by with-dunecommon
_dune_cm_CPPFLAGS="-I$_DUNE_MODULE[]_ROOT/include"
_DUNE_MODULE[]_BUILDDIR=_DUNE_MODULE[]_ROOT
_DUNE_MODULE[]_VERSION="`PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$_DUNE_MODULE[]_ROOT/lib/pkgconfig $PKG_CONFIG --modversion _dune_name`" 2>/dev/null
],[
_DUNE_MODULE[]_SRCDIR=$_DUNE_MODULE[]_ROOT
# extract src and build path from Makefile, if found
AS_IF([test -f $_DUNE_MODULE[]_ROOT/Makefile],[
_DUNE_MODULE[]_SRCDIR="`sed -ne '/^abs_top_srcdir = /{s/^abs_top_srcdir = //; p;}' $_DUNE_MODULE[]_ROOT/Makefile`"
])
_dune_cm_CPPFLAGS="-I$_DUNE_MODULE[]_SRCDIR"
_DUNE_MODULE[]_VERSION="`grep Version $_DUNE_MODULE[]_SRCDIR/dune.module | sed -e 's/^Version: *//'`" 2>/dev/null
])
_dune_cm_LDFLAGS=""
ifelse(_dune_symbol,,
[_DUNE_MODULE[]_LIBDIR=""
_dune_cm_LIBS=""],
[_DUNE_MODULE[]_LIBDIR="$_DUNE_MODULE[]_ROOT/lib"
_dune_cm_LIBS="-L$_DUNE_MODULE[]_LIBDIR -l[]_dune_lib"])
# set expanded module path
with_[]_dune_module="$_DUNE_MODULE[]_ROOT"
HAVE_[]_DUNE_MODULE=1
AC_MSG_RESULT([found in $_DUNE_MODULE[]_ROOT])
],[
HAVE_[]_DUNE_MODULE=0
AC_MSG_RESULT([not found])
AC_MSG_ERROR([_dune_name-directory $with_[]_dune_module does not exist])
])
])
CPPFLAGS="$ac_save_CPPFLAGS $DUNE_CPPFLAGS $_dune_cm_CPPFLAGS"
##
## check for an arbitrary header
##
AC_CHECK_HEADER([_dune_header],
[HAVE_[]_DUNE_MODULE=1],
[HAVE_[]_DUNE_MODULE=0
AS_IF([test -n "$_DUNE_MODULE[]_ROOT"],[
AC_MSG_WARN([$_DUNE_MODULE[]_ROOT does not seem to contain a valid _dune_name (_dune_header not found)])
])
]
)
##
## check for lib (if lib name was provided)
##
ifelse(_dune_symbol,,
AC_MSG_NOTICE([_dune_name does not provide libs]),
AS_IF([test "x$enable_dunelibcheck" = "xno"],[
AC_MSG_WARN([library check for _dune_name is disabled. DANGEROUS!])
],[
AS_IF([test "x$HAVE_[]_DUNE_MODULE" = "x1"],[
# save current LDFLAGS
ac_save_CXX="$CXX"
HAVE_[]_DUNE_MODULE=0
# define LTCXXLINK like it will be defined in the Makefile
CXX="./libtool --tag=CXX --mode=link $ac_save_CXX"
# use module LDFLAGS
LDFLAGS="$ac_save_LDFLAGS $DUNE_LDFLAGS $DUNE_PKG_LDFLAGS $_dune_cm_LDFLAGS"
LIBS="$_dune_cm_LIBS $DUNE_LIBS $LIBS"
AC_MSG_CHECKING([for lib[]_dune_lib])
AC_TRY_LINK(dnl
[#]include<_dune_header>,
_dune_symbol,
[
AC_MSG_RESULT([yes])
HAVE_[]_DUNE_MODULE=1
],[
AC_MSG_RESULT([no])
HAVE_[]_DUNE_MODULE=0
AS_IF([test -n "$_DUNE_MODULE[]_ROOT"],[
AC_MSG_WARN([$with_[]_dune_module does not seem to contain a valid _dune_name (failed to link with lib[]_dune_lib[].la)])
])
]
)
])
# reset variables
CXX="$ac_save_CXX"
])
)
# did we succeed?
AS_IF([test "x$HAVE_[]_DUNE_MODULE" = "x1"],[
# add the module's own flags and libs to the modules and the global
# variables
DUNE_ADD_MODULE_DEPS(m4_defn([_dune_name]), m4_defn([_dune_name]),
[$_dune_cm_CPPFLAGS], [$_dune_cm_LDFLAGS], [$_dune_cm_LIBS])
# set variables for our modules
AC_SUBST(_DUNE_MODULE[]_CPPFLAGS, "$_DUNE_MODULE[]_CPPFLAGS")
AC_SUBST(_DUNE_MODULE[]_LDFLAGS, "$_DUNE_MODULE[]_LDFLAGS")
AC_SUBST(_DUNE_MODULE[]_LIBS, "$_DUNE_MODULE[]_LIBS")
AC_SUBST(_DUNE_MODULE[]_ROOT, "$_DUNE_MODULE[]_ROOT")
ifelse(m4_defn([_dune_symbol]),,
[],
[AC_SUBST(_DUNE_MODULE[]_LIBDIR)
])
AC_DEFINE(HAVE_[]_DUNE_MODULE, 1, [Define to 1 if] _dune_name [was found])
DUNE_PARSE_MODULE_VERSION(_dune_name, $_DUNE_MODULE[]_VERSION)
# set DUNE_* variables
# This should actually be unneccesary, but I'm keeping it in here for now
# for backward compatibility
DUNE_LDFLAGS="$DUNE_LDFLAGS $_DUNE_MODULE[]_LDFLAGS"
DUNE_LIBS="$_DUNE_MODULE[]_LIBS $DUNE_LIBS"
# add to global list
# only add my flags other flags are added by other packages
DUNE_PKG_CPPFLAGS="$DUNE_PKG_CPPFLAGS $_DUNE_MODULE[]_CPPFLAGS"
DUNE_PKG_LIBS="$DUNE_PKG_LIBS $LIBS"
DUNE_PKG_LDFLAGS="$DUNE_PKG_LDFLAGS $_DUNE_MODULE[]_LDFLAGS"
with_[]_dune_module="yes"
],[
with_[]_dune_module="no"
])
AM_CONDITIONAL(HAVE_[]_DUNE_MODULE, test x$HAVE_[]_DUNE_MODULE = x1)
# reset previous flags
CPPFLAGS="$ac_save_CPPFLAGS"
LDFLAGS="$ac_save_LDFLAGS"
LIBS="$ac_save_LIBS"
# add this module to DUNE_SUMMARY
DUNE_MODULE_ADD_SUMMARY_ENTRY(_dune_name)
# remove local variables
m4_popdef([_dune_name])
m4_popdef([_dune_module])
m4_popdef([_dune_header])
m4_popdef([_dune_ldpath])
m4_popdef([_dune_lib])
m4_popdef([_dune_symbol])
m4_popdef([_DUNE_MODULE])
# restore previous language settings (leave C++)
AC_LANG_POP([C++])
])
# Additional checks needed to find dumux
# This macro should be invoked by every module which depends on dumux, but
# not by dumux itself
AC_DEFUN([DUMUX_CHECK_MODULE],
[

Andreas Lauser
committed
DUMUX_CHECK_MODULES([dumux],[dumux/common/exceptions.hh])