Added possibility to build statically linked agents (with platform subagent linked in)
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 15 Sep 2005 21:22:58 +0000 (21:22 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 15 Sep 2005 21:22:58 +0000 (21:22 +0000)
For now, agent has to be linked manually. I'll fix it later.

.gitattributes
configure.ac
src/agent/Makefile.am
src/agent/core/Makefile.am
src/agent/core/nxagentd.cpp
src/agent/subagents/linux/linux.cpp
tools/create_ssa_list.sh [new file with mode: 0755]

index 0a004d0..e9670f6 100644 (file)
@@ -945,6 +945,7 @@ src/server/tools/nxupload/nxupload.cpp -text
 src/server/tools/nxupload/nxupload.dsp -text
 src/server/tools/nxupload/nxupload.dsw -text
 tools/Makefile.am -text
+tools/create_ssa_list.sh -text
 tools/mc.pl -text
 tools/nwmkimp.pl -text
 tools/patch_libtool.pl -text
index d2ba4d8..48ec790 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: configure.ac,v 1.102 2005-09-13 11:10:36 victor Exp $
+# $Id: configure.ac,v 1.103 2005-09-15 21:22:56 victor Exp $
 #
 # Process this file with autoconf to produce a configure script.
 #
@@ -17,16 +17,12 @@ AC_PROG_CPP
 AC_PROG_CXX
 AC_PROG_INSTALL
 
-AC_DISABLE_STATIC
-AC_LIBTOOL_DLOPEN
-AC_PROG_LIBTOOL
-
-
 # --------------------------------------------------------------------------
 # disable C++ exceptions
 CFLAGS="$CFLAGS -fno-exceptions"
 CPPFLAGS="$CPPFLAGS -fno-exceptions"
 LDFLAGS="$LDFLAGS"
+SUBAGENT_LIBS=""
 
 # --------------------------------------------------------------------------
 # misc
@@ -65,6 +61,7 @@ AC_ARG_WITH(odbc,
                LDFLAGS="$LDFLAGS -L${withval}/lib"
                CPPFLAGS="$CPPFLAGS -I${withval}/include"
    fi
+   DYNAMIC_COMPONENTS="yes"
        with_odbc="yes"
        AC_DEFINE(WITH_ODBC,,[with odbc])
        DB_DRIVERS="$DB_DRIVERS odbc"
@@ -84,6 +81,7 @@ AC_ARG_WITH(mysql,
                LDFLAGS="$LDFLAGS -L/usr/local/mysql/lib -L/usr/lib/mysql -L/usr/mysql/lib -L/usr/local/lib/mysql -L/usr/local/mysql/lib/mysql -L/usr/mysql/lib/mysql"
                CPPFLAGS="$CPPFLAGS -I/usr/local/mysql/include -I/usr/include/mysql -I/usr/mysql/include -I/usr/local/include/mysql -I/usr/local/mysql/include/mysql -I/usr/mysql/include/mysql"
        fi
+   DYNAMIC_COMPONENTS="yes"
        AC_CHECK_LIB(m, floor)
        AC_CHECK_LIB(z, gzclose)
        with_mysql="yes"
@@ -120,6 +118,7 @@ AC_ARG_WITH(pgsql,
                LDFLAGS="$LDFLAGS -L/usr/local/pgsql/lib -L/usr/lib/pgsql -L/usr/pgsql/lib -L/usr/local/lib/pgsql -L/usr/local/pgsql/lib/pgsql -L/usr/pgsql/lib/pgsql -L/usr/local/postgresql/lib -L/usr/lib/postgresql -L/usr/postgresql/lib -L/usr/local/lib/postgresql -L/usr/local/postgresql/lib/postgresql -L/usr/postgresql/lib/postgresql"
                CPPFLAGS="$CPPFLAGS -I/usr/local/pgsql/include -I/usr/include/pgsql -I/usr/pgsql/include -I/usr/local/include/pgsql -I/usr/local/pgsql/include/pgsql -I/usr/pgsql/include/pgsql -I/usr/local/postgresql/include -I/usr/include/postgresql -I/usr/postgresql/include -I/usr/local/include/postgresql -I/usr/local/postgresql/include/postgresql -I/usr/postgresql/include/postgresql"
        fi
+   DYNAMIC_COMPONENTS="yes"
        AC_CHECK_LIB(m, floor)
        AC_CHECK_LIB(z, gzclose)
        with_pgsql="yes"
@@ -150,6 +149,7 @@ AC_ARG_WITH(server,
    TOP_LEVEL_MODULES="$TOP_LEVEL_MODULES sql images"
    CONTRIB_MODULES="$CONTRIB_MODULES mibs"
        BUILD_SERVER="yes"
+   DYNAMIC_COMPONENTS="yes"
 ])
 
 
@@ -158,6 +158,7 @@ AC_ARG_WITH(client,
 [
        MODULES="$MODULES libnxcl nxevent nxreport console"
        BUILD_CLIENT="yes"
+   DYNAMIC_COMPONENTS="yes"
 ])
 
 
@@ -181,6 +182,37 @@ AC_ARG_WITH(agent,
                        # unknown
                        ;;
        esac
+   DYNAMIC_COMPONENTS="yes"
+])
+
+AC_ARG_WITH(static-agent,
+[AS_HELP_STRING(--with-static-agent,build statically linked agent)],
+[
+       BUILD_STATIC_AGENT="yes"
+       MODULES="$MODULES agent"
+   CFLAGS="$CFLAGS -D_STATIC_AGENT"
+   CPPFLAGS="$CPPFLAGS -D_STATIC_AGENT"
+#   STATIC_SUBAGENT_LIST="ping portcheck"
+       case `uname -s` in
+               Linux)
+                       SUBAGENT_DIRS="linux"
+         SUBAGENT_LIBS="../subagents/linux/libnsm_linux.la"
+         STATIC_SUBAGENT_LIST="linux $STATIC_SUBAGENT_LIST"
+                       ;;
+               FreeBSD)
+                       SUBAGENT_DIRS="freebsd"
+         SUBAGENT_LIBS="../subagents/freebsd/libnsm_freebsd.la"
+         STATIC_SUBAGENT_LIST="freebsd $STATIC_SUBAGENT_LIST"
+                       ;;
+               SunOS)
+                       SUBAGENT_DIRS="sunos"
+         SUBAGENT_LIBS="../subagents/sunos/libnsm_sunos.la"
+         STATIC_SUBAGENT_LIST="sunos $STATIC_SUBAGENT_LIST"
+                       ;;
+               *)
+                       # unknown
+                       ;;
+       esac
 ])
 
 AC_ARG_WITH(dist,
@@ -198,6 +230,7 @@ AC_ARG_WITH(nxsm,
 [
        MODULES="$MODULES www"
        BUILD_CLIENT="yes"
+   DYNAMIC_COMPONENTS="yes"
 ])
 
 AC_ARG_WITH(openssl,
@@ -250,6 +283,23 @@ AC_SUBST(SUBAGENT_DIRS)
 AC_SUBST(NXCONFIG)
 AC_SUBST(TOP_LEVEL_MODULES)
 AC_SUBST(CONTRIB_MODULES)
+AC_SUBST(STATIC_SUBAGENT_LIST)
+AC_SUBST(SUBAGENT_LIBS)
+
+# --------------------------------------------------------------------------
+# If --with-static-agent selected, other components cannot be selected
+# Select shared or static libraries depending on agent build type
+if test "x$BUILD_STATIC_AGENT" = "xyes" ; then
+   if test "x$DYNAMIC_COMPONENTS" = "xyes" ; then
+      AC_MSG_ERROR(Static agent and other components are mutally exclusive.)
+   fi
+   AC_DISABLE_SHARED
+else
+   AC_DISABLE_STATIC
+fi
+
+AC_LIBTOOL_DLOPEN
+AC_PROG_LIBTOOL
 
 # --------------------------------------------------------------------------
 # checks for libs.
@@ -569,3 +619,9 @@ if test "x${BUILD_AGENT}" = "xyes"; then
 else
        echo "Build Agent         : NO"
 fi
+if test "x${BUILD_STATIC_AGENT}" = "xyes"; then
+       echo "Build Static Agent  : YES"
+       echo "Subagents list      : ${STATIC_SUBAGENT_LIST}"
+else
+       echo "Build Static Agent  : NO"
+fi
index 5d39407..764d1d2 100644 (file)
@@ -8,4 +8,4 @@
 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
-SUBDIRS = core subagents install
+SUBDIRS = subagents core install
index 7cea98a..9bb58ed 100644 (file)
@@ -10,11 +10,14 @@ EXTRA_DIST = \
 INCLUDES=-I@top_srcdir@/include
 
 bin_PROGRAMS = nxagentd
-nxagentd_SOURCES = messages.c actions.cpp comm.cpp exec.cpp getparam.cpp log.cpp nxagentd.cpp session.cpp subagent.cpp sysinfo.cpp tools.cpp upgrade.cpp
-nxagentd_LDADD = @PTHREAD_LIBS@ ../../libnetxms/libnetxms.la ../../libnxcscp/libnxcscp.la
+nxagentd_SOURCES = messages.c actions.cpp comm.cpp exec.cpp getparam.cpp log.cpp nxagentd.cpp session.cpp static_subagents.cpp subagent.cpp sysinfo.cpp tools.cpp upgrade.cpp
+nxagentd_LDADD = @PTHREAD_LIBS@ ../../libnetxms/libnetxms.la ../../libnxcscp/libnxcscp.la @SUBAGENT_LIBS@
 AM_CPPFLAGS = $(all_includes) -DPREFIX=\"@prefix@\"
 
 messages.c: messages.h
 
 messages.h: messages.mc
        $(PERL) @top_builddir@/tools/mc.pl messages.mc
+
+static_subagents.cpp: @top_srcdir@/config.h
+       @top_builddir@/tools/create_ssa_list.sh "@STATIC_SUBAGENT_LIST@" > static_subagents.cpp
index 7d41daf..50cd613 100644 (file)
 # include <sys/wait.h>
 #endif
 
+
 //
 // Externals
 //
 
 THREAD_RESULT THREAD_CALL ListenerThread(void *);
 THREAD_RESULT THREAD_CALL SessionWatchdog(void *);
+void InitStaticSubagents(void);
 
 
 //
@@ -561,6 +563,7 @@ BOOL Initialize(void)
    AddAction("Agent.Restart", AGENT_ACTION_SUBAGENT, NULL, H_RestartAgent, "CORE", "Restart agent");
 
    // Load subagents
+   InitStaticSubagents();
 #ifdef _WIN32
    LoadWindowsSubagent();
 #endif
index 172629d..b794673 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: linux.cpp,v 1.19 2005-08-22 00:11:46 alk Exp $ */
+/* $Id: linux.cpp,v 1.20 2005-09-15 21:22:58 victor Exp $ */
 
 /* 
 ** NetXMS subagent for GNU/Linux
@@ -158,17 +158,31 @@ static NETXMS_SUBAGENT_INFO m_info =
 // Entry point for NetXMS agent
 //
 
-extern "C" BOOL NxSubAgentInit(NETXMS_SUBAGENT_INFO **ppInfo)
+#ifdef _STATIC_AGENT
+
+extern "C" BOOL NxSubAgentInit_LINUX(NETXMS_SUBAGENT_INFO **ppInfo)
 {
    *ppInfo = &m_info;
+   return TRUE;
+}
+
+#else
 
+extern "C" BOOL NxSubAgentInit(NETXMS_SUBAGENT_INFO **ppInfo)
+{
+   *ppInfo = &m_info;
    return TRUE;
 }
 
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 /*
 
 $Log: not supported by cvs2svn $
+Revision 1.19  2005/08/22 00:11:46  alk
+Net.IP.RoutingTable added
+
 Revision 1.18  2005/08/19 15:23:50  victor
 Added new parameters
 
diff --git a/tools/create_ssa_list.sh b/tools/create_ssa_list.sh
new file mode 100755 (executable)
index 0000000..0bb2cf6
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+TIMESTAMP=`date`
+LIST=`echo $1 | tr a-z A-Z`
+
+echo "/* static_subagents.cpp  Generated at $TIMESTAMP */"
+cat << EOT
+#include <nxagentd.h>
+
+extern "C"
+{
+EOT
+
+for sa in $LIST; do
+   echo "   BOOL NxSubAgentInit_$sa(NETXMS_SUBAGENT_INFO **, TCHAR *);"
+done
+
+cat << EOT
+}
+
+void InitStaticSubagents(void)
+{
+EOT
+
+for sa in $LIST; do
+   echo "   InitSubAgent(NULL, \"static: $sa\", NxSubAgentInit_$sa);"
+done
+
+echo "}"
+
+exit 0