Added libalien-wxwidgets-perl
[pkg-perl] / deb-src / libalien-wxwidgets-perl / libalien-wxwidgets-perl-0.50 / inc / My / Build / Win32_MinGW.pm
1 package My::Build::Win32_MinGW;
2
3 use strict;
4 use base qw(My::Build::Win32);
5 use My::Build::Utility qw(awx_arch_file awx_install_arch_file
6                           awx_install_arch_dir awx_arch_dir);
7 use Config;
8 use File::Basename qw();
9 use File::Glob qw(bsd_glob);
10
11 sub _find_make {
12     my( @try ) = qw(mingw32-make gmake make);
13     push @try, $Config{gmake} if $Config{gmake};
14
15     foreach my $name ( @try ) {
16         foreach my $dir ( File::Spec->path ) {
17             my $abs = File::Spec->catfile( $dir, "$name.exe" );
18             return $name if -x $abs;
19         }
20     }
21
22     return 'make';
23 }
24
25 sub awx_configure {
26     my $self = shift;
27     my %config = $self->SUPER::awx_configure;
28
29     $config{c_flags} .= " -fvtable-thunks ";
30
31     if( $self->awx_debug ) {
32         $config{c_flags} .= ' -g ';
33     } else {
34         $config{link_flags} .= ' -s ';
35     }
36
37     my $cccflags = $self->wx_config( 'cxxflags' );
38     my $libs = $self->wx_config( 'libs' );
39     my $incdir = $self->awx_wx_config_data->{wxinc};
40     my $cincdir = $self->awx_wx_config_data->{wxcontrinc};
41     my $iincdir = awx_install_arch_dir( $self, 'rEpLaCe/include' );
42
43     foreach ( split /\s+/, $cccflags ) {
44         m(^-DSTRICT) && next;
45         m(^\.d$) && next; # broken makefile
46         m(^-W.*) && next; # under Win32 -Wall gives you TONS of warnings
47         m(^-I) && do {
48             next if m{(?:regex|zlib|jpeg|png|tiff)$};
49             if( $self->notes( 'build_wx' ) ) {
50                 $_ =~ s{\Q$cincdir\E}{$iincdir};
51                 $_ =~ s{\Q$incdir\E}{$iincdir};
52             }
53             if( $_ =~ /-I\Q$self->{awx_setup_dir}\E/ ) {
54                 $config{include_path} .=
55                   '-I' . awx_install_arch_file( $self, 'rEpLaCe/lib' ) . ' ';
56             } else {
57                 $config{include_path} .= "$_ ";
58             }
59             next;
60         };
61         m(^-D) && do { $config{defines} .= "$_ "; next; };
62         $config{c_flags} .= "$_ ";
63     }
64
65     foreach ( split /\s+/, $libs ) {
66         m(wx|unicows)i || next;
67         next if m{(?:wx(?:zlib|regexu?|expat|png|jpeg|tiff)[ud]{0,2})$};
68         $config{link_libraries} .= "$_ ";
69     }
70
71     my $dlls = $self->awx_wx_config_data->{dlls};
72     $config{_libraries} = {};
73
74     while( my( $key, $value ) = each %$dlls ) {
75         $config{_libraries}{$key} =
76           { map { $_ => File::Basename::basename( $value->{$_} ) }
77                 keys %$value };
78         if( $value->{link} ) {
79             $config{_libraries}{$key}{link} = $value->{link};
80         } elsif( $value->{lib} ) {
81             my $lib = $config{_libraries}{$key}{lib};
82             $lib =~ s/^lib(.*?)(?:\.dll)?\.a$/$1/;
83             $config{_libraries}{$key}{link} = '-l' . $lib;
84         }
85     }
86
87     return %config;
88 }
89
90 sub awx_compiler_kind { 'gcc' }
91
92 sub files_to_install {
93     my $self = shift;
94     my( @try ) = qw(mingwm10.dll libgcc_*.dll);
95     my( $dll, $dll_from );
96
97     foreach my $d ( @try ) {
98         $dll_from = $self->awx_path_search( $d );
99         if( defined $dll_from ) {
100             $dll = File::Basename::basename( $dll_from );
101             last;
102         }
103     }
104
105     return ( $self->SUPER::files_to_install(),
106              ( $dll_from => awx_arch_file( "rEpLaCe/lib/$dll" ) ) );
107 }
108
109 sub awx_strip_dlls {
110     my( $self ) = @_;
111     my( $dir ) = grep !/Config/, bsd_glob( awx_arch_dir( '*' ) );
112
113     $self->_system( "attrib -r $dir\\lib\\*.dll" );
114     $self->_system( "strip $dir\\lib\\*.dll" );
115     $self->_system( "attrib +r $dir\\lib\\*.dll" );
116 }
117
118 1;