]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl -w | |
2 | ||
3 | # mkflat.pl: Makes a flat, statically linked version of newserv | |
4 | ||
5 | my @coredirs = ( "core", "parser", "lib" ); | |
6 | my @moduledirs; | |
7 | my $configfile="newserv.conf"; | |
8 | my $flatdir="flat"; | |
9 | ||
10 | if (defined $ARGV[0]) { | |
11 | $configfile=$ARGV[0]; | |
12 | } | |
13 | ||
14 | open CFG, $configfile or die "Unable to open $configfile: $!"; | |
15 | ||
16 | my $insection=0; | |
17 | ||
18 | while (<CFG>) { | |
19 | chomp; | |
20 | ||
21 | if (/\[core\]/) { | |
22 | $insection=1; | |
23 | next; | |
24 | } elsif (/\[\.*\]/) { | |
25 | $insection=0; | |
26 | next; | |
27 | } else { | |
28 | if ($insection && m/^loadmodule=(.*)$/) { | |
29 | push @moduledirs, $1; | |
30 | } | |
31 | } | |
32 | } | |
33 | ||
34 | close CFG; | |
35 | ||
36 | open NEWSERVH,">", $flatdir."/newserv.h" or die "Unable to open flat header: $!"; | |
37 | open NEWSERVC,">", $flatdir."/newserv.c" or die "Unable to open flat file : $!"; | |
38 | ||
39 | print NEWSERVC '#include "newserv.h"'."\n\n"; | |
40 | ||
41 | foreach (@coredirs) { | |
42 | my $dir=$_; | |
43 | opendir DIR, $_; | |
44 | my @files=readdir DIR; | |
45 | closedir DIR; | |
46 | ||
47 | foreach (@files) { | |
48 | if (/\.[ch]$/) { | |
49 | dofile($dir, $_, undef); | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | foreach (@moduledirs) { | |
55 | my $dir=$_; | |
56 | opendir DIR, $_; | |
57 | my @files=readdir DIR; | |
58 | closedir DIR; | |
59 | ||
60 | foreach (@files) { | |
61 | if (/\.[ch]$/) { | |
62 | dofile($dir, $_, $dir); | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | ||
68 | sub dofile { | |
69 | my ($dirname, $filename, $modname) = @_; | |
70 | ||
71 | open INFILE, $dirname."/".$filename or die "Unable to open file: $!"; | |
72 | ||
73 | if ($filename =~ /h$/) { | |
74 | # header file | |
75 | ||
76 | while(<INFILE>) { | |
77 | print NEWSERVH $_; | |
78 | } | |
79 | } else { | |
80 | # .c file | |
81 | ||
82 | open OUTFILE, ">", $flatdir."/".$dirname."_".$filename or die "Unable to open file $flatdir/${dirname}_$filename: "; | |
83 | ||
84 | # print OUTFILE '#include "newserv.h"'."\n\n"; | |
85 | ||
86 | while (<INFILE>) { | |
87 | # next if (/^#include \"/); # Skip local include files | |
88 | ||
89 | if (/void _init\(\)/ && defined $modname) { | |
90 | s/_init/${modname}_init/; | |
91 | } | |
92 | ||
93 | if (/void _fini\(\)/ && defined $modname) { | |
94 | s/_fini/${modname}_fini/; | |
95 | } | |
96 | ||
97 | if (/initmodules\(\);/) { | |
98 | foreach (@moduledirs) { | |
99 | print OUTFILE $_."_init\(\);"; | |
100 | print NEWSERVC $_."_init\(\);"; | |
101 | } | |
102 | next; | |
103 | } | |
104 | ||
105 | print OUTFILE $_; | |
106 | print NEWSERVC $_; | |
107 | } | |
108 | ||
109 | close OUTFILE; | |
110 | } | |
111 | } |