[RFC PATCH] build: add meson build system

Jani Nikula jani at nikula.org
Sat Jan 11 08:40:49 PST 2020


Add initial support for configuring and building notmuch using the
Meson Build System [1].

The "home-brew" configure script in notmuch has grown rather
complicated, although the goal was originally to avoid the complexity
of using autotools. Since then, meson has emerged as a viable option
for replacing autotools and make.

The benefits compared to the current configure are most evident in the
feature tests. Many things that require tens of lines of shell and/or
C feature test code are simple one-liners in meson. Some
self-explanatory examples:

 - dep_gmime = dependency('gmime-3.0', version: '>=3.0.3')
 - cmd_python = find_program('python3', 'python', 'python2')
 - have_d_type = cc.has_member('struct dirent', 'd_type',
                               prefix: '#include <dirent.h>')

Additionally, meson provides basic install targets automatically, as
well as a test runner with built-in parallelization.

This is a draft patch adding basic configure, build and test support
for the binaries. Everything else is left out for now. It would be a
considerable amount of work to convert everything, and I don't expect
it to be possible in one go anyway. If there's interest in adding
meson support, it would have to happen gradually, side-by-side with
the current system, with a reasonably long transition period. But
there's no point in going beyond the patch at hand if folks decide the
focus should remain on the current system.

[1] https://mesonbuild.com/
---
 compat/config.h.in            |  11 +++
 compat/meson.build            | 169 ++++++++++++++++++++++++++++++++++
 lib/meson.build               |  36 ++++++++
 meson.build                   |  77 ++++++++++++++++
 parse-time-string/meson.build |   4 +
 sh.config.in                  |  31 +++++++
 test/meson.build              | 133 ++++++++++++++++++++++++++
 util/meson.build              |  19 ++++
 8 files changed, 480 insertions(+)
 create mode 100644 compat/config.h.in
 create mode 100644 compat/meson.build
 create mode 100644 lib/meson.build
 create mode 100644 meson.build
 create mode 100644 parse-time-string/meson.build
 create mode 100644 sh.config.in
 create mode 100644 test/meson.build
 create mode 100644 util/meson.build

diff --git a/compat/config.h.in b/compat/config.h.in
new file mode 100644
index 000000000000..22269a84c8a4
--- /dev/null
+++ b/compat/config.h.in
@@ -0,0 +1,11 @@
+#define HAVE_CANONICALIZE_FILE_NAME @HAVE_CANONICALIZE_FILE_NAME@
+#define HAVE_D_TYPE @HAVE_D_TYPE@
+#define HAVE_GETLINE @HAVE_GETLINE@
+#define HAVE_STRCASESTR @HAVE_STRCASESTR@
+#define HAVE_STRSEP @HAVE_STRSEP@
+#define HAVE_TIMEGM @HAVE_TIMEGM@
+#define HAVE_XAPIAN_COMPACT @HAVE_XAPIAN_COMPACT@
+#define HAVE_XAPIAN_DB_RETRY_LOCK @HAVE_XAPIAN_DB_RETRY_LOCK@
+#define HAVE_XAPIAN_FIELD_PROCESSOR @HAVE_XAPIAN_FIELD_PROCESSOR@
+#define STD_ASCTIME @STD_ASCTIME@
+#define STD_GETPWUID @STD_GETPWUID@
diff --git a/compat/meson.build b/compat/meson.build
new file mode 100644
index 000000000000..ed79bd2ec83c
--- /dev/null
+++ b/compat/meson.build
@@ -0,0 +1,169 @@
+notmuch_compat_srcs = [
+]
+
+config = configuration_data()
+
+config.set_quoted('NOTMUCH_SRCDIR', meson.source_root())
+
+# FIXME: this differs from the legacy build
+config.set('PLATFORM', build_machine.system())
+
+cc = meson.get_compiler('c')
+cxx = meson.get_compiler('cpp')
+
+have_canonicalize_file_name = cc.has_function('canonicalize_file_name',
+					      prefix: '#include <stdlib.h>',
+					      args: '-D_GNU_SOURCE')
+config.set10('HAVE_CANONICALIZE_FILE_NAME', have_canonicalize_file_name)
+if not have_canonicalize_file_name
+	notmuch_compat_srcs += 'canonicalize_file_name.c'
+endif
+
+have_getline = cc.has_function('getline', prefix: '''#include <stdio.h>
+#include <sys/types.h>
+''')
+config.set10('HAVE_GETLINE', have_getline)
+if not have_getline
+	notmuch_compat_srcs += [ 'getline.c', 'getdelim.c' ]
+endif
+
+have_strcasestr = cc.has_function('strcasestr', prefix: '#include <string.h>',
+				  args: '-D_GNU_SOURCE')
+config.set10('HAVE_STRCASESTR', have_strcasestr)
+if not have_strcasestr
+	notmuch_compat_srcs += 'strcasestr.c'
+endif
+
+have_strsep = cc.has_function('strsep', prefix: '#include <string.h>')
+config.set10('HAVE_STRSEP', have_strsep)
+if not have_strsep
+	notmuch_compat_srcs += 'strsep.c'
+endif
+
+have_timegm = cc.has_function('timegm', prefix: '#include <time.h>')
+config.set10('HAVE_TIMEGM', have_timegm)
+if not have_timegm
+	notmuch_compat_srcs += 'timegm.c'
+endif
+
+have_d_type = cc.has_member('struct dirent', 'd_type',
+			    prefix: '#include <dirent.h>')
+config.set10('HAVE_D_TYPE', have_d_type)
+
+getpwuid_code = '''
+#include <stdio.h>
+#include <pwd.h>
+int main()
+{
+	struct passwd passwd, *ignored;
+	getpwuid_r (0, &passwd, NULL, 0, &ignored);
+}
+'''
+std_getpwuid = cc.compiles(getpwuid_code, name: 'standard getpwuid_r')
+config.set10('STD_GETPWUID', std_getpwuid)
+
+asctime_code = '''
+#include <time.h>
+#include <stdio.h>
+int main()
+{
+	struct tm tm;
+	asctime_r (&tm, NULL);
+}
+'''
+std_asctime = cc.compiles(asctime_code, name: 'standard asctime_r')
+config.set10('STD_ASCTIME', std_asctime)
+
+xapian_compact_code = '''
+#include <xapian.h>
+class TestCompactor : public Xapian::Compactor { };
+'''
+have_xapian_compact = cxx.compiles(xapian_compact_code, name: 'Xapian compact',
+				   dependencies: dep_xapian)
+config.set10('HAVE_XAPIAN_COMPACT', have_xapian_compact)
+
+xapian_field_processor_code = '''
+#include <xapian.h>
+class TitleFieldProcessor : public Xapian::FieldProcessor { };
+'''
+have_xapian_field_processor = cxx.compiles(xapian_field_processor_code,
+					   name: 'Xapian field processor',
+					   dependencies: dep_xapian)
+config.set10('HAVE_XAPIAN_FIELD_PROCESSOR', have_xapian_field_processor)
+
+xapian_db_retry_lock_code = '''
+#include <xapian.h>
+int flag = Xapian::DB_RETRY_LOCK;
+'''
+have_xapian_db_retry_lock = cxx.compiles(xapian_db_retry_lock_code,
+					 name: 'Xapian retry lock',
+					 dependencies: dep_xapian)
+config.set10('HAVE_XAPIAN_DB_RETRY_LOCK', have_xapian_db_retry_lock)
+
+default_xapian_backend_code = '''
+#include <xapian.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define TESTDB "test.db"
+int main(void) {
+	int i;
+	struct {
+		const char *file;
+		const char *name;
+	} backends[] = {
+		{ TESTDB "/iamglass", "glass" },
+		{ TESTDB "/iamchert", "chert" },
+		{ TESTDB "/iamflint", "flint" },
+		{ NULL, "unknown" },
+	};
+
+	Xapian::WritableDatabase db("test.db", Xapian::DB_CREATE_OR_OPEN);
+
+	for (i = 0; backends[i].file && access(backends[i].file, R_OK); i++)
+		;
+
+	printf("%s", backends[i].name);
+}
+
+'''
+default_xapian_backend = cxx.run(default_xapian_backend_code,
+				 name: 'Xapian default backend',
+				 dependencies: dep_xapian)
+message('Default Xapian backend: ' + default_xapian_backend.stdout())
+config.set('DEFAULT_XAPIAN_BACKEND', default_xapian_backend.stdout())
+
+configure_inc = include_directories('../lib')
+libnotmuch_version_major = cc.get_define('LIBNOTMUCH_MAJOR_VERSION',
+					 prefix: '#include <notmuch.h>',
+					 include_directories: configure_inc)
+libnotmuch_version_minor = cc.get_define('LIBNOTMUCH_MINOR_VERSION',
+					 prefix: '#include <notmuch.h>',
+					 include_directories: configure_inc)
+libnotmuch_version_micro = cc.get_define('LIBNOTMUCH_MICRO_VERSION',
+					 prefix: '#include <notmuch.h>',
+					 include_directories: configure_inc)
+libnotmuch_version = libnotmuch_version_major + '.' + libnotmuch_version_minor + '.' + libnotmuch_version_micro
+
+
+config.set_quoted('PYTHON', cmd_python.path())
+
+config.set('GMIME_MAJOR', dep_gmime.version().split('.')[0])
+
+if cmd_ruby.found()
+	ruby_dev = run_command(cmd_ruby.path(), ['-e', 'require \'mkmf\''])
+	have_ruby_dev = ruby_dev.returncode() == 0
+else
+	have_ruby_dev = false
+endif
+config.set10('HAVE_RUBY_DEV', have_ruby_dev)
+
+
+configure_file(input: 'config.h.in',
+	       output: 'config.h',
+	       configuration: config)
+
+inc_compat = include_directories('.')
+
+lib_compat = static_library('notmuch-compat',
+			    notmuch_compat_srcs)
diff --git a/lib/meson.build b/lib/meson.build
new file mode 100644
index 000000000000..82c920cfab81
--- /dev/null
+++ b/lib/meson.build
@@ -0,0 +1,36 @@
+libnotmuch_srcs = [
+	'add-message.cc',
+	'built-with.c',
+	'config.cc',
+	'database.cc',
+	'directory.cc',
+	'filenames.c',
+	'index.cc',
+	'indexopts.c',
+	'message-file.c',
+	'message-id.c',
+	'message-property.cc',
+	'message.cc',
+	'messages.c',
+	'parse-time-vrp.cc',
+	'query-fp.cc',
+	'query.cc',
+	'regexp-fields.cc',
+	'sha1.c',
+	'string-list.c',
+	'string-map.c',
+	'tags.c',
+	'thread-fp.cc',
+	'thread.cc',
+]
+
+inc_lib = include_directories('.')
+
+lib_notmuch = both_libraries('notmuch', libnotmuch_srcs,
+			     include_directories: [inc_compat,
+						   inc_util,
+						   inc_parse_time],
+			     link_with: [lib_compat, lib_util, lib_parse_time],
+			     dependencies: [dep_gmime, dep_glib, dep_xapian, dep_talloc],
+			     version: libnotmuch_version,
+			     install: true)
diff --git a/meson.build b/meson.build
new file mode 100644
index 000000000000..6a924a684cad
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,77 @@
+project('notmuch',
+	['c', 'cpp'],
+	license: 'GPLv3+',
+       meson_version: '>=0.49.2')
+
+dep_xapian = dependency('xapian-core')
+dep_gmime = dependency('gmime-3.0', version: '>=3.0.3')
+dep_glib = dependency('glib-2.0', version: '>=2.22')
+dep_zlib = dependency('zlib', version: '>=1.2.5.2')
+dep_talloc = dependency('talloc')
+dep_valgrind = dependency('valgrind', required: false)
+dep_bash_completion = dependency('bash-completion', version: '>=1.90',
+				 required: false)
+cmd_python = find_program('python3', 'python', 'python2')
+cmd_doxygen = find_program('doxygen', required: false)
+cmd_ruby = find_program('ruby', required: false)
+cmd_sphinx = find_program('sphinx-build', required: false)
+cmd_emacs = find_program('emacs', required: false)
+cmd_desktop_file_install = find_program('desktop-file-install', required: false)
+
+add_global_arguments('-Wno-deprecated-declarations', language: ['c', 'cpp'])
+
+add_project_arguments('-D_GNU_SOURCE', language: ['c', 'cpp'])
+add_project_arguments('-include', 'config.h', language: ['c', 'cpp'])
+
+inc_cli = include_directories('.')
+
+subdir('compat')
+subdir('parse-time-string')
+subdir('util')
+subdir('lib')
+subdir('test')
+
+notmuch_client_srcs = [
+	'command-line-arguments.c',
+	'debugger.c',
+	'gmime-filter-reply.c',
+	'hooks.c',
+	'mime-node.c',
+	'notmuch-compact.c',
+	'notmuch-config.c',
+	'notmuch-count.c',
+	'notmuch-dump.c',
+	'notmuch-insert.c',
+	'notmuch-new.c',
+	'notmuch-reindex.c',
+	'notmuch-reply.c',
+	'notmuch-restore.c',
+	'notmuch-search.c',
+	'notmuch-setup.c',
+	'notmuch-show.c',
+	'notmuch-tag.c',
+	'notmuch-time.c',
+	'notmuch.c',
+	'query-string.c',
+	'sprinter-json.c',
+	'sprinter-sexp.c',
+	'sprinter-text.c',
+	'status.c',
+	'tag-util.c',
+]
+
+executable('notmuch', notmuch_client_srcs,
+	   include_directories: [inc_util, inc_compat, inc_lib],
+	   dependencies: [dep_gmime, dep_zlib, dep_glib, dep_talloc],
+	   link_with: [lib_compat, lib_util, lib_parse_time, lib_notmuch.get_static_lib()],
+	   install: true)
+
+executable('notmuch-shared', notmuch_client_srcs,
+	   include_directories: [inc_util, inc_compat, inc_lib],
+	   dependencies: [dep_gmime, dep_zlib, dep_glib, dep_talloc],
+	   link_with: [lib_compat, lib_util, lib_parse_time, lib_notmuch],
+	   install: true)
+
+configure_file(input: 'sh.config.in',
+	       output: 'sh.config',
+	       configuration: config)
diff --git a/parse-time-string/meson.build b/parse-time-string/meson.build
new file mode 100644
index 000000000000..30c938d0a118
--- /dev/null
+++ b/parse-time-string/meson.build
@@ -0,0 +1,4 @@
+inc_parse_time = include_directories('.')
+lib_parse_time = static_library('parse-time-string',
+				'parse-time-string.c',
+				include_directories: inc_compat)
diff --git a/sh.config.in b/sh.config.in
new file mode 100644
index 000000000000..8ec4ed314aaf
--- /dev/null
+++ b/sh.config.in
@@ -0,0 +1,31 @@
+NOTMUCH_SRCDIR=@NOTMUCH_SRCDIR@
+
+# Whether the Xapian version in use supports compaction
+NOTMUCH_HAVE_XAPIAN_COMPACT=@HAVE_XAPIAN_COMPACT@
+
+# Whether the Xapian version in use supports field processors
+NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR=@HAVE_XAPIAN_FIELD_PROCESSOR@
+
+# Whether the Xapian version in use supports lock retry
+NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK=@HAVE_XAPIAN_DB_RETRY_LOCK@
+
+# Which backend will Xapian use by default?
+NOTMUCH_DEFAULT_XAPIAN_BACKEND=@DEFAULT_XAPIAN_BACKEND@
+
+# do we have man pages?
+NOTMUCH_HAVE_MAN=1
+
+# Name of python interpreter
+NOTMUCH_PYTHON=@PYTHON@
+
+# Are the ruby development files (and ruby) available? If not skip
+# building/testing ruby bindings.
+NOTMUCH_HAVE_RUBY_DEV=@HAVE_RUBY_DEV@
+
+# Major version of gmime
+NOTMUCH_GMIME_MAJOR=@GMIME_MAJOR@
+
+# Platform we are run on
+PLATFORM=Linux
+
+NOTMUCH_PLATFORM=@PLATFORM@
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 000000000000..e7a3c3e9c21f
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,133 @@
+
+executable('arg-test', ['arg-test.c', '../command-line-arguments.c'],
+	   include_directories: [inc_compat, inc_util, inc_cli],
+	   link_with: [lib_compat, lib_util],
+	   dependencies: dep_talloc)
+executable('hex-xcode', ['hex-xcode.c', '../command-line-arguments.c'],
+	   include_directories: [inc_compat, inc_util, inc_cli],
+	   link_with: [lib_compat, lib_util],
+	   dependencies: [dep_talloc, dep_gmime])
+executable('random-corpus', ['random-corpus.c',
+			     'database-test.c',
+			     '../notmuch-config.c',
+			     '../status.c',
+			     '../command-line-arguments.c'],
+	   include_directories: [inc_compat, inc_util, inc_cli, inc_lib],
+	   link_with: [lib_compat, lib_util, lib_parse_time, lib_notmuch],
+	   dependencies: [dep_talloc, dep_gmime])
+executable('smtp-dummy', ['smtp-dummy.c'],
+	   include_directories: [inc_compat, inc_util],
+	   link_with: [lib_compat, lib_util])
+executable('symbol-test', ['symbol-test.cc'],
+	   include_directories: [inc_compat, inc_util],
+	   link_with: [lib_compat, lib_util, lib_notmuch],
+	   dependencies: dep_xapian)
+executable('parse-time', ['parse-time.c'],
+	   include_directories: [inc_compat, inc_util, inc_parse_time],
+	   link_with: [lib_compat, lib_util, lib_parse_time])
+executable('make-db-version', ['make-db-version.cc'],
+	   include_directories: [inc_compat, inc_util],
+	   link_with: [lib_compat, lib_util],
+	   dependencies: dep_xapian)
+executable('ghost-report', ['ghost-report.cc'],
+	   include_directories: [inc_compat, inc_util],
+	   link_with: [lib_compat, lib_util],
+	   dependencies: dep_xapian)
+
+build_dir = meson.current_build_dir()
+
+tests = [
+	'T000-basic.sh',
+	'T010-help-test.sh',
+	'T020-compact.sh',
+	'T030-config.sh',
+	'T040-setup.sh',
+	'T050-new.sh',
+	'T060-count.sh',
+	'T070-insert.sh',
+	'T080-search.sh',
+	'T090-search-output.sh',
+	'T095-address.sh',
+	'T100-search-by-folder.sh',
+	'T110-search-position-overlap-bug.sh',
+	'T120-search-insufficient-from-quoting.sh',
+	'T130-search-limiting.sh',
+	'T140-excludes.sh',
+	'T150-tagging.sh',
+	'T160-json.sh',
+	'T170-sexp.sh',
+	'T180-text.sh',
+	'T190-multipart.sh',
+	'T200-thread-naming.sh',
+	'T205-author-naming.sh',
+	'T210-raw.sh',
+	'T220-reply.sh',
+	'T230-reply-to-sender.sh',
+	'T240-dump-restore.sh',
+	'T250-uuencode.sh',
+	'T260-thread-order.sh',
+	'T270-author-order.sh',
+	'T280-from-guessing.sh',
+	'T290-long-id.sh',
+	'T300-encoding.sh',
+	'T310-emacs.sh',
+	'T320-emacs-large-search-buffer.sh',
+	'T330-emacs-subject-to-filename.sh',
+	'T340-maildir-sync.sh',
+	'T350-crypto.sh',
+	'T351-pgpmime-mangling.sh',
+	'T355-smime.sh',
+	'T356-protected-headers.sh',
+	'T357-index-decryption.sh',
+	'T358-emacs-protected-headers.sh',
+	'T360-symbol-hiding.sh',
+	'T370-search-folder-coherence.sh',
+	'T380-atomicity.sh',
+	'T390-python.sh',
+	'T391-python-cffi.sh',
+	'T395-ruby.sh',
+	'T400-hooks.sh',
+	'T410-argument-parsing.sh',
+	'T420-emacs-test-functions.sh',
+	'T430-emacs-address-cleaning.sh',
+	'T440-emacs-hello.sh',
+	'T450-emacs-show.sh',
+	'T455-emacs-charsets.sh',
+	'T460-emacs-tree.sh',
+	'T470-missing-headers.sh',
+	'T480-hex-escaping.sh',
+	'T490-parse-time-string.sh',
+	'T500-search-date.sh',
+	'T510-thread-replies.sh',
+	'T520-show.sh',
+	'T530-upgrade.sh',
+	'T550-db-features.sh',
+	'T560-lib-error.sh',
+	'T570-revision-tracking.sh',
+	'T580-thread-search.sh',
+	'T585-thread-subquery.sh',
+	'T590-libconfig.sh',
+	'T590-thread-breakage.sh',
+	'T600-named-queries.sh',
+	'T610-message-property.sh',
+	'T620-lock.sh',
+	'T630-emacs-draft.sh',
+	'T640-database-modified.sh',
+	'T650-regexp-query.sh',
+	'T660-bad-date.sh',
+	'T670-duplicate-mid.sh',
+	'T680-html-indexing.sh',
+	'T690-command-line-args.sh',
+	'T700-reindex.sh',
+	'T710-message-id.sh',
+	'T720-emacs-attachment-warnings.sh',
+	'T720-lib-lifetime.sh',
+	'T730-emacs-forwarding.sh',
+	'T740-body.sh',
+	'T750-gzip.sh',
+	'T750-user-header.sh',
+]
+
+foreach test: tests
+	test(test, find_program(test), workdir: build_dir)
+endforeach
diff --git a/util/meson.build b/util/meson.build
new file mode 100644
index 000000000000..95a960b12411
--- /dev/null
+++ b/util/meson.build
@@ -0,0 +1,19 @@
+notmuch_util_srcs = [
+	'crypto.c',
+	'error_util.c',
+	'gmime-extra.c',
+	'hex-escape.c',
+	'repair.c',
+	'string-util.c',
+	'talloc-extra.c',
+	'unicode-util.c',
+	'util.c',
+	'xutil.c',
+	'zlib-extra.c',
+]
+
+inc_util = include_directories('.')
+
+lib_util = static_library('notmuch-util', notmuch_util_srcs,
+			  include_directories: [inc_compat, inc_util],
+			  dependencies: dep_gmime)
-- 
2.20.1



More information about the notmuch mailing list