PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Makefile.PL

https://bitbucket.org/dginev/perl-xml-libxml
Perl | 730 lines | 607 code | 49 blank | 74 comment | 43 complexity | 16b18d48088a7b7079fd51384f76c1b2 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. [2,7,8,1], # tested, ok
  154. );
  155. my $xml2cfg = "xml2-config";
  156. my $libprefix = $ENV{XMLPREFIX} || $config{XMLPREFIX};
  157. delete $config{XMLPREFIX}; # delete if exists, otherwise MakeMaker gets confused
  158. if ( defined $libprefix ) {
  159. $xml2cfg = $libprefix . '/bin/' . $xml2cfg;
  160. }
  161. # if a user defined INC and LIBS on the command line we must not
  162. # override them
  163. if ( not defined $config{LIBS} and not defined $config{INC} ) {
  164. print "running xml2-config...";
  165. eval {
  166. try_libconfig( $xml2cfg, \%config, @blacklist );
  167. };
  168. if ( $@ ) {
  169. if ( $@ =~ /^VERSION|^FORCED/ ) {
  170. print STDERR "The installed version of libxml2 not compatible with XML::LibXML (and probably buggy)!\n\n".
  171. "You may continue at your own risk using 'perl Makefile.PL FORCE=1', but:\n\n".
  172. " - don't expect XML::LibXML to build or work correctly!\n".
  173. " - don't report errors!\n".
  174. " - don't send patches!\n\n".
  175. "Check the README file for more information on versions\n".
  176. "that are tested with XML::LibXML\n\n";
  177. exit 0 unless $FORCE; # 0 recommended by http://cpantest.grango.org (Notes for CPAN Authors)
  178. }
  179. if ( $@ =~ /^UNTESTED (\S*)/ ) {
  180. warn "Note: libxml2 $1 was not tested with this XML::LibXML version.\n"
  181. # warn <<UNTESTED;
  182. # WARNING!
  183. # The installed version of libxml2 was not tested with this version of XML::LibXML.
  184. # XML::LibXML may fail building or some tests may not pass.
  185. # Expect strange errors and unstable scripts.
  186. # Check the README file for more informations
  187. # END OF WARNING
  188. # UNTESTED
  189. }
  190. if ( not defined $config{LIBS} and not defined $config{INC} ) {
  191. warn "\nusing fallback values for LIBS and INC\n";
  192. $config{LIBS} = '-L/usr/local/lib -L/usr/lib -lxml2 -lm';
  193. $config{INC} = '-I/usr/local/include -I/usr/include';
  194. print <<OPT;
  195. options:
  196. LIBS='$config{LIBS}'
  197. INC='$config{INC}'
  198. If this is wrong, Re-run as:
  199. \$ $^X Makefile.PL LIBS='-L/path/to/lib' INC='-I/path/to/include'
  200. OPT
  201. }
  202. }
  203. }
  204. }
  205. # -------------------------------------------------------------------------- #
  206. # -------------------------------------------------------------------------- #
  207. # GDOME Support
  208. #
  209. # GDOME Support has to get explicitly activated by setting GDOME=1 as a config param.
  210. #
  211. unless ( $is_Win32 ) { # cannot get config in W32
  212. if ( $config{GDOME} ) {
  213. my $ver;
  214. my $state = undef; # there are three possible states:
  215. # 1 : works
  216. # 0 : works not
  217. # undef : not yet tested
  218. my @blacklist = (
  219. [0,7,2,0],
  220. [0,7,3,1],
  221. );
  222. print <<GDOME;
  223. GDOME Support (experimental):
  224. XML::LibXML can parse into XML::GDOME DOMs if libgdome is installed.
  225. This feature is optional and is not required for using XML::LibXML.
  226. GDOME
  227. print "running gdome-config...";
  228. eval {
  229. test_libconfig( "gdome-config", \%config, @blacklist );
  230. print "NOTE: You will need to install XML::GDOME to use this feature\n";
  231. };
  232. if ( $@ ) {
  233. if ( $@ =~ /^VERSION/ ) {
  234. warn "The installed libgdome version is not supported\n";
  235. }
  236. elsif ( $@ =~ /^UNTESTED/ ) {
  237. warn "The installed libgdome version was not yet tested with XML::LibXML.\n";
  238. print "NOTE: You will need to install XML::GDOME to use this feature\n";
  239. }
  240. }
  241. }
  242. }
  243. # -------------------------------------------------------------------------- #
  244. # -------------------------------------------------------------------------- #
  245. # fix the ld flags
  246. # -------------------------------------------------------------------------- #
  247. if ($config{LIBS} !~ /\-l(?:lib)?xml2\b/) {
  248. # in this case we are not able to run xml2-config. therefore we need to
  249. # expand the libz as well.
  250. if ($is_Win32) {
  251. if( $ENV{ACTIVEPERL_MINGW} ) {
  252. $config{LIBS} .= ' -llibxml2.lib -lzlib.lib';
  253. } else {
  254. $config{LIBS} .= ' -llibxml2 -lzlib -llibgettextlib.dll';
  255. }
  256. } else {
  257. $config{LIBS} .= ' -lxml2 -lz -lm';
  258. }
  259. }
  260. if ($config{LIBS} !~ /\-lz\b/ and !($is_Win32 && $config{LIBS} !~ /\-lzlib\b/)) {
  261. # note if libxml2 has not -lz within its cflags, we should not use
  262. # it! We should trust libxml2 and assume libz is not available on the
  263. # current system (this is ofcourse not true with win32 systems.
  264. # $config{LIBS} .= $is_Win32 ? ' -lzlib' :' -lz';
  265. if ( $config{DEBUG} ) {
  266. warn "zlib was not configured\n";
  267. warn "set zlib\n" if $is_Win32;
  268. }
  269. if ($is_Win32) {
  270. if( $ENV{ACTIVEPERL_MINGW} ) {
  271. $config{LIBS} .= ' -lzlib.lib';
  272. } else {
  273. $config{LIBS} .= ' -lzlib';
  274. }
  275. } else {
  276. $config{LIBS} .= ' -lz';
  277. }
  278. }
  279. # -------------------------------------------------------------------------- #
  280. # MacOS X Compiler switches have to go here
  281. #
  282. # if we run on MacOSX, we should check if 10.2 is running and if so,
  283. # if the Build Target is set correctly. Otherwise we have to set it by
  284. # hand
  285. # -------------------------------------------------------------------------- #
  286. # -------------------------------------------------------------------------- #
  287. # test if the libraries are really installed!
  288. unless (have_library("xml2") or have_library("libxml2")) {
  289. print STDERR <<DEATH;
  290. libxml2, zlib, and/or the Math library (-lm) have not been found.
  291. Try setting LIBS and INC values on the command line
  292. Or get libxml2 from
  293. http://xmlsoft.org/
  294. If you install via RPMs, make sure you also install the -devel
  295. RPMs, as this is where the headers (.h files) are.
  296. Also, you may try to run perl Makefile.PL with the DEBUG=1 parameter
  297. to see the exact reason why the detection of libxml2 installation
  298. failed or why Makefile.PL was not able to compile a test program.
  299. DEATH
  300. exit 0; # 0 recommended by http://cpantest.grango.org (Notes for CPAN Authors)
  301. }
  302. # -------------------------------------------------------------------------- #
  303. # -------------------------------------------------------------------------- #
  304. # _NOW_ write the Makefile
  305. my $ldflags = delete $config{LDFLAGS};
  306. if ($ldflags) {
  307. $config{dynamic_lib} = { OTHERLDFLAGS => " $ldflags " };
  308. }
  309. WriteMakefile(
  310. %INFOS,
  311. %config,
  312. );
  313. # -------------------------------------------------------------------------- #
  314. # -------------------------------------------------------------------------- #
  315. # helper functions to build the Makefile
  316. sub MY::manifypods {
  317. package MY;
  318. my $str = shift->SUPER::manifypods(@_);
  319. # warn $str;
  320. # $str =~ s/^manifypods : pure_all (.*)$/manifypods : pure_all docs $1/m;
  321. $str .= <<EOF;
  322. docs-fast :
  323. \t\@$^X -pi~ -e 's{<edition>[0-9.]*</edition>}{<edition>'"\$(VERSION)"'</edition>}' docs/libxml.dbk
  324. \t\@$^X -Iblib/arch -Iblib/lib example/xmllibxmldocs.pl docs/libxml.dbk lib/XML/LibXML/
  325. docs : pure_all
  326. \t\@$^X -pi~ -e 's{<edition>[0-9.]*</edition>}{<edition>'"\$(VERSION)"'</edition>}' docs/libxml.dbk
  327. \t\@$^X -Iblib/arch -Iblib/lib example/xmllibxmldocs.pl docs/libxml.dbk lib/XML/LibXML/
  328. \t\@$^X -pi.old -e 's/a/a/' Makefile.PL
  329. \t\@echo "==> YOU MUST NOW RE-RUN $^X Makefile.PL <=="
  330. \t\@false
  331. EOF
  332. return $str;
  333. }
  334. sub MY::install {
  335. package MY;
  336. my $script = shift->SUPER::install(@_);
  337. unless ( $::skipsaxinstall ) {
  338. $script =~ s/install :: (.*)$/install :: $1 install_sax_driver/m;
  339. $script .= <<"INSTALL";
  340. install_sax_driver :
  341. \t\@\$(PERL) -I\$(INSTALLSITELIB) -I\$(INSTALLSITEARCH) -MXML::SAX -e "XML::SAX->add_parser(q(XML::LibXML::SAX::Parser))->save_parsers()"
  342. \t\@\$(PERL) -I\$(INSTALLSITELIB) -I\$(INSTALLSITEARCH) -MXML::SAX -e "XML::SAX->add_parser(q(XML::LibXML::SAX))->save_parsers()"
  343. INSTALL
  344. } else {
  345. warn "Note: 'make install' will skip XML::LibXML::SAX registration with XML::SAX!\n";
  346. }
  347. return $script;
  348. }
  349. sub MY::test {
  350. package MY;
  351. my $script = shift->SUPER::test(@_);
  352. if ( $::extralibdir ) {
  353. $script =~ s/(\$\(TEST_VERBOSE\),)/$1 \'$::extralibdir\',/m;
  354. }
  355. return $script;
  356. }
  357. # echo perl -pi~ -e '$$_=q($(version))."\n" if /#\ VERSION TEMPLATE/ ' $(TO_INST_PM)
  358. sub MY::postamble {
  359. return <<'MAKE_FRAG';
  360. # used to update version numbers in all modules
  361. version:
  362. @version=`grep '\# VERSION TEMPLATE' $(VERSION_FROM)`; \
  363. echo "New version line: $$version"; \
  364. perl -pi~ -e '$$_=q('"$$version"')."\n" if /#\ VERSION TEMPLATE/ ' $(TO_INST_PM);
  365. runtest: pure_all
  366. perl -MFile::Spec -MTest::Run::CmdLine::Iface -e \
  367. "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();"
  368. distruntest: distdir
  369. cd $(DISTVNAME) && $(ABSPERLRUN) Makefile.PL
  370. cd $(DISTVNAME) && $(MAKE) $(PASTHRU)
  371. cd $(DISTVNAME) && $(MAKE) runtest $(PASTHRU)
  372. MAKE_FRAG
  373. }
  374. # -------------------------------------------------------------------------- #
  375. # -------------------------------------------------------------------------- #
  376. # Functions
  377. # - these should really be in MakeMaker... But &shrug;
  378. # -------------------------------------------------------------------------- #
  379. use Config;
  380. use Cwd;
  381. use Symbol;
  382. use File::Spec;
  383. BEGIN {
  384. $is_Win32 = ($^O =~ /Win32/);
  385. if ($is_Win32) {
  386. $DEVNULL = 'DEVNULL';
  387. }
  388. else {
  389. $DEVNULL = eval { File::Spec->devnull };
  390. if ($@) { $DEVNULL = '/dev/null' }
  391. }
  392. }
  393. sub rm_f {
  394. my @files = @_;
  395. my @realfiles;
  396. foreach (@files) {
  397. push @realfiles, glob($_);
  398. }
  399. if (@realfiles) {
  400. chmod(0777, @realfiles);
  401. unlink(@realfiles);
  402. }
  403. }
  404. sub rm_fr {
  405. my @files = @_;
  406. my @realfiles;
  407. foreach (@files) {
  408. push @realfiles, glob($_);
  409. }
  410. foreach my $file (@realfiles) {
  411. if (-d $file) {
  412. # warn("$file is a directory\n");
  413. rm_fr("$file/*");
  414. rm_fr("$file/.exists");
  415. rmdir($file) || die "Couldn't remove $file: $!";
  416. }
  417. else {
  418. # warn("removing $file\n");
  419. chmod(0777, $file);
  420. unlink($file);
  421. }
  422. }
  423. }
  424. sub xsystem {
  425. my $command = shift;
  426. if ($DEBUG) {
  427. print $command, "\n";
  428. if (system($command) != 0) {
  429. die "system call to '$command' failed";
  430. }
  431. return 1;
  432. }
  433. open(OLDOUT, ">&STDOUT");
  434. open(OLDERR, ">&STDERR");
  435. open(STDOUT, ">$DEVNULL");
  436. open(STDERR, ">$DEVNULL");
  437. my $retval = system($command);
  438. open(STDOUT, ">&OLDOUT");
  439. open(STDERR, ">&OLDERR");
  440. if ($retval != 0) {
  441. die "system call to '$command' failed";
  442. }
  443. return 1;
  444. }
  445. sub backtick {
  446. my $command = shift;
  447. if ($DEBUG) {
  448. print $command, "\n";
  449. my $results = `$command`;
  450. chomp $results;
  451. if ($? != 0) {
  452. die "backticks call to '$command' failed";
  453. }
  454. return $results;
  455. }
  456. open(OLDOUT, ">&STDOUT");
  457. open(OLDERR, ">&STDERR");
  458. open(STDOUT, ">$DEVNULL");
  459. open(STDERR, ">$DEVNULL");
  460. my $results = `$command`;
  461. my $retval = $?;
  462. open(STDOUT, ">&OLDOUT");
  463. open(STDERR, ">&OLDERR");
  464. if ($retval != 0) {
  465. die "backticks call to '$command' failed";
  466. }
  467. chomp $results;
  468. return $results;
  469. }
  470. sub try_link0 {
  471. my ($src, $opt) = @_;
  472. # local $config{LIBS};
  473. # $config{LIBS} .= $opt;
  474. unless (mkdir(".testlink", 0777)) {
  475. rm_fr(".testlink");
  476. mkdir(".testlink", 0777) || die "Cannot create .testlink dir: $!";
  477. }
  478. chdir(".testlink");
  479. {
  480. open(my $cfile, '>', 'Conftest.xs')
  481. or die "Cannot write to file Conftest.xs: $!";
  482. print {$cfile} <<EOT;
  483. #ifdef __cplusplus
  484. extern "C" {
  485. #endif
  486. #include <EXTERN.h>
  487. #include <perl.h>
  488. #include <XSUB.h>
  489. #ifdef __cplusplus
  490. }
  491. #endif
  492. EOT
  493. print {$cfile} $src;
  494. print {$cfile} <<EOT;
  495. MODULE = Conftest PACKAGE = Conftest
  496. PROTOTYPES: DISABLE
  497. EOT
  498. close($cfile);
  499. }
  500. {
  501. open(my $cfile, '>', 'Conftest.pm')
  502. or die "Cannot write to file Conftest.pm: $!";
  503. print {$cfile} <<'EOT';
  504. package Conftest;
  505. $VERSION = 1.0;
  506. require DynaLoader;
  507. @ISA = ('DynaLoader');
  508. bootstrap Conftest $VERSION;
  509. 1;
  510. EOT
  511. close($cfile);
  512. }
  513. {
  514. open (my $cfile, '>', 'Makefile.PL')
  515. or die "Cannot write to file Makefile.PL: $!";
  516. print {$cfile} <<'EOT';
  517. use ExtUtils::MakeMaker;
  518. my %config;
  519. while($_ = shift @ARGV) {
  520. my ($k, $v) = split /=/, $_, 2;
  521. warn("$k = $v\n");
  522. $config{$k} = $v;
  523. }
  524. WriteMakefile(NAME => "Conftest", VERSION_FROM => "Conftest.pm", %config);
  525. EOT
  526. close($cfile);
  527. }
  528. {
  529. open(my $cfile, ">test.pl")
  530. or die "Cannot write to file test.pl: $!";
  531. print {$cfile} <<EOT;
  532. use Test; BEGIN { plan tests => 1; } END { ok(\$loaded) }
  533. use Conftest; \$loaded++;
  534. EOT
  535. close($cfile);
  536. }
  537. my $quote = $is_Win32 ? '"' : "'";
  538. xsystem("$^X Makefile.PL "
  539. . join(' ', map { "${quote}$_=$config{$_}${quote}" } keys %config)
  540. );
  541. my $def_opt = defined($opt) ? $opt : '';
  542. # I am not shure if OTHERLDFLAGS is really required - at least the
  543. # libraries to include do not belong here!
  544. # I would assume a user to set OTHERLDFLAGS in the %config if they are
  545. # really required. if done so, we don't have to pass them here ...
  546. xsystem("$Config{make} test ${quote}OTHERLDFLAGS=${def_opt}${quote}");
  547. } # end try_link0
  548. sub try_link {
  549. my $start_dir = cwd();
  550. my $result = eval {
  551. try_link0(@_);
  552. };
  553. warn $@ if $DEBUG && $@;
  554. chdir($start_dir);
  555. rm_fr(".testlink");
  556. return $result;
  557. }
  558. sub have_library {
  559. my ($lib, $func) = (@_, "blank");
  560. printf("checking for %s() in -l%s... ", $func, $lib) if $func ne "blank";
  561. printf("looking for -l%s... ", $lib) if $func eq "blank";
  562. my $result;
  563. if ($func) {
  564. my $libs = $is_Win32 ? " $lib.lib " : "-l$lib";
  565. # my $libs = "-l$lib";
  566. if ($is_Win32) {
  567. $result = try_link(<<"SRC", undef);
  568. #include <windows.h>
  569. #include <winsock.h>
  570. blank() { return 0; }
  571. int t() { ${func}(); return 0; }
  572. SRC
  573. unless ($result) {
  574. $result = try_link(<<"SRC", undef);
  575. #include <windows.h>
  576. #include <winsock.h>
  577. blank() { return 0; }
  578. int t() { void ((*p)()); p = (void ((*)()))${func}; return 0; }
  579. SRC
  580. }
  581. }
  582. else {
  583. $result = try_link(<<"SRC", undef);
  584. blank() { return 0; }
  585. int t() { ${func}(); return 0; }
  586. SRC
  587. }
  588. }
  589. unless ($result) {
  590. print "no\n";
  591. return 0;
  592. }
  593. if ($func ne "main") {
  594. $config{DEFINE} .= uc(" -Dhave_$func");
  595. }
  596. print "yes\n";
  597. return 1;
  598. }
  599. # -------------------------------------------------------------------------- #
  600. # try_libconfig class a generic config file and requests --version, --libs and
  601. # --cflags
  602. sub try_libconfig {
  603. my $cfgscript = shift;
  604. my $config = shift;
  605. my @bl = @_;
  606. my $state = undef; # there are three possible states:
  607. # 1 : works
  608. # 0 : works not
  609. # undef : not yet tested
  610. my $ver = backtick("$cfgscript --version");
  611. if ( defined $ver ) {
  612. my ( $major, $minor, $point) = $ver =~ /(\d+).(\d+)\.(\d+)/g;
  613. foreach ( @bl ) {
  614. $state = $_->[3];
  615. last if $major < $_->[0];
  616. next if $major > $_->[0];
  617. last if $minor < $_->[1];
  618. next if $minor > $_->[1];
  619. last if $point <= $_->[2];
  620. $state = undef;
  621. }
  622. $config->{LIBS} = backtick("$cfgscript --libs");
  623. $config->{INC} = backtick("$cfgscript --cflags");
  624. if ( defined $state and $state == 0 ) {
  625. print "failed\n";
  626. if ($FORCE) {
  627. die "FORCED $ver\n";
  628. }
  629. else {
  630. die "VERSION $ver\n";
  631. }
  632. }
  633. unless ( defined $state ) {
  634. print "untested\n";
  635. die "UNTESTED $ver\n";
  636. }
  637. print "ok ($ver)\n";
  638. }
  639. else {
  640. print "failed\n";
  641. die "FAILED\n"; # strange error
  642. }
  643. }
  644. # -------------------------------------------------------------------------- #