Debian Codegraph @

t/symbol-test/Makefile.PL

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