Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / blib / lib / Wx / build / MakeMaker / Core.pm
1 package Wx::build::MakeMaker::Core::Dummy;
2
3 # to avoid W::b::MM clobbering our wxWriteMakefile
4
5 use Wx::build::MakeMaker;
6
7 package Wx::build::MakeMaker::Core;
8
9 use strict;
10 use ExtUtils::MakeMaker;
11 use Wx::build::Utils qw'obj_from_src';
12 use Wx::build::Options;
13 use File::Path 'mkpath';
14 use base 'Exporter';
15 use vars qw(@EXPORT @subdirs);
16
17 @EXPORT = 'wxWriteMakefile';
18
19 my @top_level_xs = qw(Wx.xs Constant.xs Controls.xs Event.xs
20                       Frames.xs GDI.xs Window.xs);
21 @subdirs = qw(socket dnd filesys grid help html mdi print xrc stc docview
22               calendar datetime media richtext aui dataview);
23 my %subdirs;
24
25 Wx::build::MakeMaker::_set_is_wxPerl_tree( 1 );
26 eval { require Alien::wxWidgets };
27 our $has_alien = $@ ? 0 : 1;
28 my %options = Wx::build::Options->get_makemaker_options if $has_alien;
29
30 if( $has_alien ) {
31   @subdirs{@subdirs} = (1) x @subdirs;
32   my %opt = %{$options{subdirs}};
33
34   @subdirs{keys %opt} = values %opt;
35
36   @subdirs = grep { $subdirs{$_} } keys %subdirs;
37 }
38
39 #
40 # make symlinks to the source tree
41 #
42 if( $options{mksymlinks} ) {
43   require FindBin;
44   require ExtUtils::Manifest;
45   require File::Spec::Functions;
46
47   local *catfile = \&File::Spec::Functions::catfile;
48   local *splitpath = \&File::Spec::Functions::splitpath;
49
50   my $manifest = MM->catfile( $FindBin::RealBin, 'MANIFEST' );
51   die "Can't find MANIFEST" unless -e $manifest;
52   my $files = ExtUtils::Manifest::maniread( $manifest );
53
54   foreach my $f ( keys %$files ) {
55     my( $fr, $to ) = ( catfile( $FindBin::RealBin, $f ), $f );
56     my $dir;
57     ( undef, $dir, undef ) = splitpath( $to );
58     mkpath( $dir ) if length $dir && !-d $dir;
59     next if -l $to;
60     if( -e $to ){ unlink $to or die "unlink '$to' failed: $!" }
61     symlink( $fr, $to ) or die "symlink '$fr' => '$to' failed: $!";
62   }
63 }
64
65 #
66 # write cpp/setup.h
67 #
68 if( $has_alien ) {
69   unless( -d 'cpp' ) {
70     mkpath( 'cpp' ) or die "mkpath 'cpp': $!";
71   }
72
73   local *OUT;
74   open OUT, "> cpp/setup.h" or die "open 'cpp/setup.h': $!";
75
76   print OUT <<EOT;
77 //
78 // GENERATED BY Makefile.PL, DO NOT EDIT
79 //
80
81 #ifndef __CPP_SETUP_H__
82 #define __CPP_SETUP_H__
83
84 EOT
85
86   foreach my $o ( sort keys %subdirs ) {
87     print OUT "#define wxPERL_USE_", uc $o, " ", $subdirs{$o} ,"\n";
88   }
89
90   print OUT <<EOT;
91
92 #endif // __CPP_SETUP_H__
93 EOT
94
95   close OUT;
96 }
97
98 Wx::build::Options->write_config_file( 'Opt' ) if $has_alien;
99
100 #
101 # WriteMakefile wrapper
102 #
103 sub wxWriteMakefile {
104   my %params = @_;
105   local $Wx::build::MakeMaker::is_core = 1;
106
107   if( $has_alien ) {
108       $params{XSOPT}     = ' -nolinenumbers -noprototypes ';
109       $params{CONFIGURE} = \&Wx::build::MakeMaker::configure;
110       $params{OBJECT}    = join ' ', obj_from_src( @top_level_xs ), '';
111   }
112
113   my $build = Wx::build::MakeMaker::_process_mm_arguments( \%params, $has_alien );
114
115   if( $build ) {
116     WriteMakefile( %params );
117     unless( Alien::wxWidgets->can( 'load' ) ) {
118         print <<EOT;
119 ======================================================================
120 Alien::wxWidgets is missing, you will need to re-run Makefile.PL after
121 it is installed.
122 ======================================================================
123 EOT
124         sleep 3;
125         open my $fh, ">> alien_wxwidgets_missing";
126         print $fh "touched";
127     }
128   } else {
129     ExtUtils::MakeMaker::WriteEmptyMakefile( %params );
130   }
131 }
132
133 1;
134
135 # local variables:
136 # mode: cperl
137 # end: