]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | ||
5 | my @cmdnames; | |
6 | my @cmdlevels; | |
7 | my @cmdargs; | |
8 | my @cmddesc; | |
9 | my @cmdfunc; | |
10 | my @protos; | |
11 | my @files; | |
35227ed4 | 12 | my @help; |
1dd6d55d | 13 | |
14 | my @filelist = <*.c>; | |
15 | ||
16 | my $modname; | |
17 | ||
18 | unless (@ARGV) { | |
19 | print "Usage: $0 <module name>\n"; | |
20 | exit(0); | |
21 | } else { | |
22 | $modname=$ARGV[0]; | |
23 | } | |
24 | ||
b3565978 CP |
25 | my $smallname; |
26 | $smallname=$modname; | |
27 | $smallname=~s/^chanserv_//; | |
28 | $smallname=~s/\.so$//; | |
29 | ||
1dd6d55d | 30 | for (@filelist) { |
31 | next if (/commandlist.c/); | |
b3565978 | 32 | next if (/init.c/); |
1dd6d55d | 33 | |
34 | my $fname = $_; | |
35227ed4 | 35 | my ($cn, $cl, $ca, $cd, $cf, $cp, $ch); |
36 | $ch=""; | |
1dd6d55d | 37 | |
38 | open INFILE,"<$fname"; | |
39 | ||
40 | while(<INFILE>) { | |
41 | chomp; | |
42 | ||
43 | if (/CMDNAME: (.*)/) { | |
44 | $cn=$1; | |
45 | } | |
46 | ||
47 | if (/CMDLEVEL: (.*)/) { | |
48 | $cl=$1; | |
49 | } | |
50 | ||
51 | if (/CMDARGS: (.*)/) { | |
52 | $ca=$1; | |
53 | } | |
54 | ||
55 | if (/CMDDESC: (.*)/) { | |
56 | $cd=$1; | |
57 | } | |
58 | ||
59 | if (/CMDFUNC: (.*)/) { | |
60 | $cf=$1; | |
61 | } | |
62 | ||
63 | if (/CMDPROTO: (.*)/) { | |
64 | $cp=$1; | |
65 | } | |
35227ed4 | 66 | |
67 | if (/CMDHELP: (.*)/) { | |
68 | $ch.=$1."\\n"; | |
69 | } | |
1dd6d55d | 70 | } |
71 | ||
72 | if (defined $cn and defined $cl and defined $ca and defined $cd and defined $cf and defined $cp) { | |
73 | # valid command found | |
74 | push @files, $fname; | |
75 | push @cmdnames, $cn; | |
76 | push @cmdlevels, $cl; | |
77 | push @cmdargs, $ca; | |
78 | push @cmddesc, $cd; | |
79 | push @cmdfunc, $cf; | |
80 | push @protos, $cp; | |
35227ed4 | 81 | push @help, $ch; |
1dd6d55d | 82 | } else { |
83 | print "Warning: found source file $fname without complete tags, skipping...\n"; | |
84 | } | |
85 | } | |
86 | ||
87 | if (@files < 1) { | |
88 | print "No commands found - are you in the right directory?\n"; | |
89 | print "Exiting before I destroy something important.\n"; | |
90 | exit(0); | |
91 | } | |
92 | ||
93 | ||
94 | open CL, ">commandlist.c"; | |
95 | ||
96 | print CL "/* Automatically generated by mkcommandlist.pl, do not edit. */\n\n"; | |
97 | print CL "#include \"../chanserv.h\"\n\n"; | |
98 | ||
99 | # Print prototypes | |
100 | print CL "/* Prototypes */\n"; | |
101 | foreach (@protos) { | |
102 | print CL "$_\n"; | |
103 | } | |
104 | ||
105 | my @names2 = @cmdnames; | |
106 | my @func2 = @cmdfunc; | |
107 | ||
b3565978 CP |
108 | print CL "void ".$smallname."_init(void);\n"; |
109 | print CL "void ".$smallname."_fini(void);\n\n"; | |
110 | ||
1dd6d55d | 111 | print CL "\nvoid _init() {\n"; |
b3565978 | 112 | print CL " ".$smallname."_init();\n"; |
1dd6d55d | 113 | |
114 | while (my $cn = shift @cmdnames) { | |
115 | print CL " chanservaddcommand(\"".$cn."\", ".(shift @cmdlevels).", ".(shift @cmdargs).", "; | |
35227ed4 | 116 | print CL (shift @cmdfunc).", \"".(shift @cmddesc)."\", \"".(shift @help),"\");\n"; |
1dd6d55d | 117 | } |
118 | ||
119 | print CL "}\n\nvoid _fini() {\n"; | |
b3565978 | 120 | print CL " ".$smallname."_fini();\n"; |
1dd6d55d | 121 | |
122 | while (my $cn = shift @names2) { | |
123 | print CL " chanservremovecommand(\"".$cn."\", ".(shift @func2).");\n"; | |
124 | } | |
125 | ||
126 | print CL "}\n"; | |
127 | ||
128 | close CL; | |
129 | ||
130 | open MF,">Makefile"; | |
131 | ||
132 | print MF "# Automatically generated Makefile, do not edit.\n\n"; | |
133 | ||
134 | print MF ".PHONY: all Makefile\n"; | |
135 | ||
136 | print MF "all: Makefile $modname\n\n"; | |
137 | ||
138 | print MF "Makefile:\n"; | |
139 | print MF "\t../mkcommandlist.pl $modname\n"; | |
140 | ||
141 | print MF "\n$modname: "; | |
142 | ||
143 | push @files,"commandlist.c"; | |
b3565978 | 144 | push @files,"init.c"; |
1dd6d55d | 145 | |
146 | foreach (@files) { | |
147 | s/.c$/.o/; | |
148 | print MF "$_ "; | |
149 | } | |
150 | ||
151 | print MF "\n"; | |
152 | print MF "\t ld -shared -Bdynamic -o \$\@ \$\^ \n"; | |
153 | ||
154 | close MF; |