| 1 | use ExtUtils::MakeMaker; |
| 2 | use strict; |
| 3 | use Config; |
| 4 | |
| 5 | # Suppress warnings about parameters we allow the user to specify. |
| 6 | $ExtUtils::MakeMaker::Recognized_Att_Keys{CXX} = 1; |
| 7 | $ExtUtils::MakeMaker::Recognized_Att_Keys{XAPIAN_CONFIG} = 1; |
| 8 | |
| 9 | my $builddir; |
| 10 | |
| 11 | my $srcdir = $0; |
| 12 | if ($srcdir =~ s!/([^/]*)$!!) { |
| 13 | # Set $0 to be just the leafname. If we don't, WriteMakefile() reruns this |
| 14 | # script for reasons unknown, leading to a seemingly infinite loop |
| 15 | # consuming increasing amounts of memory. With setting $0, it still reruns |
| 16 | # this script, but only once. |
| 17 | $0 = $1; |
| 18 | chomp($builddir = `pwd`); |
| 19 | chdir $srcdir; |
| 20 | } |
| 21 | |
| 22 | my $xapian_config; |
| 23 | my $CC; |
| 24 | for (@ARGV) { |
| 25 | if (/^XAPIAN_CONFIG=(.*)/) { |
| 26 | $xapian_config = $1; |
| 27 | } elsif (/^CXX=(.*)/) { |
| 28 | $CC = $1; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if (!defined $xapian_config && exists $ENV{XAPIAN_CONFIG}) { |
| 33 | $xapian_config = $ENV{XAPIAN_CONFIG}; |
| 34 | push @ARGV, "XAPIAN_CONFIG=$xapian_config"; |
| 35 | } |
| 36 | $xapian_config ||= 'xapian-config'; |
| 37 | |
| 38 | if (!defined $CC && exists $ENV{CXX}) { |
| 39 | $CC = $ENV{CXX}; |
| 40 | push @ARGV, "CXX=$CC"; |
| 41 | } |
| 42 | $CC ||= 'g++'; |
| 43 | |
| 44 | my $LD = '$(CC)'; |
| 45 | if ($^O eq 'cygwin' and $CC eq 'g++') { |
| 46 | # Cygwin packages of Perl < 5.9.5 used "ld2" for $Config{ld} and |
| 47 | # $Config{lddlflags} didn't contain -shared so we need to specify |
| 48 | # this explicitly. Perl >= 5.9.5 package do away with "ld2", but |
| 49 | # it should be harmless to specify "-shared" there. |
| 50 | $LD = 'g++ -shared'; |
| 51 | } |
| 52 | |
| 53 | my $xver = `$xapian_config --version`; |
| 54 | if ($xver eq '') { |
| 55 | print STDERR <<END; |
| 56 | $xapian_config not found. |
| 57 | |
| 58 | You need Xapian installed before you can build CanIt::LogSearch::XapianXSIndexer. If you have |
| 59 | installed Xapian from a package, you will also need to install the correspoding |
| 60 | -dev or -devel package. If Xapian is installed but xapian-config isn't on your |
| 61 | PATH you can tell Makefile.PL this by running it like so: |
| 62 | |
| 63 | perl Makefile.PL XAPIAN_CONFIG=/path/to/xapian-config |
| 64 | END |
| 65 | # Perversely, the CPAN automatic testing script expects exit status 0 to |
| 66 | # indicate "can't build because of missing dependencies" (which it |
| 67 | # distinguishes from "all OK" by seeing if Makefile is generated). So we |
| 68 | # exit with status 0 in this case to avoid being spammed with useless |
| 69 | # "bug" reports from testers without Xapian installed. |
| 70 | exit(0); |
| 71 | } |
| 72 | chomp($xver); |
| 73 | $xver =~ s/.*\s//; # "xapian 1.2.0" -> "1.2.0" |
| 74 | |
| 75 | my $inc = `$xapian_config --cxxflags`; |
| 76 | chomp($inc); |
| 77 | |
| 78 | my @writemakefile_args = (); |
| 79 | my $libsvar = 'LIBS'; |
| 80 | my $libs = `$xapian_config --libs 2> /dev/null`; |
| 81 | chomp($libs); |
| 82 | my ($xapian_config_dir) = $xapian_config =~ /^(.*?)[^\/]*$/; |
| 83 | if ($? || ($xapian_config_dir ne '' && -f "${xapian_config_dir}Makefile")) { |
| 84 | # Assume we're being asked to build against an uninstalled xapian-core. |
| 85 | my $libtool = "${xapian_config_dir}libtool"; |
| 86 | unless (-x $libtool) { |
| 87 | die "You've asked me to link against what appears to be an uninstalled xapian-core tree, but I can't find libtool in that tree\n"; |
| 88 | } |
| 89 | |
| 90 | # We can't pass a .la file in LIBS since MakeMaker "knows better" and |
| 91 | # ignores it. Passing it in LDLOADLIBS works, but generates a warning. |
| 92 | # We can avoid the warning by setting LDLOADLIBS using 'macro'. |
| 93 | $libsvar = 'macro'; |
| 94 | $libs = `$xapian_config --ltlibs`; |
| 95 | chomp($libs); |
| 96 | $libs = {'LDLOADLIBS' => $libs}; |
| 97 | $LD = "$libtool --tag=CXX --mode=link $CC -avoid-version -module"; |
| 98 | $LD .= " -rpath \$(PERL_ARCHLIB)/auto/\$(FULLEXT)"; |
| 99 | $LD .= " -shrext .".$Config{'dlext'}; |
| 100 | $CC = "$libtool --tag=CXX --mode=compile $CC"; |
| 101 | push @writemakefile_args, ( |
| 102 | 'OBJ_EXT' => '.lo', |
| 103 | 'DLEXT' => 'la', |
| 104 | 'FULLPERL' => '$(PERL) "-I$(INST_ARCHAUTODIR)/.libs"', |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | # Filter out some gcc options which g++ doesn't support. |
| 109 | my $CCFLAGS = $Config{'ccflags'}; |
| 110 | # Perl is built with -Wdeclaration-after-statement on RHEL5 - this isn't |
| 111 | # meaningful for C++ - it only emits a warning but it's easy to fix. |
| 112 | $CCFLAGS =~ s/(?:^|\s+)-Wdeclaration-after-statement(?:\s+|$)/ /; |
| 113 | # The generated code causes "variable may be used uninitialized" warnings |
| 114 | # if Perl was built with -Wall. |
| 115 | $CCFLAGS =~ s/(^|\s+)-Wall(\s+|$)/$1-Wall -Wno-uninitialized$2/; |
| 116 | |
| 117 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
| 118 | # the contents of the Makefile that is written. |
| 119 | push @writemakefile_args, ( |
| 120 | 'NAME' => 'SymbolTest', |
| 121 | 'VERSION_FROM' => 'SymbolTest.pm', # finds $VERSION |
| 122 | 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 |
| 123 | AUTHOR => q{Dave O'Neill <dmo@roaringpenguin.com>}, |
| 124 | $libsvar => $libs, # e.g., '-lm' |
| 125 | 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' |
| 126 | 'CC' => $CC, |
| 127 | 'CCFLAGS' => $CCFLAGS, |
| 128 | 'LD' => $LD, |
| 129 | 'INC' => $inc, # e.g., '-I/usr/include/other' |
| 130 | 'OBJECT' => '$(BASEEXT)$(OBJ_EXT)', |
| 131 | 'XSOPT' => '-C++ -hiertype', |
| 132 | ); |
| 133 | WriteMakefile(@writemakefile_args); |