f78fa80439be0f4d36c8e777bcff074edfdd5f17
[citadel.git] / citadel / scripts / mk_module_init.sh
1 #!/bin/sh
2 #
3 # Script to generate $C_FILE
4 #
5
6 ECHO=/usr/bin/printf
7 SED=/bin/sed
8
9 #MINUS_e=X`$ECHO -n -e`
10 #if [ $MINUS_e != "X" ] ; then
11 #       MINUS_e=""
12 #else
13 #       MINUS_e="-e"
14 #fi
15
16 #MINUS_E=X`$ECHO -n -E`
17 #if [ $MINUS_E != "X" ] ; then
18 #       MINUS_E=""
19 #else
20 #       MINUS_E="-E"
21 #fi
22
23
24 CUR_DIR=`pwd`
25 C_FILE="$CUR_DIR/modules_init.c"
26 H_FILE="$CUR_DIR/modules_init.h"
27 MOD_FILE="$CUR_DIR/Make_modules"
28 SRC_FILE="$CUR_DIR/Make_sources"
29 U_FILE="$CUR_DIR/modules_upgrade.c"
30
31 /usr/bin/printf "Scanning extension modules for entry points.\n"
32
33 STATIC_FIRST_MODULES="citserver control modules euidindex file_ops msgbase room_ops user_ops nttlist"
34 DYNAMIC_MODULES=`grep CTDL_MODULE_INIT modules/*/*.c |$SED 's;.*(\(.*\));\1;'`
35 if test -d user_modules; then 
36     USER_MODULES=`grep CTDL_MODULE_INIT user_modules/*/*.c |$SED 's;.*(\(.*\));\1;'`
37 else
38     USER_MODULES=
39 fi
40 STATIC_LAST_MODULES="netconfig"
41
42 ###############################################################################
43 #                        start the c file                                     #
44 ###############################################################################
45
46 cat <<EOF  >$C_FILE
47 /*
48  * $C_FILE
49  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
50  */
51
52
53
54 #include "sysdep.h"
55 #include <stdlib.h>
56 #include <time.h>
57 #include <ctype.h>
58 #include <stdio.h>
59 #include <sys/types.h>
60 #include <unistd.h>
61 #include <libcitadel.h>
62 #include "citadel.h"
63 #include "modules_init.h"
64 #include "sysdep_decls.h"
65 #include "serv_extensions.h"
66
67
68 void LogPrintMessages(long err);
69 extern long DetailErrorFlags;
70
71 void initialise_modules (int threading)
72 {
73     long filter;
74     const char *pMod;
75
76     if (threading) {
77         MODM_syslog(LOG_DEBUG, "Initializing, CtdlThreads enabled.\n");
78     }
79     else {
80         MODM_syslog(LOG_INFO, "Initializing. CtdlThreads not yet enabled.\n");
81     }
82
83 EOF
84
85
86 for i in ${STATIC_FIRST_MODULES} ${DYNAMIC_MODULES} ${USER_MODULES} ${STATIC_LAST_MODULES}; do 
87 cat <<EOF >> $C_FILE
88         pMod = CTDL_INIT_CALL($i);
89         MOD_syslog(LOG_DEBUG, "Loaded module: %s\n", pMod);
90 EOF
91
92 done
93 cat <<EOF >> $C_FILE
94
95         for (filter = 1; filter != 0; filter = filter << 1)
96                 if ((filter & DetailErrorFlags) != 0)
97                         LogPrintMessages(filter);
98 }
99
100 EOF
101
102
103
104
105
106 ###############################################################################
107 #                        start the header file                                #
108 ###############################################################################
109 cat <<EOF > $H_FILE
110 /* 
111  * $H_FILE
112  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
113  */
114
115
116 #ifndef MODULES_INIT_H
117 #define MODULES_INIT_H
118 #include "ctdl_module.h"
119 extern size_t nSizErrmsg;
120 void initialise_modules (int threading);
121 void upgrade_modules(void);
122
123 EOF
124
125 for i in ${STATIC_FIRST_MODULES} ${DYNAMIC_MODULES} ${USER_MODULES} ${STATIC_LAST_MODULES}; do 
126 # Add this entry point to the .h file
127 cat <<EOF >> $H_FILE
128         CTDL_MODULE_INIT($i);
129 EOF
130 done
131
132 grep CTDL_MODULE_UPGRADE *.c modules/*/*.c  |$SED 's;.*(\(.*\));\CTDL_MODULE_UPGRADE(\1)\;\n;' >> $H_FILE
133
134 cat <<EOF >> $H_FILE
135
136
137 #endif /* MODULES_INIT_H */
138
139 EOF
140
141
142 ###############################################################################
143 #             u start the Makefile included file for $SERV_MODULES            #
144 ###############################################################################
145 cat <<EOF  >$MOD_FILE
146 #
147 # Make_modules
148 # This file is to be included by Makefile to dynamically add modules to the build process
149 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
150 #
151
152 SERV_MODULES = \\
153 EOF
154
155 echo modules/*/*.c | $SED -e "s;\.c ;.o \\\\\n;g" -e "s;\.c;.o;" >> $MOD_FILE
156 echo >> $MOD_FILE
157
158
159 ###############################################################################
160 #       start of the files which inturn removes any existing file             #
161 ###############################################################################
162
163
164 # start the Makefile included file for $SOURCES
165 cat <<EOF  >$SRC_FILE
166 #
167 # Make_sources
168 # This file is to be included by Makefile to dynamically add modules to the build process
169 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
170 #
171
172 SOURCES = \\
173 EOF
174
175 echo modules/*/*.c | $SED "s;\.c ;.c \\\\\n;g" >> $SRC_FILE
176 echo >> $SRC_FILE
177
178
179
180 ###############################################################################
181 #                     start the upgrade file                                  #
182 ###############################################################################
183 cat <<EOF  >$U_FILE
184 /*
185  * $U_FILE
186  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
187  */
188
189
190
191 #include "sysdep.h"
192 #include <stdlib.h>
193 #include <unistd.h>
194 #include <time.h>
195 #include <ctype.h>
196 #include <stdio.h>
197 #include <sys/types.h>
198 #include <unistd.h>
199 #include <libcitadel.h>
200 #include "citadel.h"
201 #include "modules_init.h"
202 #include "sysdep_decls.h"
203 #include "serv_extensions.h"
204
205
206
207 void upgrade_modules (void)
208 {
209         const char *pMod;
210
211         MODM_syslog(LOG_INFO, "Upgrade modules.\n");
212
213 EOF
214
215 # Add this entry point to the .c file
216
217 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
218
219 #close the upgrade file
220 /usr/bin/printf "}\n" >> $U_FILE