Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / usr.sbin / traceroute / trrt2netbsd
blob18336a78bbe8aa3f5aa91f475db8d66612b02e8c
1 #!/usr/local/bin/perl
3 # $NetBSD: trrt2netbsd,v 1.3 1999/02/26 22:43:03 christos Exp $
5 # Perl script to convert a standard distribution directory for traceroute into
6 # a NetBSD source tree.
8 # This is done as a script so that as each distribution is released,
9 # only changes from the previous one need to be dealt with as
10 # modifications to this script and related files. This should
11 # reduce the cost of updating from a new release of traceroute by an
12 # order of magnitude (or more?)
14 # This script requires two environment variables set:
15 # SRCDIR - traceroute source directory
16 # TARGETDIR - name of the high level directory to make
18 # Written by Christos Zoulas Oct 2nd, 1997 for traceroute-1.4a5
21 $version = "1.4a5";
23 # definitions ...
25 @subdirs = ("usr.sbin/traceroute");
27 @trrtf = ("ifaddrlist.c", "savestr.c", "traceroute.c");
29 @trrthf = ("gnuc.h", "ifaddrlist.h", "savestr.h");
31 @trrtmf = ("traceroute.8");
32 @trrtdf = ("CHANGES", "README");
33 @trrtaf = ("mean.awk", "median.awk");
36 # sed edit list: file, sed-program
37 %sedlist = ();
40 # Utility Subroutines
43 sub makedir {
44 system("mkdir -p @_");
47 # &fixrcs (fromfile, tofile);
48 sub fixrcs
50 my ($f, $t) = @_;
51 my @keywords = ("Author", "Date", "Header", "Id", "Locker", "Log",
52 "Name", "RCSfile", "Revision", "Source", "State");
53 my $state = 0;
54 my $hdr = 0;
56 open(IFILE, "<$f") || die "Cannot open $f";
57 open(OFILE, ">$t") || die "Cannot create $t";
59 if ($t =~ /.*\.[0-9]/) {
60 print OFILE '.\\" $', 'NetBSD', '$', "\n.\\\"", "\n";
62 elsif ($t =~ /.*\.[ch]/) {
63 print OFILE "/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
65 elsif ($t =~ /.*\.[yl]/) {
66 $hdr = 1;
68 else {
69 print OFILE '$', 'NetBSD', '$', "\n";
71 while (<IFILE>) {
72 if ($hdr == 1) {
73 if (/%{/) {
74 print OFILE "%{\n/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
75 $hdr = 0;
76 next;
79 if ($state == 2) {
80 if (/#endif/) {
81 print OFILE "#else\n__RCSID(", '"$', 'NetBSD', '$"',
82 ");\n#endif\n";
83 $state = 0;
86 if ($state == 1) {
87 print OFILE "#if 0\n";
88 $state = 2;
90 if (/#ifndef lint/) {
91 print OFILE "#include <sys/cdefs.h>\n";
92 $state = 1;
94 foreach $key (@keywords) {
95 s/\$$key\$/$key/g;
96 s/\$$key:(.*)\$/$key:$1/g;
98 print OFILE $_;
100 close(IFILE) || die "closing input file";
101 close(OFILE) || die "closing output file";
104 # &copyfiles (fromdir, todir, list of files);
105 sub copyfiles {
106 local ($fdir, $tdir, @list) = @_;
107 local ($f);
109 foreach $f (@list) {
110 print " $fdir/$f --> $tdir/$f\n";
111 &fixrcs("$fdir/$f", "$tdir/$f");
115 # &copyfile (fromfile, tofile);
116 sub copyfile {
117 local ($f, $t) = @_;
119 print " $f --> $t\n";
120 system ("cp $f $t");
123 sub uniq {
124 local (@inlist) = @_;
125 local (@outlist);
127 @outlist = ($inlist[0]);
128 for ( $i=1; $i < @inlist; $i++ ) {
129 if ($inlist[$i] ne $inlist[$i-1]) {
130 push (@outlist, $inlist[$i]);
134 @outlist;
137 sub dumpsrcs {
138 local (@names) = @_;
139 local ($count);
141 $count = 0;
142 while ($f = pop(@names)) {
143 print ODATA "$f ";
144 if ($count == 5 && @names > 0) {
145 print ODATA "\\\n";
146 $count = 0;
147 } else {
148 $count += 1;
151 if ($count != 0) {
152 print ODATA "\n";
157 # Main program.
160 $srcdir = $ENV{'SRCDIR'};
161 $targetdir = $ENV{'TARGETDIR'};
162 $incdirs = "-I. -I$srcdir/config -I$srcdir";
164 if (!$srcdir | !targetdir) {
165 die "You must define the environment variables SRCDIR and TARGETDIR.\n"
167 print "Making the NetBSD directory tree.\n";
168 foreach $f (@subdirs) {
169 print " -->$f\n";
170 makedir ("$targetdir/$f");
173 print "Populating the usr.sbin/traceroute directory.\n";
174 &copyfiles ("$srcdir", "$targetdir/usr.sbin/traceroute", @trrtf, @trrthf, @trrtdf,
175 @trrtmf, @trrtaf);
178 # Build makefiles
181 $first = "True";
182 while ($line = <DATA>) {
183 chop ($line);
184 if (substr($line,0,2) eq "%%") {
185 @cmd = split (/ /,$line);
186 if ($cmd[1] eq "file") {
187 print "Building $targetdir/$cmd[2]\n";
188 if ($first eq "") {
189 close (ODATA);
190 } else {
191 $first = "";
193 open (ODATA, ">$targetdir/$cmd[2]") ||
194 die "Could not create $targetdir/$cmd[2]";
195 } elsif ($cmd[1] eq "awks") {
196 print " Defining AWKS\n";
197 if ($first) {
198 die "Data file must start with a %% file!";
200 print ODATA "AWKS=\t";
201 &dumpsrcs (@trrtaf);
202 } elsif ($cmd[1] eq "srcs") {
203 print " Defining SRCS\n";
204 if ($first) {
205 die "Data file must start with a %% file!";
207 print ODATA "SRCS=\t";
208 &dumpsrcs (@trrtf);
209 } elsif ($cmd[1] eq "man") {
210 print " Defining MAN\n";
211 if ($first) {
212 die "Data file must start with a %% file!";
214 print ODATA "MAN=\t";
215 &dumpsrcs (@trrtmf);
216 } elsif ($cmd[1] eq "version") {
217 print " Defining VERSION\n";
218 print ODATA "char version[] = \"$version\";";
219 } elsif ($cmd[1] eq "NetBSD") {
220 if ($first) {
221 die "Data section must start with a %% file!";
223 print ODATA "$cmd[2] \$"."NetBSD".": \$ $cmd[3]\n";
225 } else {
226 if ($first) {
227 die "Data file must start with a %% file!";
229 print ODATA "$line\n";
232 close (ODATA);
235 # Sed transformations of files
237 foreach $n (keys(%sedlist)) {
238 print "Modifying $n\n";
239 system ("cd $targetdir; sed $sedlist{$n} $n > tmp; mv -f tmp $n");
243 # end of the script
246 # what follows is the data for makefiles and other special files
247 # that need to be created.
249 __END__
250 %% file usr.sbin/traceroute/Makefile
251 %% NetBSD #
253 WARNS?= 1
254 PROG= traceroute
255 %% man
257 CPPFLAGS+=-DHAVE_MALLOC_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_SOCKIO_H=1
258 CPPFLAGS+=-DHAVE_STRERROR=1 -DHAVE_SETLINEBUF=1 -DHAVE_SOCKADDR_SA_LEN=1
259 CPPFLAGS+=-DHAVE_RAW_OPTIONS=1
261 BINOWN= root
262 BINMODE=4555
264 %% srcs
265 SRCS+= version.c
267 %% awks
269 .include <bsd.prog.mk>
270 %% file usr.sbin/traceroute/version.c
271 %% NetBSD /* */
272 %% version