diff --git a/lib/Alien/Base/Wrapper.pm b/lib/Alien/Base/Wrapper.pm index cca973e7..702c798e 100644 --- a/lib/Alien/Base/Wrapper.pm +++ b/lib/Alien/Base/Wrapper.pm @@ -441,6 +441,77 @@ sub mm_args2 %args; } +=head2 checklib_args2 + + my %args = $abw->checklib_args2(%args); + my %args = Alien::Base::Wrapper->checklib_args2(%args); + +Returns arguments that you can pass into C, C or C from +L in order to compile/link against the Aliens specified. It works a little like +C above, except that instead of being applied to a hash of L +arguments, it is applied to a hash of L arguments. + + use Devel::CheckLib qw( check_lib_or_exit ); + use Alien::Base::Wrapper (); + + check_lib_or_exit( + Alien::Base::Wrapper->new('Alien::Foo')->checklib_args2( + lib => 'foo', + header => 'foo.h', + ), + ); + +The Alien's include paths are merged into C, its other compiler flags (such as +C<-D> defines) are merged into C, its library paths are merged into C, and +its libraries and other linker flags are merged into C, so that the C and +C
that you are checking for can be found using the environment provided by the Alien. + +Since L also allows you to specify C and C in the +L style, and merging those styles with the Alien flags is ambiguous, +C will throw an exception if you attempt to specify either of those. Use +C / C and C / C instead. + +=cut + +sub checklib_args2 +{ + my $self = shift; + $self = $default_abw unless ref $self; + my %args = @_; + + if(defined $args{LIBS} || defined $args{INC}) + { + require Carp; + Carp::croak("please do not specify your own LIBS or INC key with checklib_args2"); + } + + if(@{ $self->{cflags_I} }) + { + my @old = defined $args{incpath} ? (ref $args{incpath} ? @{ $args{incpath} } : ($args{incpath})) : (); + my @new = map { (my $x = $_) =~ s/^-I//; $x } @{ $self->{cflags_I} }; + $args{incpath} = [ @new, @old ]; + } + + if(@{ $self->{cflags_other} }) + { + $args{ccflags} = join ' ', @{ $self->{cflags_other} }, (defined $args{ccflags} ? $args{ccflags} : ()); + } + + if(@{ $self->{ldflags_L} }) + { + my @old = defined $args{libpath} ? (ref $args{libpath} ? @{ $args{libpath} } : ($args{libpath})) : (); + my @new = map { (my $x = $_) =~ s/^-L//; $x } @{ $self->{ldflags_L} }; + $args{libpath} = [ @new, @old ]; + } + + if(@{ $self->{ldflags_l} } || @{ $self->{ldflags_other} }) + { + $args{ldflags} = join ' ', @{ $self->{ldflags_l} }, @{ $self->{ldflags_other} }, (defined $args{ldflags} ? $args{ldflags} : ()); + } + + %args; +} + =head2 mb_args my %args = $abw->mb_args; diff --git a/t/alien_base_wrapper.t b/t/alien_base_wrapper.t index 79a4a48e..ad174972 100644 --- a/t/alien_base_wrapper.t +++ b/t/alien_base_wrapper.t @@ -376,6 +376,47 @@ subtest 'combine aliens' => sub { }; + subtest 'checklib_args2' => sub { + + my %cl_args = Alien::Base::Wrapper->checklib_args2( + lib => 'baz', + header => 'baz.h', + incpath => '/baz/include', + libpath => '/baz/lib', + ); + + note _dump(\%cl_args); + + is( + \%cl_args, + hash { + field lib => 'baz'; + field header => 'baz.h'; + field incpath => [ '/foo/include', '/bar/include', '/baz/include' ]; + field ccflags => '-DFOO5=1 -DBAR5=1'; + field libpath => [ '/foo/lib', '/foo/lib', '/baz/lib' ]; + field ldflags => '-lfoo -lbar --ld-foo --ld-bar'; + }, + ); + + }; + + subtest 'checklib_args2 refuses LIBS/INC' => sub { + + like( + dies { Alien::Base::Wrapper->checklib_args2( LIBS => '-lbaz' ) }, + qr{please do not specify your own LIBS or INC key}, + 'LIBS', + ); + + like( + dies { Alien::Base::Wrapper->checklib_args2( INC => '-I/baz/include' ) }, + qr{please do not specify your own LIBS or INC key}, + 'INC', + ); + + }; + subtest 'mb_args' => sub { my %mb_args = Alien::Base::Wrapper->mb_args;