#!/usr/bin/perl -w BEGIN { our $NO_INIT = 1 } use strict; use lib "lib", "inc"; use My::Build; our( $TYPE, $URL ); my %VERSIONS = ( '2.8.10' => 'patches/data-2.8.10', '2.9.0' => 'patches/data-2.9.0', ); my $DEFAULT_VERSION = '2.8.10'; # new_from_context is broken: it does not restore # @INC set in Build.PL before trying to load a base class not # defined using ->subclass... my $class = Module::Build->subclass ( class => 'My::Build::new_from_context_is_broken', code => <<'EOC' ); use lib qw(lib inc); @ISA = qw(My::Build Module::Build); require My::Build; EOC my $build = $class->new ( module_name => 'Alien::wxWidgets', license => 'perl', author => 'Mattia Barbon ', requires => { perl => '5.006', 'Module::Pluggable' => '2.6', }, build_requires => { 'Module::Build' => '0.28', 'ExtUtils::CBuilder' => '0.24', }, configure_requires => { 'Module::Build' => '0.28', }, get_options => { 'wxWidgets-debug' => { type => '!' }, 'wxWidgets-unicode' => { type => '!' }, 'wxWidgets-mslu' => { type => '!' }, 'wxWidgets-static' => { type => '!' }, 'wxWidgets-monolithic' => { type => '!' }, 'wxWidgets-universal' => { type => '!' }, 'wxWidgets-build' => { type => '!' }, 'wxWidgets-portable' => { type => '!', default => $^O eq 'MSWin32' }, 'wxWidgets-build-opengl' => { type => '!' }, 'wxWidgets-source' => { type => '=s' }, 'wxWidgets-version' => { type => '=s' }, }, create_makefile_pl => 'passthrough', ); my $accept_defaults = $ENV{PERL5_CPANPLUS_IS_RUNNING} || $ENV{CPAN_SHELL_LEVEL}; my $build_wx_dflt = 'yes'; my $build_wx_opengl_dflt = 'yes'; my $build_prompt = 'Do you want to fetch and build wxWidgets from sources?'; if( $^O eq 'MSWin32' && ( $ENV{WXWIN} || $ENV{WXDIR} ) ) { $build_wx_dflt = 'no'; $build_prompt = sprintf <awx_path_search( 'wx-config' ); if( $wx_config ) { my $ans = `wx-config --version`; if( $ans =~ /^2\./ ) { my $prefix = `wx-config --prefix`; chomp foreach $ans, $prefix; $build_wx_dflt = 'no' ; $build_prompt = sprintf <&1`; unless( $ans =~ /^2\./ ) { print <notes( 'build_wx' => $build_wx ); $build->notes( 'mk_portable' => $build->args('wxWidgets-portable') ); if( $build_wx ) { $wx_version = _askmulti( $build, 'wxWidgets-version', 'Which wxWidgets version?', [ sort keys %VERSIONS ], $DEFAULT_VERSION ); $TYPE = _ask( $build, 'wxWidgets-source', 'Which archive type?', 'tar.gz' ); $URL = $ENV{AWX_URL}; $build->notes( 'build_data' => do $VERSIONS{$wx_version} ); } if( $build_wx && $wx_version !~ /^2\.9/ ) { my $build_wx_unicode = _askyn( $build, 'wxWidgets-unicode', 'Do you want to enable Unicode support', 'yes' ); $build->notes( 'build_wx_unicode' => $build_wx_unicode ); } elsif( $build_wx ) { # Unicode-only for 2.9.x and higher $build->notes( 'build_wx_unicode' => 1 ); } if( $build_wx ) { my $build_wx_opengl = _askyn( $build, 'wxWidgets-build-opengl', 'Do you want to include OpenGL support', $build_wx_opengl_dflt ); $build->notes( 'build_wx_opengl' => $build_wx_opengl ); } $build->create_build_script; sub _is_yes { return lc( $_[0] ) eq 'y' || lc( $_[0] ) eq 'yes'; } sub _askyn { my( $build, $arg, $question, $default ) = @_; my $res = defined $build->args( $arg ) ? _is_yes( $build->args( $arg ) ) : exists $ENV{"AWX_\U$arg"} ? _is_yes( $ENV{"AWX_\U$arg"} ) : $accept_defaults ? _is_yes( $default ) : $build->y_n( $question, $default ); return $res } sub _askmulti { my( $build, $arg, $question, $options, $default ) = @_; $question .= " (" . join( ', ', @$options ) . ")"; my $res = defined $build->args( $arg ) ? $build->args( $arg ) : exists $ENV{"AWX_\U$arg"} ? $ENV{"AWX_\U$arg"} : $accept_defaults ? $default : $build->prompt( $question, $default ); die "Invalid value '$res' for option '$arg': must be one of ", join( ', ', map "'$_'", @$options ), "\n" unless grep $_ eq $res, @$options; return $res } sub _ask { my( $build, $arg, $question, $default ) = @_; my $res = defined $build->args( $arg ) ? $build->args( $arg ) : exists $ENV{"AWX_\U$arg"} ? $ENV{"AWX_\U$arg"} : $accept_defaults ? $default : $build->prompt( $question, $default ); return $res }