NAME
PkgConfig - Pure-Perl Core-Only replacement for pkg-config
NOTE
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.
SYNOPSIS
As a replacement for pkg-config
$ 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
From another Perl module
use PkgConfig;
my $o = PkgConfig->find('gio');
if($o->errmsg) {
#handle error
} else {
my @cflags = $o->get_cflags;
my @ldflags = $o->get_ldflags;
}
DESCRIPTION
PkgConfig provides a pure-perl, core-only replacement for the pkg-config utility.
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.
SCRIPT 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.
--libs
(Also) print linker flags. Dependencies are traverse in order. Top-level dependencies will appear earlier in the command line than bottom-level dependencies.
--cflags
(Also) print compiler and C preprocessor flags.
--static
Use extra dependencies and libraries if linking against a static version of the requested library
--exists
Return success (0) if the package exists in the search path.
ENVIRONMENT
the PKG_CONFIG_PATH variable is honored and used as a colon-delimited list of directories with contain .pc files.
MODULE OPTIONS
<PkgConfig-find>>
my $result = PkgConfig->find($libary, %options);
Find a library and return a result object.
The options are in the form of hash keys and values, and the following are recognized:
search_pathsearch_path_override-
Prepend search paths in addition to the paths specified in
$ENV{PKG_CONFIG_PATH}The value is an array reference.the
_overridevariant ignores defaults (like c<PKG_CONFIG_PATH). exclude_cflagsexclude_ldflagsexclude_cflags_overrideexclude_ldflags_override-
Some
.pcfiles 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.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_LFLAGSand@PkgConfig::DEFAULT_EXCLUDE_CFLAGS, respectively. static-
Also specify static libraries.
no_recurse-
Do not recurse dependencies. This is useful for just doing version checks.
A PkgConfig object is returned and may be queried about the results:
$o->errmsg
An error message, if any. This is a string and indicates an error.
$o->pkg_exists
Boolean value, true if the package exists.
$o->pkg_version
The version of the package
$o->get_cflags
$o->get_ldflags
Returns a list of compiler and linker flags, respectively.
BUGS
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.
There is currently a dependency on a debugging module, just to preserve my sanity. This will be removed in a future release.
While pkg-config allows definition of arbitrary variables, only the following variables are currently recognized by Perl:
Variables:
my ($prefix,$exec_prefix,$libdir,$includedir);
Sections: (e.g. LibsDOTprivate is a .pc 'Libs.private:')
my ($Libs,$LibsDOTprivate,$Cflags,$Requires,$RequiresDOTprivate);
my ($Name,$Version);
Module tests are missing.
SEE ALSO
ExtUtils::PkgConfig, a wrapper around the pkg-config binary
AUTHOR & COPYRIGHT
Copyright (C) 2012 M. Nunberg
You may use and distribute this software under the same terms and conditions as Perl itself.