How to convert autotools to meson

GNU's build system ("autotools", ./configure, etc) was previously the main one used by most of the open source world. However, lots of high profile projects (GNOME, etc) have been switching from it to a new python-based one, called meson.

Many things in pkgsrc have needed to be updated to use meson, so here's a guide on doing it properly.

Basics

You won't need the following, so delete them:

GNU_CONFIGURE=      yes
USE_LIBTOOL=        yes
USE_PKGLOCALEDIR=   yes

Neither meson or cmake (another increasingly popular alternative) uses libtool to make shared libraries.

USE_PKGLOCALEDIR is also actively harmful here.

You will need the following:

.include "../../devel/meson/build.mk"

Tools

Only the following tools are generally needed:

USE_TOOLS+= pkg-config msgfmt xgettext

Nearly every meson package needs pkg-config, since it's the main way it resolves dependencies. This also means that dependencies where the buildlink isn't included won't be detected.

meson does not use intltool or other gettext tools than xgettext and msgfmt. If your package uses i18n.gettext in a meson.build file it needs xgettext, and if it uses i18n.merge_file it needs msgfmt. It's easy to check this with grep.

Python

Every Meson project uses Python to build, but many don't install Python scripts and don't need it to run, so you should add the following:

PYTHON_FOR_BUILD_ONLY=  tool

If the build process needs a python3, python2, or python binary to execute scripts during the build, you should also include the following:

.include "../../lang/python/tool.mk"

This will automatically create a python executable with the appropriate suffix (or lack of suffix) for the duration of the build.

pkgconfig overrides

Libraries that use meson generally generate .pc files for use by pkg-config. This happens during the build, while previously they would have been pregenerated.

You should search for .pc files after the build is complete and set the appropriate flags:

PKGCONFIG_OVERRIDE_STAGE=   pre-install
PKGCONFIG_OVERRIDE+=        output/meson-private/glesv2.pc

This is necessary so that pkgsrc sets the correct runtime path for libraries.

Remove any old references to nonexistent .pc files from the old build system in the PKGCONFIG_OVERRIDE.

gettext issues on NetBSD

NetBSD includes an (old, pre-GPLv3?) version of msgfmt. This doesn't have the new --desktop or --xml flags, so you'll get a build error if a package attempts to use these.

There's an easy workaround:

.include "../../mk/bsd.prefs.mk"

# msgfmt: unknown option -- desktop
.if ${OPSYS} == "NetBSD"
TOOLS_PLATFORM.msgfmt=
.endif

Flags

Flags of the following form:

CONFIGURE_ARGS+=    --enable-opengl

Generally now take the following form:

MESON_ARGS+=        -Dopengl=true

Check the meson_options.txt file.