PKG.M4(7)

๐Ÿ“ฆ
version 3.0.10 ยท 2 versions
  • 3.0.10 ยท alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 1.6.3 ยท opensuse-leap 16.0
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

โœจ NAME โœจ

okay so the name of this page is pkg.m4, and it's giving autoconf macros for using pkgconf ๐Ÿ’–

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

PKG_PREREQ
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES
PKG_CHECK_MODULES_STATIC
PKG_INSTALLDIR
PKG_NOARCH_INSTALLDIR
PKG_CHECK_VAR
PKG_WITH_MODULES
PKG_HAVE_WITH_MODULES
PKG_HAVE_DEFINE_WITH_MODULES

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

bestie, pkg.m4 is a whole collection of autoconf macros that help you set up compiler and linker flags for development libraries ๐Ÿ”ฅ Your build system can detect other dependencies and then use them with the system toolchain. literally so useful, no cap.

๐Ÿ’… AUTOCONF MACROS ๐Ÿ’…

๐ŸŒธ PKG_PREREQ(MIN-VERSION)

this one checks that the version of the pkg.m4 autoconf macros you're using is at least MIN-VERSION ๐Ÿซถ It's how you make sure a particular pkg.m4 macro is actually going to be there when you need it.

โœจ PKG_PROG_PKG_CONFIG([MIN-VERSION])

checks for an implementation of pkg-config that's at least MIN-VERSION or newer ๐Ÿ’œ

๐Ÿงš PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])

๐Ÿงš PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])

this is the iconic one ๐Ÿ‘‘ It checks whether a given module set exists, and if it does, it defines CFLAGS and LIBS variables prefixed by VARIABLE-PREFIX, filled with the output from --cflags and --libs respectively.

the optional ACTION-IF-FOUND and ACTION-IF-NOT-FOUND arguments are shell fragments that get executed if the module set is found or not found ๐Ÿ“

if $PKG_CONFIG isn't defined, the PKG_PROG_PKG_CONFIG macro will run to go find a pkg-config implementation ๐Ÿ”

and PKG_CHECK_MODULES_STATIC gives you the same behaviour as PKG_CHECK_MODULES, except with static linking turned on via the --static flag ๐ŸŒˆ

๐ŸŽ€ PKG_INSTALLDIR(DIRECTORY)

this one defines the variable $pkgconfigdir as the spot where a package should install its pkg-config .pc files ๐Ÿ“ฆ

by default that directory is $libdir/pkgconfig, but you can change the default by passing in the DIRECTORY parameter ๐Ÿ› ๏ธ

and if you want to override it, use the --with-pkgconfigdir configure parameter ๐Ÿ’–

๐ŸŽ€ PKG_NOARCH_INSTALLDIR(DIRECTORY)

this one defines the variable $noarch_pkgconfigdir as the spot where a package should install its pkg-config .pc files, but for the architecture-independent stuff ๐Ÿฆ‹

by default that directory is $datadir/pkgconfig, but again, you can change it by passing in the DIRECTORY parameter ๐ŸŒธ

to override it, use the --with-noarch-pkgconfigdir configure parameter โœจ

๐Ÿ”ฎ PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])

this one grabs the value of the pkg-config variable CONFIG-VARIABLE from MODULE and stores it in the VARIABLE variable ๐Ÿง 

heads up: using VARIABLE more than once is not recommended! The check gets skipped if the variable is already set, so don't be surprised when your second call does nothing ๐Ÿ™ˆ

๐ŸŒˆ PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND], [DESCRIPTION], [DEFAULT])

this one sets up a "--with-" configure option using the lowercase VARIABLE-PREFIX name ๐ŸŽจ It merges the behaviour of AC_ARG_WITH and PKG_CHECK_MODULES into one single macro, so you get two-in-one energy ๐Ÿ’…

๐ŸŒ™ PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES, [DESCRIPTION], [DEFAULT])

a cute little convenience macro that triggers AM_CONDITIONAL after a PKG_WITH_MODULES check ๐Ÿซถ VARIABLE-PREFIX gets exported as a make variable.

๐Ÿ’œ PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES, [DESCRIPTION], [DEFAULT])

same vibe as above, but this one triggers both AM_CONDITIONAL and AC_DEFINE after a PKG_WITH_MODULES check ๐Ÿ”ฅ And yep, VARIABLE-PREFIX gets exported as a make variable too.


bestie, that's the whole page ๐Ÿ’– Brought to you by Debian, last updated December 5, 2017, filed under PKG.M4(7) ๐ŸŒˆโœจ slay the autoconf! ๐Ÿ’…๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from