Added libalien-wxwidgets-perl
[pkg-perl] / deb-src / libalien-wxwidgets-perl / libalien-wxwidgets-perl-0.50 / Build.PL
1 #!/usr/bin/perl -w
2
3 BEGIN { our $NO_INIT = 1 }
4
5 use strict;
6 use lib "lib", "inc";
7 use My::Build;
8
9 our( $TYPE, $URL );
10
11 my %VERSIONS =
12   ( '2.8.10'        => 'patches/data-2.8.10',
13     '2.9.0'         => 'patches/data-2.9.0',
14     );
15 my $DEFAULT_VERSION = '2.8.10';
16
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',
22     code             => <<'EOC' );
23 use lib qw(lib inc);
24 @ISA = qw(My::Build Module::Build);
25 require My::Build;
26 EOC
27 my $build = $class->new
28   ( module_name     => 'Alien::wxWidgets',
29     license         => 'perl',
30     author          => 'Mattia Barbon <mbarbon@cpan.org>',
31     requires        => { perl                             => '5.006',
32                          'Module::Pluggable'              => '2.6',
33                         },
34     build_requires  => { 'Module::Build'                  => '0.28',
35                          'ExtUtils::CBuilder'             => '0.24',
36                          },
37     configure_requires => { 'Module::Build'               => '0.28',
38                             },
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' },
51                          },
52     create_makefile_pl => 'passthrough',
53     meta_merge =>
54       { resources       =>
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',
60             },
61         },
62   );
63
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;
70
71 # try to detect if wxWidgets has been installed using Alien::wxWidgets and if
72 # it is the latest version; the rule is:
73 #
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
77 my $ok = eval {
78     require Alien::wxWidgets;
79     require File::Basename;
80     require File::Spec;
81     require Cwd;
82
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;
86
87     $build_wx_dflt = 'no' if @configs;
88     $have_alien_configuration = @configs;
89
90     foreach my $config ( @configs ) {
91         last if $config->{version} >= $install_version;
92
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 ),
99                                           File::Spec->updir );
100         my $prefix = File::Spec->catdir( $values{prefix}, File::Spec->updir );
101
102         if( Cwd::realpath( $pm_path ) eq Cwd::realpath( $prefix ) ) {
103             $build_wx_dflt = 'yes';
104         }
105     }
106
107     1;
108 };
109 # if anything went wrong in the autodetection, revert to the correct
110 # default
111 if( !$ok ) {
112     $build_wx_dflt = 'yes';
113 }
114
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
122
123 $build_prompt
124 EOP
125 } else {
126     require My::Build::Base;
127     my $wx_config = My::Build::Base->awx_path_search( 'wx-config' );
128     if( $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:
137
138 $build_prompt
139 EOP
140         }
141     }
142 }
143 if( $^O ne 'darwin' && $^O ne 'MSWin32' ) {
144     $build_wx_opengl_dflt = 'no';
145 }
146 if( $ENV{AWX_URL} ) {
147     $build_wx_dflt = 'yes';
148 }
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\./ ) {
154             print <<EOT;
155 Could not detect GTK+ 2 by running '$pkg_config': aborting
156
157 == pkg-config output: ====================================
158 $ans==========================================================
159 EOT
160             exit 0;
161         }
162     }
163     if( $^O eq 'solaris' )
164     {
165         my $ans = `gmake -v`;
166         unless( $ans =~ /gnu make/i ) {
167             print <<EOT;
168 Could not find GNU Make as 'gmake': aborting
169 EOT
170             exit 0;
171         }
172     }
173 }
174 chomp $build_prompt;
175 my $build_wx = _askyn( $build, 'wxWidgets-build',
176                        $build_prompt, $build_wx_dflt );
177 my $wx_version;
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 );
181 if( $build_wx ) {
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} );
188 }
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',
192                                    'yes' );
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 );
197 }
198 if( $build_wx ) {
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 );
203 }
204
205 $build->create_build_script;
206
207 sub _is_yes {
208     return lc( $_[0] ) eq 'y' || lc( $_[0] ) eq 'yes';
209 }
210
211 sub _askyn {
212     my( $build, $arg, $question, $default ) = @_;
213     my $res =
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 );
218
219     return $res
220 }
221
222 sub _askmulti {
223     my( $build, $arg, $question, $options, $default ) = @_;
224     $question .= " (" . join( ', ', @$options ) . ")";
225     my $res =
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 );
230
231     die "Invalid value '$res' for option '$arg': must be one of ",
232         join( ', ', map "'$_'", @$options ), "\n"
233         unless grep $_ eq $res, @$options;
234
235     return $res
236 }
237
238 sub _ask {
239     my( $build, $arg, $question, $default ) = @_;
240     my $res =
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 );
245
246     return $res
247 }