-# Read configuration target stanzas from a file, so that people can have

-# local files with their own definitions

-sub read_config {

- my $fname = shift;

- open(CONFFILE, "< $fname")

- or die "Can't open configuration file '$fname'!\n";

- my $x = $/;

- undef $/;

- my $content = <CONFFILE>;

- $/ = $x;

- close(CONFFILE);

- my %targets = ();

- eval $content;

+my $base_target = "BASE"; # The template that all other inherit from

+our %table = ();

+our %config = ();

- # Make sure we have debug- targets first

- my @keys =

- sort {

- my $a_nd = $a =~ m/^debug-/ ? $' :$a;

- my $b_nd = $b =~ m/^debug-/ ? $' :$b;

- my $res = 0;

-

- if (($a_nd == $a) == ($b_nd == $b)) {

- # they are both debug- or not, compare them as they are

- $res = $a cmp $b;

- } elsif ($a_nd != $a) {

- # $a is debug-, make it lesser

- $res = -1;

- } else {

- # $b is debug-, make $a greater

- $res = 1;

- }

- $res;

- } keys %targets;

-

- foreach (@keys) {

- if (ref($targets{$_}) ne "HASH") {

- # Value is assumed to be a string. Split it up to

- # become a hash table of parameters. Also, try to

- # merge debug- variants with the non-debug target.

-

- # Start with converting the value from a string to a

- # standardised hash of fields. Using $tohash is safe,

- # if the input is already a hash ref, it's just returned

- # back.

- $targets{$_} = stringtohash($targets{$_});

-

- # If the current target is a debug target, there might

- # be a corresponding non-debug target that we can merge

- # with. If it isn't a debug- target, we've already done

- # as much merging as we can and do not need to bother

- # with that any more.

- if ($_ =~ m/^debug-/) {

- my $debugkey = $_;

- my $nondebugkey = $';

- my $debug = $targets{$debugkey};

- my $nondebug;

-

- if ($targets{$nondebugkey}) {

- $nondebug = stringtohash($targets{$nondebugkey});

- }

-

- if ($nondebug) {

- # There's both a debug and non-debug variant of

- # this target, so we should try to merge them

- # together.

-

- # First, check that the non-debug variant isn't

- # already built up with all it should have.

- if ($nondebug->{debug_cflags}

- || $nondebug->{release_cflags}

- || $nondebug->{debug_lflags}

- || $nondebug->{release_lflags}) {

- warn "there's a debug target $debugkey to be merged with a target $nondebugkey, but the latter seems to already have both nodebug and debug information. This requires human intervention. Skipping $debugkey...";