1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
#! /usr/local/bin/perl -w
# vim: tabstop=4
# Makefile generator for libintl-perl.
# Copyright (C) 2002-2013 Guido Flohr <guido@imperia.net>,
# all rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.use ExtUtils::MakeMaker;
use 5.004;
use ExtUtils::MakeMaker;
use strict;
# Make standard channels unbuffered.
select STDERR; $| = 1;
select STDOUT; $| = 1;
sub ac_try_link;
use Config;
# Now try to compile and link a simple test program that uses all
# gettext facilities we need. Failure of the test is not fatal
# since the pure Perl implementation will provide the same functionality.
# However, any help on making this test more portable would be
# highly appreciated!
unlink "config.log";
my $c = <<'EOF';
/* The following code only compiles if the interface to gettext is
complete. */
#include <libintl.h>
/* Handle the case that we link against GNU libintl but include a non
* GNU libintl.h. */
#ifndef __USE_GNU_GETTEXT
# error "<libintl.h> is not GNU gettext. Maybe you have to adjust your include path."
#endif
#include <locale.h>
int
main (argc, argv)
int argc;
char* argv[];
{
/* FIXME: The gettext runtime libraries provided by Solaris 8 and 9
are not sufficient. Those of Solaris 10 *may* work. To play
safe, we currently only compile the XS version for GNU gettext
and use some undocumented features, to test for that. Thanks
to Bruno Haible for the hint. */
extern int _nl_msg_cat_cntr;
#if 0
/* This seems to be defined in the GNU libc only, not in standalone
* GNU gettext. */
extern int* _nl_domain_bindings;
#endif
textdomain ("dummy");
bindtextdomain ("dummy", ".");
bind_textdomain_codeset ("dummy", "us-ascii");
gettext ("msgid");
dgettext ("dummy", "msgid");
dcgettext ("dummy", "msgid", LC_MESSAGES);
ngettext ("msgid", "msgid_plural",
#if 0
_nl_msg_cat_cntr + *_nl_domain_bindings);
#else
_nl_msg_cat_cntr);
#endif
dngettext ("dummy", "msgid", "msgid_plural", 1);
dcngettext ("dummy", "msgid", "msgid_plural", 1, LC_MESSAGES);
return 0;
}
EOF
my $build_gettext_xs = ac_try_link $c, "Checking whether we can compile the XS version";
unless ($build_gettext_xs) {
$build_gettext_xs = ac_try_link $c, " Trying again with -lintl", "-lintl";
}
unless ($build_gettext_xs) {
$build_gettext_xs = ac_try_link $c, " Trying again with -lintl -liconv", "-lintl", "-liconv";
}
unless ($build_gettext_xs) {
$build_gettext_xs = ac_try_link $c, " Trying again with -liconv", "-liconv";
}
unless ($build_gettext_xs) {
print STDERR <<EOF;
=> Cannot build the XS version of libintl-perl (see 'config.log' for
=> details). This is harmless!
EOF
} else {
print STDERR <<EOF;
=> Building the XS version of libintl-perl.
EOF
}
sub ac_try_link {
my ($c_code, $msg, @options) = @_;
print STDERR "$msg ... ";
local *HANDLE;
open HANDLE, ">gettest.c" or die "cannot create file 'gettest.c': $!\n";
print HANDLE $c_code;
close HANDLE or die "cannot close file 'gettest.c': $!\n";
my @cmd = $Config{cc};
push @cmd, $Config{ccflags};
push @cmd, $Config{ldflags};
push @cmd, $Config{perllibs};
push @cmd, @options;
push @cmd, "-o", "gettest.exe", "gettest.c";
# Temporarily redirect stdout and stderr.
open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
open OLDERR, ">&STDERR" or die "cannot dup STDERR: $!";
open STDOUT, ">>config.log" or die "cannot redirect STDOUT: $!";
open STDERR, ">&STDOUT" or die "cannot dup STDOUT: $!";
select STDERR; $| = 1;
select STDOUT; $| = 1;
my $cmd = join ' ', @cmd;
print <<EOC;
cat >gettext.c <<EOF
$c_code
EOF
EOC
print "$cmd\n";
my $result = system $cmd;
# Restore standard file descriptors
close STDOUT; #or die "cannot close STDOUT: $!";
close STDERR; #or die "cannot close STDERR: $!";
open STDOUT, ">&OLDOUT" or die "cannot dup \$oldout: $!";
open STDERR, ">&OLDERR" or die "cannot dup OLDERR: $!";
close OLDOUT; close OLDERR; # Shut up warnings.
unlink "gettest.c", "gettest.exe";
print STDERR $result ? "no.\n" : "yes.\n";
return !$result;
}
package MY;
# FIXME: This is really a hack! Problem: Depending on the build system,
# we may or may not build and install the XS version. If the XS version
# is being built, the directory blib/arch will be populated, if it is
# not being built, blib/arch will be empty. Unfortunately, if blib/arch
# is not empty, *all* library files will be installed in the architecture
# dependent locations, if it is empty, they will be installed in the
# architecture independent tree.
#
# Unfortunately, ExtUtils::MakeMaker does not take care of uninstalling
# files from previous installations. Consequently, we cannot determine
# which version of the library will be loaded, since this depends on the
# current value of @INC.
#
# The solution does not really make me happy. The Makefile will be patched,
# so that instead of ExtUtils::Install a custom module MyInstall.pm will
# be used. This custom module overwrites the subroutine that detects
# whether a directory is empty in ExtUtils::Install, and will lie if that
# directory happens to be "blib/arch". This little hack effectively disables
# the annoying behavior of ExtUtils::Install (and I sincerely hope that
# this is portable).
sub libscan
{
my ($self, $file) = @_;
return if 'MyInstall.pm' eq $file;
$self->SUPER::libscan ($file);
}
sub tools_other
{
my $self = shift;
my $fragment = $self->SUPER::tools_other (@_);
$fragment =~ s/^MOD_INSTALL\s*=\s*(.*?)-MExtUtils::Install
/MOD_INSTALL =$1-MMyInstall/msx;
return $fragment;
}
package main;
my $name = $0;
$name =~ s,Makefile\.PL$,xs_disabled,;
local *HANDLE;
open HANDLE, ">$name" or die "cannot open '$name' for writing: $!";
print HANDLE !$build_gettext_xs;
close HANDLE or die "cannot close '$name': $!";
WriteMakefile (
NAME => 'libintl-perl',
VERSION_FROM => 'lib/Locale/Messages.pm',
($] >= 5.005 ?
(ABSTRACT => 'High-Level Interface to Uniforum Message'
. ' Translation',
AUTHOR => 'Guido Flohr <guido@imperia.net>',
) : (),
),
PREREQ_PM => { 'File::Spec' => 0, version => 0.77 },
META_MERGE => {
recommends => { 'File::ShareDir' => 0 },
resources => {
homepage => 'http://git.guido-flohr.net/projects/libintl-perl/',
bugtracker => 'http://rt.cpan.org/Public/Dist/Display.html?Name=libintl-perl',
repository => 'git://git.guido-flohr.net/perl/libintl-perl.git',
},
},
PL_FILES => {},
DIR => [$build_gettext_xs ? ('gettext_xs') : ()],
clean => { FILES => 'xs_disabled build_xs' }
# If you want to build the XS version although the automatic detection
# suggests not to build it, uncomment the following line.
#DIR => [ ('gettext_xs') ],,
);
sub MY::postamble {
'
all :: Credits ReleaseNotes
# Make search.cpan.org happy but still follow GNU standards:
# # (Thanks to Graham Barr for the hint)
Credits: THANKS
cat THANKS >$@
ReleaseNotes: NEWS
cat NEWS >$@
'
}
__END__
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
perl-label-offset: -4
cperl-indent-level: 4
cperl-continued-statement-offset: 2
tab-width: 4
End:
|