diff --git a/tools/tools/README b/tools/tools/README index 4f3206f92f46..fb28a807d9dc 100644 --- a/tools/tools/README +++ b/tools/tools/README @@ -23,6 +23,8 @@ gdb_regofs A simple tool that prints out a register offset table for mapping gdb(1) register numbers to struct reg and struct fpreg offsets. The tool is useful on selected platforms only. +genericize Turn a kernel config into something that can more easily + be diffed against the appropriate GENERIC. hcomp Compress header files by removing comments and whitespace. html-mv Rename HTML generated filenames to human readable filenames. ifinfo Uses the interface MIB to print out all the information diff --git a/tools/tools/genericize/Makefile b/tools/tools/genericize/Makefile new file mode 100644 index 000000000000..54b3fdb86134 --- /dev/null +++ b/tools/tools/genericize/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +SCRIPTS= genericize.pl + +.include diff --git a/tools/tools/genericize/genericize.pl b/tools/tools/genericize/genericize.pl new file mode 100755 index 000000000000..3cef7b1f6cd8 --- /dev/null +++ b/tools/tools/genericize/genericize.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2004 Dag-Erling Coïdan Smørgrav +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# $FreeBSD$ +# + +use strict; + +MAIN:{ + my %config; + my $machine; + my $ident; + + while (<>) { + chomp(); + s/\s*(\#.*)?$//; + next unless $_; + #print("$_\n"); + my ($keyword, $values) = split(' ', $_, 2); + foreach my $value (split(/,\s*/, $values)) { + if ($keyword eq 'machine') { + $machine = $value; + } elsif ($keyword eq 'ident') { + $ident = $value; + } else { + $config{$keyword}->{$value} = 1; + } + #print "$keyword $value\n"; + } + } + + my $generic = "/usr/src/sys/$machine/conf/GENERIC"; + local *GENERIC; + open(GENERIC, "<", $generic) + or die("$generic: $!\n"); + my $blank = 0; + while () { + my $line = $_; + chomp(); + ++$blank unless $_; + s/\s*(\#.*)?$//; + next unless $_; + my ($keyword, $value) = split(' ', $_); + if ($keyword eq 'machine') { + die("$generic is for $value, not $machine\n") + unless ($value eq $machine); + if ($blank) { + print "\n"; + $blank = 0; + } + } elsif ($keyword eq 'ident') { + $line =~ s/$value/$ident/; + } elsif ($config{$keyword}->{$value}) { + delete($config{$keyword}->{$value}); + delete($config{$keyword}) + unless %{$config{$keyword}}; + } else { + next; + } + if ($blank) { + print "\n"; + $blank = 0; + } + print $line; + } + close(GENERIC); + + if (%config) { + print "\n# Addenda\n"; + foreach my $keyword (sort(keys(%config))) { + foreach my $value (sort(keys(%{$config{$keyword}}))) { + print "$keyword"; + if (length($keyword) < 7) { + print "\t"; + } elsif (length($keyword) == 7) { + print " "; + } + print "\t$value\n"; + } + } + } + exit(0); +}