On Wed Apr 23 18:40:46 2008, [EMAIL PROTECTED] wrote:
> There are five configuration step classes where the class's runstep()
> method has an internal subroutine called _handle_mswin32(). These
> classes are:
>
> config/auto//crypto.pm
> config/auto//gettext.pm
> config/auto//gmp.pm
> config/auto//opengl.pm
> config/auto//readline.pm
>
> Attached is an example of this subroutine, in this case, from
> auto::readline:
>
Please see patch attached. It turned out that config/auto/opengl.pm
didn't quite conform to the pattern, so I left it unchanged.
Thank you very much.
kid51
Index: lib/Parrot/Configure/Step/Methods.pm
===================================================================
--- lib/Parrot/Configure/Step/Methods.pm (revision 27160)
+++ lib/Parrot/Configure/Step/Methods.pm (working copy)
@@ -24,12 +24,10 @@
Since the methods are not part of the public interface, their names should
begin with an underscore 'C<_>'.
-=head2 Methods
+=head1 METHODS
-=over 4
+=head2 C<_recheck_settings()>
-=item C<_recheck_settings()>
-
$self->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
Currently used in configuration step classes auto::gmp, auto::readline,
@@ -46,7 +44,7 @@
$self->set_result('no');
}
-=item C<_handle_darwin_for_fink()>
+=head2 C<_handle_darwin_for_fink()>
$self->_handle_darwin_for_fink($conf, $libs, $osname, $file);
@@ -83,6 +81,21 @@
return 1;
}
+=head2 C<_handle_darwin_for_macports()>
+
+ $self->_handle_darwin_for_macports($conf, $libs, $osname, $file);
+
+Currently used in configuration step classes auto::gmp, auto::readline and
+auto::opengl.
+
+Modifies settings for C<linkflags>, C<ldflags> and C<ccflags> in the
+Parrot::Configure object's data structure.
+
+Potentially expandable to cover all BSD-ports systems -- but as yet there has
+been no demand.
+
+=cut
+
sub _handle_darwin_for_macports {
my ($self, $conf, $osname, $file) = @_;
if ( $osname =~ /darwin/ ) {
@@ -98,8 +111,90 @@
return 1;
}
+=head2 C<_add_to_libs()>
+
+ $self->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lglut32 -lglu32 -lopengl32',
+ win32_other => 'readline.lib',
+ non_win32 => '-lreadline',
+ } );
+
+B<Purpose>: In a number of configuration step classes, the class's
+C<runstep()> method adds libraries to the wordspace-delimited string found in
+the Parrot::Configure object's C<libs> attribute. In these classes, the
+libraries to be added fall into one of three categories:
+
+=over 4
+
+=item * What to do on mswin32 with F<gcc> as the C-compiler?
+
+=item * What to do on mswin32 with any C-compiler other thann F<gcc>?
+
+=item * What to do on any operating system other than mswin32?
+
=back
+This method provides a uniform interface to this internal subroutine.
+
+B<Arguments>: Reference to a hash with the following key-value pairs:
+
+=over 4
+
+=item * C<conf>
+
+The Parrot::Configure object. Supplied within C<runstep()>.
+
+=item * C<osname>
+
+The name of the operating system. Supplied within C<runstep()>.
+
+=item * C<cc>
+
+The name of the C-compiler. Supplied within C<runstep()>.
+
+=item * C<win32_gcc>
+
+Libraries to be added where OS is mswin32 and C-compiler is F<gcc>.
+Wordspace-delimited string.
+
+=item * C<win32_other>
+
+Libraries to be added where OS is mswin32 and C-compiler is not F<gcc>.
+Wordspace-delimited string.
+
+=item * C<non_win32>
+
+Libraries to be added where OS is not mswin32.
+Wordspace-delimited string.
+
+=back
+
+B<Return Value>: Returns true value upon success.
+
+=cut
+
+sub _add_to_libs {
+ my $self = shift;
+ my $args = shift;
+ die "_add_to_libs() takes hashref: $!" unless ref($args) eq 'HASH';
+ if ( $args->{osname} =~ /mswin32/i ) {
+ if ( $args->{cc} =~ /^gcc/i ) {
+ $args->{conf}->data->add( ' ', libs => $args->{win32_gcc} );
+ }
+ else {
+ $args->{conf}->data->add( ' ', libs => $args->{win32_other} );
+ }
+ }
+ else {
+ $args->{conf}->data->add( ' ', libs => $args->{non_win32} );
+ }
+ return 1;
+}
+
+
=head1 SEE ALSO
Parrot::Configure::Step.
Index: t/steps/auto_readline-01.t
===================================================================
--- t/steps/auto_readline-01.t (revision 27160)
+++ t/steps/auto_readline-01.t (working copy)
@@ -46,22 +46,43 @@
my ($osname, $cc);
$osname = 'mswin32';
$cc = 'gcc';
-ok(auto::readline::_handle_mswin32($conf, $osname, $cc),
- "_handle_mswin32() returned true value");
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lreadline',
+ win32_other => 'readline.lib',
+ non_win32 => '-lreadline',
+} ),
+ "_add_to_libs() returned true value");
like($conf->data->get( 'libs' ), qr/-lreadline/,
"'libs' modified as expected");
$osname = 'mswin32';
$cc = 'cc';
-ok(auto::readline::_handle_mswin32($conf, $osname, $cc),
- "_handle_mswin32() returned true value");
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lreadline',
+ win32_other => 'readline.lib',
+ non_win32 => '-lreadline',
+} ),
+ "_add_to_libs() returned true value");
like($conf->data->get( 'libs' ), qr/readline\.lib/,
"'libs' modified as expected");
$osname = 'foobar';
$cc = undef;
-ok(auto::readline::_handle_mswin32($conf, $osname, $cc),
- "_handle_mswin32() returned true value");
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lreadline',
+ win32_other => 'readline.lib',
+ non_win32 => '-lreadline',
+} ),
+ "_add_to_libs() returned true value");
like($conf->data->get( 'libs' ), qr/-lreadline/,
"'libs' modified as expected");
Index: t/steps/auto_gmp-02.t
===================================================================
--- t/steps/auto_gmp-02.t (revision 27160)
+++ t/steps/auto_gmp-02.t (working copy)
@@ -43,27 +43,55 @@
ok( $step->description(), "$step_name has description" );
# Mock values for OS and C-compiler
-my ($osname, $cc);
+my ($osname, $cc, $initial_value);
$osname = 'mswin32';
$cc = 'gcc';
-ok(auto::gmp::_handle_mswin32($conf, $osname, $cc),
- "_handle_mswin32() returned true value");
+$initial_value = $conf->data->get( 'libs' );
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lgmp',
+ win32_other => 'gmp.lib',
+ non_win32 => '-lgmp',
+} ),
+ "_add_to_libs() returned true value");
like($conf->data->get( 'libs' ), qr/-lgmp/,
"'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
$osname = 'mswin32';
$cc = 'cc';
-ok(auto::gmp::_handle_mswin32($conf, $osname, $cc),
- "_handle_mswin32() returned true value");
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lgmp',
+ win32_other => 'gmp.lib',
+ non_win32 => '-lgmp',
+} ),
+ "_add_to_libs() returned true value");
like($conf->data->get( 'libs' ), qr/gmp\.lib/,
"'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
$osname = 'foobar';
$cc = undef;
-ok(auto::gmp::_handle_mswin32($conf, $osname, $cc),
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lgmp',
+ win32_other => 'gmp.lib',
+ non_win32 => '-lgmp',
+} ),
"_handle_mswin32() returned true value");
like($conf->data->get( 'libs' ), qr/-lgmp/,
"'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
my ($flagsbefore, $flagsafter);
$osname = 'foobar';
Index: t/steps/auto_gettext-02.t
===================================================================
--- t/steps/auto_gettext-02.t (revision 27160)
+++ t/steps/auto_gettext-02.t (working copy)
@@ -5,7 +5,7 @@
use strict;
use warnings;
-use Test::More tests => 18;
+use Test::More tests => 26;
use Carp;
use lib qw( lib t/configure/testlib );
use_ok('config::init::defaults');
@@ -41,6 +41,73 @@
isa_ok( $step, $step_name );
ok( $step->description(), "$step_name has description" );
+# Mock values for OS and C-compiler
+my ($osname, $cc, $initial_value);
+$osname = 'mswin32';
+$cc = 'gcc';
+$initial_value = $conf->data->get( 'libs' );
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lintl',
+ win32_other => 'intl.lib',
+ non_win32 => defined $conf->data->get('glibc') ? '' : '-lintl',
+} ),
+ "_add_to_libs() returned true value");
+like($conf->data->get( 'libs' ), qr/-lintl/,
+ "'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
+
+$osname = 'mswin32';
+$cc = 'cc';
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lintl',
+ win32_other => 'intl.lib',
+ non_win32 => defined $conf->data->get('glibc') ? '' : '-lintl',
+} ),
+ "_add_to_libs() returned true value");
+like($conf->data->get( 'libs' ), qr/intl.lib/,
+ "'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
+
+$osname = 'foobar';
+$cc = 'cc';
+$conf->data->set( glibc => 1 );
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lintl',
+ win32_other => 'intl.lib',
+ non_win32 => defined $conf->data->get('glibc') ? '' : '-lintl',
+} ),
+ "_add_to_libs() returned true value");
+unlike($conf->data->get( 'libs' ), qr/-lintl/,
+ "'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
+
+$osname = 'foobar';
+$cc = 'cc';
+$conf->data->set( glibc => undef );
+ok($step->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lintl',
+ win32_other => 'intl.lib',
+ non_win32 => defined $conf->data->get('glibc') ? '' : '-lintl',
+} ),
+ "_add_to_libs() returned true value");
+like($conf->data->get( 'libs' ), qr/-lintl/,
+ "'libs' modified as expected");
+
my ($test, $verbose);
my $has_gettext;
Index: config/auto/gettext.pm
===================================================================
--- config/auto/gettext.pm (revision 27160)
+++ config/auto/gettext.pm (working copy)
@@ -57,7 +57,14 @@
my $osname = $conf->data->get_p5('OSNAME');
- _handle_mswin32($conf, $osname, $cc);
+ $self->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lintl',
+ win32_other => 'intl.lib',
+ non_win32 => defined $conf->data->get('glibc') ? '' : '-lintl',
+ } );
# On OS X check the presence of the gettext header in the standard
# Fink location.
@@ -82,24 +89,6 @@
return 1;
}
-sub _handle_mswin32 {
- my ($conf, $osname, $cc) = @_;
- if ( $osname =~ /mswin32/i ) {
- if ( $cc =~ /^gcc/i ) {
- $conf->data->add( ' ', libs => '-lintl' );
- }
- else {
- $conf->data->add( ' ', libs => 'intl.lib' );
- }
- }
- else {
- # don't need to link with libintl if we have GNU libc
- my $linklibs = defined $conf->data->get('glibc') ? '' : '-lintl';
- $conf->data->add( ' ', libs => $linklibs );
- }
- return 1;
-}
-
sub _evaluate_cc_run {
my $self = shift;
my ($test, $verbose) = @_;
Index: config/auto/gmp.pm
===================================================================
--- config/auto/gmp.pm (revision 27160)
+++ config/auto/gmp.pm (working copy)
@@ -63,7 +63,14 @@
my $osname = $conf->data->get_p5('OSNAME');
- _handle_mswin32($conf, $osname, $cc);
+ $self->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lgmp',
+ win32_other => 'gmp.lib',
+ non_win32 => '-lgmp',
+ } );
# On OS X check the presence of the gmp header in the standard
# Fink location.
@@ -85,22 +92,6 @@
return 1;
}
-sub _handle_mswin32 {
- my ($conf, $osname, $cc) = @_;
- if ( $osname =~ /mswin32/i ) {
- if ( $cc =~ /^gcc/i ) {
- $conf->data->add( ' ', libs => '-lgmp' );
- }
- else {
- $conf->data->add( ' ', libs => 'gmp.lib' );
- }
- }
- else {
- $conf->data->add( ' ', libs => '-lgmp' );
- }
- return 1;
-}
-
sub _evaluate_cc_run {
my ($self, $conf, $test, $has_gmp, $verbose) = @_;
if ( $test eq $self->{cc_run_expected} ) {
Index: config/auto/crypto.pm
===================================================================
--- config/auto/crypto.pm (revision 27160)
+++ config/auto/crypto.pm (working copy)
@@ -52,7 +52,14 @@
my $osname = $conf->data->get_p5('OSNAME');
- _handle_mswin32($conf, $osname, $cc);
+ $self->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lcrypto',
+ win32_other => 'libcrypto.lib',
+ non_win32 => '-lcrypto',
+ } );
$conf->cc_gen('config/auto/crypto/crypto.in');
eval { $conf->cc_build(); };
@@ -70,22 +77,6 @@
return 1;
}
-sub _handle_mswin32 {
- my ($conf, $osname, $cc) = @_;
- if ( $osname =~ /mswin32/i ) {
- if ( $cc =~ /^gcc/i ) {
- $conf->data->add( ' ', libs => '-lcrypto' );
- }
- else {
- $conf->data->add( ' ', libs => 'libcrypto.lib' );
- }
- }
- else {
- $conf->data->add( ' ', libs => '-lcrypto' );
- }
- return 1;
-}
-
sub _evaluate_cc_run {
my $self = shift;
my ($conf, $test, $has_crypto, $verbose) = @_;
Index: config/auto/readline.pm
===================================================================
--- config/auto/readline.pm (revision 27160)
+++ config/auto/readline.pm (working copy)
@@ -45,7 +45,14 @@
my $osname = $conf->data->get_p5('OSNAME');
- _handle_mswin32($conf, $osname, $cc);
+ $self->_add_to_libs( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_gcc => '-lreadline',
+ win32_other => 'readline.lib',
+ non_win32 => '-lreadline',
+ } );
# On OS X check the presence of the readline header in the standard
# Fink/macports locations.
@@ -79,22 +86,6 @@
return 1;
}
-sub _handle_mswin32 {
- my ($conf, $osname, $cc) = @_;
- if ( $osname =~ /mswin32/i ) {
- if ( $cc =~ /^gcc/i ) {
- $conf->data->add( ' ', libs => '-lreadline' );
- }
- else {
- $conf->data->add( ' ', libs => 'readline.lib' );
- }
- }
- else {
- $conf->data->add( ' ', libs => '-lreadline' );
- }
- return 1;
-}
-
sub _handle_ncurses_need {
my ($conf, $osname, $cc) = @_;
if ( $osname =~ /mswin32/i ) {