Alien-wxWidgets
view release on metacpan or search on metacpan
inc/My/Build/Any_wx_config.pm view on Meta::CPAN
package My::Build::Any_wx_config;
use strict;
use base qw(My::Build::Any_wx_config_Bakefile);
use My::Build::Utility qw(awx_arch_dir awx_install_arch_dir);
our $WX_CONFIG_LIBSEP;
our @LIBRARIES = qw(base net xml adv animate aui core fl gizmos gl html
media propgrid qa ribbon richtext stc webview xrc);
our @MONO_LIBRARIES_2_9 = qw(core gl);
our @MONO_LIBRARIES_2_8 = qw(core stc gl);
our @CONTRIB_LIBRARIES = qw(gizmos_xrc ogl plot svg);
our @CRITICAL = qw(base core);
our @IMPORTANT = qw(net xml adv aui gl html media richtext stc xrc );
my $initialized;
my( $wx_debug, $wx_unicode, $wx_monolithic );
sub _find {
my( $name ) = @_;
return $name if File::Spec->file_name_is_absolute( $name );
foreach my $dir ( File::Spec->path ) {
my $abs = File::Spec->catfile( $dir, $name );
return $abs if -x $abs;
}
return $name;
}
sub _init {
my $build = shift;
return if $initialized;
$initialized = 1;
lib->import( qw(lib inc) );
my $wx_config = ( $build && $build->notes( 'wx_config' ) )
|| $ENV{WX_CONFIG} || 'wx-config';
my $ver = `$wx_config --version` or die "Can't execute '$wx_config': $!";
$build->notes( 'wx_config' => _find( $wx_config ) )
if $build && !$build->notes( 'wx_config' );
$ver = __PACKAGE__->_version_2_dec( $ver );
my $base = `$wx_config --basename`;
$wx_debug = $base =~ m/d$/ ? 1 : 0;
$wx_unicode = $base =~ m/ud?$/ ? 1 : 0;
$WX_CONFIG_LIBSEP = `$wx_config --libs base > /dev/null 2>&1 || echo 'X'` eq "X\n" ? '=' : ' ';
$wx_monolithic = `$wx_config --libs${WX_CONFIG_LIBSEP}adv` eq
`$wx_config --libs${WX_CONFIG_LIBSEP}core`;
sub awx_is_debug {
$_[0]->notes( 'build_wx' )
? $_[0]->SUPER::awx_is_debug
: $wx_debug;
}
sub awx_is_unicode {
$_[0]->notes( 'build_wx' )
? $_[0]->SUPER::awx_is_unicode
: $wx_unicode;
}
sub awx_is_monolithic {
$_[0]->notes( 'build_wx' )
? $_[0]->SUPER::awx_is_monolithic
: $wx_monolithic;
}
}
package My::Build::Any_wx_config::Base;
use strict;
use base qw(My::Build::Base);
use Fatal qw(chdir mkdir);
use Cwd ();
use Config;
use My::Build::Utility qw(awx_arch_dir awx_install_arch_dir);
sub awx_configure {
My::Build::Any_wx_config::_init( $_[0] );
my $self = shift;
my %config = $self->SUPER::awx_configure;
my $cf = $self->wx_config( 'cxxflags' );
$config{prefix} = $self->wx_config( 'prefix' );
$cf =~ m/__WX(x11|msw|motif|gtk|mac|osx_carbon|osx_cocoa)__/i or
die "Unable to determine toolkit!";
$config{config}{toolkit} = lc $1;
$config{config}{build} = $self->awx_is_monolithic ? 'mono' : 'multi';
if( $config{config}{toolkit} eq 'gtk' ) {
$self->wx_config( 'basename' ) =~ m/(gtk2?)/i or
die 'PANIC: ', $self->wx_config( 'basename' );
$config{config}{toolkit} = lc $1;
}
$config{compiler} = $ENV{CXX} || $self->wx_config( 'cxx' );
if( $self->awx_debug ) {
$config{c_flags} .= ' -g ';
}
my $cccflags = $self->wx_config( 'cxxflags' );
my $libs = $self->wx_config( 'libs' );
foreach ( split /\s+/, $cccflags ) {
m(^[-/]I) && do { $config{include_path} .= "$_ "; next; };
m(^[-/]D) && do { $config{defines} .= "$_ "; next; };
$config{c_flags} .= "$_ ";
}
my @paths = ( ( map { s/^-L//; $_ } grep { /^-L/ } split ' ', $libs ),
qw(/usr/local/lib /usr/lib /usr/lib64) );
foreach ( split /\s+/, $libs ) {
m{^-[lL]|/} && do { $config{link_libraries} .= " $_"; next; };
if( $_ eq '-pthread' && $^O =~ m/(?:linux|freebsd)/i ) {
$config{link_libraries} .= " -lpthread";
next;
}
$config{link_libraries} .= " $_";
}
my %dlls = %{$self->wx_config( 'dlls' )};
$config{_libraries} = {};
while( my( $k, $v ) = each %dlls ) {
if( @paths ) {
my $found = 0;
foreach my $path ( @paths ) {
$found = 1 if -f File::Spec->catfile( $path, $v->{dll} );
}
unless( $found || $self->notes( 'build_wx' ) ) {
if( grep $_ eq $k, @My::Build::Any_wx_config::CRITICAL ) {
warn "'$k' library not found: can't use wxWidgets\n";
} elsif( grep $_ eq $k, @My::Build::Any_wx_config::IMPORTANT ) {
warn "'$k' library not found: some functionality will be missing\n";
}
next;
}
}
$config{_libraries}{$k} = $v;
( run in 0.790 second using v1.01-cache-2.11-cpan-39bf76dae61 )