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
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
44 system("mkdir -p @_");
47 # &fixrcs (fromfile, tofile);
51 my @keywords = ("Author", "Date", "Header", "Id", "Locker", "Log",
52 "Name", "RCSfile", "Revision", "Source", "State");
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]/) {
69 print OFILE
'$', 'NetBSD', '$', "\n";
74 print OFILE
"%{\n/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
81 print OFILE
"#else\n__RCSID(", '"$', 'NetBSD', '$"',
87 print OFILE
"#if 0\n";
91 print OFILE
"#include <sys/cdefs.h>\n";
94 foreach $key (@keywords) {
96 s/\$$key:(.*)\$/$key:$1/g;
100 close(IFILE
) || die "closing input file";
101 close(OFILE
) || die "closing output file";
104 # ©files (fromdir, todir, list of files);
106 local ($fdir, $tdir, @list) = @_;
110 print " $fdir/$f --> $tdir/$f\n";
111 &fixrcs
("$fdir/$f", "$tdir/$f");
115 # ©file (fromfile, tofile);
119 print " $f --> $t\n";
124 local (@inlist) = @_;
127 @outlist = ($inlist[0]);
128 for ( $i=1; $i < @inlist; $i++ ) {
129 if ($inlist[$i] ne $inlist[$i-1]) {
130 push (@outlist, $inlist[$i]);
142 while ($f = pop(@names)) {
144 if ($count == 5 && @names > 0) {
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) {
170 makedir
("$targetdir/$f");
173 print "Populating the usr.sbin/traceroute directory.\n";
174 ©files
("$srcdir", "$targetdir/usr.sbin/traceroute", @trrtf, @trrthf, @trrtdf,
182 while ($line = <DATA
>) {
184 if (substr($line,0,2) eq "%%") {
185 @cmd = split (/ /,$line);
186 if ($cmd[1] eq "file") {
187 print "Building $targetdir/$cmd[2]\n";
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";
198 die "Data file must start with a %% file!";
200 print ODATA
"AWKS=\t";
202 } elsif ($cmd[1] eq "srcs") {
203 print " Defining SRCS\n";
205 die "Data file must start with a %% file!";
207 print ODATA
"SRCS=\t";
209 } elsif ($cmd[1] eq "man") {
210 print " Defining MAN\n";
212 die "Data file must start with a %% file!";
214 print ODATA
"MAN=\t";
216 } elsif ($cmd[1] eq "version") {
217 print " Defining VERSION\n";
218 print ODATA
"char version[] = \"$version\";";
219 } elsif ($cmd[1] eq "NetBSD") {
221 die "Data section must start with a %% file!";
223 print ODATA
"$cmd[2] \$"."NetBSD".": \$ $cmd[3]\n";
227 die "Data file must start with a %% file!";
229 print ODATA
"$line\n";
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");
246 # what follows is the data for makefiles and other special files
247 # that need to be created.
250 %% file usr
.sbin
/traceroute/Makefile
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
269 .include
<bsd
.prog
.mk
>
270 %% file usr
.sbin
/traceroute/version
.c