diff --git a/config/init/optimize.pm b/config/init/optimize.pm index ff97e57..c2d88e8 100644 --- a/config/init/optimize.pm +++ b/config/init/optimize.pm @@ -35,35 +35,34 @@ sub runstep { # A plain --optimize means use perl5's $Config{optimize}. If an argument # is given, however, use that instead. - my $request_optimize = $conf->options->get('optimize'); + my $request_optimize = $conf->options->get('optimize') || ''; - if (! defined $request_optimize) { + if (! $request_optimize) { $self->set_result('no'); $conf->debug("(none requested) "); return 1; } - $self->set_result('yes'); - my $gccversion = $conf->data->get( 'gccversion' ); - - my $options; - if ( $request_optimize ) { + my $optimization_level; + if ( $request_optimize eq '1' ) { + # i.e., if command-line has '--optimize', # start with perl5's flags ... - $options = $conf->data->get('optimize_provisional'); + $optimization_level = $conf->data->get('optimize_provisional'); # ... but gcc 4.1 doesn't like -mcpu=xx, i.e. it's deprecated + my $gccversion = $conf->data->get( 'gccversion' ); if ( defined $gccversion and $gccversion > 3.3 ) { - $options =~ s/-mcpu=/-march=/; + $optimization_level =~ s/-mcpu=/-march=/; } } else { - # use the command line verbatim - $options = $request_optimize; + # Otherwise, use the command-line verbatim, e.g. '--optimize=O3' + $optimization_level = $request_optimize; } # save the options, however we got them. - $conf->data->set( optimize => $options ); - $conf->debug("optimize options: ", $options, "\n"); + $conf->data->set( optimize => $optimization_level ); + $conf->debug("optimize options: ", $optimization_level, "\n"); # disable debug flags. $conf->data->set( cc_debug => '' ); @@ -73,6 +72,7 @@ sub runstep { if ($conf->data->get('cpuarch') eq 'amd64') { $conf->data->set('optimize::src/gc/system.c',''); } + $self->set_result('yes'); return 1; } diff --git a/t/steps/init/optimize-01.t b/t/steps/init/optimize-01.t index 39c37bb..f2a6502 100644 --- a/t/steps/init/optimize-01.t +++ b/t/steps/init/optimize-01.t @@ -3,7 +3,7 @@ # init/optimize-01.t use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 34; use Carp; use lib qw( lib t/configure/testlib ); use_ok('config::init::optimize'); @@ -68,16 +68,37 @@ $step = test_step_constructor_and_description($conf); $conf->replenish($serialized); +########## --optimize ########## + +# 'bare' --optimize should mean: default to what Perl 5 uses (typically, -O2), +# but perhaps with some manipulation due to GCC variations +($args, $step_list_ref) = process_options( { + argv => [q{--optimize}], + mode => q{configure}, +} ); +$conf->options->set( %{$args} ); +$step = test_step_constructor_and_description($conf); +$ret = $step->runstep($conf); +ok( defined $ret, "runstep() returned defined value" ); +my $perl5_setting = $conf->data->get('optimize_provisional'); +like( $conf->data->get('optimize'), + qr/$perl5_setting/, + "Simple '--optimize' defaulted to Perl 5 optimization level" ); + +$conf->replenish($serialized); + ########## --optimize=O2 ########## ($args, $step_list_ref) = process_options( { - argv => [q{--optimize=O2}], + argv => [q{--optimize=-O3}], mode => q{configure}, } ); $conf->options->set( %{$args} ); $step = test_step_constructor_and_description($conf); $ret = $step->runstep($conf); ok( defined $ret, "runstep() returned defined value" ); +is( $conf->data->get('optimize'), '-O3', + "Got optimization level explicitly requested" ); $conf->replenish($serialized);