From 77acae51a35718bf858e6e20a621ef175642c40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Thu, 8 Feb 2018 11:26:06 +0100 Subject: [PATCH] Port to meson build system meson is a build system focused on speed an ease of use, which helps speeding up the software development. This patch adds meson support along autotools. https://bugs.freedesktop.org/show_bug.cgi?id=104273 --- data/meson.build | 50 ++++++++ doc/dbus/meson.build | 46 ++++++++ doc/libaccountsservice/meson.build | 12 ++ meson.build | 233 +++++++++++++++++++++++++++++++++++++ meson_options.txt | 18 +++ meson_post_install.py | 18 +++ po/meson.build | 1 + src/libaccountsservice/meson.build | 121 +++++++++++++++++++ src/libaccountsservice/symbol.map | 4 + src/meson.build | 72 ++++++++++++ 10 files changed, 575 insertions(+) create mode 100644 data/meson.build create mode 100644 doc/dbus/meson.build create mode 100644 doc/libaccountsservice/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 meson_post_install.py create mode 100644 po/meson.build create mode 100644 src/libaccountsservice/meson.build create mode 100644 src/libaccountsservice/symbol.map create mode 100644 src/meson.build diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..21a4dc4 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,50 @@ +ifaces = files( + 'org.freedesktop.Accounts.xml', + 'org.freedesktop.Accounts.User.xml' +) + +install_data( + ifaces, + install_dir: dbus_ifaces_dir +) + +install_data( + 'org.freedesktop.Accounts.conf', + install_dir: dbus_conf_dir +) + +service_conf = configuration_data() +service_conf.set('libexecdir', act_libexecdir) + +service = 'org.freedesktop.Accounts.service' + +configure_file( + input: service + '.in', + output: service, + configuration: service_conf, + install: true, + install_dir: dbus_sys_dir +) + +policy = 'org.freedesktop.accounts.policy' + +custom_target( + policy, + input: policy + '.in', + output: policy, + command: intltool_xml_cmd, + install: true, + install_dir: polkit_dir +) + +if install_systemd_unit_dir + service = 'accounts-daemon.service' + + configure_file( + input: service + '.in', + output: service, + configuration: service_conf, + install: true, + install_dir: systemd_system_unit_dir + ) +endif diff --git a/doc/dbus/meson.build b/doc/dbus/meson.build new file mode 100644 index 0000000..360dee8 --- /dev/null +++ b/doc/dbus/meson.build @@ -0,0 +1,46 @@ +ifaces_refs = [] + +ifaces = [ + 'org.freedesktop.Accounts', + 'org.freedesktop.Accounts.User', +] + +xsltproc = find_program('xsltproc') +spec_to_docbook = files('spec-to-docbook.xsl') + +foreach iface: ifaces + iface_ref = iface + '.ref.xml' + + ifaces_refs += custom_target( + iface_ref, + input: join_paths(data_dir, iface + '.xml'), + output: iface_ref, + command: [xsltproc, '--output', '@OUTPUT@', spec_to_docbook, '@INPUT@'] + ) +endforeach + +output = 'AccountsService.xml' + +docbook_conf = configuration_data() +docbook_conf.set('srcdir', meson.current_build_dir()) +docbook_conf.set('VERSION', act_version) + +docbook = 'AccountsService.xml' + +docbook_xml = configure_file( + input: docbook + '.in', + output: docbook, + configuration: docbook_conf +) + +html = 'AccountsService.html' + +custom_target( + html, + input: docbook_xml, + output: html, + command: [find_program('xmlto'), 'xhtml-nochunks', '-o', meson.current_build_dir(), '-m', files('config.xsl'), '@INPUT@'], + depends: ifaces_refs, + install: true, + install_dir: join_paths(act_datadir, 'doc', act_name, 'spec') +) diff --git a/doc/libaccountsservice/meson.build b/doc/libaccountsservice/meson.build new file mode 100644 index 0000000..62acdb4 --- /dev/null +++ b/doc/libaccountsservice/meson.build @@ -0,0 +1,12 @@ +doc_module = 'libaccountsservice' + +gnome.gtkdoc( + doc_module, + main_xml: doc_module + '-docs.xml', + src_dir: join_paths(meson.source_root(), 'src', 'libaccountsservice'), + dependencies: libaccountsservice_dep, + mkdb_args: '--name-space=' + act_id.to_lower(), + fixxref_args: '--html-dir=' + join_paths(act_prefix, gnome.gtkdoc_html_dir(doc_module)), + gobject_typesfile: files(doc_module + '.types'), + install: true +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..3af4ba3 --- /dev/null +++ b/meson.build @@ -0,0 +1,233 @@ +project( + 'AccountsService', 'c', + version: '0.6.45', + license: 'GPL3+', + default_options: 'buildtype=debugoptimized', + meson_version: '>= 0.44.0' +) + +act_name = meson.project_name().to_lower() +act_version = meson.project_version() + +act_api_version = '1.0' +act_api_name = '@0@-@1@'.format(act_name, act_api_version) + +act_id = 'Act' + +act_prefix = get_option('prefix') +act_datadir = join_paths(act_prefix, get_option('datadir')) +act_includedir = join_paths(act_prefix, get_option('includedir')) +act_libexecdir = join_paths(act_prefix, get_option('libexecdir')) +act_localstatedir = join_paths(act_prefix, get_option('localstatedir')) + +act_pkgincludedir = join_paths(act_includedir, act_api_name) + +soversion = 0 +current = 0 +revision = 0 +libversion = '@0@.@1@.@2@'.format(soversion, current, revision) + +act_gettext = 'accounts-service' + +act_buildtype = get_option('buildtype') + +cc = meson.get_compiler('c') + +config_h = configuration_data() + +# defines +config_h.set_quoted('VERSION', act_version) +config_h.set('_DEFAULT_SOURCE', true) +config_h.set('_GNU_SOURCE', true) + +# i18n +config_h.set_quoted('GETTEXT_PACKAGE', act_gettext) + +# headers +check_headers = [ + 'paths.h', + 'shadow.h', + 'utmpx.h' +] + +foreach header: check_headers + config_h.set('HAVE_' + header.underscorify().to_upper(), cc.has_header(header)) +endforeach + +# functions +check_functions = [ + 'getusershell', + 'setutxdb', + 'fgetpwent' +] + +foreach func: check_functions + config_h.set('HAVE_' + func.underscorify().to_upper(), cc.has_function(func)) +endforeach + +if cc.has_header_symbol('utmpx.h', 'WTMPX_FILENAME', prefix: '#define _GNU_SOURCE') + config_h.set('PATH_WTMP', 'WTMPX_FILENAME') +elif cc.has_header_symbol('paths.h', '_PATH_WTMPX') + config_h.set('PATH_WTMP', '_PATH_WTMPX') +else + assert(run_command('test', '-e', '/var/log/utx.log').returncode() == 0, 'Do not know which filename to watch for wtmp changes') + config_h.set('PATH_WTMP', '/var/log/utx.log') +endif + +# compiler flags +common_flags = [] + +# Only add this when optimizing is enabled +optimized_src = ''' + #ifdef __OPTIMIZE__ + #error No optimization + #endif +''' + +act_optimized = act_buildtype.contains('optimized') and cc.compiles(optimized_src) +message('whether optimization is enabled: ' + act_optimized.to_string()) +if act_optimized + common_flags += '-Wp,-D_FORTIFY_SOURCE=2' +endif + +if act_buildtype.contains('debug') + test_cflags = [ + '-Wcast-align', + '-Winit-self', + '-Wmissing-declarations', + '-Wmissing-prototypes', + '-Wnested-externs', + '-Wno-deprecated-declarations', + '-Wswitch-enum', + '-Wunsafe-loop-optimizations', + '-Wwrite-strings' + ] + + common_flags += cc.get_supported_arguments(test_cflags) +endif + +add_project_arguments(common_flags, language: 'c') + +version_script_ldflag = '-Wl,--version-script' +have_version_script = host_machine.system().contains('linux') and cc.has_argument(version_script_ldflag) + +dbus_dep = dependency('dbus-1', required: false) +gio_dep = dependency('gio-2.0', version: '>= 2.37.3') +gio_unix_dep = dependency('gio-unix-2.0') +glib_dep = dependency('glib-2.0', version: '>= 2.44') +polkit_dep = dependency('polkit-gobject-1') + +dbus_conf_dir = get_option('dbus_conf_dir') +if dbus_conf_dir == '' + assert(dbus_dep.found(), 'D-Bus required but not found, please provide a valid system bus config dir') + dbus_conf_dir = join_paths(dbus_dep.get_pkgconfig_variable('sysconfdir'), 'dbus-1', 'system.d') +endif + +dbus_ifaces_dir = get_option('dbus_ifaces_dir') +if dbus_ifaces_dir == '' + assert(dbus_dep.found(), 'D-Bus required but not found, please provide a valid interfaces dir') + dbus_ifaces_dir = dbus_dep.get_pkgconfig_variable('interfaces_dir') +endif + +dbus_sys_dir = get_option('dbus_sys_dir') +if dbus_sys_dir == '' + assert(dbus_dep.found(), 'D-Bus required but not found, please provide a valid system bus services dir') + dbus_sys_dir = dbus_dep.get_pkgconfig_variable('system_bus_services_dir') +endif + +# polkit +polkit_dir = get_option('polkit_dir') +if polkit_dir == '' + polkit_dir = polkit_dep.get_pkgconfig_variable('policydir') +endif + +systemd_system_unit_dir = get_option('systemdsystemunitdir') +install_systemd_unit_dir = (systemd_system_unit_dir != 'no') + +if install_systemd_unit_dir and systemd_system_unit_dir == '' + systemd_dep = dependency('systemd', required: false) + assert(systemd_dep.found(), 'systemd required but not found, please provide a valid systemd user unit dir or disable it') + systemd_system_unit_dir = systemd_dep.get_pkgconfig_variable('systemdsystemunitdir') +endif + +# Core configuration +admin_group = get_option('admin_group') +if admin_group == '' + if run_command('test', '-e', '/etc/sysconfig/network-scripts').returncode() == 0 + admin_group = 'wheel' + elif run_command('test', '-e', '/etc/debian_version').returncode() == 0 + admin_group = 'sudo' + else + admin_group = 'wheel' + endif +endif + +extra_admin_groups = ','.join(get_option('extra_admin_groups')) + +config_h.set_quoted('ADMIN_GROUP', admin_group) +config_h.set_quoted('EXTRA_ADMIN_GROUPS', extra_admin_groups) + +config_h.set('ENABLE_USER_HEURISTICS', get_option('user_heuristics')) +config_h.set_quoted('MINIMUM_UID', get_option('minimum_uid')) + +# GDM +gdm_conf_file = get_option('gdmconffile') + +config_h.set_quoted('PATH_GDM_CUSTOM', gdm_conf_file) + +enable_systemd = get_option('systemd') +enable_elogind = get_option('elogind') +assert(not enable_systemd or not enable_elogind, 'systemd and elogind support requested, please choose only one.') + +if enable_systemd + libsystemd_dep = dependency('libsystemd', version: '>= 186') +endif + +if enable_elogind + libelogind_dep = dependency('libelogind', version: '>= 229.4') +endif +config_h.set('WITH_SYSTEMD', enable_systemd or enable_elogind) + +gnome = import('gnome') +i18n = import('i18n') +pkg = import('pkgconfig') + +data_dir = join_paths(meson.source_root(), 'data') +po_dir = join_paths(meson.source_root(), 'po') + +intltool_merge = find_program('intltool-merge') +intltool_cache = join_paths(po_dir, '.intltool-merge-cache') +intltool_desktop_cmd = [intltool_merge, '-d', '-u', '-c', intltool_cache, po_dir, '@INPUT@', '@OUTPUT@'] +intltool_xml_cmd = [intltool_merge, '-x', '-u', '-c', intltool_cache, po_dir, '@INPUT@', '@OUTPUT@'] + +top_inc = include_directories('.') + +subdir('data') +subdir('src') +subdir('po') + +enable_docbook_doc = get_option('docbook_doc') +if enable_docbook_doc + subdir('doc/dbus') +endif + +if get_option('gtk_doc') + subdir('doc/libaccountsservice') +endif + +configure_file( + output: 'config.h', + configuration: config_h +) + +meson.add_install_script( + 'meson_post_install.py', + act_localstatedir +) + +output = '\n' + meson.project_name() + ' was configured with the following options:\n' +output += '** DocBook documentation build: ' + enable_docbook_doc.to_string() + '\n' +output += '** Administrator group: ' + admin_group + '\n' +output += '** Extra administrator groups: ' + extra_admin_groups + '\n' +output += '** GDM configuration: ' + gdm_conf_file +message(output) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..70b9edb --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,18 @@ +option('systemdsystemunitdir', type: 'string', value: '', description: 'custom directory for systemd system units') +option('dbus_conf_dir', type: 'string', value: '', description: 'where D-Bus system.d directory is') +option('dbus_ifaces_dir', type: 'string', value: '', description: 'where D-Bus interfaces directory is') +option('dbus_sys_dir', type: 'string', value: '', description: 'where D-Bus system service directory is') +option('polkit_dir', type: 'string', value: '', description: 'where PolicyKit policy directory is') +option('gdmconffile', type: 'string', value: '/etc/gdm/custom.conf', description: 'GDM configuration file') + +option('admin_group', type: 'string', value: '', description: 'Set group for administrative accounts') +option('user_heuristics', type: 'boolean', value: true, description: 'Enable heuristics for guessing system vs. human users in the range 500-minimum-uid') +option('extra_admin_groups', type: 'array', value: [], description: 'Comma-separated list of extra groups that administrator users are part of') +option('minimum_uid', type: 'string', value: '1000', description: 'Set minimum uid for human users') + +option('systemd', type: 'boolean', value: false, description: 'Use systemd') +option('elogind', type: 'boolean', value: false, description: 'Use elogind') + +option('introspection', type: 'boolean', value: true, description: 'Enable introspection for this build') +option('docbook_doc', type: 'boolean', value: false, description: 'build documentation (requires xmlto)') +option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation') diff --git a/meson_post_install.py b/meson_post_install.py new file mode 100644 index 0000000..abd3bc1 --- /dev/null +++ b/meson_post_install.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import os +import sys + +destdir = os.environ.get('DESTDIR', '') +localstatedir = os.path.normpath(destdir + os.sep + sys.argv[1]) + +# FIXME: meson will not track the creation of these directories +# https://github.com/mesonbuild/meson/blob/master/mesonbuild/scripts/uninstall.py#L39 +dst_dirs = [ + os.path.join(localstatedir, 'lib', 'AccountsService', 'icons'), + os.path.join(localstatedir, 'lib', 'AccountsService', 'users') +] + +for dst_dir in dst_dirs: + if not os.path.exists(dst_dir): + os.makedirs(dst_dir) diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..1227d0f --- /dev/null +++ b/po/meson.build @@ -0,0 +1 @@ +i18n.gettext(act_gettext, preset: 'glib') diff --git a/src/libaccountsservice/meson.build b/src/libaccountsservice/meson.build new file mode 100644 index 0000000..bed08df --- /dev/null +++ b/src/libaccountsservice/meson.build @@ -0,0 +1,121 @@ +subdir = act_id.to_lower() + +act_h = 'act.h' + +headers = files( + 'act-user.h', + 'act-user-manager.h' +) + +install_headers( + headers + [act_h], + install_dir: join_paths(act_pkgincludedir, subdir) +) + +sources = files( + 'act-user.c', + 'act-user-manager.c' +) + +enum_sources = [] +enum_types = 'act-user-enum-types' + +enum_sources += gnome.mkenums( + enum_types + '.h', + sources: headers, + fhead: '#ifndef __ACT_USER_ENUM_TYPES_H__\n#define __ACT_USER_ENUM_TYPES_H__\n\n#include \n\nG_BEGIN_DECLS\n', + fprod: '/* enumerations from "@filename@" */\n', + vhead: 'GType @enum_name@_get_type (void);\n#define ACT_USER_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n', + ftail: 'G_END_DECLS\n\n#endif /* __ACT_USER_ENUM_TYPES_H__ */', + install_header: true, + install_dir: join_paths(act_pkgincludedir, subdir) +) + +enum_sources += gnome.mkenums( + enum_types + '.c', + sources: headers, + fhead: '#include "act-user.h"\n#include "act-user-manager.h"\n#include "act-user-enum-types.h"\n#include \n\n', + fprod: '\n/* enumerations from "@filename@" */', + vhead: 'GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {', + vprod: ' { @VALUENAME@, "@VALUENAME@", "@valuenick@" },', + vtail: ' { 0, NULL, NULL }\n };\n etype = g_@type@_register_static ("@EnumName@", values);\n }\n return etype;\n}\n' +) + +dbus_sources = [] + +ifaces = [ + 'Manager', + 'Seat', + 'Session' +] + +ns = 'ConsoleKit' +prefix = 'org.freedesktop.' + ns + +foreach iface: ifaces + dbus_sources += gnome.gdbus_codegen( + 'ck-@0@-generated'.format(iface.to_lower()), + '@0@.@1@.xml'.format(prefix, iface), + interface_prefix: prefix, + namespace: ns + ) +endforeach + +libaccountsservice_deps = [ + gio_dep, + gio_unix_dep, + glib_dep, + libaccounts_generated_dep, + dependency('libcrypto') +] + +cflags = '-DG_LOG_DOMAIN="@0@"'.format(meson.project_name()) + +symbol_map = join_paths(meson.current_source_dir(), 'symbol.map') + +ldflags = [] +if have_version_script + ldflags += version_script_ldflag + ',@0@'.format(symbol_map) +endif + +libaccountsservice = shared_library( + act_name, + sources: sources + enum_sources + dbus_sources, + version: libversion, + include_directories: top_inc, + dependencies: deps, + c_args: cflags, + link_args: ldflags, + link_depends: symbol_map, + install: true +) + +libaccountsservice_dep = declare_dependency( + include_directories: include_directories('.'), + compile_args: cflags, + link_with: libaccountsservice +) + +pkg.generate( + libraries: libaccountsservice, + version: act_version, + name: 'Accounts Service', + description: 'Client Library for communicating with accounts service', + filebase: act_name, + subdirs: act_api_name, + variables: 'exec_prefix=' + act_prefix +) + +if get_option('introspection') + gnome.generate_gir( + libaccountsservice , + sources: sources + headers + [enum_sources[0]], + dependencies: libaccountsservice_dep, + nsversion: act_api_version, + namespace: meson.project_name(), + identifier_prefix: act_id, + includes: ['GObject-2.0', 'Gio-2.0'], + header: join_paths(subdir, act_h), + install: true + ) +endif diff --git a/src/libaccountsservice/symbol.map b/src/libaccountsservice/symbol.map new file mode 100644 index 0000000..39dd8cb --- /dev/null +++ b/src/libaccountsservice/symbol.map @@ -0,0 +1,4 @@ +{ +local: + _*; +}; diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..511607a --- /dev/null +++ b/src/meson.build @@ -0,0 +1,72 @@ +sources = [] + +ifaces = [ + ['accounts-generated', 'org.freedesktop.', 'Accounts'], + ['accounts-user-generated', 'org.freedesktop.Accounts.', 'User'] +] + +foreach iface: ifaces + sources += gnome.gdbus_codegen( + iface[0], + join_paths(data_dir, iface[1] + iface[2] + '.xml'), + interface_prefix: iface[1], + namespace: 'Accounts' + ) +endforeach + +deps = [ + gio_unix_dep, + glib_dep, + polkit_dep, + cc.find_library('crypt') +] + +cflags = [ + '-DLOCALSTATEDIR="@0@"'.format(act_localstatedir), + '-DDATADIR="@0@"'.format(act_datadir), + '-DICONDIR="@0@"'.format(join_paths(act_localstatedir, 'lib', meson.project_name(), 'icons')), + '-DUSERDIR="@0@"'.format(join_paths(act_localstatedir, 'lib', meson.project_name(), 'users')) +] + +libaccounts_generated = static_library( + 'accounts-generated', + sources: sources, + include_directories: top_inc, + dependencies: deps, + c_args: cflags +) + +libaccounts_generated_dep = declare_dependency( + # FIXME: this must include only the header files due to the + # Opaque target return from gdbus_codegen + # Please see: + # https://bugzilla.gnome.org/show_bug.cgi?id=791015 + # https://github.com/mesonbuild/meson/pull/2930 + sources: sources, + include_directories: include_directories('.'), + link_with: libaccounts_generated +) + +sources = files( + 'daemon.c', + 'extensions.c', + 'main.c', + 'user.c', + 'user-classify.c', + 'util.c', + 'wtmp-helper.c' +) + +deps += libaccounts_generated_dep + +executable( + 'accounts-daemon', + sources, + include_directories: top_inc, + dependencies: deps, + c_args: cflags, + install: true, + install_dir: act_libexecdir +) + +subdir('libaccountsservice') -- 2.16.1