Initial revision
[freeradius.git] / src / main / modules.sh
1 #!/bin/sh
2 OUTPUT=static_modules.h
3 INPUT=../raddb/modules
4
5 rm -f $OUTPUT
6
7 #######################################################################
8 #
9 #  Make static_modules.h from ../raddb/modules
10 #
11 #  This process is a little complicated.
12 #
13 #  We're trying to build a C header file, which defines a static
14 # structure, from the ../raddb/modules configuration file.  We want
15 # to include ONLY the modules which are being built, and ignore the others.
16 #  
17 #######################################################################
18
19
20 #######################################################################
21 #
22 #  Root through ../raddb/modules:
23 #
24 #  Remove comments
25 #
26 #  Remove blank lines (by looking for NON-blank lines)
27 #
28 #  Remove '.so' trailers from the module config file
29 # also, replace the FIRST '../' with '/', the FIRST './' with '/',
30 # and the delete from the FIRST '/' to the LAST '/', which is followed
31 # by an 'rlm'.
32 #
33 #  The last sed rule is a bit iffy... It requires ALL modules to begin
34 # with rlm, and there to be NO module configuration parameters containing
35 # the string '/rlm'.  It's rare, so I guess we're safe.
36 #
37 #  Look for pre-build rlm_foo.o files.  ONLY include the ones we're told
38 # too use, and ignore the rlm_bar.so's in ../raddb/modules which are
39 # there, but aren't in the MODULES list.
40 #
41 #######################################################################
42 MODULES=`echo $* | sed 's/ rlm/|rlm/g;s/\.o//g;'`
43 cat $INPUT | egrep -v '^#' \
44            | grep -i '^[a-z]' \
45            | egrep "$MODULES" \
46            | sed 's/\.so//;s/\.\.\//\//;s/\.\//\//;s/\/.*\/rlm/rlm/;' \
47            > .tmp.$$
48
49 #######################################################################
50 #
51 #  Create the output file a piece at a time.
52 #
53 #######################################################################
54 echo '#ifndef __STATIC_MODULES_H' >> $OUTPUT
55 echo '#define __STATIC_MODULES_H' >> $OUTPUT
56 echo >> $OUTPUT
57
58 echo '/* Automatically created header file: do not edit! */' >> $OUTPUT
59 echo >> $OUTPUT
60
61 # define the external functions by grabbing the module name
62 awk '{print "extern module_t " $2 ";"}' .tmp.$$ >> $OUTPUT
63
64 echo >> $OUTPUT
65
66 # initialize the array
67 echo 'static static_modules_t modules[] = {' >>  $OUTPUT
68
69 # grab the two fields from the input, and add structure wrappers
70 awk '{print "  {\"" $1 "\", \t&" $2 " },"}' .tmp.$$ >> $OUTPUT
71
72 # output a trailing empty structure for the array
73 echo '  { NULL, NULL }' >> $OUTPUT
74
75 # and close off the array
76 echo '};' >> $OUTPUT
77
78 echo >> $OUTPUT
79 echo '#endif __STATIC_MODULES_H' >> $OUTPUT
80
81 #######################################################################
82 #
83 #  Warn about modules in ../raddb/modules which will NOT be included
84 # in the static server.
85 #
86 #  The 'sort' and 'uniq' are the to be sure we complain only once.
87 #
88 #######################################################################
89 cat $INPUT | egrep -v '^#' \
90            | grep -i '^[a-z]' \
91            | awk '{print $2}' \
92            | egrep -v "$MODULES" \
93            | sed 's/\.so//;s/\.\.\//\//;s/\.\//\//;s/\/.*\/rlm/rlm/;' \
94            | sort \
95            | uniq \
96            > .tmp.$$
97 for x in `cat .tmp.$$`;do
98   echo Warning: Module $x will NOT be included in the server. >/dev/stderr
99   echo "         Delete it from ../raddb/modules, or ensure that $x can be built." >/dev/stderr
100 done
101
102 #######################################################################
103 #
104 #  Don't warn about modules in the MODULES list which are built, but are
105 # NOT in ../raddb/modules, and so will NOT be included in the server.
106 #
107 #######################################################################
108
109 # remove the intermediate config file
110 rm -f .tmp.$$
111