1999-11-01 20:39:26 +03:00
|
|
|
#!/usr/pkg/bin/perl
|
1998-09-19 22:07:40 +04:00
|
|
|
#
|
1999-11-01 20:39:26 +03:00
|
|
|
# $NetBSD: file2netbsd,v 1.3 1999/11/01 17:39:26 christos Exp $
|
1998-09-19 22:07:40 +04:00
|
|
|
#
|
|
|
|
# Perl script to convert a standard distribution directory for file into
|
|
|
|
# a NetBSD source tree.
|
|
|
|
#
|
|
|
|
# This is done as a script so that as each distribution is released,
|
|
|
|
# only changes from the previous one need to be dealt with as
|
|
|
|
# modifications to this script and related files. This should
|
|
|
|
# reduce the cost of updating from a new release of xntp by an
|
|
|
|
# order of magnitude (or more?)
|
|
|
|
#
|
|
|
|
# This script requires two environment variables set:
|
|
|
|
# SRCDIR - file source directory
|
|
|
|
# TARGETDIR - name of the high level directory to make
|
|
|
|
#
|
|
|
|
# Written by Christos Zoulas July 17, 1997 for file-3.26
|
|
|
|
#
|
|
|
|
|
1999-11-01 20:39:26 +03:00
|
|
|
$version = "3.28";
|
1998-09-19 22:07:40 +04:00
|
|
|
|
|
|
|
# definitions ...
|
|
|
|
|
|
|
|
@subdirs = ("usr.bin/file", "usr.bin/file/magdir");
|
|
|
|
|
|
|
|
|
|
|
|
@filef = ("LEGAL.NOTICE", "MAINT",
|
1999-11-01 20:39:26 +03:00
|
|
|
"README", "apprentice.c", "ascmagic.c",
|
1998-09-19 22:07:40 +04:00
|
|
|
"compress.c", "file.c", "file.h", "fsmagic.c",
|
|
|
|
"internat.c", "is_tar.c", "names.h", "patchlevel.h",
|
|
|
|
"print.c", "readelf.c", "readelf.h", "softmagic.c", "tar.h");
|
|
|
|
#
|
|
|
|
# Utility Subroutines
|
|
|
|
#
|
|
|
|
|
|
|
|
sub makedir {
|
|
|
|
system("mkdir -p @_");
|
|
|
|
}
|
|
|
|
|
|
|
|
# &fixrcs (fromfile, tofile);
|
|
|
|
sub fixrcs
|
|
|
|
{
|
|
|
|
my ($f, $t) = @_;
|
|
|
|
my @keywords = ("Author", "Date", "Header", "Id", "Locker", "Log",
|
|
|
|
"Name", "RCSfile", "Revision", "Source", "State");
|
|
|
|
my $state = 0;
|
|
|
|
my $hdr = 0;
|
|
|
|
|
|
|
|
open(IFILE, "<$f") || die "Cannot open $f";
|
|
|
|
open(OFILE, ">$t") || die "Cannot create $t";
|
|
|
|
|
|
|
|
if ($t =~ /.*\.[0-9]/) {
|
|
|
|
print OFILE '.\\" $', 'NetBSD', '$', "\n", '.\\"', "\n";
|
|
|
|
}
|
|
|
|
elsif ($t =~ /.*\.[ch]/) {
|
|
|
|
print OFILE "/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
|
|
|
|
}
|
|
|
|
elsif ($t =~ /.*\.[yl]/) {
|
|
|
|
$hdr = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print OFILE '$', 'NetBSD', '$', "\n";
|
|
|
|
}
|
|
|
|
while (<IFILE>) {
|
|
|
|
if ($hdr == 1) {
|
|
|
|
if (/%{/) {
|
|
|
|
print OFILE "%{\n/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
|
|
|
|
$hdr = 0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($state == 2) {
|
|
|
|
if (/#endif/) {
|
|
|
|
print OFILE "#else\n__RCSID(", '"$', 'NetBSD', '$"',
|
|
|
|
");\n#endif\n";
|
|
|
|
$state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($state == 1) {
|
|
|
|
print OFILE "#if 0\n";
|
|
|
|
$state = 2;
|
|
|
|
}
|
|
|
|
if (/#ifndef lint/) {
|
|
|
|
print OFILE "#include <sys/cdefs.h>\n";
|
|
|
|
$state = 1;
|
|
|
|
}
|
|
|
|
foreach $key (@keywords) {
|
|
|
|
s/\$$key\$/$key/g;
|
|
|
|
s/\$$key:(.*)\$/$key:$1/g;
|
|
|
|
}
|
|
|
|
print OFILE $_;
|
|
|
|
}
|
|
|
|
close(IFILE) || die "closing input file";
|
|
|
|
close(OFILE) || die "closing output file";
|
|
|
|
}
|
|
|
|
|
|
|
|
# ©files (fromdir, todir, list of files);
|
|
|
|
sub copyfiles {
|
|
|
|
local ($fdir, $tdir, @list) = @_;
|
|
|
|
local ($f);
|
|
|
|
|
|
|
|
foreach $f (@list) {
|
|
|
|
print " $fdir/$f --> $tdir/$f\n";
|
|
|
|
&fixrcs("$fdir/$f", "$tdir/$f");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ©file (fromfile, tofile);
|
|
|
|
sub copyfile {
|
|
|
|
local ($f, $t) = @_;
|
|
|
|
|
|
|
|
print " $f --> $t\n";
|
|
|
|
&fixrcs("$f", "$t");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub uniq {
|
|
|
|
local (@inlist) = @_;
|
|
|
|
local (@outlist);
|
|
|
|
|
|
|
|
@outlist = ($inlist[0]);
|
|
|
|
for ( $i=1; $i < @inlist; $i++ ) {
|
|
|
|
if ($inlist[$i] ne $inlist[$i-1]) {
|
|
|
|
push (@outlist, $inlist[$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@outlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dumpsrcs {
|
|
|
|
local (@names) = @_;
|
|
|
|
local ($count);
|
|
|
|
|
|
|
|
print ODATA "SRCS=\t";
|
|
|
|
$count = 0;
|
|
|
|
while ($f = pop(@names)) {
|
|
|
|
print ODATA "$f ";
|
|
|
|
if ($count == 5 && @names > 0) {
|
|
|
|
print ODATA "\\\n";
|
|
|
|
$count = 0;
|
|
|
|
} else {
|
|
|
|
$count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($count != 0) {
|
|
|
|
print ODATA "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Main progarm.
|
|
|
|
#
|
|
|
|
|
|
|
|
$srcdir = $ENV{'SRCDIR'};
|
|
|
|
$targetdir = $ENV{'TARGETDIR'};
|
|
|
|
$incdirs = "-I. -I$srcdir/config -I$srcdir";
|
|
|
|
|
|
|
|
if (!$srcdir | !targetdir) {
|
|
|
|
die "You must define the environment variables SRCDIR and TARGETDIR.\n"
|
|
|
|
}
|
|
|
|
print "Making the NetBSD directory tree.\n";
|
|
|
|
foreach $f (@subdirs) {
|
|
|
|
print " -->$f\n";
|
|
|
|
makedir ("$targetdir/$f");
|
|
|
|
}
|
|
|
|
|
|
|
|
print "Populating the usr.bin/file directory.\n";
|
|
|
|
©files ("$srcdir", "$targetdir/usr.bin/file", @filef);
|
|
|
|
©file("$srcdir/file.man", "$targetdir/usr.bin/file/file.1");
|
|
|
|
©file("$srcdir/magic.man", "$targetdir/usr.bin/file/magic.5");
|
|
|
|
system("cat $srcdir/Header > $targetdir/usr.bin/file/Header");
|
|
|
|
system("cat $srcdir/Localstuff > $targetdir/usr.bin/file/Localstuff");
|
|
|
|
|
|
|
|
print "Populating the usr.bin/file/magdir directory.\n";
|
1999-11-01 20:39:26 +03:00
|
|
|
system("cp -rp $srcdir/Magdir/* $targetdir/usr.bin/file/magdir; chmod -R ug+w magdir");
|
1998-09-19 22:07:40 +04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Build makefiles
|
|
|
|
#
|
|
|
|
|
|
|
|
$first = "True";
|
|
|
|
while ($line = <DATA>) {
|
|
|
|
chop ($line);
|
|
|
|
if (substr($line,0,2) eq "%%") {
|
|
|
|
@cmd = split (/ /,$line);
|
|
|
|
if ($cmd[1] eq "file") {
|
|
|
|
print "Building $targetdir/$cmd[2]\n";
|
|
|
|
if ($first eq "") {
|
|
|
|
close (ODATA);
|
|
|
|
} else {
|
|
|
|
$first = "";
|
|
|
|
}
|
|
|
|
open (ODATA, ">$targetdir/$cmd[2]") ||
|
|
|
|
die "Could not create $targetdir/$cmd[2]";
|
|
|
|
} elsif ($cmd[1] eq "srcs") {
|
|
|
|
print " Defining SRCS for $cmd[2]\n";
|
|
|
|
if ($first) {
|
|
|
|
die "Data file must start with a %% file!";
|
|
|
|
}
|
|
|
|
if ($cmd[2] eq "amd") {
|
|
|
|
&dumpsrcs (@amdf, @amdef);
|
|
|
|
} elsif ($cmd[2] eq "amq") {
|
|
|
|
&dumpsrcs (@amqf, @amqef);
|
|
|
|
} elsif ($cmd[2] eq "pawd") {
|
|
|
|
&dumpsrcs (@pawdf, @pawdef);
|
|
|
|
} elsif ($cmd[2] eq "hlfsd") {
|
|
|
|
&dumpsrcs (@hlfsdf, @hlfsdef);
|
|
|
|
} elsif ($cmd[2] eq "fixmount") {
|
|
|
|
&dumpsrcs (@fixmountf, @fixmountef);
|
|
|
|
} elsif ($cmd[2] eq "fsinfo") {
|
|
|
|
&dumpsrcs (@fsinfof, @fsinfoef);
|
|
|
|
} elsif ($cmd[2] eq "libamu") {
|
|
|
|
&dumpsrcs (@libamuf, @libamuef);
|
|
|
|
} elsif ($cmd[2] eq "mk-amd-map") {
|
|
|
|
&dumpsrcs (@mkamdmapf, @mkamdmapef);
|
|
|
|
} elsif ($cmd[2] eq "wire-test") {
|
|
|
|
&dumpsrcs (@wiretestf, @wiretestef);
|
|
|
|
} elsif ($cmd[2] eq "doc") {
|
|
|
|
&dumpsrcs (@docf, @docef);
|
|
|
|
} else {
|
|
|
|
die "Unknown SRCS command";
|
|
|
|
}
|
|
|
|
} elsif ($cmd[1] eq "NetBSD") {
|
|
|
|
if ($first) {
|
|
|
|
die "Data section must start with a %% file!";
|
|
|
|
}
|
|
|
|
print ODATA "$cmd[2] \$"."NetBSD".": \$\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($first) {
|
|
|
|
die "Data file must start with a %% file!";
|
|
|
|
}
|
|
|
|
print ODATA "$line\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (ODATA);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sed transformations of files
|
|
|
|
#
|
|
|
|
|
|
|
|
foreach $n (keys(%sedlist)) {
|
|
|
|
print "Modifying $n\n";
|
|
|
|
system ("cd $targetdir; sed $sedlist{$n} $n > tmp; mv -f tmp $n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# end of the script
|
|
|
|
#
|
|
|
|
|
|
|
|
# what follows is the data for makefiles and other special files
|
|
|
|
# that need to be created.
|
|
|
|
|
|
|
|
__END__
|
|
|
|
%% file usr.bin/file/Makefile
|
|
|
|
%% NetBSD #
|
|
|
|
|
1999-11-01 20:39:26 +03:00
|
|
|
.include <bsd.own.mk>
|
|
|
|
|
|
|
|
MFILESDIR= /usr/share/misc
|
|
|
|
MFILES= magic
|
|
|
|
MAGIC= ${MFILESDIR}/${MFILES}
|
|
|
|
.if ${MKSHARE} != "no"
|
|
|
|
FILESDIR= ${MFILESDIR}
|
|
|
|
FILES= ${MFILES}
|
|
|
|
.endif
|
1998-09-19 22:07:40 +04:00
|
|
|
|
|
|
|
PROG= file
|
|
|
|
SRCS= file.c apprentice.c fsmagic.c softmagic.c ascmagic.c is_tar.c \
|
|
|
|
print.c compress.c readelf.c internat.c
|
1999-11-01 20:39:26 +03:00
|
|
|
CPPFLAGS+= -DMAGIC='"$(MAGIC)"' -DHAVE_CONFIG_H -I${.CURDIR}
|
1998-09-20 19:36:46 +04:00
|
|
|
CPPFLAGS+= -DBUILTIN_ELF -DELFCORE
|
1998-09-19 22:07:40 +04:00
|
|
|
MAN= file.1 magic.5
|
|
|
|
|
|
|
|
CLEANFILES+= magic
|
|
|
|
all: file magic
|
|
|
|
|
|
|
|
MAGDIRF:sh= echo $(.CURDIR)/magdir/[0-9a-z]*
|
|
|
|
MAGFILES= $(.CURDIR)/Header \
|
|
|
|
$(.CURDIR)/Localstuff \
|
|
|
|
$(.CURDIR)/magdir/netbsd \
|
|
|
|
${MAGDIRF}
|
|
|
|
|
1999-11-01 20:39:26 +03:00
|
|
|
.if ${MKSHARE} != "no"
|
1998-09-19 22:07:40 +04:00
|
|
|
magic: $(MAGFILES)
|
|
|
|
cat $(MAGFILES) > $(.TARGET)
|
1999-11-01 20:39:26 +03:00
|
|
|
.else
|
|
|
|
magic:
|
|
|
|
.endif
|
1998-09-19 22:07:40 +04:00
|
|
|
|
|
|
|
.include <bsd.prog.mk>
|
1999-11-01 20:39:26 +03:00
|
|
|
%% file usr.bin/file/config.h
|
|
|
|
/* config.h. Generated automatically by configure. */
|
|
|
|
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
|
|
|
|
|
|
|
/* Define to empty if the keyword does not work. */
|
|
|
|
/* #undef const */
|
|
|
|
|
|
|
|
/* Define if your struct stat has st_rdev. */
|
|
|
|
#define HAVE_ST_RDEV 1
|
|
|
|
|
|
|
|
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
|
|
|
|
#define HAVE_SYS_WAIT_H 1
|
|
|
|
|
|
|
|
/* Define if major, minor, and makedev are declared in <mkdev.h>. */
|
|
|
|
/* #undef MAJOR_IN_MKDEV */
|
|
|
|
|
|
|
|
/* Define if major, minor, and makedev are declared in <sysmacros.h>. */
|
|
|
|
/* #undef MAJOR_IN_SYSMACROS */
|
|
|
|
|
|
|
|
/* Define to `long' if <sys/types.h> doesn't define. */
|
|
|
|
/* #undef off_t */
|
|
|
|
|
|
|
|
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
|
|
|
/* #undef size_t */
|
|
|
|
|
|
|
|
/* Define if you have the ANSI C header files. */
|
|
|
|
#define STDC_HEADERS 1
|
|
|
|
|
|
|
|
/* Autoheader needs me */
|
|
|
|
#define PACKAGE "file"
|
|
|
|
|
|
|
|
/* Autoheader needs me */
|
|
|
|
#define VERSION "3.28"
|
|
|
|
|
|
|
|
/* Define if builtin ELF support is enabled. */
|
|
|
|
#define BUILTIN_ELF 1
|
|
|
|
|
|
|
|
/* Define if ELF core file support is enabled. */
|
|
|
|
#define ELFCORE 1
|
|
|
|
|
|
|
|
/* Define if the `long long' type works. */
|
|
|
|
#define HAVE_LONG_LONG 1
|
|
|
|
|
|
|
|
/* Define to `unsigned char' if standard headers don't define. */
|
|
|
|
#define uint8_t unsigned char
|
|
|
|
|
|
|
|
/* Define to `unsigned short' if standard headers don't define. */
|
|
|
|
#define uint16_t unsigned short
|
|
|
|
|
|
|
|
/* Define to `unsigned int' if standard headers don't define. */
|
|
|
|
#define uint32_t unsigned int
|
|
|
|
|
|
|
|
/* Define to `unsigned long long', if available, or `unsigned long', if
|
|
|
|
standard headers don't define. */
|
|
|
|
#define uint64_t unsigned long long
|
|
|
|
|
|
|
|
/* The number of bytes in a uint8_t. */
|
|
|
|
#define SIZEOF_UINT8_T 1
|
|
|
|
|
|
|
|
/* The number of bytes in a uint16_t. */
|
|
|
|
#define SIZEOF_UINT16_T 2
|
|
|
|
|
|
|
|
/* The number of bytes in a uint32_t. */
|
|
|
|
#define SIZEOF_UINT32_T 4
|
|
|
|
|
|
|
|
/* The number of bytes in a uint64_t. */
|
|
|
|
#define SIZEOF_UINT64_T 8
|
|
|
|
|
|
|
|
/* Define if you have the strerror function. */
|
|
|
|
#define HAVE_STRERROR 1
|
|
|
|
|
|
|
|
/* Define if you have the strtoul function. */
|
|
|
|
#define HAVE_STRTOUL 1
|
|
|
|
|
|
|
|
/* Define if you have the <unistd.h> header file. */
|
|
|
|
#define HAVE_UNISTD_H 1
|