Blame Makefile.PL

Packit 583149
#! /usr/local/bin/perl -w
Packit 583149
Packit 583149
# vim: tabstop=4
Packit 583149
Packit 583149
# Makefile generator for libintl-perl.
Packit 583149
# Copyright (C) 2002-2017 Guido Flohr <guido.flohr@cantanea.com>, 
Packit 583149
# all rights reserved.
Packit 583149
Packit 583149
# This program is free software; you can redistribute it and/or modify it
Packit 583149
# under the terms of the GNU Library General Public License as published
Packit 583149
# by the Free Software Foundation; either version 2, or (at your option)
Packit 583149
# any later version.
Packit 583149
Packit 583149
# This program is distributed in the hope that it will be useful,
Packit 583149
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 583149
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 583149
# Library General Public License for more details.
Packit 583149
Packit 583149
# You should have received a copy of the GNU Library General Public
Packit 583149
# License along with this program; if not, write to the Free Software
Packit 583149
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335,
Packit 583149
# USA.
Packit 583149
Packit 583149
use 5.004;
Packit 583149
use ExtUtils::MakeMaker;
Packit 583149
Packit 583149
use strict;
Packit 583149
Packit 583149
# Make standard channels unbuffered.
Packit 583149
select STDERR; $| = 1;
Packit 583149
select STDOUT; $| = 1; 
Packit 583149
Packit 583149
sub ac_try_link;
Packit 583149
Packit 583149
use Config;
Packit 583149
Packit 583149
# Now try to compile and link a simple test program that uses all
Packit 583149
# gettext facilities we need.  Failure of the test is not fatal
Packit 583149
# since the pure Perl implementation will provide the same functionality.
Packit 583149
# However, any help on making this test more portable would be
Packit 583149
# highly appreciated!
Packit 583149
Packit 583149
unlink "config.log";
Packit 583149
Packit 583149
my $c = <<'EOF';
Packit 583149
/* The following code only compiles if the interface to gettext is
Packit 583149
   complete.  */
Packit 583149
Packit 583149
#include <libintl.h>
Packit 583149
/* Handle the case that we link against GNU libintl but include a non
Packit 583149
 * GNU libintl.h.  */
Packit 583149
#ifndef __USE_GNU_GETTEXT
Packit 583149
# error "<libintl.h> is not GNU gettext.  Maybe you have to adjust your include path."
Packit 583149
#endif
Packit 583149
Packit 583149
#include <locale.h>
Packit 583149
Packit 583149
int
Packit 583149
main (argc, argv)
Packit 583149
	int argc;
Packit 583149
    char* argv[];
Packit 583149
{
Packit 583149
	/* FIXME: The gettext runtime libraries provided by Solaris 8 and 9
Packit 583149
       are not sufficient.  Those of Solaris 10 *may* work.  To play
Packit 583149
       safe, we currently only compile the XS version for GNU gettext
Packit 583149
       and use some undocumented features, to test for that.  Thanks
Packit 583149
       to Bruno Haible for the hint.  */
Packit 583149
	extern int _nl_msg_cat_cntr;
Packit 583149
#if 0
Packit 583149
        /* This seems to be defined in the GNU libc only, not in standalone
Packit 583149
         * GNU gettext.  */
Packit 583149
        extern int* _nl_domain_bindings;
Packit 583149
#endif
Packit 583149
Packit 583149
	textdomain ("dummy");
Packit 583149
	bindtextdomain ("dummy", ".");
Packit 583149
	bind_textdomain_codeset ("dummy", "us-ascii");
Packit 583149
Packit 583149
	gettext ("msgid");
Packit 583149
    	dgettext ("dummy", "msgid");
Packit 583149
    	dcgettext ("dummy", "msgid", LC_MESSAGES);
Packit 583149
	ngettext ("msgid", "msgid_plural", 
Packit 583149
#if 0
Packit 583149
		  _nl_msg_cat_cntr + *_nl_domain_bindings); 
Packit 583149
#else
Packit 583149
                  _nl_msg_cat_cntr);
Packit 583149
#endif
Packit 583149
	dngettext ("dummy", "msgid", "msgid_plural", 1);
Packit 583149
	dcngettext ("dummy", "msgid", "msgid_plural", 1, LC_MESSAGES);
Packit 583149
Packit 583149
    	return 0;
Packit 583149
}
Packit 583149
EOF
Packit 583149
Packit 583149
my $build_gettext_xs = ac_try_link $c, "Checking whether we can compile the XS version";
Packit 583149
unless ($build_gettext_xs) {
Packit 583149
    $build_gettext_xs = ac_try_link $c, "  Trying again with -lintl", "-lintl";
Packit 583149
}
Packit 583149
unless ($build_gettext_xs) {
Packit 583149
    $build_gettext_xs = ac_try_link $c, "  Trying again with -lintl -liconv", "-lintl", "-liconv";
Packit 583149
}
Packit 583149
unless ($build_gettext_xs) {
Packit 583149
    $build_gettext_xs = ac_try_link $c, "  Trying again with -liconv", "-liconv";
Packit 583149
}
Packit 583149
Packit 583149
unless ($build_gettext_xs) {
Packit 583149
	print STDERR <
Packit 583149
=> Cannot build the XS version of libintl-perl (see 'config.log' for
Packit 583149
=> details).  This is harmless!
Packit 583149
EOF
Packit 583149
} else {
Packit 583149
	print STDERR <
Packit 583149
=> Building the XS version of libintl-perl.
Packit 583149
EOF
Packit 583149
}
Packit 583149
Packit 583149
sub ac_try_link {
Packit 583149
    my ($c_code, $msg, @options) = @_;
Packit 583149
Packit 583149
	print STDERR "$msg ... ";
Packit 583149
    local *HANDLE;
Packit 583149
    open HANDLE, ">gettest.c" or die "cannot create file 'gettest.c': $!\n";
Packit 583149
    print HANDLE $c_code;
Packit 583149
    close HANDLE or die "cannot close file 'gettest.c': $!\n";
Packit 583149
Packit 583149
	my @cmd = $Config{cc};
Packit 583149
    push @cmd, $Config{ccflags};
Packit 583149
    push @cmd, $Config{ldflags};
Packit 583149
    push @cmd, $Config{perllibs};
Packit 583149
	push @cmd, @options;
Packit 583149
    push @cmd, "-o", "gettest.exe", "gettest.c";
Packit 583149
Packit 583149
    # Temporarily redirect stdout and stderr.
Packit 583149
    open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
Packit 583149
    open OLDERR, ">&STDERR" or die "cannot dup STDERR: $!";
Packit 583149
    open STDOUT, ">>config.log" or die "cannot redirect STDOUT: $!";
Packit 583149
    open STDERR, ">&STDOUT" or die "cannot dup STDOUT: $!";
Packit 583149
    select STDERR; $| = 1;
Packit 583149
    select STDOUT; $| = 1;
Packit 583149
Packit 583149
    my $cmd = join ' ', @cmd;
Packit 583149
    print <
Packit 583149
cat >gettext.c <
Packit 583149
$c_code
Packit 583149
EOF
Packit 583149
EOC
Packit 583149
    print "$cmd\n";
Packit 583149
    my $result = system $cmd;
Packit 583149
Packit 583149
	# Restore standard file descriptors
Packit 583149
	close STDOUT; #or die "cannot close STDOUT: $!";
Packit 583149
	close STDERR; #or die "cannot close STDERR: $!";
Packit 583149
	open STDOUT, ">&OLDOUT" or die "cannot dup \$oldout: $!";
Packit 583149
	open STDERR, ">&OLDERR" or die "cannot dup OLDERR: $!";
Packit 583149
	close OLDOUT; close OLDERR; # Shut up warnings.
Packit 583149
Packit 583149
	unlink "gettest.c", "gettest.exe";
Packit 583149
Packit 583149
	print STDERR $result ? "no.\n" : "yes.\n";
Packit 583149
Packit 583149
	return !$result;
Packit 583149
}
Packit 583149
Packit 583149
package MY;
Packit 583149
Packit 583149
# FIXME: This is really a hack! Problem: Depending on the build system,
Packit 583149
# we may or may not build and install the XS version.  If the XS version
Packit 583149
# is being built, the directory blib/arch will be populated, if it is
Packit 583149
# not being built, blib/arch will be empty.  Unfortunately, if blib/arch
Packit 583149
# is not empty, *all* library files will be installed in the architecture
Packit 583149
# dependent locations, if it is empty, they will be installed in the
Packit 583149
# architecture independent tree.
Packit 583149
#
Packit 583149
# Unfortunately, ExtUtils::MakeMaker does not take care of uninstalling
Packit 583149
# files from previous installations.  Consequently, we cannot determine
Packit 583149
# which version of the library will be loaded, since this depends on the
Packit 583149
# current value of @INC.
Packit 583149
#
Packit 583149
# The solution does not really make me happy.  The Makefile will be patched,
Packit 583149
# so that instead of ExtUtils::Install a custom module MyInstall.pm will
Packit 583149
# be used.  This custom module overwrites the subroutine that detects
Packit 583149
# whether a directory is empty in ExtUtils::Install, and will lie if that
Packit 583149
# directory happens to be "blib/arch".  This little hack effectively disables 
Packit 583149
# the annoying behavior of ExtUtils::Install (and I sincerely hope that
Packit 583149
# this is portable).
Packit 583149
sub libscan 
Packit 583149
{
Packit 583149
	my ($self, $file) = @_;
Packit 583149
Packit 583149
	return if 'MyInstall.pm' eq $file;
Packit 583149
Packit 583149
	$self->SUPER::libscan ($file);	
Packit 583149
}
Packit 583149
Packit 583149
sub tools_other 
Packit 583149
{
Packit 583149
	my $self = shift;
Packit 583149
Packit 583149
	my $fragment = $self->SUPER::tools_other (@_);
Packit 583149
Packit 583149
	$fragment =~ s/^MOD_INSTALL\s*=\s*(.*?)-MExtUtils::Install
Packit 583149
		/MOD_INSTALL =$1-I. -MMyInstall/msx;
Packit 583149
Packit 583149
	return $fragment;
Packit 583149
}
Packit 583149
Packit 583149
package main;
Packit 583149
Packit 583149
my $name = $0;
Packit 583149
$name =~ s,Makefile\.PL$,xs_disabled,;
Packit 583149
local *HANDLE;
Packit 583149
open HANDLE, ">$name" or die "cannot open '$name' for writing: $!";
Packit 583149
print HANDLE !$build_gettext_xs;
Packit 583149
close HANDLE or die "cannot close '$name': $!";
Packit 583149
Packit 583149
WriteMakefile (
Packit 583149
    NAME		    => 'libintl-perl',
Packit 583149
	VERSION_FROM	=> 'lib/Locale/Messages.pm',
Packit 583149
    ($] >= 5.005 ?
Packit 583149
         (ABSTRACT          => 'High-Level Interface to Uniforum Message'
Packit 583149
                                 . ' Translation',
Packit 583149
	  AUTHOR	    => 'Guido Flohr <guido.flohr@cantanea.com>',
Packit 583149
	 ) : (),
Packit 583149
    ),
Packit 583149
    PREREQ_PM		    => { 'File::Spec' => 0, version => 0.77 },
Packit 583149
    META_MERGE		    => {
Packit 583149
        recommends => { 'File::ShareDir' => 0 },
Packit 583149
        resources  => {
Packit 583149
            homepage   => 'http://www.guido-flohr.net/en/projects/',
Packit 583149
            bugtracker => 'https://github.com/gflohr/libintl-perl/issues',
Packit 583149
            repository => 'https://github.com/gflohr/libintl-perl.git',
Packit 583149
        },
Packit 583149
    },
Packit 583149
    PL_FILES                => {},
Packit 583149
    DIR		            => [$build_gettext_xs ? ('gettext_xs') : ()],
Packit 583149
    clean		    => { FILES => 'xs_disabled build_xs' },
Packit 583149
    (MM->can ('signature_target') ? (SIGN => 1) : ()),
Packit 583149
    # If you want to build the XS version although the automatic detection
Packit 583149
    # suggests not to build it, uncomment the following line.
Packit 583149
    #DIR => [ ('gettext_xs') ],
Packit 583149
);
Packit 583149
Packit 583149
sub MY::postamble {
Packit 583149
        # This is for developers only.
Packit 583149
        return '' if ! -e '.git';
Packit 583149
Packit 583149
        '
Packit 583149
all :: Credits Changes README
Packit 583149
Packit 583149
# Make search.cpan.org happy but still follow GNU standards:
Packit 583149
# # (Thanks to Graham Barr for the hint)
Packit 583149
Credits: THANKS
Packit 583149
	cat THANKS >$@
Packit 583149
Packit 583149
Changes: NEWS
Packit 583149
	cat NEWS >$@
Packit 583149
Packit 583149
README: README.md
Packit 583149
	cat README.md >$@
Packit 583149
'
Packit 583149
}
Packit 583149
Packit 583149
__END__
Packit 583149
Packit 583149
Local Variables:
Packit 583149
mode: perl
Packit 583149
perl-indent-level: 4
Packit 583149
perl-continued-statement-offset: 4
Packit 583149
perl-continued-brace-offset: 0
Packit 583149
perl-brace-offset: -4
Packit 583149
perl-brace-imaginary-offset: 0
Packit 583149
perl-label-offset: -4
Packit 583149
cperl-indent-level: 4
Packit 583149
cperl-continued-statement-offset: 2
Packit 583149
tab-width: 4
Packit 583149
End: