Did away with lprintf all together now its called CtdlLogPrintf()
[citadel.git] / citadel / mk_module_init.sh
1 #!/bin/sh
2 #
3 # Script to generate $C_FILE
4 #
5
6 ECHO=/usr/bin/printf
7
8 #MINUS_e=X`$ECHO -n -e`
9 #if [ $MINUS_e != "X" ] ; then
10 #       MINUS_e=""
11 #else
12 #       MINUS_e="-e"
13 #fi
14
15 #MINUS_E=X`$ECHO -n -E`
16 #if [ $MINUS_E != "X" ] ; then
17 #       MINUS_E=""
18 #else
19 #       MINUS_E="-E"
20 #fi
21
22
23 CUR_DIR=`pwd`
24 C_FILE="$CUR_DIR/modules_init.c"
25 H_FILE="$CUR_DIR/modules_init.h"
26 MOD_FILE="$CUR_DIR/Make_modules"
27 SRC_FILE="$CUR_DIR/Make_sources"
28 U_FILE="$CUR_DIR/modules_upgrade.c"
29
30 /usr/bin/printf "Scanning extension modules for entry points.\n"
31
32
33 #start of the files which inturn removes any existing file
34 #
35
36 # start the Makefile included file for $SERV_MODULES
37 cat <<EOF  >$MOD_FILE
38 #
39 # Make_modules
40 # This file is to be included by Makefile to dynamically add modules to the build process
41 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
42 #
43
44 EOF
45
46 # start the Makefile included file for $SOURCES
47 cat <<EOF  >$SRC_FILE
48 #
49 # Make_sources
50 # This file is to be included by Makefile to dynamically add modules to the build process
51 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
52 #
53
54 EOF
55
56 # start the upgrade file
57 cat <<EOF  >$U_FILE
58 /*
59  * $U_FILE
60  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
61  */
62
63
64
65 #include "sysdep.h"
66 #include <stdlib.h>
67 #include <time.h>
68 #include <ctype.h>
69 #include <stdio.h>
70 #include <sys/types.h>
71 #include <unistd.h>
72 #include "citadel.h"
73 #include "modules_init.h"
74 #include "sysdep_decls.h"
75
76
77
78
79 void upgrade_modules (void)
80 {
81
82     CtdlLogPrintf (CTDL_INFO, "Upgrade modules.\n");
83
84 EOF
85
86 # start the c file
87 cat <<EOF  >$C_FILE
88 /*
89  * $C_FILE
90  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
91  */
92
93
94
95 #include "sysdep.h"
96 #include <stdlib.h>
97 #include <time.h>
98 #include <ctype.h>
99 #include <stdio.h>
100 #include <sys/types.h>
101 #include <unistd.h>
102 #include "citadel.h"
103 #include "modules_init.h"
104 #include "sysdep_decls.h"
105
106
107 void LogPrintMessages(long err);
108 extern long DetailErrorFlags;
109
110
111
112 void initialise_modules (int threading)
113 {
114     long filter;
115     nSizErrmsg = 0;
116
117     if (threading)
118         CtdlLogPrintf (CTDL_INFO, "Initialise modules, CtdlThreads enabled.\n");
119     else
120         CtdlLogPrintf (CTDL_INFO, "Initialise modules, CtdlThreads not yet enabled.\n");
121 EOF
122
123
124 #start the header file
125 cat <<EOF > $H_FILE
126 /* 
127  * $H_FILE
128  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
129  */
130
131
132 #ifndef MODULES_INIT_H
133 #define MODULES_INIT_H
134 #include "ctdl_module.h"
135 extern size_t nSizErrmsg;
136 void initialise_modules (int threading);
137 void upgrade_modules(void);
138 EOF
139
140 for i in serv_*.c
141 do
142         RES=X`grep CTDL_MODULE_INIT $i | cut -f2 -d\( | cut -f1 -d\)`
143         if [ $RES != "X" ] ; then
144                 RES_OUT=`echo $RES | cut -b2-`
145                 /usr/bin/printf "Found entry point in file $i\n"
146 cat <<EOF  >> $C_FILE
147         CtdlLogPrintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT));
148
149 EOF
150 cat <<EOF >>$H_FILE
151 CTDL_MODULE_INIT($RES_OUT);
152 EOF
153         fi
154         RES=X`grep CTDL_MODULE_UPGRADE $i | cut -f2 -d\( | cut -f1 -d\)`
155         if [ $RES != "X" ] ; then
156                 RES_OUT=`echo $RES | cut -b2-`
157                 /usr/bin/printf "Found upgrade point in file $i\n"
158 cat <<EOF  >> $U_FILE
159         CtdlLogPrintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
160
161 EOF
162 cat <<EOF >>$H_FILE
163 CTDL_MODULE_UPGRADE($RES_OUT);
164 EOF
165         fi
166 done
167
168
169 if [ -d "modules" ] ; then
170         cd modules
171         for j in *
172         do
173                 if [ -d $j ] ; then
174                         cd $j
175                         for k in *.c
176                         do
177                                 if [ -f "$k" ] ; then
178 # Add this .c file to the Makefile included list of SOURCES
179 cat <<EOF >> $SRC_FILE
180 SOURCES += modules/$j/$k
181 EOF
182
183 # Generate a .o file name
184 O_FILE=`basename $k .c`
185 O_FILE="$O_FILE.o"
186 # Add this .o file to the Makefile included list of SERV_MODULES
187 cat <<EOF >> $MOD_FILE
188 SERV_MODULES += modules/$j/$O_FILE
189 EOF
190         
191                                         RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
192                                         if [ $RES != "X" ] ; then
193                                                 RES_OUT=`echo $RES | cut -b2-`
194                                                 /usr/bin/printf "Found entry point in file modules/$j/$k\n"
195 # Add this entry point to the .c file
196 cat <<EOF >> $C_FILE
197         CtdlLogPrintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT));
198 EOF
199 # Add this entry point to the .h file
200 cat <<EOF >> $H_FILE
201         CTDL_MODULE_INIT($RES_OUT);
202 EOF
203                                         fi
204                                         RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)`
205                                         if [ $RES != "X" ] ; then
206                                                 RES_OUT=`echo $RES | cut -b2-`
207                                                 /usr/bin/printf "Found upgrade point in file modules/$j/$k\n"
208 # Add this entry point to the .c file
209 cat <<EOF >> $U_FILE
210         CtdlLogPrintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
211 EOF
212 # Add this entry point to the .h file
213 cat <<EOF >> $H_FILE
214         CTDL_MODULE_UPGRADE($RES_OUT);
215 EOF
216                                         fi
217                                 fi
218                         done
219                         cd ..
220                 fi
221         done
222 fi
223
224 cd $CUR_DIR
225
226 if [ -d "user_modules" ] ; then
227         cd user_modules
228         for j in *
229         do
230                 if [ -d $j ] ; then
231                         cd $j
232                         for k in *.c
233                         do
234                                 if [ -f "$k" ] ; then
235 # Add this .c file to the Makefile included list of SOURCES
236 cat <<EOF >> $SRC_FILE
237 SOURCES=\$(SOURCES) user_modules/$j/$k
238 EOF
239
240 # Generate a .o file name
241 O_FILE=`basename $k .c`
242 O_FILE="$O_FILE.o"
243 # Add this .o file to the Makefile included list of SERV_MODULES
244 cat <<EOF >> $MOD_FILE
245 SERV_MODULES += user_modules/$j/$O_FILE
246 EOF
247         
248                                         RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
249                                         if [ $RES != "X" ] ; then
250                                                 RES_OUT=`echo $RES | cut -b2-`
251                                                 /usr/bin/printf "Found entry point in file user_modules/$j/$k\n"
252 cat <<EOF >> $C_FILE
253         CtdlLogPrintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT));
254 EOF
255 cat <<EOF >> $H_FILE
256 CTDL_MODULE_INIT($RES_OUT);
257 EOF
258                                         fi
259                                         RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)`
260                                         if [ $RES != "X" ] ; then
261                                                 RES_OUT=`echo $RES | cut -b2-`
262                                                 /usr/bin/printf "Found upgrade point in file user_modules/$j/$k\n"
263 cat <<EOF >> $U_FILE
264         CtdlLogPrintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
265 EOF
266 cat <<EOF >> $H_FILE
267 CTDL_MODULE_UPGRADE($RES_OUT);
268 EOF
269                                         fi
270                                 fi
271                         done
272                         cd ..
273                 fi
274         done
275 fi
276
277 cd $CUR_DIR
278
279 /usr/bin/printf "\n\n" >> $C_FILE
280 /usr/bin/printf "\tfor (filter = 1; filter != 0; filter = filter << 1)\n" >> $C_FILE
281 /usr/bin/printf "\t\tif ((filter & DetailErrorFlags) != 0)\n" >> $C_FILE
282 /usr/bin/printf "\t\t\tLogPrintMessages(filter);\n" >> $C_FILE
283 /usr/bin/printf "}\n" >> $C_FILE
284
285 #close the upgrade file
286 /usr/bin/printf "}\n" >> $U_FILE
287
288 /usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE