3 BEGIN { our $NO_INIT = 1 }
12 ( '2.8.10' => 'patches/data-2.8.10',
13 '2.9.0' => 'patches/data-2.9.0',
15 my $DEFAULT_VERSION = '2.8.10';
17 # new_from_context is broken: it does not restore
18 # @INC set in Build.PL before trying to load a base class not
19 # defined using ->subclass...
20 my $class = Module::Build->subclass
21 ( class => 'My::Build::new_from_context_is_broken',
24 @ISA = qw(My::Build Module::Build);
27 my $build = $class->new
28 ( module_name => 'Alien::wxWidgets',
30 author => 'Mattia Barbon <mbarbon@cpan.org>',
31 requires => { perl => '5.006',
32 'Module::Pluggable' => '2.6',
34 build_requires => { 'Module::Build' => '0.28',
35 'ExtUtils::CBuilder' => '0.24',
37 configure_requires => { 'Module::Build' => '0.28',
39 get_options => { 'wxWidgets-debug' => { type => '!' },
40 'wxWidgets-unicode' => { type => '!' },
41 'wxWidgets-mslu' => { type => '!' },
42 'wxWidgets-static' => { type => '!' },
43 'wxWidgets-monolithic' => { type => '!' },
44 'wxWidgets-universal' => { type => '!' },
45 'wxWidgets-build' => { type => '!' },
46 'wxWidgets-portable' => { type => '!',
47 default => $^O eq 'MSWin32' },
48 'wxWidgets-build-opengl' => { type => '!' },
49 'wxWidgets-source' => { type => '=s' },
50 'wxWidgets-version' => { type => '=s' },
52 create_makefile_pl => 'passthrough',
55 { 'license' => 'http://dev.perl.org/licenses/',
56 'homepage' => 'http://wxperl.eu/',
57 'bugtracker' => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=Alien-wxWidgets',
58 'repository' => 'https://wxperl.svn.sourceforge.net/svnroot/wxperl/Alien-wxWidgets',
59 'MailingList' => 'http://lists.perl.org/list/wxperl-users.html',
64 my $accept_defaults = $ENV{PERL5_CPANPLUS_IS_RUNNING}
65 || $ENV{CPAN_SHELL_LEVEL};
66 my $build_wx_dflt = 'yes';
67 my $build_wx_opengl_dflt = 'yes';
68 my $build_prompt = 'Do you want to fetch and build wxWidgets from sources?';
69 my $have_alien_configuration = 0;
71 # try to detect if wxWidgets has been installed using Alien::wxWidgets and if
72 # it is the latest version; the rule is:
74 # if there is any any wxWidgets installation registered with Alien::wxWidgets
75 # it will only get upgraded if it was compiled using Alien::wxWidgets itself and
76 # it is older than $DEFAULT_VERSION
78 require Alien::wxWidgets;
79 require File::Basename;
83 $DEFAULT_VERSION =~ m/^(\d+)\.(\d+)\.(\d+)$/ or die "Wrong default version";
84 my $install_version = $1 + $2 / 1000 + $3 / 1000000;
85 my @configs = Alien::wxWidgets->get_configurations;
87 $build_wx_dflt = 'no' if @configs;
88 $have_alien_configuration = @configs;
90 foreach my $config ( @configs ) {
91 last if $config->{version} >= $install_version;
93 # installed version is older than $DEFAULT_VERSION, check if it
94 # has been installed using Alien::wxWidgets
95 my %values = $config->{package}->values;
96 ( my $pm_filename = $config->{package} . '.pm' ) =~ s{::}{/}g;
97 my $pm_file = $INC{$pm_filename};
98 my $pm_path = File::Spec->catdir( File::Basename::dirname( $pm_file ),
100 my $prefix = File::Spec->catdir( $values{prefix}, File::Spec->updir );
102 if( Cwd::realpath( $pm_path ) eq Cwd::realpath( $prefix ) ) {
103 $build_wx_dflt = 'yes';
109 # if anything went wrong in the autodetection, revert to the correct
112 $build_wx_dflt = 'yes';
115 # detect wxWidgets using WXDIR/WXWIN environment variables on Win32
116 # and wx-config on other platforms
117 if( $^O eq 'MSWin32' && ( $ENV{WXWIN} || $ENV{WXDIR} ) ) {
118 $build_wx_dflt = 'no';
119 $build_prompt = sprintf <<EOP, ( $ENV{WXWIN} || $ENV{WXDIR} );
120 A wxWidgets build seems to be in '%s', so it should be safe to answer
121 'no' to the following question
126 require My::Build::Base;
127 my $wx_config = My::Build::Base->awx_path_search( 'wx-config' );
129 my $ans = `wx-config --version`;
130 if( $ans =~ /^2\./ ) {
131 my $prefix = `wx-config --prefix`;
132 chomp foreach $ans, $prefix;
133 $build_wx_dflt = 'no' ;
134 $build_prompt = sprintf <<EOP, $ans, $prefix;
135 wxWidgets %s seems to be installed in '%s', so it should be safe to
136 answer 'no' to the following question:
143 if( $^O ne 'darwin' && $^O ne 'MSWin32' ) {
144 $build_wx_opengl_dflt = 'no';
146 if( $ENV{AWX_URL} ) {
147 $build_wx_dflt = 'yes';
149 if( $ENV{AUTOMATED_TESTING} ) {
150 if( $^O ne 'darwin' && $^O ne 'MSWin32' ) {
151 my $pkg_config = $ENV{PKG_CONFIG} || 'pkg-config';
152 my $ans = `$pkg_config --modversion gtk+-2.0 2>&1`;
153 unless( $ans =~ /^2\./ ) {
155 Could not detect GTK+ 2 by running '$pkg_config': aborting
157 == pkg-config output: ====================================
158 $ans==========================================================
163 if( $^O eq 'solaris' )
165 my $ans = `gmake -v`;
166 unless( $ans =~ /gnu make/i ) {
168 Could not find GNU Make as 'gmake': aborting
175 my $build_wx = _askyn( $build, 'wxWidgets-build',
176 $build_prompt, $build_wx_dflt );
178 $build->notes( 'build_wx' => $build_wx );
179 $build->notes( 'mk_portable' => $build->args('wxWidgets-portable') );
180 $build->notes( 'install_only' => $have_alien_configuration && !$build_wx && $accept_defaults );
182 $wx_version = _askmulti( $build, 'wxWidgets-version',
183 'Which wxWidgets version?',
184 [ sort keys %VERSIONS ], $DEFAULT_VERSION );
185 $TYPE = _ask( $build, 'wxWidgets-source', 'Which archive type?', 'tar.gz' );
186 $URL = $ENV{AWX_URL};
187 $build->notes( 'build_data' => do $VERSIONS{$wx_version} );
189 if( $build_wx && $wx_version !~ /^2\.9/ ) {
190 my $build_wx_unicode = _askyn( $build, 'wxWidgets-unicode',
191 'Do you want to enable Unicode support',
193 $build->notes( 'build_wx_unicode' => $build_wx_unicode );
194 } elsif( $build_wx ) {
195 # Unicode-only for 2.9.x and higher
196 $build->notes( 'build_wx_unicode' => 1 );
199 my $build_wx_opengl = _askyn( $build, 'wxWidgets-build-opengl',
200 'Do you want to include OpenGL support',
201 $build_wx_opengl_dflt );
202 $build->notes( 'build_wx_opengl' => $build_wx_opengl );
205 $build->create_build_script;
208 return lc( $_[0] ) eq 'y' || lc( $_[0] ) eq 'yes';
212 my( $build, $arg, $question, $default ) = @_;
214 defined $build->args( $arg ) ? _is_yes( $build->args( $arg ) ) :
215 exists $ENV{"AWX_\U$arg"} ? _is_yes( $ENV{"AWX_\U$arg"} ) :
216 $accept_defaults ? _is_yes( $default ) :
217 $build->y_n( $question, $default );
223 my( $build, $arg, $question, $options, $default ) = @_;
224 $question .= " (" . join( ', ', @$options ) . ")";
226 defined $build->args( $arg ) ? $build->args( $arg ) :
227 exists $ENV{"AWX_\U$arg"} ? $ENV{"AWX_\U$arg"} :
228 $accept_defaults ? $default :
229 $build->prompt( $question, $default );
231 die "Invalid value '$res' for option '$arg': must be one of ",
232 join( ', ', map "'$_'", @$options ), "\n"
233 unless grep $_ eq $res, @$options;
239 my( $build, $arg, $question, $default ) = @_;
241 defined $build->args( $arg ) ? $build->args( $arg ) :
242 exists $ENV{"AWX_\U$arg"} ? $ENV{"AWX_\U$arg"} :
243 $accept_defaults ? $default :
244 $build->prompt( $question, $default );