How to check for python GObject Introspection modules in Autotools

When we are using compiled languages – we are usually depending on pkg-config files. For example, “PKG_CHECK_MODULES(GLIB, glib2)”, but what if we are using Python?

Autoconf Archive has AX_PYTHON_MODULE macros. We can use it very easy.

How about Python + GObject Introspection? Let’s take GTK+ as an example. I wrote special m4 file (see below), you can place it in “m4” directory. Then you just need add “AX_PYTHON_GI(Gtk, 3.0)” into “configure.ac” and autoconf will check if GI works and Gtk-3.0.typelib is usable.

P.S. note that I’m not m4 expert, but it works for me.

# SYNOPSIS
#
#   AX_PYTHON_GI(gi_module, version[, python])
#
# DESCRIPTION
#
#   Checks for Python GObject Introspection and GI module with the given
#   version.
#
# LICENSE
#
#    Copyright (C) 2015 Igor Gnatenko <ignatenko@src.gnome.org>
#
#    Copying and distribution of this file, with or without modification, are
#    permitted in any medium without royalty provided the copyright notice
#    and this notice are preserved. This file is offered as-is, without any
#    warranty.

AC_DEFUN([AX_PYTHON_GI], [
    AC_MSG_CHECKING([for bindings for GObject Introspection])
    AX_PYTHON_MODULE([gi], [required], [$3])
    AC_MSG_CHECKING([for version $2 of $1 GObject Introspection module])
    $PYTHON -c "import gi; gi.require_version('$1', '$2')" 2> /dev/null
    AS_IF([test $? -eq 0], [], [
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([You need version $2 of the $1 GObject Introspection module.])
    ])
    AC_MSG_RESULT([yes])
])

Meson and 3rd party dependencies. Only one correct way

Intro

As you know, many projects bundling libs (including source code of 3rd party libs). For example, SuperTuxKart bundles angelscript, bullet, enet, glew, irrlicht, jpeglib, libpng, wiiuse, zlib. All of this libs package in my favorite distro Fedora.

As Fedora maintainer I need to check what changed in bundled libs code, if nothing – write patch to use system lib, if few changes – write patch to use system lib and report bug against this lib in Fedora, if big changes – try to understand what changed, why it’s not in upstream, create FPC ticket and they will accept bundle – use bundle. If all devs will allow to use system libs – this will be great (0 A.D. and Xonotic does this). Yes, this is also cross-platform games.

In CMake I need to write custom FindSomething.cmake and fix some things in CMakeLists.txt. Providing switch between system and bundled sources is not easy. For example, in stuntrally to unbundle ~ 50% of libs I should Showing 49 changed files with 238 additions and 108 deletions. I hate it.

In Autotools I never tried to do this, I think I will kill myself if will try.

With Meson it’s really simple. Meson is designed to be simple for developers, maintainers and fast. Hi to m4 and that black magic.

I don’t want to write more here, please read manual at official meson wiki. Much better to see real example.

Example

If we don’t have library in system (I renamed libenet to libent to not delete enet from my system):
Meson wrap bundled
If we have library in system:
Meson wrap system

Feedback

Please do not hesitate to contact us via IRC (#mesonbuild on freenode) or send patches/issues via GitHub (https://github.com/jpakkane/meson)

P.S. When I wrote this example I found some missing functionality and minor bugs and sent patches[1][2]. If you want to try this example – you need apply those patches.

css.php