1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
|
use strict;
use warnings;
use 5.014;
use vars qw/ $DEVNULL $is_Win32 /;
use ExtUtils::MakeMaker;
use Config;
use Cwd qw/ cwd /;
use File::Spec ();
use File::Path 2.06 qw( make_path remove_tree );
BEGIN {
$::is_Win32 = ($^O =~ /Win32/);
if ($::is_Win32) {
$DEVNULL = 'DEVNULL';
}
else {
$DEVNULL = eval { File::Spec->devnull };
if ($@) { $DEVNULL = '/dev/null' }
}
};
STDOUT->autoflush(1);
my %config;
while (my $arg = shift(@ARGV)) {
my ($key, $val) = split(/=/, $arg, 2);
$config{$key} = $val;
}
my $DEBUG = delete $config{DEBUG};
if ( delete $config{NO_THREADS} ) {
warn "disabling XML::LibXML support for Perl threads\n";
$config{DEFINE} .= " -DNO_XML_LIBXML_THREADS";
}
# We use it several times later. See:
# https://rt.cpan.org/Public/Bug/Display.html?id=116461
my $HAVE_USER_DEFINED = (defined($config{LIBS}) or defined($config{INC}) );
unless ( $::is_Win32 ) { # cannot get config in W32
my $xsltcfg = "pkg-config libxslt";
my $libprefix = $ENV{XSLTPREFIX} || $config{XSLTPREFIX};
delete $config{XSLTPREFIX}; # delete if exists, otherwise MakeMaker gets confused
if ( defined $libprefix ) {
$xsltcfg = $libprefix . '/bin/' . $xsltcfg;
}
# if a user defined INC and LIBS on the command line we must not
# override them
if ( ! $HAVE_USER_DEFINED ) {
# get libs and inc from gnome-config
eval {
print "running $xsltcfg... ";
my $ver = backtick("$xsltcfg --modversion");
my ($major, $minor, $point) = $ver =~ /(\d+)\.(\d+)\.(\d+)/g;
if (not
(
($major > 1)
or
(($major == 1) && ($minor > 1))
or
(($major == 1) && ($minor == 1) && ($point >= 18))
)
)
{
die +{ type => "ver", msg => <<'EOF'};
libxslt versions before 1.1.18 are buggy. Please install the latest version
EOF
}
elsif ($major == 1 and $minor == 1 and $point == 25)
{
die +{ type => "ver", msg => <<'EOF'};
libxslt-1.1.25 contains a deadlock that breaks the tests, and is not supported.
See: https://rt.cpan.org/Ticket/Display.html?id=50487 .
EOF
}
elsif ($major == 1 and $minor == 1 and $point == 27)
{
die +{ type => "ver", msg => <<'EOF'};
libxslt-1.1.27 does not handle namespaces well, and is not supported.
See: https://bugzilla.gnome.org/show_bug.cgi?id=684564 .
EOF
}
($config{LIBS} ||= '' ) .= backtick("$xsltcfg --libs");
($config{INC} ||= '') .= backtick("$xsltcfg --cflags");
print "ok\n";
};
my $Err = $@;
if ($Err) {
print "failed\n";
if ((ref($Err) eq 'HASH') && (($Err->{type} || '') eq 'ver')) {
print {*STDERR} ($Err->{msg}, "\n");
exit 0; # 0 recommended by http://cpantest.grango.org (Notes for CPAN Authors)
}
warn "*** ", $@ if $DEBUG;
warn "using fallback values for LIBS and INC\n";
# backtick fails if gnome-config didn't exist...
($config{LIBS} ||= '' ) .= ' -L/usr/local/lib -L/usr/lib -lxslt -lxml2 -lz -lm';
($config{INC} ||= '') .= ' -I/usr/local/include -I/usr/include';
print <<"OPT";
options:
LIBS='$config{LIBS}'
INC='$config{INC}'
If this is wrong, Re-run as:
\$ $^X Makefile.PL LIBS='-L/path/to/lib' INC='-I/path/to/include'
OPT
}
}
}
if ($config{LIBS} !~ /\-l(lib)?xslt\b/) {
# in this case we are not able to run xml2-config. therefore we need to
# expand the libz as well.
if ($::is_Win32) {
if( $ENV{ACTIVEPERL_MINGW} ) {
$config{LIBS} .= ' -llibxslt.lib -llibxml2.lib';
} else {
$config{LIBS} .= ' -llibxslt -llibxml2';
}
} else {
$config{LIBS} .= ' -lxml2 -lxslt -lz';
}
}
if (!have_library($::is_Win32 ? "libxslt" : "xslt")) {
print STDERR <<"DEATH";
libxslt not found
Try setting LIBS and INC values on the command line
Or get libxslt and libxml2 from
http://www.libxml.org/
If you install via RPMs, make sure you also install the -devel
RPMs, as this is where the headers (.h files) are.
DEATH
exit 1; # make Debian build fail
}
if (have_library($::is_Win32 ? "libexslt" : "exslt")) {
if (! $HAVE_USER_DEFINED) {
my $exslt_defaults = $::is_Win32 ?
($ENV{ACTIVEPERL_MINGW} ? q/-llibexslt.lib/ : q/-llibexslt/) :
q/-lexslt/; # -lgcrypt -lgpg-error/;
my $exsltcfg = 'pkg-config libexslt';
my ($exslt_libs,$exslt_inc);
eval {
print "running $exsltcfg... ";
$exslt_libs = backtick("$exsltcfg --libs");
$exslt_inc = backtick("$exsltcfg --cflags");
$exslt_libs =~ s/-l(xml2|xslt|z|m)\s+//g;
print "ok\n";
};
if ($@) {
print "failed\n";
warn "*** ", $@ if $DEBUG;
warn "using fallback values for LIBS and INC\n";
# backtick fails if gnome-config didn't exist...
$exslt_libs = $exslt_defaults;
$exslt_inc = '';
}
$config{LIBS} .= ' '.$exslt_libs;
$config{INC} .= ' '.$exslt_inc;
}
$config{DEFINE} .= " -DHAVE_EXSLT"
}
if ($DEBUG) {
print "LIBS: $config{LIBS}\n";
print "INC: $config{INC}\n";
}
my $ldflags = delete $config{LDFLAGS};
if ($ldflags) {
$config{dynamic_lib} = { OTHERLDFLAGS => " $ldflags " };
}
# Avoid possible shared library name conflict. On Win32 systems
# the name of system DLL libxlst.dll clashes with module's LibXSLT.dll.
# To handle this we are gonna rename module's DLL to LibXSLT.xs.dll.
if ($::is_Win32)
{
# Fix for RT #94516 :
# https://rt.cpan.org/Ticket/Display.html?id=94516
$config{DLEXT} = 'xs.'.$Config{dlext};
}
WriteMakefile(
'NAME' => 'XML::LibXSLT',
'VERSION_FROM' => 'lib/XML/LibXSLT.pm', # finds $VERSION
'AUTHOR' => 'Matt Sergeant',
'ABSTRACT' => 'Interface to GNOME libxslt library',
'LICENSE' => 'perl_5',
'PREREQ_PM' =>
{
'Encode' => 0,
'File::Path' => "2.06",
'XML::LibXML' => "1.70",
'strict' => 0,
'warnings' => 0,
},
'OBJECT' => '$(O_FILES)',
(($ExtUtils::MakeMaker::VERSION >= 6.52)
? (
'CONFIGURE_REQUIRES' =>
{
'File::Path' => "2.06",
'strict' => 0,
'warnings' => 0,
},
)
: ()
),
(($ExtUtils::MakeMaker::VERSION >= 6.48)
? (MIN_PERL_VERSION => '5.014',)
: ()
),
'META_MERGE' => {
'meta-spec' => {
'version' => 2,
},
'resources' => {
'repository' => {
'type' => 'git',
'url' => 'https://github.com/shlomif/perl-XML-LibXSLT',
'web' => 'https://github.com/shlomif/perl-XML-LibXSLT',
},
},
},
%config,
);
###################################################################
# Functions
# - these should really be in MakeMaker... But &shrug;
###################################################################
sub xsystem {
my (@command)=@_;
if ($DEBUG) {
print "@command\n";
if (system(@command) != 0) {
die "system call to '@command' failed";
}
return 1;
}
open(OLDOUT, ">&STDOUT");
open(OLDERR, ">&STDERR");
open(STDOUT, ">$DEVNULL");
open(STDERR, ">$DEVNULL");
my $retval = system(@command);
open(STDOUT, ">&OLDOUT");
open(STDERR, ">&OLDERR");
if ($retval != 0) {
die "system call to '@command' failed";
}
return 1;
}
sub backtick {
my $command = shift;
if ($DEBUG) {
print $command, "\n";
my $results = `$command`;
chomp $results;
if ($? != 0) {
die "backticks call to '$command' failed";
}
return $results;
}
open(OLDOUT, ">&STDOUT");
open(OLDERR, ">&STDERR");
open(STDOUT, ">$DEVNULL");
open(STDERR, ">$DEVNULL");
my $results = `$command`;
my $retval = $?;
open(STDOUT, ">&OLDOUT");
open(STDERR, ">&OLDERR");
if ($retval != 0) {
die "backticks call to '$command' failed";
}
chomp $results;
return $results;
}
sub _write_utf8_file
{
my ($out_path, $contents) = @_;
open my $out_fh, '>:encoding(utf8)', $out_path
or die "Cannot open '$out_path' for writing - $!";
print {$out_fh} $contents;
close($out_fh);
return;
}
sub _write_raw_file
{
my ($out_path, $contents) = @_;
open my $out_fh, '>:raw', $out_path
or die "Cannot open '$out_path' for writing - $!";
print {$out_fh} $contents;
close($out_fh);
return;
}
sub try_link0 {
my ($src, $opt) = @_;
# local $config{LIBS};
# $config{LIBS} .= $opt;
unless (mkdir(".testlink", 0777)) {
remove_tree(".testlink");
mkdir(".testlink", 0777) || die "Cannot create .testlink dir: $!";
}
chdir(".testlink");
_write_utf8_file("Conftest.xs", <<"EOT");
#ifdef __cplusplus
extern "C" {
#endif
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#ifdef __cplusplus
}
#endif
$src
MODULE = Conftest PACKAGE = Conftest
PROTOTYPES: DISABLE
EOT
_write_utf8_file("Conftest.pm", <<'EOT');
package Conftest;
$VERSION = 1.0;
require DynaLoader;
@ISA = ('DynaLoader');
bootstrap Conftest $VERSION;
1;
EOT
_write_utf8_file("Makefile.PL", <<'EOT');
use ExtUtils::MakeMaker;
my %config;
while($_ = shift @ARGV) {
my ($k, $v) = split /=/, $_, 2;
warn("$k = $v\n");
$config{$k} = $v;
}
WriteMakefile(NAME => "Conftest", VERSION_FROM => "Conftest.pm", %config);
EOT
_write_utf8_file("test.pl", <<"EOT");
use Test::More tests => 1;
use Conftest;
++\$::loaded;
ok(\$::loaded, "loaded") ;
EOT
xsystem($^X, 'Makefile.PL', map { "$_=$config{$_}" } keys %config);
xsystem($Config{make},
($config{MAKEAPERL} ? qw(-f Makefile.aperl FIRST_MAKEFILE=Makefile.aperl) : ()),
'test'); #,"OTHERLDFLAGS=".$opt);
}
sub try_link {
my $start_dir = cwd();
my $result = eval {
try_link0(@_);
};
warn $@ if $DEBUG && $@;
chdir($start_dir);
remove_tree(".testlink");
return $result;
}
sub have_library {
my ($lib, $func) = (@_, "blank");
if ($func eq "blank")
{
printf("looking for -l%s... ", $lib);
}
else
{
printf("checking for %s() in -l%s... ", $func, $lib);
}
my $result;
if ($func) {
my $libs = $::is_Win32 ? " $lib.lib " : "-l$lib";
if ($::is_Win32) {
$result = try_link(<<"SRC", $libs);
#include <windows.h>
#include <winsock.h>
blank() { return 0; }
int t() { ${func}(); return 0; }
SRC
unless ($result) {
$result = try_link(<<"SRC", $libs);
#include <windows.h>
#include <winsock.h>
blank() { return 0; }
int t() { void ((*p)()); p = (void ((*)()))${func}; return 0; }
SRC
}
}
else {
# Use a fake prototype in the style of autoconf.
$result = try_link(<<"SRC", $libs);
char blank(void) { return 0; }
char ${func}(void);
int t(void) { ${func}(); return 0; }
SRC
}
}
unless ($result) {
print "no\n";
return 0;
}
if ($func ne "main") {
$config{DEFINE} .= uc(" -Dhave_$func");
}
print "yes\n";
return 1;
}
sub MY::postamble {
return <<'MAKE_FRAG';
runtest: pure_all
perl -MFile::Spec -MTest::Run::CmdLine::Iface -e \
"local @INC = @INC; unshift @INC, map { File::Spec->rel2abs(\$$_) } ('$(INST_LIB)', '$(INST_ARCHLIB)'); Test::Run::CmdLine::Iface->new({test_files => [glob(q{t/*.t})]})->run();"
distruntest: distdir
cd $(DISTVNAME) && $(ABSPERLRUN) Makefile.PL
cd $(DISTVNAME) && $(MAKE) $(PASTHRU)
cd $(DISTVNAME) && $(MAKE) runtest $(PASTHRU)
MAKE_FRAG
}
|