1#							-*- Autoconf -*-
2# This file is part of the aMule Project.
3#
4# Copyright (c) 2015 aMule Team ( admin@amule.org / http://www.amule.org )
5#
6# Any parts of this program derived from the xMule, lMule or eMule project,
7# or contributed by third-party developers are copyrighted by their
8# respective authors.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
23#
24
25# -----------------------------------------------------------------------------
26# Fake libtool initialization just for Boost
27#
28# We do not really want to use libtool, but Boost requires it. Let's just
29# pretend we did initialize libtool for that single variable ($libext) Boost
30# needs.
31# -----------------------------------------------------------------------------
32m4_defun([_FAKE_LT_INIT],
33[# Calculate cc_basename. Skip known compiler wrappers and cross-prefix.
34for cc_temp in $compiler""; do
35  case $cc_temp in
36    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
37    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
38    \-*) ;;
39    *) break;;
40 esac
41done
42cc_basename=`echo "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"`
43# All known linkers require a `.a' archive for static linking (except MSVC,
44# which needs '.lib').
45libext=a
46case $cc_basename in
47  cl*) libext=lib ;;
48esac
49])
50
51# -----------------------------------------------------------------------------
52# MULE_CHECK_BOOST(MINIMUM-BOOST-VERSION)
53#
54# Adds a configure flag --with-boost[=DIR]. You may optionally specify the
55# location of boost headers (or sources), if they are in a non-standard
56# location. If --with-boost if not given, nothing is done. Otherwise it
57# checks for the required minumum Boost version, and Boost.Asio. If everything
58# is fine, defines ASIO_SOCKETS. If the Boost sources are found, also defines
59# HAVE_BOOST_SOURCES. Other flags defined for using Boost:
60#   - BOOST_CPPFLAGS
61#   - BOOST_SYSTEM_LDFLAGS
62#   - BOOST_SYSTEM_LIBS
63# -----------------------------------------------------------------------------
64AC_DEFUN([MULE_CHECK_BOOST],
65[
66	AC_ARG_WITH([boost],
67		[AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use Boost.Asio for networking])],
68		,
69		[with_boost=no]
70	)
71	AS_IF([test ${with_boost:-no} != no], [
72		BOOST_REQUIRE([$1], [with_boost=disabled])
73		AS_IF([test ${with_boost:-no} != disabled], [
74dnl Boost requires libtool. We don't.
75			_FAKE_LT_INIT
76dnl Expand required macros here, otherwise autoconf may decide to expand them at
77dnl the top level, which is highly unwanted and would mess up Boost detection.
78			_BOOST_FIND_COMPILER_TAG
79			BOOST_STATIC
80			_BOOST_GUESS_WHETHER_TO_USE_MT
81			AC_MSG_CHECKING([for Boost sources])
82			MULE_BACKUP([CPPFLAGS])
83			MULE_APPEND([CPPFLAGS], [$BOOST_CPPFLAGS])
84			AC_COMPILE_IFELSE([
85				AC_LANG_PROGRAM([[#include <boost/../libs/system/src/error_code.cpp>]])
86			], [
87				AC_DEFINE([HAVE_BOOST_SOURCES], [1], [Define to 1 if you have the Boost sources])
88				AC_MSG_RESULT([yes])
89			], [
90				AC_MSG_RESULT([no])
91				BOOST_SYSTEM([mt])
92				AS_IF([test ${boost_cv_lib_system:-no} != yes], [
93					MULE_WARNING([Boost support has been disabled because Boost.System not found])
94					with_boost=disabled
95				])
96			])
97			MULE_RESTORE([CPPFLAGS])
98dnl Not using BOOST_ASIO here, because it doesn't have ACTION-IF[-NOT]-FOUND parameters.
99			BOOST_FIND_HEADER([boost/asio.hpp], [
100				MULE_WARNING([Boost support has been disabled because Boost.Asio not found])
101				with_boost=disabled
102			], [AC_DEFINE([ASIO_SOCKETS], [1], [Define to 1 if you have <boost/asio.hpp> and are using Boost.Asio for networking.])])
103		], [MULE_WARNING([Boost support has been disabled because of insufficient Boost version.])])
104	])
105])
106