Subject: | Issue with Text::Hunspell Makefile.PL portability |
Date: | Thu, 16 Oct 2014 22:48:27 -0400 |
To: | bug-Text-Hunspell [...] rt.cpan.org |
From: | "David H. Gutteridge" <dhgutteridge [...] sympatico.ca> |
Hello,
In the Makefile.PL file distributed in Text::Hunspell 2.08 (and
earlier versions), there's a check to see if the hunspell shared
library is installed. It's not particularly useful as-is, given it
checks for an unversioned link to the library, and hunspell doesn't
provide any such thing. Similarly, the subsequent check that repeats
this effort also doesn't really work well. hunspell provides a
pkgconfig file for dependencies to use, and this works best for these
purposes. (If an OS distribution hasn't installed the pkgconfig file,
it's not likely they've installed any usable symlinks for the library
either.)
I've appended below a patch which uses ExtUtils::PkgConfig to get the
right paths from the hunspell pkgconfig file. You may or may not find
it to your liking as-is. I'm submitting it downstream to pkgsrc
(www.pkgsrc.org) so various BSDs and other OSes can use your module.
(As-is, it comments out the existing code.)
Regards,
Dave
--- Makefile.PL.orig 2013-03-26 15:52:12.000000000 -0400
+++ Makefile.PL 2014-10-16 22:18:56.000000000 -0400
@@ -1,6 +1,6 @@
-use lib qw(inc);
-use Config;
-use Devel::CheckLib;
+#use lib qw(inc);
+#use Config;
+#use Devel::CheckLib;
#
# Try to warn the user if linking might fail.
@@ -8,53 +8,66 @@
#
# Probably too platform specific, but seemed an acceptable compromise.
#
-my $dlext = $Config{dlext} || 'so';
-my $candidate_lib;
-for (split " " => $Config{libpth}) {
- my $lib_path = "$_/libhunspell.$dlext";
- #warn "Checking $lib_path\n";
- if (-e $lib_path) {
- $candidate_lib++;
- warn "Found '$lib_path'. Good.\n";
- }
-}
-
-if (0 == $candidate_lib) {
- my $def_lib = "/usr/lib/libhunspell";
- my ($possible_candidate) = glob("$def_lib-*.so");
- $possible_candidate ||= "/usr/lib/libhunspell-<ver>.so";
- warn "---------------------------------------------------------------------\n";
- warn "Your system doesn't appear to have a libhunspell.$dlext link.\n";
- warn "Linking might fail. If it does, you might want to try installing\n";
- warn "the libhunspell-dev package (or the equivalent on your OS) or try:\n";
- warn "\n";
- warn " $Config{lns} $possible_candidate $def_lib.so\n";
- warn "---------------------------------------------------------------------\n";
- warn "\n";
-}
-
-check_lib_or_exit(
- lib => 'hunspell',
- header => 'hunspell/hunspell.h',
-);
+#my $dlext = $Config{dlext} || 'so';
+#my $candidate_lib;
+#for (split " " => $Config{libpth}) {
+# my $lib_path = "$_/libhunspell.$dlext";
+# #warn "Checking $lib_path\n";
+# if (-e $lib_path) {
+# $candidate_lib++;
+# warn "Found '$lib_path'. Good.\n";
+# }
+#}
+#
+#if (0 == $candidate_lib) {
+# my $def_lib = "/usr/lib/libhunspell";
+# my ($possible_candidate) = glob("$def_lib-*.so");
+# $possible_candidate ||= "/usr/lib/libhunspell-<ver>.so";
+# warn "---------------------------------------------------------------------\n";
+# warn "Your system doesn't appear to have a libhunspell.$dlext link.\n";
+# warn "Linking might fail. If it does, you might want to try installing\n";
+# warn "the libhunspell-dev package (or the equivalent on your OS) or try:\n";
+# warn "\n";
+# warn " $Config{lns} $possible_candidate $def_lib.so\n";
+# warn "---------------------------------------------------------------------\n";
+# warn "\n";
+#}
+#
+#check_lib_or_exit(
+# lib => 'hunspell',
+# header => 'hunspell/hunspell.h',
+#);
use ExtUtils::MakeMaker;
+use ExtUtils::PkgConfig;
my $CC = $ENV{"CXX"} || 'g++';
-WriteMakefile(
- NAME => 'Text::Hunspell',
- VERSION_FROM => 'Hunspell.pm',
- LIBS => ['-lhunspell'],
- CC => $CC,
- LD => '$(CC)',
- PREREQ_PM => {}, # e.g., Module::Name => 1.1
- XSOPT => '-C++',
- TYPEMAPS => ['perlobject.map', 'typemap'],
- META_MERGE => {
- resources => {
- repository => 'https://github.com/cosimo/perl5-text-hunspell',
- },
- keywords => [ qw(hunspell spelling spell-checker text-processing) ],
- },
-);
+my $shlib_location = ExtUtils::PkgConfig->libs_only_l('hunspell');
+my $header_location = ExtUtils::PkgConfig->cflags_only_I('hunspell');
+
+if ($shlib_location ne '' && $header_location ne '') {
+ WriteMakefile(
+ NAME => 'Text::Hunspell',
+ VERSION_FROM => 'Hunspell.pm',
+ LIBS => [$shlib_location],
+ CC => $CC,
+ LD => '$(CC)',
+ PREREQ_PM => {}, # e.g., Module::Name => 1.1
+ XSOPT => '-C++',
+ TYPEMAPS => ['perlobject.map', 'typemap'],
+ META_MERGE => {
+ resources => {
+ repository => 'https://github.com/cosimo/perl5-text-hunspell',
+ },
+ keywords => [ qw(hunspell spelling spell-checker text-processing) ],
+ },
+ );
+}
+else {
+ # By default, ExtUtils::PkgConfig provides a verbose warning about
+ # being unable to locate the pkgconfig file and such. This adds an
+ # additional comment after that output.
+ warn "You may need to install the libhunspell-dev package (or the ";
+ warn "equivalent on your OS).\n";
+}