Merge branch 'master' into mfriedrich/compatido

This commit is contained in:
Michael Friedrich 2012-09-27 15:10:04 +02:00
commit ea9309096c
25 changed files with 218 additions and 307 deletions

View File

@ -30,6 +30,26 @@ fi
DIE=1
}
(grep "^AC_PROG_LEX" $srcdir/configure.ac >/dev/null) && {
(lex --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`lex' installed."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball for flex at http://flex.sourceforge.net/"
DIE=1
}
}
(grep "^AC_PROG_YACC" $srcdir/configure.ac >/dev/null) && {
(yacc --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`yacc' installed."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball for bison at http://ftp.gnu.org/gnu/bison/"
DIE=1
}
}
(grep "^IT_PROG_INTLTOOL" $srcdir/configure.ac >/dev/null) && {
(intltoolize --version) < /dev/null > /dev/null 2>&1 || {
echo

View File

@ -47,7 +47,7 @@ DX_PS_FEATURE(OFF)
DX_INIT_DOXYGEN([icinga], [docs/Doxyfile], [docs/dev])
AC_PROG_INSTALL
AM_PROG_LEX
AC_PROG_LEX
AC_PROG_YACC
AC_PROG_LIBTOOL
AX_CXX_GCC_ABI_DEMANGLE
@ -64,6 +64,7 @@ AC_CHECK_LIB(m, floor)
AC_CHECK_LIB(socket, getsockname)
AC_CHECK_LIB(ws2_32, getsockname)
AC_CHECK_LIB(shlwapi, PathRemoveFileSpecA)
AC_CHECK_FUNCS([backtrace_symbols])
AC_CONFIG_FILES([
Makefile

View File

@ -3,7 +3,7 @@
SUBDIRS = \
config
bin_PROGRAMS = \
sbin_PROGRAMS = \
icinga2
icinga2_SOURCES = \
@ -17,10 +17,12 @@ icinga2_CPPFLAGS = \
-I${top_srcdir}/lib/config \
-I${top_srcdir}/lib/remoting \
-I${top_srcdir}/lib/icinga \
-I${top_srcdir}
-I${top_srcdir} \
-DICINGA_LIBDIR="\"$(pkglibdir)\""
icinga2_LDFLAGS = \
$(BOOST_LDFLAGS)
$(BOOST_LDFLAGS) \
-export-dynamic
icinga2_LDADD = \
$(LIBLTDL) \

View File

@ -1,10 +1,5 @@
icinga2confdir = $(sysconfdir)/icinga2
icinga2conf_DATA = \
icinga2.conf.dist \
example-ca.crt \
example-ca.key \
icinga-c1.pem \
icinga-c2.pem \
icinga-c3.pem
icinga2.conf.dist
EXTRA_DIST = $(icinga2conf_DATA)

View File

@ -1,17 +0,0 @@
-----BEGIN CERTIFICATE-----
MIICnjCCAgegAwIBAgIJAOP3gULX9+xgMA0GCSqGSIb3DQEBBQUAMGgxCzAJBgNV
BAYTAkRFMRAwDgYDVQQIDAdCYXZhcmlhMRIwEAYDVQQHDAlOdXJlbWJlcmcxFTAT
BgNVBAoMDE5FVFdBWVMgR21iSDEcMBoGA1UEAwwTSWNpbmdhIFNuYWtlIE9pbCBD
QTAeFw0xMjA0MjQxMTQyMzFaFw0yMjA0MjIxMTQyMzFaMGgxCzAJBgNVBAYTAkRF
MRAwDgYDVQQIDAdCYXZhcmlhMRIwEAYDVQQHDAlOdXJlbWJlcmcxFTATBgNVBAoM
DE5FVFdBWVMgR21iSDEcMBoGA1UEAwwTSWNpbmdhIFNuYWtlIE9pbCBDQTCBnzAN
BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyxlEqY9AcY0YwpMIsirzy/6o9M29LRa4
ziHURLugpyTKugtAkS5c2Gyt9lf7gdZBcVZ8KD6cszanQqKlZrl0h74E/S13tDqM
rhR4DHeZssstn5LNK57WYx/vw84bmd6Yq6SeP4geq0JfO+y3Ruu+eePtQSOSzS9F
wGpKyAHo4AcCAwEAAaNQME4wHQYDVR0OBBYEFNVJHVPJNwqEcG51lpqZJWVPaysF
MB8GA1UdIwQYMBaAFNVJHVPJNwqEcG51lpqZJWVPaysFMAwGA1UdEwQFMAMBAf8w
DQYJKoZIhvcNAQEFBQADgYEAA1CMZgzQuQAslZ/i6OpFmRzuT/0KAfd6s8n6rf+6
xRvbgLlop8b8XfhhC/IwwoHU0i86o3vV3ZJjEVcdwTDEwpnyCfhFjhXzNZFqL8Ak
Olqy5HFd/+xysTLbdmhHtBIdOeUK1qz/u9I14A71XWiknjcxHya2Ghxg4yIZVdKh
oTQ=
-----END CERTIFICATE-----

View File

@ -1,16 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMsZRKmPQHGNGMKT
CLIq88v+qPTNvS0WuM4h1ES7oKckyroLQJEuXNhsrfZX+4HWQXFWfCg+nLM2p0Ki
pWa5dIe+BP0td7Q6jK4UeAx3mbLLLZ+SzSue1mMf78POG5nemKuknj+IHqtCXzvs
t0brvnnj7UEjks0vRcBqSsgB6OAHAgMBAAECgYBg4Ku06cUGpRQjc/lY604hh1bW
dvD++fCrOs3C/3DRaaZd+hIRbnkRLz4H3M32j9nlkyhkFgGvJqnACk81Yc8oOu86
Pm7bOdEj8v31qq943NCps5tdKHepXM0Z6A8GjaR2ias39NKxVDacBoFzSDAVArTL
p6dyqLjsW5Y3INeHmQJBAPB6w9iqa31GLXMEMeP5LA4+2p3aHPQ25ptMCUcp/Vc6
40GOSIlLb8rfE+q1ZacChv94jSNLybR+U9++8DLIxnMCQQDYNORSo57mVSebDr7e
Gx8BDbyC+yAgiAi+qfJRekQ0I+R1SxfkCIBSWNrQ944isn0eRcr7+BWVl/WOrVSk
vccdAkBEwbURU9ib3t7Lzd0941ZXVF1JWL2CjdftexYEBNtsf2fOrJHMv4bdKF8X
cnn4AF782EjyWI75Tk1I4dzniERFAkBKZ9lzvy9+ISwiJq71DOxclnebtATYbThl
NWNZOvSh5QBIhXFRXsOak02qwKc/taFte6Nhl30GIGe3lFse3tjZAkBguOZFeSOO
hIAxMD+QpDUHZRYEjhDtPn3oAkLgBNUdeajffLdt4SmRa26t4QnSAE8kkbadIm6A
z52CJc8G2ALA
-----END PRIVATE KEY-----

View File

@ -1,33 +0,0 @@
-----BEGIN CERTIFICATE-----
MIICtzCCA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Po9uzRrOfjgTDYLuh3MD8EKNs0M6l15UqbQ
nfBBE0oIPH4j+K++7xWUQ7vbiyBc7C7H3NZeE6xqfS0=
-----END RSA PRIVATE KEY-----

View File

@ -18,6 +18,9 @@
******************************************************************************/
#include <i2-icinga.h>
#ifdef HAVE_BACKTRACE_SYMBOLS
# include <execinfo.h>
#endif /* HAVE_BACKTRACE_SYMBOLS */
#ifndef _WIN32
# include "icinga-version.h"
@ -28,6 +31,65 @@
using namespace icinga;
/**
* Handler for unhandled exceptions.
*
*/
static void exception_handler(void)
{
static bool rethrow = true;
try {
rethrow = false;
throw;
} catch (const std::exception& ex) {
std::cerr << std::endl;
std::cerr << "Unhandled exception of type "
<< Utility::GetTypeName(typeid(ex))
<< std::endl;
std::cerr << "Diagnostic Information: "
<< ex.what()
<< std::endl;
}
#ifdef HAVE_BACKTRACE_SYMBOLS
void *frames[50];
int framecount = backtrace(frames, sizeof(frames) / sizeof(frames[0]));
char **messages = backtrace_symbols(frames, framecount);
std::cerr << std::endl << "Stacktrace:" << std::endl;
for (int i = 0; i < framecount && messages != NULL; ++i) {
String message = messages[i];
char *sym_begin = strchr(messages[i], '(');
if (sym_begin != NULL) {
char *sym_end = strchr(sym_begin, '+');
if (sym_end != NULL) {
String sym = String(sym_begin + 1, sym_end);
String sym_demangled = Utility::DemangleSymbolName(sym);
if (sym_demangled.IsEmpty())
sym_demangled = "<unknown function>";
message = String(messages[i], sym_begin) + ": " + sym_demangled + " (" + String(sym_end);
}
}
std::cerr << "\t(" << i << ") " << message << std::endl;
}
free(messages);
std::cerr << std::endl;
#endif /* HAVE_BACKTRACE_SYMBOLS */
abort();
}
/**
* Entry point for the Icinga application.
*
@ -37,6 +99,8 @@ using namespace icinga;
*/
int main(int argc, char **argv)
{
std::set_terminate(exception_handler);
#ifndef _WIN32
LTDL_SET_PRELOADED_SYMBOLS();
#endif /* _WIN32 */
@ -66,20 +130,29 @@ int main(int argc, char **argv)
Component::AddSearchDir(exeDirectory + "/../lib/icinga2");
Component::AddSearchDir(exeDirectory + "/../lib64/icinga2");
DynamicObject::BeginTx();
#ifdef ICINGA_LIBDIR
Component::AddSearchDir(ICINGA_LIBDIR);
#endif /* ICINGA_LIBDIR */
/* load config file */
String configFile = argv[2];
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
try {
DynamicObject::BeginTx();
Logger::Write(LogInformation, "icinga", "Executing config items...");
/* load config file */
String configFile = argv[2];
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
item->Commit();
Logger::Write(LogInformation, "icinga", "Executing config items...");
BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
item->Commit();
}
DynamicObject::FinishTx();
} catch (const exception& ex) {
Logger::Write(LogCritical, "icinga", "Configuration error: " + String(ex.what()));
return EXIT_FAILURE;
}
DynamicObject::FinishTx();
Application::Ptr app = Application::GetInstance();
if (!app)

View File

@ -54,13 +54,11 @@ libbase_la_SOURCES = \
timer.h \
tlsclient.cpp \
tlsclient.h \
unix.cpp \
unix.h \
utility.cpp \
utility.h \
value.cpp \
value.h \
win32.cpp \
win32.h
libbase_la_CPPFLAGS = \

View File

@ -138,7 +138,7 @@ void Application::TimeWatchThreadProc(void)
double lastLoop = Utility::GetTime();
for (;;) {
Sleep(5);
Utility::Sleep(5);
double now = Utility::GetTime();
double timeDiff = lastLoop - now;
@ -147,7 +147,7 @@ void Application::TimeWatchThreadProc(void)
/* We made a significant jump in time. */
stringstream msgbuf;
msgbuf << "We jumped "
<< (timeDiff < 0 ? "forwards" : "backwards")
<< (timeDiff < 0 ? "forward" : "backward")
<< " in time: " << abs(timeDiff) << " seconds";
Logger::Write(LogInformation, "base", msgbuf.str());
@ -167,11 +167,19 @@ void Application::TimeWatchThreadProc(void)
* Signals the application to shut down during the next
* execution of the event loop.
*/
void Application::Shutdown(void)
void Application::RequestShutdown(void)
{
m_ShuttingDown = true;
}
/**
* Terminates the application.
*/
void Application::Terminate(int exitCode)
{
_exit(exitCode);
}
/**
* Retrieves the full path of the executable.
*
@ -283,7 +291,7 @@ void Application::SigIntHandler(int signum)
if (!instance)
return;
instance->Shutdown();
instance->RequestShutdown();
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
@ -302,7 +310,7 @@ BOOL WINAPI Application::CtrlHandler(DWORD type)
if (!instance)
return TRUE;
instance->GetInstance()->Shutdown();
instance->GetInstance()->RequestShutdown();
SetConsoleCtrlHandler(NULL, FALSE);
return TRUE;
@ -338,19 +346,7 @@ int Application::Run(int argc, char **argv)
DynamicObject::BeginTx();
if (IsDebugging()) {
result = Main(m_Arguments);
} else {
try {
result = Main(m_Arguments);
} catch (const exception& ex) {
Logger::Write(LogCritical, "base", "---");
Logger::Write(LogCritical, "base", "Exception: " + Utility::GetTypeName(typeid(ex)));
Logger::Write(LogCritical, "base", "Message: " + String(ex.what()));
result = EXIT_FAILURE;
}
}
result = Main(m_Arguments);
DynamicObject::FinishTx();
DynamicObject::DeactivateObjects();
@ -359,7 +355,8 @@ int Application::Run(int argc, char **argv)
}
/**
* Grabs the PID file lock and updates the PID.
* Grabs the PID file lock and updates the PID. Terminates the application
* if the PID file is already locked by another instance of the application.
*
* @param filename The name of the PID file.
*/
@ -378,9 +375,11 @@ void Application::UpdatePidFile(const String& filename)
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
ClosePidFile();
throw_exception(runtime_error("Another instance of the application is "
Logger::Write(LogCritical, "base",
"Another instance of the application is "
"already running. Remove the '" + filename + "' file if "
"you're certain that this is not the case."));
"you're certain that this is not the case.");
Terminate(EXIT_FAILURE);
}
#endif /* _WIN32 */

View File

@ -49,7 +49,8 @@ public:
*/
virtual int Main(const vector<String>& args) = 0;
static void Shutdown(void);
static void RequestShutdown(void);
static void Terminate(int exitCode);
static bool IsDebugging(void);

View File

@ -48,10 +48,8 @@
<ClCompile Include="tcpsocket.cpp" />
<ClCompile Include="timer.cpp" />
<ClCompile Include="tlsclient.cpp" />
<ClCompile Include="unix.cpp" />
<ClCompile Include="utility.cpp" />
<ClCompile Include="value.cpp" />
<ClCompile Include="win32.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="application.h" />
@ -242,4 +240,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -81,7 +81,7 @@ void Process::WorkerThreadProc(void)
tv.tv_usec = 0;
select(nfds + 1, &readfds, NULL, NULL, &tv);
#else /* _MSC_VER */
Sleep(1000);
Utility::Sleep(1);
#endif /* _MSC_VER */
for (it = tasks.begin(); it != tasks.end(); ) {

View File

@ -1,9 +1,30 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
using namespace icinga;
ScriptTask::ScriptTask(const ScriptFunction::Ptr& function, const vector<Value>& arguments)
: AsyncTask<ScriptTask, Value>(), m_Function(function), m_Arguments(arguments)
ScriptTask::ScriptTask(const ScriptFunction::Ptr& function,
const vector<Value>& arguments)
: AsyncTask<ScriptTask, Value>(), m_Function(function),
m_Arguments(arguments)
{ }
void ScriptTask::Run(void)

View File

@ -1,47 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
#ifndef _WIN32
#include <ltdl.h>
using namespace icinga;
/**
* Sleeps for the specified amount of time.
*
* @param milliseconds The amount of time in milliseconds.
*/
void Sleep(unsigned long milliseconds)
{
usleep(milliseconds * 1000);
}
/**
* Closes a socket.
*
* @param fd The socket that is to be closed.
*/
void closesocket(SOCKET fd)
{
close(fd);
}
#endif /* _WIN32 */

View File

@ -37,12 +37,10 @@
#include <sys/file.h>
#include <sys/wait.h>
void Sleep(unsigned long milliseconds);
typedef int SOCKET;
#define INVALID_SOCKET (-1)
void closesocket(SOCKET fd);
#define closesocket close
#define ioctlsocket ioctl
#ifndef MAXPATHLEN

View File

@ -24,6 +24,29 @@ using namespace icinga;
bool I2_EXPORT Utility::m_SSLInitialized = false;
/**
* Demangles a symbol name.
*
* @param sym The symbol name.
* @returns A human-readable version of the symbol name.
*/
String Utility::DemangleSymbolName(const String& sym)
{
String result = sym;
#ifdef HAVE_GCC_ABI_DEMANGLE
int status;
char *realname = abi::__cxa_demangle(sym.CStr(), 0, 0, &status);
if (realname != NULL) {
result = String(realname);
free(realname);
}
#endif /* HAVE_GCC_ABI_DEMANGLE */
return result;
}
/**
* Returns a human-readable type name of a type_info object.
*
@ -32,22 +55,9 @@ bool I2_EXPORT Utility::m_SSLInitialized = false;
*/
String Utility::GetTypeName(const type_info& ti)
{
String klass = ti.name();
#ifdef HAVE_GCC_ABI_DEMANGLE
int status;
char *realname = abi::__cxa_demangle(klass.CStr(), 0, 0, &status);
if (realname != NULL) {
klass = String(realname);
free(realname);
}
#endif /* HAVE_GCC_ABI_DEMANGLE */
return klass;
return DemangleSymbolName(ti.name());
}
/**
* Detaches from the controlling terminal.
*/
@ -61,7 +71,7 @@ void Utility::Daemonize(void) {
throw_exception(PosixException("fork() failed", errno));
if (pid)
exit(0);
_exit(0);
fd = open("/dev/null", O_RDWR);
@ -309,3 +319,18 @@ pid_t Utility::GetPid(void)
return GetCurrentProcessId();
#endif /* _WIN32 */
}
/**
* Sleeps for the specified amount of time.
*
* @param timeout The timeout in seconds.
*/
void Utility::Sleep(double timeout)
{
#ifndef _WIN32
usleep(timeout * 1000 * 1000);
#else /* _WIN32 */
::Sleep(timeout * 1000);
#endif /* _WIN32 */
}

View File

@ -31,6 +31,7 @@ namespace icinga
class I2_BASE_API Utility
{
public:
static String DemangleSymbolName(const String& sym);
static String GetTypeName(const type_info& ti);
static void Daemonize(void);
@ -50,6 +51,8 @@ public:
static pid_t GetPid(void);
static void Sleep(double timeout);
private:
static bool m_SSLInitialized;

View File

@ -1,27 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
#ifdef _WIN32
using namespace icinga;
/* nothing here (yet) */
#endif /* _WIN32 */

View File

@ -107,6 +107,7 @@ AC_DEFUN([AX_BOOST_SIGNALS],
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
ax_lib=""
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"

View File

@ -112,6 +112,7 @@ AC_DEFUN([AX_BOOST_SYSTEM],
if test "x$link_system" = "xno"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
ax_lib=""
fi
CPPFLAGS="$CPPFLAGS_SAVED"

View File

@ -142,6 +142,7 @@ AC_DEFUN([AX_BOOST_THREAD],
fi
fi
ax_lib=""
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"

View File

@ -73,55 +73,29 @@ AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK],
if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then
AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_Test_Framework library is available])
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then
saved_ldflags="${LDFLAGS}"
for monitor_library in `ls $BOOSTLIBDIR/libboost_unit_test_framework*.so* $BOOSTLIBDIR/libboost_unit_test_framework*.dylib* $BOOSTLIBDIR/libboost_unit_test_framework*.a* 2>/dev/null` ; do
if test -r $monitor_library ; then
libextension=`echo $monitor_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a.*$;\1;'`
ax_lib=${libextension}
link_unit_test_framework="yes"
else
link_unit_test_framework="no"
fi
if test "x$link_unit_test_framework" = "xyes"; then
BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
break
fi
done
for libextension in `ls $BOOSTLIBDIR/libboost_unit_test_framework*.so* $BOOSTLIBDIR/libboost_unit_test_framework*.dylib* $BOOSTLIBDIR/libboost_unit_test_framework*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break],
[link_unit_test_framework="no"])
done
if test "x$link_unit_test_framework" != "xyes"; then
for libextension in `ls $BOOSTLIBDIR/boost_unit_test_framework*.dll* $BOOSTLIBDIR/boost_unit_test_framework*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_unit_test_framework.*\)\.dll.*$;\1;' -e 's;^\(boost_unit_test_framework.*\)\.a.*$;\1;'` ; do
for libextension in `ls $BOOSTLIBDIR/boost_unit_test_framework*.dll* $BOOSTLIBDIR/boost_unit_test_framework*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_unit_test_framework.*\)\.dll.*$;\1;' -e 's;^\(boost_unit_test_framework.*\)\.a*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break],
[link_unit_test_framework="no"])
done
fi
else
link_unit_test_framework="no"
saved_ldflags="${LDFLAGS}"
for ax_lib in boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib $ax_boost_user_unit_test_framework_lib ; do
if test "x$link_unit_test_framework" = "xyes"; then
break;
fi
for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.so* $BOOSTLIBDIR/lib${ax_lib}.a* 2>/dev/null` ; do
if test -r $unittest_library ; then
libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'`
ax_lib=${libextension}
link_unit_test_framework="yes"
else
link_unit_test_framework="no"
fi
if test "x$link_unit_test_framework" = "xyes"; then
BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
break
fi
else
for ax_lib in $ax_boost_user_unit_test_framework_lib boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib; do
AC_CHECK_LIB($ax_lib, main,
[BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break],
[link_unit_test_framework="no"])
done
done
fi
if test "x$ax_lib" = "x"; then
AC_MSG_ERROR(Could not find a version of the library!)
@ -130,6 +104,7 @@ AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK],
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
ax_lib=""
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"