PageRenderTime 63ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Makefile.PL

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