aaa13f145b7e037b82585f1d4e4fce54211a3c4e
[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
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 c file
57 cat <<EOF  >$C_FILE
58 /*
59  * $C_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 void LogPrintMessages(long err);
78 extern long DetailErrorFlags;
79
80
81
82 void initialise_modules (int threading)
83 {
84     long filter;
85     nSizErrmsg = 0;
86
87     if (threading)
88         CtdlLogPrintf (CTDL_INFO, "Initialise modules, CtdlThreads enabled.\n");
89     else
90         CtdlLogPrintf (CTDL_INFO, "Initialise modules, CtdlThreads not yet enabled.\n");
91 EOF
92
93
94 #start the header file
95 cat <<EOF > $H_FILE
96 /* 
97  * $H_FILE
98  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
99  */
100
101
102 #ifndef MODULES_INIT_H
103 #define MODULES_INIT_H
104 #include "ctdl_module.h"
105 extern size_t nSizErrmsg;
106 void initialise_modules (int threading);
107
108 EOF
109
110 for i in serv_*.c
111 do
112         RES=X`grep CTDL_MODULE_INIT $i | cut -f2 -d\( | cut -f1 -d\)`
113         if [ $RES != "X" ] ; then
114                 RES_OUT=`echo $RES | cut -b2-`
115                 /usr/bin/printf "Found entry point in file $i\n"
116 cat <<EOF  >> $C_FILE
117         lprintf (CTDL_INFO, "%%s\n", CTDL_INIT_CALL($RES_OUT));
118
119 EOF
120 cat <<EOF >>$H_FILE
121 CTDL_MODULE_INIT($RES_OUT);
122 EOF
123         fi
124 done
125
126
127 if [ -d "modules" ] ; then
128         cd modules
129         for j in *
130         do
131                 if [ -d $j ] ; then
132                         cd $j
133                         for k in *.c
134                         do
135                                 if [ -f "$k" ] ; then
136 # Add this .c file to the Makefile included list of SOURCES
137 cat <<EOF >> $SRC_FILE
138 SOURCES += modules/$j/$k
139 EOF
140
141 # Generate a .o file name
142 O_FILE=`basename $k .c`
143 O_FILE="$O_FILE.o"
144 # Add this .o file to the Makefile included list of SERV_MODULES
145 cat <<EOF >> $MOD_FILE
146 SERV_MODULES += modules/$j/$O_FILE
147 EOF
148         
149                                         RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
150                                         if [ $RES != "X" ] ; then
151                                                 RES_OUT=`echo $RES | cut -b2-`
152                                                 /usr/bin/printf "Found entry point in file modules/$j/$k\n"
153 # Add this entry point to the .c file
154 cat <<EOF >> $C_FILE
155         lprintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT));
156 EOF
157 # Add this entry point to the .h file
158 cat <<EOF >> $H_FILE
159         CTDL_MODULE_INIT($RES_OUT);
160 EOF
161                                         fi
162                                 fi
163                         done
164                         cd ..
165                 fi
166         done
167 fi
168
169 cd $CUR_DIR
170
171 if [ -d "user_modules" ] ; then
172         cd user_modules
173         for j in *
174         do
175                 if [ -d $j ] ; then
176                         cd $j
177                         for k in *.c
178                         do
179                                 if [ -f "$k" ] ; then
180 # Add this .c file to the Makefile included list of SOURCES
181 cat <<EOF >> $SRC_FILE
182 SOURCES=\$(SOURCES) user_modules/$j/$k
183 EOF
184
185 # Generate a .o file name
186 O_FILE=`basename $k .c`
187 O_FILE="$O_FILE.o"
188 # Add this .o file to the Makefile included list of SERV_MODULES
189 cat <<EOF >> $MOD_FILE
190 SERV_MODULES += user_modules/$j/$O_FILE
191 EOF
192         
193                                         RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
194                                         if [ $RES != "X" ] ; then
195                                                 RES_OUT=`echo $RES | cut -b2-`
196                                                 /usr/bin/printf "Found entry point in file user_modules/$j/$k\n"
197 cat <<EOF >> $C_FILE
198         lprintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT));
199 EOF
200 cat <<EOF >> $H_FILE
201 CTDL_MODULE_INIT($RES_OUT);
202 EOF
203                                         fi
204                                 fi
205                         done
206                         cd ..
207                 fi
208         done
209 fi
210
211 cd $CUR_DIR
212
213 /usr/bin/printf "\n\n" >> $C_FILE
214 /usr/bin/printf "\tfor (filter = 1; filter != 0; filter = filter << 1)\n" >> $C_FILE
215 /usr/bin/printf "\t\tif ((filter & DetailErrorFlags) != 0)\n" >> $C_FILE
216 /usr/bin/printf "\t\t\tLogPrintMessages(filter);\n" >> $C_FILE
217 /usr/bin/printf "}\n" >> $C_FILE
218
219
220 /usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE