#!/usr/bin/env perl

use warnings;
use strict;

my %matrix;
my @executables;
my %objects;

sub make_matrix
{
	my ($line, $e, @fields, $field);

	while (defined($line = <>)) {
		chomp($line);
		if ($line =~ "^ *\$") {
			next;
		}
		@fields = split(" ", $line);
		while (defined(($field = shift(@fields)))) {
			if ($field =~ ":\$") {
				$field =~ s/://;
				$e = $field;
				push(@executables, $e);
				next;
			}
			$matrix{$e . ">" . $field} = 1;
			$objects{$field} = 1;
		}
	}
}

sub print_safe_objects
{
	my @objs = keys(%objects);
	my ($o1, $o2, $e);

	foreach $o1 (@objs) {
		print("#ifdef MAIN_INPUT_FILE_IS_$o1\n");
		O2: foreach $o2 (@objs) {
			foreach $e (@executables) {
				if (!defined($matrix{$e . ">" . $o1})) {
					next;
				}
				if (defined($matrix{$e . ">" . $o2})) {
					next;
				}
				next O2;
			}
			$_ = $o2;
			tr/a-z/A-Z/;
			printf("SS_ENUM(%s);\n", $_);
		}
		print("#endif\n");
	}
}
make_matrix;
print_safe_objects;
