print "Checking for GSL..\n";
chomp(my $gv = qx{gsl-config --version});
chomp(my $gsl_prefix = qx{gsl-config --prefix});
chomp(my $gsl_cflags = qx{gsl-config --cflags});
chomp(my $gsl_libs = qx{gsl-config --libs});
####
bail("Please install the taglib C++ library first. \nI need the package that has taglib-config")
unless system('taglib-config --version > /dev/null') == 0;
chomp(my $libver = qx{taglib-config --version});
...
chomp(my $libs = qx{taglib-config --libs});
...
chomp(my $inc = qx{taglib-config --cflags});
##
##
#!perl
#####################################################################
# NOTE: This script (cnf2bat.pl) requires sh.exe. #
# (Both msys and cygwin ship with sh.exe.) #
# #
# Provide an executable .bat file from a 3rd party library-config #
# file. These config files (eg gsl-config, gdlib-config, #
# taglib-config) are not executable in the cmd.exe shell. #
# This script provides an executable .bat replacement #
# (eg gsl-config.bat, gdlib-config.bat, taglib-config.bat). #
# #
# Then when a Makefile.PL does something like: #
# #
# $libs = chomp(`gsl-config --libs`); #
# #
# courtesy of gsl-config.bat, $libs will be set to the correct #
# value - instead of being set to the empty string, and we don't #
# get hit with the message that 'gsl-config' is not recognized as #
# an internal or external command, operable program or batch file. #
# #
# Obviously, this relies on the generated .bat file being in either #
# the current directory, or the path. #
# #
# NOTE: You ought to update the batch file (by re-running) this #
# script whenever the library in question is updated. #
# #
# Not all options are available in the .bat file - only --prefix, #
# --libs, --cflags and --version, as these are usually the only #
# options that a Makefile.PL queries. (Others could easily be added #
# if necessary.) #
# #
# This script takes the following arguments: #
# 1) the name (fully qualified name) of the library-config file; #
# 2) (optionally) the directory into which the generated batch #
# file is to be placed. Default is '.' (cwd). #
# #
# You'll also need to set $sh_location (below) to the location #
# of sh.exe on your machine. #
# #
# NOTE: This script can, itself, be converted to a batch file by #
# running 'pl2bat cnf2bat.pl' #
#####################################################################
use warnings;
use strict;
use File::Copy;
die "Usage: 'cnf2bat.pl /full/path/to/lib-config [/full/path/to/dest_dir]'\n"
unless $ARGV[0];
my $destination = '.';
if($ARGV[1]) {
die "$ARGV[1] is not an existing directory" unless -d $ARGV[1];
$destination = $ARGV[1];
}
#################################################
# Hard code this to the location of sh.exe. #
#################################################
my $sh_location = "C:\\MinGW\\msys\\1.0\\bin";
#################################################
# Make sure that sh.exe is in the path #
#################################################
$ENV{PATH} .= ";$sh_location";
#################################################
# Check that the config file specified in #
# $ARGV[0] exists, then run the write_bat_file #
# subroutine. #
#################################################
if(-e $ARGV[0]) {write_bat_file($ARGV[0], $destination)}
else {die "$ARGV[0]: No such file"}
sub write_bat_file {
#################################################
# Collect the --prefix, --version, --libs and #
# -cflags values from the library-config file, #
# and hard code them into the batch file. #
# The generated batch file has the same name as #
# the library-config file, but with a '.bat' #
# extension. #
#################################################
my $lc = $_[0];
$lc =~ s/\\/\//g;
my $filename = (split /\//, $lc)[-1];
my $lc_bat = "${destination}/${filename}.bat";
my $prefix = `sh $lc --prefix`;
my $version = `sh $lc --version`;
my $cflags = `sh $lc --cflags`;
my $libs = `sh $lc --libs`;
chomp for ($prefix, $version, $cflags, $libs);
open(WR, '>', $lc_bat) or die "Can't open $lc_bat for writing: $!";
print WR "\@echo off\n\n";
print WR "if \"%1\" == \"--version\" goto VERSION\n";
print WR "if \"%1\" == \"--prefix\" goto PREFIX\n";
print WR "if \"%1\" == \"--cflags\" goto CFLAGS\n";
print WR "if \"%1\" == \"--libs\" goto LIBS\n";
print WR "if \"%1\" == \"\" goto USAGE\n\n";
print WR "echo %1 : Unknown option && echo.\ngoto endofbat\n\n";
print WR ":VERSION\n";
print WR "echo $version && echo.\n";
print WR "goto endofbat\n\n";
print WR ":CFLAGS\n";
print WR "echo $cflags && echo.\n";
print WR "goto endofbat\n\n";
print WR ":PREFIX\n";
print WR "echo $prefix && echo.\n";
print WR "goto endofbat\n\n";
print WR ":LIBS\n";
print WR "echo $libs && echo.\n";
print WR "goto endofbat\n\n";
print WR ":USAGE\n";
print WR "echo Usage: %0 --arg (where arg is either version, libs, prefix, or cflags) && echo.\n";
print WR "goto endofbat\n\n";
print WR ":endofbat\n\n";
close WR or die "Can't close $lc_bat after writing: $!";
print "$lc_bat has been written\n";
}