1# ===========================================================================
2#      https://www.gnu.org/software/autoconf-archive/ax_boost_regex.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_BOOST_REGEX
8#
9# DESCRIPTION
10#
11#   Test for Regex library from the Boost C++ libraries. The macro requires
12#   a preceding call to AX_BOOST_BASE. Further documentation is available at
13#   <http://randspringer.de/boost/index.html>.
14#
15#   This macro calls:
16#
17#     AC_SUBST(BOOST_REGEX_LIB)
18#
19#   And sets:
20#
21#     HAVE_BOOST_REGEX
22#
23# LICENSE
24#
25#   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
26#   Copyright (c) 2008 Michael Tindal
27#
28#   Copying and distribution of this file, with or without modification, are
29#   permitted in any medium without royalty provided the copyright notice
30#   and this notice are preserved. This file is offered as-is, without any
31#   warranty.
32
33#serial 23
34
35AC_DEFUN([AX_BOOST_REGEX],
36[
37	AC_ARG_WITH([boost-regex],
38	AS_HELP_STRING([--with-boost-regex@<:@=special-lib@:>@],
39                   [use the Regex library from boost - it is possible to specify a certain library for the linker
40                        e.g. --with-boost-regex=boost_regex-gcc-mt-d-1_33_1 ]),
41        [
42        if test "$withval" = "no"; then
43			want_boost="no"
44        elif test "$withval" = "yes"; then
45            want_boost="yes"
46            ax_boost_user_regex_lib=""
47        else
48		    want_boost="yes"
49		ax_boost_user_regex_lib="$withval"
50		fi
51        ],
52        [want_boost="yes"]
53	)
54
55	if test "x$want_boost" = "xyes"; then
56        AC_REQUIRE([AC_PROG_CC])
57		CPPFLAGS_SAVED="$CPPFLAGS"
58		CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
59		export CPPFLAGS
60
61		LDFLAGS_SAVED="$LDFLAGS"
62		LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
63		export LDFLAGS
64
65        AC_CACHE_CHECK(whether the Boost::Regex library is available,
66					   ax_cv_boost_regex,
67        [AC_LANG_PUSH([C++])
68			 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/regex.hpp>
69												]],
70                                   [[boost::regex r(); return 0;]])],
71                   ax_cv_boost_regex=yes, ax_cv_boost_regex=no)
72         AC_LANG_POP([C++])
73		])
74		if test "x$ax_cv_boost_regex" = "xyes"; then
75			AC_DEFINE(HAVE_BOOST_REGEX,,[define if the Boost::Regex library is available])
76            BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
77            if test "x$ax_boost_user_regex_lib" = "x"; then
78                for libextension in `ls $BOOSTLIBDIR/libboost_regex*.so* $BOOSTLIBDIR/libboost_regex*.dylib* $BOOSTLIBDIR/libboost_regex*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_regex.*\)\.so.*$;\1;' -e 's;^lib\(boost_regex.*\)\.dylib.*;\1;' -e 's;^lib\(boost_regex.*\)\.a.*$;\1;'` ; do
79                     ax_lib=${libextension}
80				    AC_CHECK_LIB($ax_lib, exit,
81                                 [BOOST_REGEX_LIB="-l$ax_lib"; AC_SUBST(BOOST_REGEX_LIB) link_regex="yes"; break],
82                                 [link_regex="no"])
83				done
84                if test "x$link_regex" != "xyes"; then
85                for libextension in `ls $BOOSTLIBDIR/boost_regex*.dll* $BOOSTLIBDIR/boost_regex*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_regex.*\)\.dll.*$;\1;' -e 's;^\(boost_regex.*\)\.a.*$;\1;'` ; do
86                     ax_lib=${libextension}
87				    AC_CHECK_LIB($ax_lib, exit,
88                                 [BOOST_REGEX_LIB="-l$ax_lib"; AC_SUBST(BOOST_REGEX_LIB) link_regex="yes"; break],
89                                 [link_regex="no"])
90				done
91                fi
92
93            else
94               for ax_lib in $ax_boost_user_regex_lib boost_regex-$ax_boost_user_regex_lib; do
95				      AC_CHECK_LIB($ax_lib, main,
96                                   [BOOST_REGEX_LIB="-l$ax_lib"; AC_SUBST(BOOST_REGEX_LIB) link_regex="yes"; break],
97                                   [link_regex="no"])
98               done
99            fi
100            if test "x$ax_lib" = "x"; then
101                AC_MSG_ERROR(Could not find a version of the Boost::Regex library!)
102            fi
103			if test "x$link_regex" != "xyes"; then
104				AC_MSG_ERROR(Could not link against $ax_lib !)
105			fi
106		fi
107
108		CPPFLAGS="$CPPFLAGS_SAVED"
109	LDFLAGS="$LDFLAGS_SAVED"
110	fi
111])
112