diff --git a/Makefile.am b/Makefile.am index 5ce7c0b90..1f2d5b6bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,7 @@ icinga2doc_DATA = \ NEWS -EXTRA_DIST = $(icinga2doc_DATA) +EXTRA_DIST = $(icinga2doc_DATA) git_version.sh # Remove doc directory on uninstall diff --git a/base/Makefile.am b/base/Makefile.am index 77758017c..c8f50b602 100644 --- a/base/Makefile.am +++ b/base/Makefile.am @@ -1,10 +1,10 @@ ## Process this file with automake to produce Makefile.in -noinst_LIBRARIES = \ - libbase.a +noinst_LTLIBRARIES = \ + libbase.la -libbase_a_SOURCES = \ +libbase_la_SOURCES = \ application.cpp \ application.h \ component.cpp \ @@ -42,3 +42,8 @@ libbase_a_SOURCES = \ unix.h \ win32.cpp \ win32.h + +libbase_la_LIBADD=$(LIBLTDL) + +AM_CFLAGS=$(LTDLINCL) +AM_CXXFLAGS=$(LTDLINCL) diff --git a/base/application.cpp b/base/application.cpp index c675a9e69..9c1c5e364 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -1,5 +1,9 @@ #include "i2-base.h" +#ifndef _WIN32 +# include +#endif + using namespace icinga; Application::RefType Application::Instance; @@ -178,12 +182,27 @@ Component::RefType Application::LoadComponent(string path, ConfigObject::RefType Log("Loading component '%s'", path.c_str()); +#ifdef _WIN32 HMODULE hModule = LoadLibrary(path.c_str()); +#else /* _WIN32 */ + lt_dlhandle hModule = 0; + lt_dladvise advise; - if (hModule == INVALID_HANDLE_VALUE) + if (!lt_dladvise_init(&advise) && !lt_dladvise_global(&advise)) { + hModule = lt_dlopenadvise(path.c_str(), advise); + } + + lt_dladvise_destroy(&advise); +#endif /* _WIN32 */ + + if (hModule == NULL) throw exception(/*"Could not load module"*/); - pCreateComponent = (Component *(*)())GetProcAddress(hModule, "CreateComponent"); +#ifdef _WIN32 + pCreateComponent = (Component *(*)())GetProcAddress(hModule, ); +#else /* _WIN32 */ + pCreateComponent = (Component *(*)())lt_dlsym(hModule, "CreateComponent"); +#endif /* _WIN32 */ if (pCreateComponent == NULL) throw exception(/*"Module does not contain CreateComponent function"*/); diff --git a/base/base.vcxproj b/base/base.vcxproj index 1f4e82545..389883f45 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -27,6 +27,7 @@ + diff --git a/base/unix.cpp b/base/unix.cpp index 4cdf87edc..3e7eca403 100644 --- a/base/unix.cpp +++ b/base/unix.cpp @@ -10,34 +10,9 @@ void Sleep(unsigned long milliseconds) usleep(milliseconds * 1000); } -inline void closesocket(SOCKET fd) +void closesocket(SOCKET fd) { close(fd); } -inline HMODULE LoadLibrary(const char *filename) -{ - lt_dlhandle handle = 0; - lt_dladvise advise; - - if (!lt_dladvise_init(&advise) && !lt_dladvise_global(&advise)) { - handle = lt_dlopenadvise(filename, advise); - } - - lt_dladvise_destroy(&advise); - - return handle; -} - -inline void FreeLibrary(HMODULE module) -{ - if (module) - lt_dlclose(module); -} - -inline void *GetProcAddress(HMODULE module, const char *function) -{ - return lt_dlsym(module, function); -} - #endif /* I2_PLATFORM == PLATFORM_UNIX */ diff --git a/base/unix.h b/base/unix.h index 327fcdd57..de9892be3 100644 --- a/base/unix.h +++ b/base/unix.h @@ -23,12 +23,4 @@ void closesocket(SOCKET fd); #define I2_EXPORT #define I2_IMPORT -typedef void *HMODULE; - -#define INVALID_HANDLE_VALUE NULL - -HMODULE LoadLibrary(const char *filename); -void FreeLibrary(HMODULE module); -void *GetProcAddress(HMODULE module, const char *function); - #endif /* UNIX_H */ diff --git a/configfilecomponent/Makefile.am b/configfilecomponent/Makefile.am index 84d57ce4b..23adca4ce 100644 --- a/configfilecomponent/Makefile.am +++ b/configfilecomponent/Makefile.am @@ -10,4 +10,5 @@ libconfigfilecomponent_la_SOURCES = \ libconfigfilecomponent_la_CXXFLAGS = -I${top_srcdir}/base -I${top_srcdir}/jsonrpc -libconfigfilecomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined \ No newline at end of file +libconfigfilecomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined +libconfigfilecomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/jsonrpc/libjsonrpc.la \ No newline at end of file diff --git a/configrpccomponent/Makefile.am b/configrpccomponent/Makefile.am index 4435dddf9..dbdcbca54 100644 --- a/configrpccomponent/Makefile.am +++ b/configrpccomponent/Makefile.am @@ -10,4 +10,5 @@ libconfigrpccomponent_la_SOURCES = \ libconfigrpccomponent_la_CXXFLAGS = -I${top_srcdir}/base -I${top_srcdir}/jsonrpc -I${top_srcdir}/icinga -libconfigrpccomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined \ No newline at end of file +libconfigrpccomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined +libconfigfilecomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/jsonrpc/libjsonrpc.la diff --git a/configure.ac b/configure.ac index 06238a114..2e618d159 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,11 @@ LT_INIT LT_CONFIG_LTDL_DIR([ltdl]) LTDL_INIT - +if test "x$with_included_ltdl" != "xyes"; then + AC_CHECK_LIB([ltdl], [lt_dladvise_init], + [], + [AC_MSG_ERROR([installed libltdl is too old])]) +fi diff --git a/icinga/Makefile.am b/icinga/Makefile.am index 1c9db3a29..598c4cd42 100644 --- a/icinga/Makefile.am +++ b/icinga/Makefile.am @@ -12,5 +12,5 @@ icinga_SOURCES = \ icinga_CXXFLAGS = -I${top_srcdir}/base \ -I${top_srcdir}/jsonrpc -I${top_srcdir} -icinga_LDFLAGS = $(top_builddir)/base/libbase.a \ - $(top_builddir)/jsonrpc/libjsonrpc.a -lltdl \ No newline at end of file +icinga_LDFLAGS = $(top_builddir)/base/libbase.la \ + $(top_builddir)/jsonrpc/libjsonrpc.la \ No newline at end of file diff --git a/jsonrpc/Makefile.am b/jsonrpc/Makefile.am index 54a417845..a74d76e4a 100644 --- a/jsonrpc/Makefile.am +++ b/jsonrpc/Makefile.am @@ -1,10 +1,10 @@ ## Process this file with automake to produce Makefile.in -noinst_LIBRARIES = \ - libjsonrpc.a +noinst_LTLIBRARIES = \ + libjsonrpc.la -libjsonrpc_a_SOURCES = \ +libjsonrpc_la_SOURCES = \ cJSON.c \ cJSON.h \ connectionmanager.cpp \ @@ -19,4 +19,4 @@ libjsonrpc_a_SOURCES = \ netstring.cpp \ netstring.h -libjsonrpc_a_CXXFLAGS = -I${top_srcdir}/base +libjsonrpc_la_CXXFLAGS = -I${top_srcdir}/base