PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Makefile.PL

https://bitbucket.org/Mithaldu/perl-xml-libxml
Perl | 729 lines | 606 code | 49 blank | 74 comment | 43 complexity | 0b0e69fe32c9fccb2e8d070e013e271f 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. #
  8. #
  9. # This is free software, you may use it and distribute it under the same terms as
  10. # Perl itself.
  11. #
  12. # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
  13. #
  14. use strict;
  15. use warnings;
  16. require 5.008;
  17. use vars qw/$DEVNULL $is_Win32 $extralibdir $skipsaxinstall/;
  18. use ExtUtils::MakeMaker;
  19. use Config;
  20. use Symbol;
  21. use File::Spec;
  22. $|=0;
  23. my %config;
  24. # -------------------------------------------------------------------------- #
  25. # -------------------------------------------------------------------------- #
  26. # common information go to the top, so they are easier to find
  27. # -------------------------------------------------------------------------- #
  28. my %INFOS = (
  29. 'NAME' => 'XML::LibXML',
  30. 'VERSION_FROM' => 'LibXML.pm', # finds $VERSION
  31. 'AUTHOR' => 'Petr Pajas',
  32. 'ABSTRACT' => 'Interface to Gnome libxml2 xml parsing and DOM library',
  33. 'LICENSE' => 'perl',
  34. 'PREREQ_PM' => {
  35. 'base' => 0,
  36. 'ExtUtils::MakeMaker' => '6.56',
  37. 'strict' => 0,
  38. 'Test::More' => 0,
  39. 'vars' => 0,
  40. 'warnings' => 0,
  41. 'XML::NamespaceSupport' => '1.07',
  42. 'XML::SAX' => '0.11',
  43. },
  44. 'OBJECT' => '$(O_FILES)', # add the DOM extensions to libxml2
  45. META_MERGE =>
  46. {
  47. resources =>
  48. {
  49. repository => 'https://bitbucket.org/shlomif/perl-xml-libxml',
  50. homepage => 'https://bitbucket.org/shlomif/perl-xml-libxml',
  51. },
  52. keywords =>
  53. [
  54. "dom",
  55. "html",
  56. "libxml",
  57. "object oriented",
  58. "oop",
  59. "parse",
  60. "parser",
  61. "parsing",
  62. "pullparser",
  63. "sax",
  64. "sgml",
  65. "xml",
  66. "xpath",
  67. "XPath",
  68. "xs",
  69. ],
  70. },
  71. );
  72. # -------------------------------------------------------------------------- #
  73. # -------------------------------------------------------------------------- #
  74. # -------------------------------------------------------------------------- #
  75. # libxml2 valid versions
  76. # -------------------------------------------------------------------------- #
  77. # -------------------------------------------------------------------------- #
  78. # read extra configurations from the commandline
  79. my %params;
  80. @params{qw(FORCE DEBUG DEFINE EXTRALIBDIR GDOME INC LIBS SKIP_SAX_INSTALL XMLPREFIX NO_THREADS LDFLAGS)}=();
  81. @ARGV = grep {
  82. my ($key, $val) = split(/=/, $_, 2);
  83. if (exists $params{$key}) {
  84. $config{$key} = $val; 0
  85. } else { 1 }
  86. } @ARGV;
  87. $extralibdir = $config{EXTRALIBDIR};
  88. delete $config{EXTRALIBDIR};
  89. # -------------------------------------------------------------------------- #
  90. # -------------------------------------------------------------------------- #
  91. # force unsupported version
  92. my $FORCE = delete $config{FORCE};
  93. # switch Debugging messages on
  94. my $DEBUG = delete $config{DEBUG};
  95. if ( $config{DEBUG} and $is_Win32 ) {
  96. warn "win32 compile\n";
  97. }
  98. # -------------------------------------------------------------------------- #
  99. # -------------------------------------------------------------------------- #
  100. # enable perls UTF8 support if available
  101. if ( $] >= 5.006 ) {
  102. warn "enable native perl UTF8\n";
  103. $config{DEFINE} .= " -DHAVE_UTF8";
  104. }
  105. if ( $] < 5.008 or $config{NO_THREADS} ) {
  106. warn "disabling XML::LibXML support for Perl threads\n";
  107. $config{DEFINE} .= " -DNO_XML_LIBXML_THREADS";
  108. }
  109. delete $config{NO_THREADS};
  110. # -------------------------------------------------------------------------- #
  111. # -------------------------------------------------------------------------- #
  112. # get the libxml2 configuration
  113. #
  114. # For each release we already know which libxml2 versions work with the given
  115. # module. All we need is to keep track of bad versions.
  116. # If a user wants to build XML::LibXML with a newer version, there will be
  117. # a warning, that errors are possible.
  118. #
  119. # We keep track of the valid versions by keeping a blacklist of intervals
  120. # of working and not working versions where Ma.Mi.Pt <= X.Y.Z is of the same
  121. # state.
  122. #
  123. # NOTE: All versions, the tests pass will be marked as working.
  124. #
  125. $skipsaxinstall = $ENV{SKIP_SAX_INSTALL} || $config{SKIP_SAX_INSTALL};
  126. delete $config{SKIP_SAX_INSTALL};
  127. unless ( $is_Win32 ) { # cannot get config in W32
  128. my @blacklist = (
  129. # format X,Y,Z,is_ok, X,Y,Z is version,
  130. # is_ok applies also to *preceding* versions
  131. [2,4,22,0],
  132. [2,4,25,0], # broken XPath
  133. [2,4,28,0], # unsupported, may work fine with earlier XML::LibXML versions
  134. [2,4,29,0], # broken
  135. [2,4,30,0], # broken
  136. [2,5,0,0], # unsupported
  137. [2,5,1,0], # all pre 2.5.4 version have broken attr output
  138. [2,5,5,0], # tests pass, but known as broken
  139. [2,5,11,0], # will partially work
  140. [2,6,0,0], # unsupported
  141. [2,6,4,0], # schema error
  142. [2,6,5,0], # broken xincludes
  143. [2,6,15,0],
  144. # [2,6,16,1], # first version to pass all tests
  145. [2,6,18,1], # up to 2.6.18 all ok
  146. [2,6,19,0], # broken c14n
  147. [2,6,20,0], # broken schemas
  148. [2,6,24,1], # all tests pass
  149. [2,6,25,0], # broken XPath
  150. [2,6,32,1], # tested, works ok
  151. [2,7,1,0], # broken release, broken utf-16
  152. [2,7,6,1], # tested, ok
  153. );
  154. my $xml2cfg = "xml2-config";
  155. my $libprefix = $ENV{XMLPREFIX} || $config{XMLPREFIX};
  156. delete $config{XMLPREFIX}; # delete if exists, otherwise MakeMaker gets confused
  157. if ( defined $libprefix ) {
  158. $xml2cfg = $libprefix . '/bin/' . $xml2cfg;
  159. }
  160. # if a user defined INC and LIBS on the command line we must not
  161. # override them
  162. if ( not defined $config{LIBS} and not defined $config{INC} ) {
  163. print "running xml2-config...";
  164. eval {
  165. try_libconfig( $xml2cfg, \%config, @blacklist );
  166. };
  167. if ( $@ ) {
  168. if ( $@ =~ /^VERSION|^FORCED/ ) {
  169. print STDERR "The installed version of libxml2 not compatible with XML::LibXML (and probably buggy)!\n\n".
  170. "You may continue at your own risk using 'perl Makefile.PL FORCE=1', but:\n\n".
  171. " - don't expect XML::LibXML to build or work correctly!\n".
  172. " - don't report errors!\n".
  173. " - don't send patches!\n\n".
  174. "Check the README file for more information on versions\n".
  175. "that are tested with XML::LibXML\n\n";
  176. exit 0 unless $FORCE; # 0 recommended by http://cpantest.grango.org (Notes for CPAN Authors)
  177. }
  178. if ( $@ =~ /^UNTESTED (\S*)/ ) {
  179. warn "Note: libxml2 $1 was not tested with this XML::LibXML version.\n"
  180. # warn <<UNTESTED;
  181. # WARNING!
  182. # The installed version of libxml2 was not tested with this version of XML::LibXML.
  183. # XML::LibXML may fail building or some tests may not pass.
  184. # Expect strange errors and unstable scripts.
  185. # Check the README file for more informations
  186. # END OF WARNING
  187. # UNTESTED
  188. }
  189. if ( not defined $config{LIBS} and not defined $config{INC} ) {
  190. warn "\nusing fallback values for LIBS and INC\n";
  191. $config{LIBS} = '-L/usr/local/lib -L/usr/lib -lxml2 -lm';
  192. $config{INC} = '-I/usr/local/include -I/usr/include';
  193. print <<OPT;
  194. options:
  195. LIBS='$config{LIBS}'
  196. INC='$config{INC}'
  197. If this is wrong, Re-run as:
  198. \$ $^X Makefile.PL LIBS='-L/path/to/lib' INC='-I/path/to/include'
  199. OPT
  200. }
  201. }
  202. }
  203. }
  204. # -------------------------------------------------------------------------- #
  205. # -------------------------------------------------------------------------- #
  206. # GDOME Support
  207. #
  208. # GDOME Support has to get explicitly activated by setting GDOME=1 as a config param.
  209. #
  210. unless ( $is_Win32 ) { # cannot get config in W32
  211. if ( $config{GDOME} ) {
  212. my $ver;
  213. my $state = undef; # there are three possible states:
  214. # 1 : works
  215. # 0 : works not
  216. # undef : not yet tested
  217. my @blacklist = (
  218. [0,7,2,0],
  219. [0,7,3,1],
  220. );
  221. print <<GDOME;
  222. GDOME Support (experimental):
  223. XML::LibXML can parse into XML::GDOME DOMs if libgdome is installed.
  224. This feature is optional and is not required for using XML::LibXML.
  225. GDOME
  226. print "running gdome-config...";
  227. eval {
  228. test_libconfig( "gdome-config", \%config, @blacklist );
  229. print "NOTE: You will need to install XML::GDOME to use this feature\n";
  230. };
  231. if ( $@ ) {
  232. if ( $@ =~ /^VERSION/ ) {
  233. warn "The installed libgdome version is not supported\n";
  234. }
  235. elsif ( $@ =~ /^UNTESTED/ ) {
  236. warn "The installed libgdome version was not yet tested with XML::LibXML.\n";
  237. print "NOTE: You will need to install XML::GDOME to use this feature\n";
  238. }
  239. }
  240. }
  241. }
  242. # -------------------------------------------------------------------------- #
  243. # -------------------------------------------------------------------------- #
  244. # fix the ld flags
  245. # -------------------------------------------------------------------------- #
  246. if ($config{LIBS} !~ /\-l(?:lib)?xml2\b/) {
  247. # in this case we are not able to run xml2-config. therefore we need to
  248. # expand the libz as well.
  249. if ($is_Win32) {
  250. if( $ENV{ACTIVEPERL_MINGW} ) {
  251. $config{LIBS} .= ' -llibxml2.lib -lzlib.lib';
  252. } else {
  253. $config{LIBS} .= ' -llibxml2 -lzlib';
  254. }
  255. } else {
  256. $config{LIBS} .= ' -lxml2 -lz -lm';
  257. }
  258. }
  259. if ($config{LIBS} !~ /\-lz\b/ and !($is_Win32 && $config{LIBS} !~ /\-lzlib\b/)) {
  260. # note if libxml2 has not -lz within its cflags, we should not use
  261. # it! We should trust libxml2 and assume libz is not available on the
  262. # current system (this is ofcourse not true with win32 systems.
  263. # $config{LIBS} .= $is_Win32 ? ' -lzlib' :' -lz';
  264. if ( $config{DEBUG} ) {
  265. warn "zlib was not configured\n";
  266. warn "set zlib\n" if $is_Win32;
  267. }
  268. if ($is_Win32) {
  269. if( $ENV{ACTIVEPERL_MINGW} ) {
  270. $config{LIBS} .= ' -lzlib.lib';
  271. } else {
  272. $config{LIBS} .= ' -lzlib';
  273. }
  274. } else {
  275. $config{LIBS} .= ' -lz';
  276. }
  277. }
  278. # -------------------------------------------------------------------------- #
  279. # MacOS X Compiler switches have to go here
  280. #
  281. # if we run on MacOSX, we should check if 10.2 is running and if so,
  282. # if the Build Target is set correctly. Otherwise we have to set it by
  283. # hand
  284. # -------------------------------------------------------------------------- #
  285. # -------------------------------------------------------------------------- #
  286. # test if the libraries are really installed!
  287. unless (have_library("xml2") or have_library("libxml2")) {
  288. print STDERR <<DEATH;
  289. libxml2, zlib, and/or the Math library (-lm) have not been found.
  290. Try setting LIBS and INC values on the command line
  291. Or get libxml2 from
  292. http://xmlsoft.org/
  293. If you install via RPMs, make sure you also install the -devel
  294. RPMs, as this is where the headers (.h files) are.
  295. Also, you may try to run perl Makefile.PL with the DEBUG=1 parameter
  296. to see the exact reason why the detection of libxml2 installation
  297. failed or why Makefile.PL was not able to compile a test program.
  298. DEATH
  299. exit 0; # 0 recommended by http://cpantest.grango.org (Notes for CPAN Authors)
  300. }
  301. # -------------------------------------------------------------------------- #
  302. # -------------------------------------------------------------------------- #
  303. # _NOW_ write the Makefile
  304. my $ldflags = delete $config{LDFLAGS};
  305. if ($ldflags) {
  306. $config{dynamic_lib} = { OTHERLDFLAGS => " $ldflags " };
  307. }
  308. WriteMakefile(
  309. %INFOS,
  310. %config,
  311. );
  312. # -------------------------------------------------------------------------- #
  313. # -------------------------------------------------------------------------- #
  314. # helper functions to build the Makefile
  315. sub MY::manifypods {
  316. package MY;
  317. my $str = shift->SUPER::manifypods(@_);
  318. # warn $str;
  319. # $str =~ s/^manifypods : pure_all (.*)$/manifypods : pure_all docs $1/m;
  320. $str .= <<EOF;
  321. docs-fast :
  322. \t\@$^X -pi~ -e 's{<edition>[0-9.]*</edition>}{<edition>'"\$(VERSION)"'</edition>}' docs/libxml.dbk
  323. \t\@$^X -Iblib/arch -Iblib/lib example/xmllibxmldocs.pl docs/libxml.dbk lib/XML/LibXML/
  324. docs : pure_all
  325. \t\@$^X -pi~ -e 's{<edition>[0-9.]*</edition>}{<edition>'"\$(VERSION)"'</edition>}' docs/libxml.dbk
  326. \t\@$^X -Iblib/arch -Iblib/lib example/xmllibxmldocs.pl docs/libxml.dbk lib/XML/LibXML/
  327. \t\@$^X -pi.old -e 's/a/a/' Makefile.PL
  328. \t\@echo "==> YOU MUST NOW RE-RUN $^X Makefile.PL <=="
  329. \t\@false
  330. EOF
  331. return $str;
  332. }
  333. sub MY::install {
  334. package MY;
  335. my $script = shift->SUPER::install(@_);
  336. unless ( $::skipsaxinstall ) {
  337. $script =~ s/install :: (.*)$/install :: $1 install_sax_driver/m;
  338. $script .= <<"INSTALL";
  339. install_sax_driver :
  340. \t\@\$(PERL) -I\$(INSTALLSITELIB) -I\$(INSTALLSITEARCH) -MXML::SAX -e "XML::SAX->add_parser(q(XML::LibXML::SAX::Parser))->save_parsers()"
  341. \t\@\$(PERL) -I\$(INSTALLSITELIB) -I\$(INSTALLSITEARCH) -MXML::SAX -e "XML::SAX->add_parser(q(XML::LibXML::SAX))->save_parsers()"
  342. INSTALL
  343. } else {
  344. warn "Note: 'make install' will skip XML::LibXML::SAX registration with XML::SAX!\n";
  345. }
  346. return $script;
  347. }
  348. sub MY::test {
  349. package MY;
  350. my $script = shift->SUPER::test(@_);
  351. if ( $::extralibdir ) {
  352. $script =~ s/(\$\(TEST_VERBOSE\),)/$1 \'$::extralibdir\',/m;
  353. }
  354. return $script;
  355. }
  356. # echo perl -pi~ -e '$$_=q($(version))."\n" if /#\ VERSION TEMPLATE/ ' $(TO_INST_PM)
  357. sub MY::postamble {
  358. return <<'MAKE_FRAG';
  359. # used to update version numbers in all modules
  360. version:
  361. @version=`grep '\# VERSION TEMPLATE' $(VERSION_FROM)`; \
  362. echo "New version line: $$version"; \
  363. perl -pi~ -e '$$_=q('"$$version"')."\n" if /#\ VERSION TEMPLATE/ ' $(TO_INST_PM);
  364. runtest: pure_all
  365. perl -MFile::Spec -MTest::Run::CmdLine::Iface -e \
  366. "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();"
  367. distruntest: distdir
  368. cd $(DISTVNAME) && $(ABSPERLRUN) Makefile.PL
  369. cd $(DISTVNAME) && $(MAKE) $(PASTHRU)
  370. cd $(DISTVNAME) && $(MAKE) runtest $(PASTHRU)
  371. MAKE_FRAG
  372. }
  373. # -------------------------------------------------------------------------- #
  374. # -------------------------------------------------------------------------- #
  375. # Functions
  376. # - these should really be in MakeMaker... But &shrug;
  377. # -------------------------------------------------------------------------- #
  378. use Config;
  379. use Cwd;
  380. use Symbol;
  381. use File::Spec;
  382. BEGIN {
  383. $is_Win32 = ($^O =~ /Win32/);
  384. if ($is_Win32) {
  385. $DEVNULL = 'DEVNULL';
  386. }
  387. else {
  388. $DEVNULL = eval { File::Spec->devnull };
  389. if ($@) { $DEVNULL = '/dev/null' }
  390. }
  391. }
  392. sub rm_f {
  393. my @files = @_;
  394. my @realfiles;
  395. foreach (@files) {
  396. push @realfiles, glob($_);
  397. }
  398. if (@realfiles) {
  399. chmod(0777, @realfiles);
  400. unlink(@realfiles);
  401. }
  402. }
  403. sub rm_fr {
  404. my @files = @_;
  405. my @realfiles;
  406. foreach (@files) {
  407. push @realfiles, glob($_);
  408. }
  409. foreach my $file (@realfiles) {
  410. if (-d $file) {
  411. # warn("$file is a directory\n");
  412. rm_fr("$file/*");
  413. rm_fr("$file/.exists");
  414. rmdir($file) || die "Couldn't remove $file: $!";
  415. }
  416. else {
  417. # warn("removing $file\n");
  418. chmod(0777, $file);
  419. unlink($file);
  420. }
  421. }
  422. }
  423. sub xsystem {
  424. my $command = shift;
  425. if ($DEBUG) {
  426. print $command, "\n";
  427. if (system($command) != 0) {
  428. die "system call to '$command' failed";
  429. }
  430. return 1;
  431. }
  432. open(OLDOUT, ">&STDOUT");
  433. open(OLDERR, ">&STDERR");
  434. open(STDOUT, ">$DEVNULL");
  435. open(STDERR, ">$DEVNULL");
  436. my $retval = system($command);
  437. open(STDOUT, ">&OLDOUT");
  438. open(STDERR, ">&OLDERR");
  439. if ($retval != 0) {
  440. die "system call to '$command' failed";
  441. }
  442. return 1;
  443. }
  444. sub backtick {
  445. my $command = shift;
  446. if ($DEBUG) {
  447. print $command, "\n";
  448. my $results = `$command`;
  449. chomp $results;
  450. if ($? != 0) {
  451. die "backticks call to '$command' failed";
  452. }
  453. return $results;
  454. }
  455. open(OLDOUT, ">&STDOUT");
  456. open(OLDERR, ">&STDERR");
  457. open(STDOUT, ">$DEVNULL");
  458. open(STDERR, ">$DEVNULL");
  459. my $results = `$command`;
  460. my $retval = $?;
  461. open(STDOUT, ">&OLDOUT");
  462. open(STDERR, ">&OLDERR");
  463. if ($retval != 0) {
  464. die "backticks call to '$command' failed";
  465. }
  466. chomp $results;
  467. return $results;
  468. }
  469. sub try_link0 {
  470. my ($src, $opt) = @_;
  471. # local $config{LIBS};
  472. # $config{LIBS} .= $opt;
  473. unless (mkdir(".testlink", 0777)) {
  474. rm_fr(".testlink");
  475. mkdir(".testlink", 0777) || die "Cannot create .testlink dir: $!";
  476. }
  477. chdir(".testlink");
  478. {
  479. open(my $cfile, '>', 'Conftest.xs')
  480. or die "Cannot write to file Conftest.xs: $!";
  481. print {$cfile} <<EOT;
  482. #ifdef __cplusplus
  483. extern "C" {
  484. #endif
  485. #include <EXTERN.h>
  486. #include <perl.h>
  487. #include <XSUB.h>
  488. #ifdef __cplusplus
  489. }
  490. #endif
  491. EOT
  492. print {$cfile} $src;
  493. print {$cfile} <<EOT;
  494. MODULE = Conftest PACKAGE = Conftest
  495. PROTOTYPES: DISABLE
  496. EOT
  497. close($cfile);
  498. }
  499. {
  500. open(my $cfile, '>', 'Conftest.pm')
  501. or die "Cannot write to file Conftest.pm: $!";
  502. print {$cfile} <<'EOT';
  503. package Conftest;
  504. $VERSION = 1.0;
  505. require DynaLoader;
  506. @ISA = ('DynaLoader');
  507. bootstrap Conftest $VERSION;
  508. 1;
  509. EOT
  510. close($cfile);
  511. }
  512. {
  513. open (my $cfile, '>', 'Makefile.PL')
  514. or die "Cannot write to file Makefile.PL: $!";
  515. print {$cfile} <<'EOT';
  516. use ExtUtils::MakeMaker;
  517. my %config;
  518. while($_ = shift @ARGV) {
  519. my ($k, $v) = split /=/, $_, 2;
  520. warn("$k = $v\n");
  521. $config{$k} = $v;
  522. }
  523. WriteMakefile(NAME => "Conftest", VERSION_FROM => "Conftest.pm", %config);
  524. EOT
  525. close($cfile);
  526. }
  527. {
  528. open(my $cfile, ">test.pl")
  529. or die "Cannot write to file test.pl: $!";
  530. print {$cfile} <<EOT;
  531. use Test; BEGIN { plan tests => 1; } END { ok(\$loaded) }
  532. use Conftest; \$loaded++;
  533. EOT
  534. close($cfile);
  535. }
  536. my $quote = $is_Win32 ? '"' : "'";
  537. xsystem("$^X Makefile.PL "
  538. . join(' ', map { "${quote}$_=$config{$_}${quote}" } keys %config)
  539. );
  540. my $def_opt = defined($opt) ? $opt : '';
  541. # I am not shure if OTHERLDFLAGS is really required - at least the
  542. # libraries to include do not belong here!
  543. # I would assume a user to set OTHERLDFLAGS in the %config if they are
  544. # really required. if done so, we don't have to pass them here ...
  545. xsystem("$Config{make} test ${quote}OTHERLDFLAGS=${def_opt}${quote}");
  546. } # end try_link0
  547. sub try_link {
  548. my $start_dir = cwd();
  549. my $result = eval {
  550. try_link0(@_);
  551. };
  552. warn $@ if $DEBUG && $@;
  553. chdir($start_dir);
  554. rm_fr(".testlink");
  555. return $result;
  556. }
  557. sub have_library {
  558. my ($lib, $func) = (@_, "blank");
  559. printf("checking for %s() in -l%s... ", $func, $lib) if $func ne "blank";
  560. printf("looking for -l%s... ", $lib) if $func eq "blank";
  561. my $result;
  562. if ($func) {
  563. my $libs = $is_Win32 ? " $lib.lib " : "-l$lib";
  564. # my $libs = "-l$lib";
  565. if ($is_Win32) {
  566. $result = try_link(<<"SRC", undef);
  567. #include <windows.h>
  568. #include <winsock.h>
  569. blank() { return 0; }
  570. int t() { ${func}(); return 0; }
  571. SRC
  572. unless ($result) {
  573. $result = try_link(<<"SRC", undef);
  574. #include <windows.h>
  575. #include <winsock.h>
  576. blank() { return 0; }
  577. int t() { void ((*p)()); p = (void ((*)()))${func}; return 0; }
  578. SRC
  579. }
  580. }
  581. else {
  582. $result = try_link(<<"SRC", undef);
  583. blank() { return 0; }
  584. int t() { ${func}(); return 0; }
  585. SRC
  586. }
  587. }
  588. unless ($result) {
  589. print "no\n";
  590. return 0;
  591. }
  592. if ($func ne "main") {
  593. $config{DEFINE} .= uc(" -Dhave_$func");
  594. }
  595. print "yes\n";
  596. return 1;
  597. }
  598. # -------------------------------------------------------------------------- #
  599. # try_libconfig class a generic config file and requests --version, --libs and
  600. # --cflags
  601. sub try_libconfig {
  602. my $cfgscript = shift;
  603. my $config = shift;
  604. my @bl = @_;
  605. my $state = undef; # there are three possible states:
  606. # 1 : works
  607. # 0 : works not
  608. # undef : not yet tested
  609. my $ver = backtick("$cfgscript --version");
  610. if ( defined $ver ) {
  611. my ( $major, $minor, $point) = $ver =~ /(\d+).(\d+)\.(\d+)/g;
  612. foreach ( @bl ) {
  613. $state = $_->[3];
  614. last if $major < $_->[0];
  615. next if $major > $_->[0];
  616. last if $minor < $_->[1];
  617. next if $minor > $_->[1];
  618. last if $point <= $_->[2];
  619. $state = undef;
  620. }
  621. $config->{LIBS} = backtick("$cfgscript --libs");
  622. $config->{INC} = backtick("$cfgscript --cflags");
  623. if ( defined $state and $state == 0 ) {
  624. print "failed\n";
  625. if ($FORCE) {
  626. die "FORCED $ver\n";
  627. }
  628. else {
  629. die "VERSION $ver\n";
  630. }
  631. }
  632. unless ( defined $state ) {
  633. print "untested\n";
  634. die "UNTESTED $ver\n";
  635. }
  636. print "ok ($ver)\n";
  637. }
  638. else {
  639. print "failed\n";
  640. die "FAILED\n"; # strange error
  641. }
  642. }
  643. # -------------------------------------------------------------------------- #