Debian Codegraph @

Makefile.PL

raw ◀ ▶
Source reconstructed at patch state 0 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 # This Makefile.PL contains portions borrowed
2 # from XML::Parser and XML::SAX
3
4 use ExtUtils::MakeMaker;
5 use Config;
6
7 $expat_libpath = '';
8 $expat_incpath = '';
9
10 my @replacement_args;
11
12 foreach (@ARGV) {
13 if (/^EXPAT(LIB|INC)PATH=(.+)/) {
14 if ($1 eq 'LIB') {
15 $expat_libpath = $2;
16 }
17 else {
18 $expat_incpath = $2;
19 }
20 }
21 else {
22 push(@replacement_args, $_);
23 }
24 }
25
26 @ARGV = @replacement_args;
27
28 if (not $expat_libpath and $] >= 5.006001) {
29 require ExtUtils::Liblist; # Buggy before this
30 ($expat_libpath) = ExtUtils::Liblist->ext('-lexpat');
31 }
32
33 unless ($expat_libpath) {
34 # Test for existence of libexpat
35 my $found = 0;
36 foreach (split(/\s+/, $Config{libpth})) {
37 if (-f "$_/libexpat." . $Config{so}) {
38 $found = 1;
39 last;
40 }
41 }
42
43 unless ($found) {
44 die <<'Expat_Not_Installed;';
45
46 Expat must be installed prior to building XML::SAX::ExpatXS and I can't
47 find it in the standard library directories. You can download expat from:
48
49 http://expat.sourceforge.net/
50
51 If expat is installed, but in a non-standard directory, then use the
52 following options to Makefile.PL:
53
54 EXPATLIBPATH=... To set the directory in which to find libexpat
55
56 EXPATINCPATH=... To set the directory in which to find expat.h
57
58 For example:
59
60 perl Makefile.PL EXPATLIBPATH=/home/me/lib EXPATINCPATH=/home/me/include
61
62 Note that if you build against a shareable library in a non-standard location
63 you may (on some platforms) also have to set your LD_LIBRARY_PATH environment
64 variable at run time for perl to find the library.
65
66 Expat_Not_Installed;
67 }
68 }
69
70 my $libs = "-lexpat";
71 $libs = "-L$expat_libpath $libs"
72 if $expat_libpath;
73
74 @extras = ();
75
76 push(@extras, INC => "-I$expat_incpath")
77 if $expat_incpath;
78
79 push(@extras,
80 CAPI => 'TRUE')
81 if ($PERL_VERSION >= 5.005 and $OSNAME eq 'MSWin32'
82 and $Config{archname} =~ /-object\b/i);
83
84 push(@extras,
85 ABSTRACT_FROM => 'lib/XML/SAX/ExpatXS.pm',
86 AUTHOR => 'Matt Sergeant <matt AT sergeant DOT org>')
87 if ($ExtUtils::MakeMaker::Version >= 5.4301);
88
89 # building XML::SAX::ExpatXS::Preload;
90 &build_xml_sax_expatxs_preload;
91
92 WriteMakefile(
93 NAME => 'XML::SAX::ExpatXS',
94 VERSION_FROM => 'lib/XML/SAX/ExpatXS.pm',
95 PREREQ_PM => {
96 'XML::SAX' => 0.96,
97 },
98 LIBS => $libs,
99 ABSTRACT => 'Perl SAX 2 XS extension to Expat parser',
100 AUTHOR => 'Petr Cimprich <pcimprich AT gmail DOT com>',
101 LICENSE => 'perl',
102 @extras
103 );
104
105
106 sub MY::install {
107 package MY;
108 my $script = shift->SUPER::install(@_);
109 if (ExtUtils::MakeMaker::prompt("Do you want to alter ParserDetails.ini?", "Y") =~ /^y/i) {
110 $script =~ s/install :: (.*)$/install :: $1 install_expat_xs/m;
111 $script .= <<"INSTALL";
112
113 install_expat_xs :
114 \t\@\$(PERL) -MXML::SAX -e "XML::SAX->add_parser(q(XML::SAX::ExpatXS))->save_parsers()"
115
116 INSTALL
117
118 }
119
120 return $script;
121 }
122
123
124 sub build_xml_sax_expatxs_preload {
125
126 print "Writing XML::SAX::ExpatXS::Preload\n";
127
128 my $code = <<'EOHEADER';
129 package XML::SAX::ExpatXS::Preload;
130
131 #-----------------------------------------------------#
132 # STOP!!!!!
133 #
134 # This file is generated by the 'Makefile.PL' file
135 # that ships with the XML::SAX::ExpatXS distribution.
136 # If you need to make changes, patch that file NOT
137 # this one.
138 #-----------------------------------------------------#
139
140 use strict;
141 use vars qw($VERSION);
142
143 $VERSION = '0.01';
144
145 EOHEADER
146
147 my %EVENT_SPEC = (
148 start_element => [qw(ContentHandler DocumentHandler Handler)],
149 end_element => [qw(ContentHandler DocumentHandler Handler)],
150 characters => [qw(ContentHandler DocumentHandler Handler)],
151 comment => [qw(DocumentHandler LexicalHandler Handler)],
152 );
153
154 for my $ev (keys %EVENT_SPEC) {
155 $code .= <<" EOTOPCODE";
156 sub get_$ev {
157 my \$self = shift;
158
159 my \$method;
160 my \$callbacks;
161 if (exists \$self->{ParseOptions}) {
162 \$callbacks = \$self->{ParseOptions};
163 }
164 else {
165 \$callbacks = \$self;
166 }
167
168 if (0) { # dummy to make elsif's below compile
169 }
170 EOTOPCODE
171
172 my ($can_string, $aload_string);
173 for my $h (@{$EVENT_SPEC{$ev}}) {
174 $can_string .= <<" EOCANBLOCK";
175 elsif (defined \$callbacks->{'$h'} and \$method = \$callbacks->{'$h'}->can('$ev') ) {
176 my \$handler = \$callbacks->{'$h'};
177 \$self->{Methods}->{'$ev'} = sub { \$method->(\$handler, \@_) };
178 }
179 EOCANBLOCK
180 $aload_string .= <<" EOALOADBLOCK";
181 elsif (defined \$callbacks->{'$h'} and \$callbacks->{'$h'}->can('AUTOLOAD') ) {
182 my \$res = eval { \$callbacks->{'$h'}->$ev(\@_) };
183 if (\$@) {
184 die \$@;
185 }
186 else {
187 my \$handler = \$callbacks->{'$h'};
188 \$self->{Methods}->{'$ev'} = sub { \$handler->$ev(\@_) };
189 }
190 }
191 EOALOADBLOCK
192 }
193
194 $code .= $can_string . $aload_string;
195
196 $code .= <<" EOFALLTHROUGH";
197 else {
198 \$self->{Methods}->{'$ev'} = sub { };
199 }
200
201 EOFALLTHROUGH
202
203 $code .= "return 1;\n}\n\n";
204 }
205
206 $code .= <<'BODY';
207
208 1;
209
210 BODY
211
212 $code .= "__END__\n";
213
214 $code .= <<'FOOTER';
215
216 =head1 NAME
217
218 XML::SAX::ExpatXS::Preload - Helper class for XML-SAX-ExpatXS
219
220 =head1 AUTHOR
221
222 Petr Cimprich ([email protected]) based on an original code of XML::SAX::Base
223 by Kip Hampton ([email protected]).
224
225 =head1 SEE ALSO
226
227 L<XML::SAX::ExpatXS>
228
229 =cut
230
231 FOOTER
232
233 open(BASE, ">" . File::Spec->catdir("lib", "XML", "SAX", "ExpatXS", "Preload.pm")) || die "Cannot write Preload.pm: $!";
234 print BASE $code;
235 close BASE;
236 }