#!/mit/watchmaker/vaxbin/perl
eval "exec /usr/bin/perl -S $0 $*"
	if $running_under_some_shell;
open(G,">Glossary") || die "Can't create Glossary.\n";
print G
'[This Glossary is automatically generated from the Unit files.  Do not edit
this file or your changes will be lost.  Edit the appropriate Unit instead.]

This file contains a listing of all the C preprocessor symbols and shell
variables whose value can be determined by a Configure script.  For the
most part, any symbol in UPPERCASE is a C preprocessor symbol, and
will be defined in config.h.  Symbols in lowercase are shell variables,
and are defined in config.sh.

If you write your shell scripts and C programs in terms of these symbols,
metaconfig can automatically build you a Configure script that will determine
the value of those symbols.  See the README file for a description of how
to use metaconfig.

In the following listing, the Unit: line indicates the name of the unit
where this symbol is defined, and the Wants: line indicates what other
symbols must be determined in order to figure out the value of this one.
If there is an "(Also defines ...)" entry, it indicates what other symbols
are defined by the Unit other than the one corresponding to the unit name.

Variable of the form d_* either have the value "define" or "/*undef", and
control whether some C preprocessor symbol gets defined or not.

';

@ARGV = <U/*.U>;
while (<>) {
    if (/^\?MAKE:.*:/) {
	($unit,$also,$wants) = /^\?MAKE:\s*(\w+)\s*(.*):\s*(.*)/;
	$head = '';
	$_ = "Unit: $unit";
	$_ .= " (Also defines $also)" if $also;
	while (length($_) > 70) {
	    $tmp = substr($_,0,70);
	    $tmp =~ s/^(.*) .*/$1/;
	    $head .= "\t$tmp\n";
	    $_ = ' ' . substr($_,length($tmp),9999);
	}
	$head .= "\t$_\n";
	$_ = "Wants: $wants";
	while (length($_) > 70) {
	    $tmp = substr($_,0,70);
	    $tmp =~ s/^(.*) .*/$1/;
	    $head .= "\t$tmp\n";
	    $_ = ' ' . substr($_,length($tmp),9999);
	}
	$head .= "\t$_\n\n";
    }
    if (s/^\?[CS]:(\w+):*[ 	]*$/$1:/) {
	$sym = $1;
	push(@syms,$sym);
	$def{$sym} .= $_ . $head;
    }
    elsif (s/^\?[CS]://) {
	if (/^\.$/) {
	    $def{$sym} .= "\n";
	    $sym = '';
	}
	else {
	    s/^(\t|  ? ? ? ? ? ? ?)//;
	    $def{$sym} .= "\t" . $_;
	}
    }
}

foreach $sym (sort @syms) {
    print G $def{$sym};
}
close G;
