PkgConfig - Pure-Perl Core-Only replacement for pkg-config
pkg-config
The script is not actually installed yet (i haven't settled on a good name), but will decide based on input in a future version.
Additionally, some dependencies are superficially included for debugging, and will be sanitized in a future 'release/stable' version.
$ pkg-config.pl --libs --cflags --static gio-2.0 #outputs (lines artifically broken up for readability): # -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include # -pthread -lgio-2.0 -lz -lresolv -lgobject-2.0 # -lgmodule-2.0 -ldl -lgthread-2.0 -pthread -lrt -lglib-2.0
Compare to: $ pkg-config --libs --cflags --static gio-2.0
#outputs ( "" ): # -pthread -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include # -pthread -lgio-2.0 -lz -lresolv -lgobject-2.0 -lgmodule-2.0 # -ldl -lgthread-2.0 -lrt -lglib-2.0
use PkgConfig; my $o = PkgConfig->find('gio'); if($o->errmsg) { #handle error } else { my @cflags = $o->get_cflags; my @ldflags = $o->get_ldflags; }
PkgConfig provides a pure-perl, core-only replacement for the pkg-config utility.
PkgConfig
This is not a description of the uses of pkg-config but rather a description of the differences between the C version and the Perl one.
While pkg-config is a compiled binary linked with glib, the pure-perl version has no such requirement, and will run wherever Perl ( >= 5.04 ) does.
The main supported options are the common --libs, --cflags, --static, --exists and --modversion.
--libs
--cflags
--static
--exists
--modversion
<packagename1 pkgname2..> [ --options ]
By default, a library name must be supplied unless one of --version, or --real-version is specified.
The output should normally be suitable for passing to your favorite compiler.
(Also) print linker flags. Dependencies are traverse in order. Top-level dependencies will appear earlier in the command line than bottom-level dependencies.
(Also) print compiler and C preprocessor flags.
Use extra dependencies and libraries if linking against a static version of the requested library
Return success (0) if the package exists in the search path.
Prepend PATH to the list of search paths containing .pc files.
PATH
.pc
This option can be specified multiple times with different paths, and they will all be added.
Using this option, only paths specified in PKG_CONFIG_PATH are recognized and any hard-coded defaults are ignored.
PKG_CONFIG_PATH
Invoke gcc and ld to determine default linker and include paths. Default paths will be excluded from explicit -L and -I flags.
gcc
ld
Define a variable, overriding any such variable definition in the .pc file, and allowing your value to interpolate with subsequent uses.
Print all defined variables found in the .pc files.
The target version of pkg-config emulated by this script
The actual version of this script
Print debugging information
Turn off errors. This is the default for non-libs/cflag/modversion arguments
This makes all errors noisy and takes precedence over --silence-errors
--silence-errors
the PKG_CONFIG_PATH variable is honored and used as a colon-delimited list of directories with contain .pc files.
my $result = PkgConfig->find($libary, %options);
Find a library and return a result object. $library can be either a single name of a library, or a reference to an array of library names
$library
The options are in the form of hash keys and values, and the following are recognized:
search_path
search_path_override
Prepend search paths in addition to the paths specified in $ENV{PKG_CONFIG_PATH} The value is an array reference.
$ENV{PKG_CONFIG_PATH}
the _override variant ignores defaults (like c<PKG_CONFIG_PATH).
_override
exclude_cflags
exclude_ldflags
exclude_cflags_override
exclude_ldflags_override
Some .pc files specify default compiler and linker search paths, e.g. -I/usr/include -L/usr/lib. Specifying them on the command line can be problematic as it drastically changes the search order.
-I/usr/include -L/usr/lib
The above options will either append or replace the options which are excluded and filtered.
The default excluded linker and compiler options can be obtained via @PkgConfig::DEFAULT_EXCLUDE_LFLAGS and @PkgConfig::DEFAULT_EXCLUDE_CFLAGS, respectively.
@PkgConfig::DEFAULT_EXCLUDE_LFLAGS
@PkgConfig::DEFAULT_EXCLUDE_CFLAGS
static
Also specify static libraries.
no_recurse
Do not recurse dependencies. This is useful for just doing version checks.
VARS
Define a hashref of variables to override any variable definitions within the .pc files. This is equivalent to the --define-variable command-line option.
--define-variable
A PkgConfig object is returned and may be queried about the results:
An error message, if any. This is a string and indicates an error.
Boolean value, true if the package exists.
The version of the package
Returns a list of compiler and linker flags, respectively.
This is a class method, and will replace the hard-coded default linker and include paths with those discovered by invoking ld(1) and cpp(1).
Currently this only works with GCC-supplied ld and GNU ld.
The order of the flags is not exactly matching to that of pkg-config. From my own observation, it seems this module does a better job, but I might be wrong.
Version checking is not yet implemented.
Unlike pkg-config, the scripts --exists function will return nonzero if a package or any of its dependencies are missing. This differs from the behavior of pkg-config which will just check for the definition of the package itself (without dependencies).
ExtUtils::PkgConfig, a wrapper around the pkg-config binary
Copyright (C) 2012 M. Nunberg
You may use and distribute this software under the same terms and conditions as Perl itself.
To install PkgConfig::Vars, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PkgConfig::Vars
CPAN shell
perl -MCPAN -e shell install PkgConfig::Vars
For more information on module installation, please visit the detailed CPAN module installation guide.