my @argvcopy=@ARGV;
if (grep /^reconf(igure)?$/, @argvcopy) {
+ die "reconfiguring with other arguments present isn't supported"
+ if scalar @argvcopy > 1;
if (-f "./configdata.pm") {
my $file = "./configdata.pm";
unless (my $return = do $file) {
}
}
-my %predefined;
+my %predefined = compiler_predefined($target{cc});
-if ($^O ne "VMS") {
- my $cc = "$config{cross_compile_prefix}$target{cc}";
-
- # collect compiler pre-defines from gcc or gcc-alike...
- open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
- while (<PIPE>) {
- m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
- $predefined{$1} = $2 // "";
- }
- close(PIPE);
-
- if (!$disabled{makedepend}) {
- # We know that GNU C version 3 and up as well as all clang
- # versions support dependency generation
- if ($predefined{__GNUC__} >= 3) {
- $config{makedepprog} = $cc;
- } else {
- $config{makedepprog} = which('makedepend');
- $disabled{makedepend} = "unavailable" unless $config{makedepprog};
- }
+if (!$disabled{makedepend}) {
+ # We know that GNU C version 3 and up as well as all clang
+ # versions support dependency generation
+ if ($predefined{__GNUC__} >= 3) {
+ $config{makedepprog} = "\$(CROSS_COMPILE)$target{cc}";
+ } else {
+ $config{makedepprog} = which('makedepend');
+ $disabled{makedepend} = "unavailable" unless $config{makedepprog};
}
}
-
# Deal with bn_ops ###################################################
$config{bn_ll} =0;
sub { _add($separator, @_, @x) };
}
+sub read_eval_file {
+ my $fname = shift;
+ my $content;
+ my @result;
+
+ open F, "< $fname" or die "Can't open '$fname': $!\n";
+ {
+ undef local $/;
+ $content = <F>;
+ }
+ close F;
+ {
+ local $@;
+
+ @result = ( eval $content );
+ warn $@ if $@;
+ }
+ return wantarray ? @result : $result[0];
+}
+
# configuration reader, evaluates the input file as a perl script and expects
# it to fill %targets with target configurations. Those are then added to
# %table.
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 = ();
+ my %targets;
+
{
# Protect certain tables from tampering
- local %table = %::table;
+ local %table = ();
- eval $content;
- warn $@ if $@;
+ %targets = read_eval_file($fname);
}
# For each target, check that it's configured with a hash table.
rename("$out.new", $out) || die "Can't rename $out.new, $!";
}
+sub compiler_predefined {
+ state %predefined;
+ my $default_compiler = shift;
+
+ return () if $^O eq 'VMS';
+
+ die 'compiler_predefines called without a default compiler'
+ unless $default_compiler;
+
+ if (! $predefined{$default_compiler}) {
+ my $cc = "$config{cross_compile_prefix}$default_compiler";
+
+ $predefined{$default_compiler} = {};
+
+ # collect compiler pre-defines from gcc or gcc-alike...
+ open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
+ while (my $l = <PIPE>) {
+ $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
+ $predefined{$default_compiler}->{$1} = $2 // '';
+ }
+ close(PIPE);
+ }
+
+ return %{$predefined{$default_compiler}};
+}
+
sub which
{
my ($name)=@_;