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

/Makefile.PL

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