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