Meson

Hace como quince años aprendí a usar autotools. Para los que no lo sepan, autotools es la combinación de autoconf, automake y un montón de otros programitas que permiten el generar un script llamado configure, con el que a su vez se generan uno o más archivos Makefile, con los que con algo de suerte se puede compilar un programa en Linux (o casi cualquier Unix, realmente).

Como dije, aprendí a usar autotools en 2002, más o menos; el proyecto ya llevaba once años de vida en ese momento, habiendo comenzado con autoconf en 1991.

El proyecto GNU se basa en gran medida en autotools, y consecuentemente Linux también. Hasta hace pocos años era medio imposible compilar un programa de software libre sin pasar por la santísima trinidad de hacer ./configure && make && make install.

Autotools es impresionante para lo que trataba de resolver en su momento; el estandarizar cómo configurar y compilar código en la miríada de unices que existían a inicios de la última década del siglo XX. Estaban Solaris, SCO, UP/UX, Irix, el resecado cadáver de BSD, y todavía faltaban Linux y FreeBSD. Especialmente porque en ese entonces no había un estándar para bibliotecas con ligado dinámico; algunos de esos unices no tenían bibliotecas con ligado dinámico.

Ya en el ocaso de la segunda década del siglo XXI, resulta que autotools no es tan terriblemente útil como antes. Linux es el Unix ganador, por mucho; Mac OS X es nominalmente Unix, pero en realidad tienen su propia manera de distribuir software, y en los hechos a Apple no le interesa que la gente pueda compilar cosas fácilmente en su plataforma de forma estándar con otros sistemas operativos.

Además es terríblemente arcaico y uno tiene que aprender dos lenguajes (al menos) para aprender a usarlo: el de autoconf y el de automake. Y realmente es necesario aprender a escribir makefiles, y si uno se clava resulta que también hay que usar M4. Y Bash está ahí, acechando en las sombras como siempre.

El odio a autotools es enorme en la comunidad del software libre, porque hay que pelar un pollo para que las cosas funcionen, y cuando no lo hacen es terriblemente difícil el descubrir qué carajo ocurre. Pero no hay una alternativa mejor, así que todo mundo se aguanta.

Yo no odio autotools; sólo me parece que es espantoso de usar. Todos mis proyectos de software libre usaban autotools hasta hace poco, y en general funciona. Medio arcaicamente, pero funciona.

Desde hace años ha habido intentos de reemplazar autotools con algo mejor, pero en general nada ha ganado suficiente tracción como para llevarlo a cabo. Lo más cercano que había aparecido fue CMake, que logró que algunos proyectos se cambiaran a usarlo; en particular KDE hace más de 10 años. Sin embargo, cuando los hippies de GNOME lo discutieron, decidieron que no lo iban a usar; como suelo confiar en esos güeyes, yo también pasé.

Así estaban las cosas hasta que hace unas semanas leí que GNOME está considerando (seriamente) cambiarse a Meson. Ya había oído del proyecto (tiene 5 años), pero yo había pensado que sería otro más del montón de intentos usurpadores; pero cuando vi que GTK+ se va a cambiar a él, y que systemd también lo está considerando, decidí que le iba a echar un ojo.

Quedé bañado de asiento; dícese, anonadado.

Por poner un ejemplo, aquí está el tiempo que me toma configurar y compilar MLM, un programita mío, utilizando autotools:

canek@dell ~/Devel/mlm $ time ( ./autogen.sh && make )
autoreconf-2.69: Entering directory `.'
autoreconf-2.69: running: autopoint --force
Copying file ABOUT-NLS
Creating directory build-aux
Copying file build-aux/config.rpath
Copying file m4/codeset.m4
Copying file m4/extern-inline.m4
Copying file m4/fcntl-o.m4
Copying file m4/gettext.m4
Copying file m4/glibc2.m4
Copying file m4/glibc21.m4
Copying file m4/iconv.m4
Copying file m4/intdiv0.m4
Copying file m4/intl.m4
Copying file m4/intldir.m4
Copying file m4/intlmacosx.m4
Copying file m4/intmax.m4
Copying file m4/inttypes-pri.m4
Copying file m4/inttypes_h.m4
Copying file m4/lcmessage.m4
Copying file m4/lib-ld.m4
Copying file m4/lib-link.m4
Copying file m4/lib-prefix.m4
Copying file m4/lock.m4
Copying file m4/longlong.m4
Copying file m4/nls.m4
Copying file m4/po.m4
Copying file m4/printf-posix.m4
Copying file m4/progtest.m4
Copying file m4/size_max.m4
Copying file m4/stdint_h.m4
Copying file m4/threadlib.m4
Copying file m4/uintmax_t.m4
Copying file m4/visibility.m4
Copying file m4/wchar_t.m4
Copying file m4/wint_t.m4
Copying file m4/xsize.m4
Copying file po/Makevars.template
Copying file po/Rules-quot
Copying file po/boldquot.sed
Copying file po/en@boldquot.header
Copying file po/en@quot.header
Copying file po/insert-header.sin
Copying file po/quot.sed
Copying file po/remove-potcdate.sin
autoreconf-2.69: running: aclocal --force 
autoreconf-2.69: configure.ac: tracing
autoreconf-2.69: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
autoreconf-2.69: running: /usr/bin/autoconf-2.69 --force
autoreconf-2.69: running: /usr/bin/autoheader-2.69 --force
autoreconf-2.69: running: automake --add-missing --copy --force-missing
configure.ac:14: installing 'build-aux/compile'
configure.ac:14: installing 'build-aux/config.guess'
configure.ac:14: installing 'build-aux/config.sub'
configure.ac:12: installing 'build-aux/install-sh'
configure.ac:12: installing 'build-aux/missing'
Makefile.am: installing 'build-aux/depcomp'
autoreconf-2.69: Leaving directory `.'
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/x86_64-pc-linux-gnu/bin/ld
checking if the linker (/usr/x86_64-pc-linux-gnu/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-pc-linux-gnu/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/x86_64-pc-linux-gnu/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for gcc option to accept ISO C99... none needed
checking for gcc option to accept ISO Standard C... (cached) none needed
checking for valac... /usr/bin/valac-0.32
checking whether /usr/bin/valac-0.32 is at least version 0.32... yes
checking for glib-compile-resources... /usr/bin/glib-compile-resources
checking for xsltproc... /usr/bin/xsltproc
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for GLIB... yes
checking for GIO... yes
checking for GEE... yes
checking for ID3TAG... yes
checking for GTK... yes
checking for GDK_PIXBUF... yes
checking for GSTREAMER... yes
checking whether NLS is requested... yes
checking for msgfmt... /usr/bin/msgfmt
checking for gmsgfmt... /usr/bin/gmsgfmt
checking for xgettext... /usr/bin/xgettext
checking for msgmerge... /usr/bin/msgmerge
checking for ld used by gcc... /usr/x86_64-pc-linux-gnu/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-pc-linux-gnu/bin/ld -m elf_x86_64) is GNU ld... yes
checking for shared library run path origin... done
checking for CFPreferencesCopyAppValue... no
checking for CFLocaleCopyCurrent... no
checking for GNU gettext in libc... yes
checking whether to use NLS... yes
checking where the gettext function comes from... libc
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating po/Makefile.in
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
make  all-recursive
make[1]: Entering directory '/home/canek/Devel/mlm'
Making all in po
make[2]: Entering directory '/home/canek/Devel/mlm/po'
test ! -f ./mlm.pot || \
  test -z "es.gmo" || make es.gmo
make[3]: Entering directory '/home/canek/Devel/mlm/po'
rm -f es.gmo && /usr/bin/gmsgfmt -c --statistics --verbose -o es.gmo es.po
es.po: 47 translated messages, 150 untranslated messages.
make[3]: Leaving directory '/home/canek/Devel/mlm/po'
touch stamp-po
make[2]: Leaving directory '/home/canek/Devel/mlm/po'
make[2]: Entering directory '/home/canek/Devel/mlm'
  VALAC    lib_libmlm_la_vala.stamp
  GEN      src/application/resources.c
  XSLT     man/mlm-analyze.1
  XSLT     man/mlm-tags.1
  GEN      data/mlm.desktop
  XSLT     man/mlm-analyze.html
  XSLT     man/mlm-tags.html
  CC       lib/id3tag-x/lib_libid3tag_x_la-id3tag-x.lo
  CC       src/application/src_mlm_gui-resources.o
  VALAC    src_mlm_tags_vala.stamp
  VALAC    src_mlm_accommodator_vala.stamp
  VALAC    src_mlm_verify_vala.stamp
  VALAC    src_mlm_copy_tags_vala.stamp
  VALAC    src_mlm_analyze_vala.stamp
  CCLD     lib/libid3tag-x.la
  CC       lib/mlm/lib_libmlm_la-genres.lo
  CC       lib/mlm/lib_libmlm_la-file-tags.lo
  CC       lib/mlm/lib_libmlm_la-pretty-box.lo
  CC       lib/mlm/lib_libmlm_la-util.lo
  VALAC    src_mlm_gui_vala.stamp
  CC       src/tags/src_mlm_tags-tags.o
  CC       src/accommodator/src_mlm_accommodator-accommodator.o
  CC       src/verify/src_mlm_verify-verify.o
  CC       src/copy-tags/src_mlm_copy_tags-copy-tags.o
  CC       src/analyze/src_mlm_analyze-analyze.o
  CCLD     lib/libmlm.la
  CC       src/application/src_mlm_gui-application-window.o
  CC       src/application/src_mlm_gui-application.o
  CC       src/application/src_mlm_gui-encoder.o
  CC       src/application/src_mlm_gui-main.o
  CC       src/application/src_mlm_gui-media.o
  CC       src/application/src_mlm_gui-player.o
  CCLD     src/mlm-tags
  CCLD     src/mlm-accommodator
  CCLD     src/mlm-verify
  CCLD     src/mlm-copy-tags
  CCLD     src/mlm-analyze
  CCLD     src/mlm-gui
make[2]: Leaving directory '/home/canek/Devel/mlm'
make[1]: Leaving directory '/home/canek/Devel/mlm'

real	0m16.562s
user	0m20.716s
sys	0m2.822s

En comparación aquí está el tiempo de configurar y compilar con Meson:

canek@dell ~/Devel/mlm $ time ( meson build && ninja -C build )
The Meson build system
Version: 0.39.1
Source dir: /home/canek/Devel/mlm
Build dir: /home/canek/Devel/mlm/build
Build type: native build
Project name: mlm
Native vala compiler: valac (valac 0.32.1)
Native c compiler: cc (gcc 5.4.0)
Appending CFLAGS from environment: '-DG_LOG_USE_STRUCTURED=1'
Build machine cpu family: x86_64
Build machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.28)
Native dependency gdk-pixbuf-2.0 found: YES 2.36.6
Native dependency gee-0.8 found: YES 0.18.1
Native dependency gio-2.0 found: YES 2.50.3
Native dependency glib-2.0 found: YES 2.50.3
Native dependency gstreamer-1.0 found: YES 1.10.3
Native dependency gtk+-3.0 found: YES 3.22.15
Native dependency id3tag found: YES 0.15.1b
Program xsltproc found: YES (/usr/bin/xsltproc)
Configuring config.h using configuration
Native dependency glib-2.0 found: YES 2.50.3
WARNING: GLib compiled dependencies do not work reliably with 
the current version of GLib. See the following upstream issue: https://bugzilla.gnome.org/show_bug.cgi?id=774368
Program msgfmt found: YES (/usr/bin/msgfmt)
Build targets in project: 17
ninja: Entering directory `build'
[38/38] Linking target src/mlm-gui

real	0m2.522s
user	0m6.895s
sys	0m0.833s

Eso es 7 más rápido. Una razón es que Meson no utiliza makefiles; utiliza Ninja, que ni siquiera trata de usar un formato para que lo escriban seres humanos. Justamente lo que hace Meson es generar el archivo que Ninja usa para compilar el programa; pero además lo hace mucho más rápido que el script configure, que dispara un montón de comandos estándares de Unix y varios scripts de varios intérpretes. En cambio Meson y Ninja son dos programas únicamente, ambos escritos en Python.

Todos mis proyectos ya soportan Meson, y estoy considerando seriamente quitar el soporte para autotools en todos.

Me parece que Meson tiene buenas posibilidades de ser adoptado en muchos proyectos en Linux; lamentablemente no sé si lo vaya a adoptar el proyecto GNU, dado que utiliza la licencia MIT. Pero si puedo compilar LibreOffice en menos tiempo que los 43 minutos que toma actualmente, yo con eso estaré contento.

2 comentarios sobre “Meson

  1. He leído que Birdie, un cliente de Twitter (libre para linux) que pinta muy bien. Está basado en meson.

    Estoy a punto de bajarlo y compilarlo con este entorno.

    Por si a alguien le interesa investigarlo aquí les dejo el lugar de donde bajar los fuentes y compilarlo con meson.

    https://github.com/ivonunes/birdie

    Un saludo desde la Patagonia y gracias por tu reseña..

    Dr.Calambre

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *