Add feature to enable specified modules at build time. 11/139811/6
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Thu, 20 Jul 2017 12:06:41 +0000 (14:06 +0200)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Thu, 27 Jul 2017 14:33:20 +0000 (16:33 +0200)
Change-Id: If40c344ef163e4855fa867cd2ed521516630295f

Makefile.am
configure.ac
modules.list [new file with mode: 0755]

index d928a0dba18557ffe85a8032ee0aeaa64959b041..e61b455bfb56e3e5656723d67aee448063ea3a9a 100644 (file)
@@ -55,10 +55,6 @@ serviceconfig_DATA = \
 sbin_PROGRAMS = faultd
 faultd_SOURCES = \
     src/action/action_executor.c \
-    src/action/service_recover.c \
-    src/action/service_restart.c \
-    src/action/system_reboot.c \
-    src/action/system_reboot_to_recovery.c \
     src/core/action.c \
     src/core/database.c \
     src/core/event.c \
@@ -66,9 +62,6 @@ faultd_SOURCES = \
     src/core/module.c \
     src/core/service.c \
     src/core/faultd-config.c \
-    src/decision_makers/rv_dm.c \
-    src/decision_makers/standard_fault_dm.c \
-    src/decision_makers/vip_fault_dm.c \
     src/event_types/action_executed_event.c \
     src/event_types/decision_made_event.c \
     src/event_types/resource_violation_event.c \
@@ -76,14 +69,27 @@ faultd_SOURCES = \
     src/event_types/faultd_started_event.c \
     src/event_types/system_booted_event.c \
     src/faultd.c \
-    src/listeners/audit.c \
-    src/listeners/systemd.c \
     src/util/common.c \
-    src/listeners/startup.c \
     src/util/log.c \
     src/util/notify_queue.c \
     src/util/systemd_dbus.c
-faultd_LDADD = $(LIBSYSTEMD_LIBS) $(AUDIT_LIBS) $(LIBEJDB_LIBS) $(JSON_C_LIBS)
+
+# Add here source files of modules that must have ability to enable/disable during build
+# This variable is parsed by Autoconf
+EXTRA_faultd_SOURCES = \
+    src/listeners/audit.c \
+    src/listeners/systemd.c \
+    src/listeners/startup.c \
+    src/decision_makers/vip_fault_dm.c \
+    src/decision_makers/rv_dm.c \
+    src/decision_makers/standard_fault_dm.c \
+    src/action/service_restart.c \
+    src/action/system_reboot.c \
+    src/action/system_reboot_to_recovery.c \
+    src/action/service_recover.c
+
+faultd_LDADD = $(ENABLED_MODULES) $(LIBSYSTEMD_LIBS) $(AUDIT_LIBS) $(LIBEJDB_LIBS) $(JSON_C_LIBS)
+faultd_DEPENDENCIES = $(ENABLED_MODULES)
 
 %.pc: %.pc.in Makefile
        $(SED_PROCESS)
index 8de74b6097b465f56c16d73e9b227988be7f7edb..1ed348e65a34d04d7a9ca5b702098c6e7b30da54 100644 (file)
@@ -47,6 +47,44 @@ AS_IF([test "x$enable_tests" = xyes], [
 ])
 AM_CONDITIONAL(ENABLE_TESTS, [test "x$enable_tests" = xyes])
 
+all_modules=`./modules.list path`
+
+AC_ARG_ENABLE([modules],
+             AS_HELP_STRING([--enable-modules=MODULES],
+             [comma-separated list of modules to enable, available:]
+             m4_split(m4_esyscmd([./modules.list name]), ' ')),
+[
+# Enable only given modules
+modules_to_enable="`echo $enableval | sed 's/,/ /g'`"
+
+for i in $modules_to_enable
+do
+       invalid=yes
+       for modpath in $all_modules
+       do
+               modname=${modpath##*/}
+               if test "x$modname" = "x$i"; then
+                       ENABLED_MODULES="$ENABLED_MODULES ${modpath}.o"
+                       invalid=
+                       break
+               fi
+       done
+
+       if test "x$invalid" = "xyes"; then
+               AC_MSG_ERROR([invalid module $i])
+       fi
+done
+],
+[
+# No --enable-modules specified, enable all modules
+for modpath in $all_modules
+do
+       ENABLED_MODULES="$ENABLED_MODULES ${modpath}.o"
+done
+])
+
+AC_SUBST([ENABLED_MODULES])
+
 PKG_CHECK_MODULES(LIBSYSTEMD,
         [libsystemd >= 231],
         have_libsystemd=yes,
@@ -115,5 +153,6 @@ AC_MSG_RESULT([
         ldflags:                ${LDFLAGS}
 
         libsystemd:             ${have_libsystemd}
-])
 
+        modules:                ${ENABLED_MODULES/ /}
+])
diff --git a/modules.list b/modules.list
new file mode 100755 (executable)
index 0000000..1180066
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+sed -ne '/EXTRA_faultd_SOURCES/,/^ *$/ { s,\(\.c.*$\|^EXTRA.*\),,; p }' < Makefile.am | \
+while read path
+do
+       if test "x$1" = "xname"; then
+               printf "%s\n" "${path##*/}"
+       elif test "x$1" = "xpath"; then
+               printf "%s\n" "$path"
+       else
+               printf "%-32s %s\n" "${path##*/}" "$path"
+       fi
+done