Philip Withnall
December 09, 2014
Reading time:
tl;dr: Use AX_PKG_CHECK_MODULES to split public/private dependencies; use AC_CONFIG_FILES to magically include the API version in the .pc file name.
A few tips for creating a pkg-config file which you will never need to think about maintaining again — because one of the most common problems with pkg-config files is that their dependency lists are years out of date compared to the dependencies checked for inconfigure.ac. See lower down for some example automake snippets.
Given all those suggestions, here’s a template libmy-project/my-project.pc.in file:
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
my_project_utility=my-project-utility-binary-name
my_project_db_dir=@sysconfdir@/my-project/db
Name: @PACKAGE_NAME@
Description: Some brief but informative description
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lmy-project-@API_VERSION@
Cflags: -I${includedir}/my-project-@API_VERSION@
Requires: @AX_PACKAGE_REQUIRES@
Requires.private: @AX_PACKAGE_REQUIRES_PRIVATE@
And here’s a a few snippets from a template configure.ac:
# Release version
m4_define([package_version_major],[1])
m4_define([package_version_minor],[2])
m4_define([package_version_micro],[3])
# API version
m4_define([api_version],[1])
AC_INIT([my-project],
[package_version_major.package_version_minor.package_version_micro],
…)
# Dependencies
PKG_PROG_PKG_CONFIG
glib_reqs=2.40
gio_reqs=2.42
gthread_reqs=2.40
nice_reqs=0.1.6
# The first list on each line is public; the second is private.
# The AX_PKG_CHECK_MODULES macro substitutes AX_PACKAGE_REQUIRES and
# AX_PACKAGE_REQUIRES_PRIVATE.
AX_PKG_CHECK_MODULES([GLIB],
[glib-2.0 >= $glib_reqs gio-2.0 >= $gio_reqs],
[gthread-2.0 >= $gthread_reqs])
AX_PKG_CHECK_MODULES([NICE],
[nice >= $nice_reqs],
[])
AC_SUBST([PACKAGE_VERSION_MAJOR],package_version_major)
AC_SUBST([PACKAGE_VERSION_MINOR],package_version_minor)
AC_SUBST([PACKAGE_VERSION_MICRO],package_version_micro)
AC_SUBST([API_VERSION],api_version)
# Output files
# Rename the template .pc file to include the API version on configure
AC_CONFIG_FILES([
libmy-project/my-project-$API_VERSION.pc:libmy-project/my-project.pc.in
…
],[],
[API_VERSION='$API_VERSION'])
AC_OUTPUT
And finally, the top-level Makefile.am:
# Install the pkg-config file. pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libmy-project/my-project-$(API_VERSION).pc DISTCLEANFILES += $(pkgconfig_DATA) EXTRA_DIST += libmy-project/my-project.pc.in
Once that’s all built, you’ll end up with an installed my-project-1.pc file containing the following (assuming a prefix of /usr):
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include
my_project_utility=my-project-utility-binary-name
my_project_db_dir=/etc/my-project/db
Name: my-project
Description: Some brief but informative description
Version: 1.2.3
Libs: -L${libdir} -lmy-project-1
Cflags: -I${includedir}/my-project-1
Requires: glib-2.0 >= 2.40 gio-2.0 >= 2.42 nice >= 0.1.6
Requires.private: gthread-2.0 >= 2.40
All code samples in this post are released into the public domain.
Assuming this is the number which will change if backwards-incompatible API/ABI changes are made.
07/05/2026
A complete breakdown of Mesa’s NIR compiler detailing how it optimizes shader memory access with SSA promotion, deref analysis, copy propagation,…
05/05/2026
Collabora brought Bluetooth Auracast broadcasting to MediaTek Genio 700 for Embedded World 2026. Here's the complete, fully Open Source…
22/04/2026
Using our XR expertise, Collabora created a standalone XR experience for our 1% for the Planet partner, SOMAR, to showcase the direct impact…
17/04/2026
BitNet-style ternary brings LLM inference to ExecuTorch via its Vulkan backend, enabling much smaller, bandwidth-efficient models with portable…
23/03/2026
PanVK’s new framebuffer abstraction for Mali GPUs removes OpenGL-specific constraints, unlocking more flexible tiled rendering features…
02/03/2026
Get the recap of Nicolas Frattaroli's FOSDEM talk detailing Rockchip’s mainline progress, including Vulkan 1.4 and NPU support as a vital…