Module...gConfig(3pm)
π NAME π
Bestie, welcome to the User Contributed Perl Documentation page for Module::Build::Using::PkgConfig (3pm). Its whole NAME-section flex is this: extend Module::Build to more easily use platform libraries provided by pkg-config. Periodt. π
π¦ SYNOPSIS π¦
In Build.PL, the setup is giving exactly this energy:
use Module::Build::Using::PkgConfig;
my $build = Module::Build::Using::PkgConfig->new(
module_name => "Module::Here",
... # other arguments as per Module::Build
);
# A platform library provided by pkg-config
$build->use_pkgconfig( "libfoo" );
# We need at least a given version
$build->use_pkgconfig( "libbar",
atleast_version => "0.5",
);
# A platform librariy that's also wrapped as an Alien module
$build->use_pkgconfig( "libsplot",
atleast_version => "1.0",
alien => "Alien::libsplot",
alien_version => "0.05", # Alien::libsplot 0.05 provides libsplot v1.0
);
$build->create_build_script;
πΈ DESCRIPTION πΈ
This subclass of Module::Build provides some handy methods to assist the Build.PL script of XS-based module distributions that make use of platform libraries managed by pkg-config.
As well as supporting libraries installed on a platform-wide basis and thus visible to pkg-config itself, this subclass also assists with Alien::-based wrappers of these system libraries, allowing them to be dynamically installed at build time if the platform does not provide them.
π οΈ RPATH generation π οΈ
This module also provides some helper code to generate the required RPATH arguments needed to link against the libraries found by inspecting the extra_linker_flags. This attempts to duplicate the same logic performed by libtool when it would link a C program or library, as we don't get to use its code when linking dynamic libraries for Perl.
π PROPERTIES π
no_late_aliens => BOOLβ If true, applies theno_late_alienoption to every use ofuse_pkgconfigthat specifies an Alien module.
β¨ METHODS β¨
π use_pkgconfig
$build->use_pkgconfig( $modname, ... )
Requires the given pkg-config module of the given version, and extends the compiler and linker arguments sufficient to build from it.
Takes the following named options:
atleast_version => $modverβ If given, the pkg-config module is required to be at least the given version. If unspecified, then any version is considered sufficient.alien => $alienβ If given and the pkg-config module does not exist, try to use the givenAlien::module to provide it instead.
If this module is not yet available and the no_late_alien option is not true, the Alien module is added to the requires dynamic dependencies and checked again at build action time.
no_late_alien => BOOLβ If true, suppresses the dynamicrequiresfeature of Alien modules described above.alien_version => $versionβ If theAlien::module is not available, gives the module version of it that will be required to provide the pkg-config module of the required version. This gets added torequires.
If neither the pkg-config module nor an Alien:: module was requested β or none was found and no_late_alien was set β this method dies with an OS unsupported message, which is usually what is required for a Build.PL script.
π¦ try_pkconfig
$ok = $build->try_pkconfig( $modname, ... )
Boolean-returning version of use_pkgconfig. If successful, returns true. If it fails it returns false rather than dying, allowing the Build.PL script to take alternative action.
π pkgconfig_atleast_version
$ok = $build->pkgconfig_atleast_version( $modname, $modver )
Returns true if the pkg-config module name exists and has at least the given version.
π§ add_cflags_libs_from_pkgconfig
$build->add_cflags_libs_from_pkgconfig( $modname )
Extend the extra_compiler_flags and extra_linker_flags arguments from the --cflags and --libs from the given pkg-config module name.
π§ alien_atleast_version
$ok = $build->alien_atleast_version( $alien, $modver )
Returns true if the given Alien:: module provides a pkg-config module version at least the given version.
π add_cflags_libs_from_alien
$build->add_cflags_libs_from_alien( $alien )
Extend the extra_compiler_flags and extra_linker_flags arguments from the --cflags and --libs from the given Alien:: module name.
π use_late_alien
$ok = $build->use_late_alien( $alien, ... )
Adds an Alien module directly to the requires hash, and makes a note to use its cflags and libraries later at build time.
Normally this method would not be necessary as it is automatically called from use_pkgconfig if required, but one use-case may be to provide a final last-ditch attempt after trying some other possible attempts, after an earlier call to use_pkgconfig with no_late_alien set.
π push_extra_compiler_flags
$build->push_extra_compiler_flags( @flags )
Appends more values onto the extra_compiler_flags.
π push_extra_linker_flags
$build->push_extra_linker_flags( @flags )
Appends more values onto the extra_linker_flags.
π TODO π
- Consider a
quietoption to suppress verbose printing - Consider defining a constructor argument, perhaps
build_requires_pkgconfig, to neaten the common case of simple requirements. - Consider further stealing the various helper methods from
ExtUtils::CCheckerand possibly splitting this class into a lowerC-using XS modulesand higher-level pkg-config+Alien layer.
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
π Cute sign-off time: this page is from perl v5.42.0, dated 2020-11-23, and it's the Module...gConfig(3pm) page. Stay slaying, bestie! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Module-Build-Using-PkgConfig 0.03-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms