--- Makefile.PL 2012-10-11 13:21:34.000000000 -0400 +++ /tmp/Makefile.PL 2012-10-11 13:21:22.000000000 -0400 @@ -12,6 +12,7 @@ ###################################################################### use ExtUtils::MakeMaker; +use ExtUtils::PkgConfig; use Getopt::Long; # Get the right lib and include dirs for different platforms @@ -28,8 +29,6 @@ libjs.a js32.dll libmozjs.so - libmozjs185.so - libmozjs187.so ); my %possible_install_paths = ( @@ -39,7 +38,7 @@ "/usr/lib/firefox" => "/usr/include/firefox", ); -my ($JS_LIB_DIR, @JS_INCL_DIRS, $JS_LIB_NAME); +my ($JS_LIB_DIR, @JS_INCL_DIRS, $JS_LIB_NAME, $JS_LIBS, $JS_INCLUDES); #### Determine compile options ############################## @@ -59,6 +58,19 @@ "JS_LIB_DIR=s" => \$JS_LIB_DIR, "JS_LIB_NAME=s" => \$JS_LIB_NAME, ); + +# try to find spidermonkey via pkg-config first + +$JS_LIBS = ExtUtils::PkgConfig->libs ('mozjs187'); +if ("".$JS_LIBS ne "") { + $JS_INCLUDES = ExtUtils::PkgConfig->cflags ('mozjs187'); +} else { + $JS_LIBS = ExtUtils::PkgConfig->libs ('mozjs185'); + if ("".$JS_LIBS ne "") { + $JS_INCLUDES = ExtUtils::PkgConfig->cflags ('mozjs185'); + } else { + +# pkg-config did not work, use the old (direct) way to find older libs if ($JS_LIB_DIR) { push @JS_INCL_DIRS, $JS_LIB_DIR; } @@ -80,13 +92,15 @@ } } if (scalar(@JS_INCL_DIRS) == scalar(@c_header_files)) { - $JS_LIB_DIR = $libfile; + $JS_LIB_DIR = "-L".$libfile; $JS_LIB_DIR =~ s/$possible_lib$//; $JS_LIB_NAME = $possible_lib; $JS_LIB_NAME =~ s/\.(a|so|dll)$//; $JS_LIB_NAME =~ s/^lib//; + $JS_LIBS = "-l".$JS_LIB_NAME; + last; } else { @JS_INCL_DIRS = (); @@ -96,15 +110,22 @@ } last if $JS_LIB_DIR; } +foreach my $include_dir(@JS_INCL_DIRS) { + $JS_INCLUDES.=" -I".$include_dir; +} if ($JS_INCL_DIRS[0] eq $JS_INCL_DIRS[1]) { shift @JS_INCL_DIRS; } +} # end of pkgcfg mozjs185 +} # end of pkgcfg mozjs187 + + ## If no SpiderMonkey library found report that and exit. ## Otherwise print lib and include paths. -if (!$JS_LIB_DIR) { +if (!$JS_LIBS) { print <= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'SpiderMonkey.pm', # retrieve abstract from module AUTHOR => 'Mike Schilli ') : ()), - 'LIBS' => ["-L$JS_LIB_DIR -l$JS_LIB_NAME"], + 'LIBS' => ["$JS_LIB_DIR $JS_LIBS"], 'DEFINE' => $JS_DEFINE, # e.g., '-DHAVE_SOMETHING' # Insert -I. if you add *.h files later: - 'INC' => "-I".join " -I", @JS_INCL_DIRS, +# 'INC' => "-I".join " -I", @JS_INCL_DIRS, + 'INC' => $JS_INCLUDES, # Un-comment this if you add C files to link with later: # 'OBJECT' => '$(O_FILES)', # link all the C files too );