MODULES: simplify scan script; add missing entry point.
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 12 Feb 2013 21:00:27 +0000 (22:00 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Tue, 12 Feb 2013 21:00:27 +0000 (22:00 +0100)
citadel/scripts/mk_module_init.sh

index bbf19b783819daeb10807659c2b6babc1806ce1b..3ed51024c54c832a5bc47c95c8e36c07ac77c3b7 100755 (executable)
@@ -4,6 +4,7 @@
 #
 
 ECHO=/usr/bin/printf
+SED=/bin/sed
 
 #MINUS_e=X`$ECHO -n -e`
 #if [ $MINUS_e != "X" ] ; then
@@ -29,64 +30,19 @@ U_FILE="$CUR_DIR/modules_upgrade.c"
 
 /usr/bin/printf "Scanning extension modules for entry points.\n"
 
+STATIC_FIRST_MODULES="citserver control modules euidindex file_ops msgbase room_ops user_ops nttlist"
+DYNAMIC_MODULES=`grep CTDL_MODULE_INIT modules/*/*.c |$SED 's;.*(\(.*\));\1;'`
+if test -d user_modules; then 
+    USER_MODULES=`grep CTDL_MODULE_INIT user_modules/*/*.c |$SED 's;.*(\(.*\));\1;'`
+else
+    USER_MODULES=
+fi
+STATIC_LAST_MODULES="netconfig"
 
-#start of the files which inturn removes any existing file
-#
-
-# start the Makefile included file for $SERV_MODULES
-cat <<EOF  >$MOD_FILE
-#
-# Make_modules
-# This file is to be included by Makefile to dynamically add modules to the build process
-# THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
-#
-
-EOF
-
-# start the Makefile included file for $SOURCES
-cat <<EOF  >$SRC_FILE
-#
-# Make_sources
-# This file is to be included by Makefile to dynamically add modules to the build process
-# THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
-#
-
-EOF
-
-# start the upgrade file
-cat <<EOF  >$U_FILE
-/*
- * $U_FILE
- * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
- */
-
-
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "modules_init.h"
-#include "sysdep_decls.h"
-#include "serv_extensions.h"
-
-
-
-void upgrade_modules (void)
-{
-    const char *pMod;
-
-    MODM_syslog(LOG_INFO, "Upgrade modules.\n");
+###############################################################################
+#                        start the c file                                     #
+###############################################################################
 
-EOF
-
-# start the c file
 cat <<EOF  >$C_FILE
 /*
  * $C_FILE
@@ -123,33 +79,33 @@ void initialise_modules (int threading)
     else {
         MODM_syslog(LOG_INFO, "Initializing. CtdlThreads not yet enabled.\n");
     }
-/* static server initialization: */
-        pMod = CTDL_INIT_CALL(citserver);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
-
-        pMod = CTDL_INIT_CALL(control);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
 
-        pMod = CTDL_INIT_CALL(euidindex);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
+EOF
 
-        pMod = CTDL_INIT_CALL(file_ops);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
 
-        pMod = CTDL_INIT_CALL(msgbase);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
+for i in ${STATIC_FIRST_MODULES} ${DYNAMIC_MODULES} ${USER_MODULES} ${STATIC_LAST_MODULES}; do 
+cat <<EOF >> $C_FILE
+       pMod = CTDL_INIT_CALL($i);
+       MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
+EOF
 
-        pMod = CTDL_INIT_CALL(room_ops);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
+done
+cat <<EOF >> $C_FILE
 
-        pMod = CTDL_INIT_CALL(user_ops);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
-/* dynamic modules: */
+       for (filter = 1; filter != 0; filter = filter << 1)
+               if ((filter & DetailErrorFlags) != 0)
+                       LogPrintMessages(filter);
+}
 
 EOF
 
 
-#start the header file
+
+
+
+###############################################################################
+#                        start the header file                                #
+###############################################################################
 cat <<EOF > $H_FILE
 /* 
  * $H_FILE
@@ -164,173 +120,100 @@ extern size_t nSizErrmsg;
 void initialise_modules (int threading);
 void upgrade_modules(void);
 
-       CTDL_MODULE_INIT(citserver);
-       CTDL_MODULE_INIT(control);
-       CTDL_MODULE_INIT(euidindex);
-       CTDL_MODULE_INIT(file_ops);
-       CTDL_MODULE_INIT(msgbase);
-       CTDL_MODULE_INIT(room_ops);
-       CTDL_MODULE_INIT(user_ops);
-       CTDL_MODULE_INIT(netconfig);
-EOF
-
-for i in serv_*.c
-do
-       RES=X`grep CTDL_MODULE_INIT $i | cut -f2 -d\( | cut -f1 -d\)`
-       if [ $RES != "X" ] ; then
-               RES_OUT=`echo $RES | cut -b2-`
-               /usr/bin/printf "Found entry point in file $i\n"
-cat <<EOF  >> $C_FILE
-       pMod = CTDL_INIT_CALL($RES_OUT);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
-
-EOF
-cat <<EOF >>$H_FILE
-CTDL_MODULE_INIT($RES_OUT);
 EOF
-       fi
-       RES=X`grep CTDL_MODULE_UPGRADE $i | cut -f2 -d\( | cut -f1 -d\)`
-       if [ $RES != "X" ] ; then
-               RES_OUT=`echo $RES | cut -b2-`
-               /usr/bin/printf "Found upgrade point in file $i\n"
-cat <<EOF  >> $U_FILE
-       pMod = CTDL_UPGRADE_CALL($RES_OUT);
-        MOD_syslog(LOG_INFO, "%s\n", pMod);
 
+for i in ${STATIC_FIRST_MODULES} ${DYNAMIC_MODULES} ${USER_MODULES} ${STATIC_LAST_MODULES}; do 
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+       CTDL_MODULE_INIT($i);
 EOF
-cat <<EOF >>$H_FILE
-CTDL_MODULE_UPGRADE($RES_OUT);
-EOF
-       fi
 done
 
+cat <<EOF >> $H_FILE
 
-if [ -d "modules" ] ; then
-       cd modules
-       for j in *
-       do
-               if [ -d $j ] ; then
-                       cd $j
-                       for k in *.c
-                       do
-                               if [ -f "$k" ] ; then
-# Add this .c file to the Makefile included list of SOURCES
-cat <<EOF >> $SRC_FILE
-SOURCES += modules/$j/$k
-EOF
 
-# Generate a .o file name
-O_FILE=`basename $k .c`
-O_FILE="$O_FILE.o"
-# Add this .o file to the Makefile included list of SERV_MODULES
-cat <<EOF >> $MOD_FILE
-SERV_MODULES += modules/$j/$O_FILE
-EOF
-       
-                                       RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
-                                       if [ $RES != "X" ] ; then
-                                               RES_OUT=`echo $RES | cut -b2-`
-                                               /usr/bin/printf "Found entry point in file modules/$j/$k\n"
-# Add this entry point to the .c file
-cat <<EOF >> $C_FILE
-       pMod = CTDL_INIT_CALL($RES_OUT);
-       MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
-EOF
-# Add this entry point to the .h file
-cat <<EOF >> $H_FILE
-       CTDL_MODULE_INIT($RES_OUT);
-EOF
-                                       fi
-                                       RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)`
-                                       if [ $RES != "X" ] ; then
-                                               RES_OUT=`echo $RES | cut -b2-`
-                                               /usr/bin/printf "Found upgrade point in file modules/$j/$k\n"
-# Add this entry point to the .c file
-cat <<EOF >> $U_FILE
-       pMod = CTDL_UPGRADE_CALL($RES_OUT);
-       MOD_syslog(LOG_INFO, "%s\n", pMod);
-EOF
-# Add this entry point to the .h file
-cat <<EOF >> $H_FILE
-       CTDL_MODULE_UPGRADE($RES_OUT);
-EOF
-                                       fi
-                               fi
-                       done
-                       cd ..
-               fi
-       done
-fi
+#endif /* MODULES_INIT_H */
 
-cd $CUR_DIR
-
-if [ -d "user_modules" ] ; then
-       cd user_modules
-       for j in *
-       do
-               if [ -d $j ] ; then
-                       cd $j
-                       for k in *.c
-                       do
-                               if [ -f "$k" ] ; then
-# Add this .c file to the Makefile included list of SOURCES
-cat <<EOF >> $SRC_FILE
-SOURCES += user_modules/$j/$k
 EOF
 
-# Generate a .o file name
-O_FILE=`basename $k .c`
-O_FILE="$O_FILE.o"
-# Add this .o file to the Makefile included list of SERV_MODULES
-cat <<EOF >> $MOD_FILE
-SERV_MODULES += user_modules/$j/$O_FILE
-EOF
-       
-                                       RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
-                                       if [ $RES != "X" ] ; then
-                                               RES_OUT=`echo $RES | cut -b2-`
-                                               /usr/bin/printf "Found entry point in file user_modules/$j/$k\n"
-cat <<EOF >> $C_FILE
-       pMod = CTDL_INIT_CALL($RES_OUT);
-       MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
-EOF
-cat <<EOF >> $H_FILE
-CTDL_MODULE_INIT($RES_OUT);
-EOF
-                                       fi
-                                       RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)`
-                                       if [ $RES != "X" ] ; then
-                                               RES_OUT=`echo $RES | cut -b2-`
-                                               /usr/bin/printf "Found upgrade point in file user_modules/$j/$k\n"
-cat <<EOF >> $U_FILE
-       pMod = CTDL_UPGRADE_CALL($RES_OUT);
-       MOD_syslog(LOG_INFO, "%s\n", pMod);
+
+###############################################################################
+#             u start the Makefile included file for $SERV_MODULES            #
+###############################################################################
+cat <<EOF  >$MOD_FILE
+#
+# Make_modules
+# This file is to be included by Makefile to dynamically add modules to the build process
+# THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
+#
+
+SERV_MODULES = \\
 EOF
-cat <<EOF >> $H_FILE
-CTDL_MODULE_UPGRADE($RES_OUT);
+
+echo modules/*/*.c | $SED "s;\.c ;.o \\\\\n;g" >> $MOD_FILE
+echo >> $MOD_FILE
+
+
+###############################################################################
+#       start of the files which inturn removes any existing file             #
+###############################################################################
+
+
+# start the Makefile included file for $SOURCES
+cat <<EOF  >$SRC_FILE
+#
+# Make_sources
+# This file is to be included by Makefile to dynamically add modules to the build process
+# THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
+#
+
+SOURCES = \\
 EOF
-                                       fi
-                               fi
-                       done
-                       cd ..
-               fi
-       done
-fi
 
-cd $CUR_DIR
 
-# this one has to be called last, else it will not find all hooks registered.
-cat <<EOF >> $C_FILE
-        pMod = CTDL_INIT_CALL(netconfig);
-        MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
+echo modules/*/*.c | $SED "s;\.c ;.c \\\\\n;g" >> $SRC_FILE
+echo >> $SRC_FILE
+
+
+
+###############################################################################
+#                     start the upgrade file                                  #
+###############################################################################
+cat <<EOF  >$U_FILE
+/*
+ * $U_FILE
+ * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
+ */
+
+
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <libcitadel.h>
+#include "citadel.h"
+#include "modules_init.h"
+#include "sysdep_decls.h"
+#include "serv_extensions.h"
+
+
+
+void upgrade_modules (void)
+{
+        const char *pMod;
+
+        MODM_syslog(LOG_INFO, "Upgrade modules.\n");
+
 EOF
-/usr/bin/printf "\n\n" >> $C_FILE
-/usr/bin/printf "\tfor (filter = 1; filter != 0; filter = filter << 1)\n" >> $C_FILE
-/usr/bin/printf "\t\tif ((filter & DetailErrorFlags) != 0)\n" >> $C_FILE
-/usr/bin/printf "\t\t\tLogPrintMessages(filter);\n" >> $C_FILE
-/usr/bin/printf "}\n" >> $C_FILE
+
+# Add this entry point to the .c file
+
+grep CTDL_MODULE_UPGRADE *.c modules/*/*.c  |$SED 's;.*(\(.*\));\tpMod = CTDL_UPGRADE_CALL(\1)\;\n\tMOD_syslog(LOG_INFO, "%s\\n", pmod)\;\n;' >> $U_FILE
 
 #close the upgrade file
 /usr/bin/printf "}\n" >> $U_FILE
-
-/usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE