PkgConfig(3pm) | User Contributed Perl Documentation | PkgConfig(3pm) |
PkgConfig - Pure-Perl Core-Only replacement for pkg-config
$ ppkg-config --libs --cflags --static gio-2.0 #outputs (lines artificially 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
"pkg-config.pl" can be used as an alias for "ppkg-config" on platforms that support it. It can also be installed as "pkg-config" though this is not recommended if your system has a native "pkg-config".
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 $prefix = $o->get_var('prefix'); my @cflags = $o->get_cflags; my @ldflags = $o->get_ldflags; }
"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.6 ) does.
The main supported options are the common "--libs", "--cflags", "--static", "--exists" and "--modversion".
USAGE
<packagename1 pkgname2..> [ --options ]
ARGUMENTS
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.
--libs-only-L
Prints -L/-R part of "--libs". It defines library search path but without libraries to link with.
--libs-only-l
Prints the -l part of "--libs".
--libs-only-other
Prints the part of "--libs" not covered by "--libs-only-L" and "--libs-only-l", such as "--pthread".
--list-all
List all know packages.
--cflags
(Also) print compiler and C preprocessor flags.
--cflags-only-I
Prints the -I part of "--cflags"
--cflags-only-other
Prints the parts of "--cflags" not covered by "--cflags-only-I".
--modversion
Print the version of a given package.
--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.
--with-path=PATH
Prepend "PATH" to the list of search paths containing ".pc" files.
This option can be specified multiple times with different paths, and they will all be added.
--env-only
Using this option, only paths specified in "PKG_CONFIG_PATH" are recognized and any hard-coded defaults are ignored.
--guess-paths
Invoke "gcc" and "ld" to determine default linker and include paths. Default paths will be excluded from explicit -L and -I flags.
--define-variable=VARIABLE=VALUE
Define a variable, overriding any such variable definition in the .pc file, and allowing your value to interpolate with subsequent uses.
--variable=VARIABLE
This returns the value of a variable defined in a package's .pc file.
--print-variables
Print all defined variables found in the .pc files.
--version
The target version of "pkg-config" emulated by this script
--real-version
The actual version of this script
--debug
Print debugging information
--silence-errors
Turn off errors. This is the default for non-libs/cflag/modversion arguments
--print-errors
Print errors to STDERR and takes precedence over "--silence-errors"
--short-errors
Ignored, but recognized for compatibility.
--errors-to-stdout
Print errors to STDOUT and takes precedence over "--print-errors"
ENVIRONMENT
the "PKG_CONFIG_PATH" and "PKG_CONFIG_LIBDIR" variables are honored and used as a colon-delimited (semicolon-delimited on Windows) list of directories with contain ".pc" files.
Other environment variables recongized by both "pkg-config" and PkgConfig include:
If Win32API::Registry is installed, on Windows (but not Cygwin) PkgConfig will also consult these registry keys. The names are ignored, but the values are paths containing ".pc" files.
Registry support should be considered somewhat experimental, subject to change in the future, though not without good reason. The rationale for this caveat is that this feature is documented in several places, but I have yet to find a working version that implements this feature.
PkgConfig->find
my $result = PkgConfig->find($library, %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
The options are in the form of hash keys and values, and the following are recognized:
the "_override" variant ignores defaults (like "PKG_CONFIG_PATH").
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.
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 compiler and linker flags, respectively.
In list context, these methods return a list with each argument split on unescaped spaces.
In list context returns a list of compiler and linker flags, respectively.
In scalar context returns a string of compiler and linker flags with spaces and quotes escaped correctly.
$o->get_var($name)
Get the variable with the given name.
PkgConfig->Guess
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 "Makefile.PL" that comes with "PkgConfig" can take one or more "--script" options to change of the name of the script or scripts that are installed.
Example, install all script names:
% perl Makefile.PL --script ppkg-config --script pkg-config.pl --script pkg-config
Example, don't install any scripts:
% perl Makefile.PL --script none
You can also set the environment variable PERL_PKG_CONFIG_SCRIPTS to the desired --script value (separating each script name with a comma ",") to ensure that upgrades of PkgConfig do the same.
On Strawberry Perl "ppkg-config" acts like Strawberry is the system. This means that
As of Strawberry 5.20.0.1 PkgConfig is bundled with Strawberry and "pkg-config" is installed by default (in addition to "ppkg-config", though the "ppkg-config" alias is NOT bundled with Strawberry itself).
For details on how to patch the .pc files bundled with older Strawberries, see the "README.win32" that comes with this Distribution.
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.
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).
Other contributors include:
Copyright (C) 2012 M. Nunberg
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2022-10-14 | perl v5.34.0 |