chiark / gitweb /
meson: generate m4 preprocessor from config.h (#8914)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 May 2018 09:17:35 +0000 (18:17 +0900)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
meson.build
src/core/meson.build
src/login/meson.build
tools/meson-apply-m4.sh [new file with mode: 0644]

index cf5db8b522a44c1a874fcd0f11b1fa6961ee43f3..2a0721849e72b9eda21428ace9fb7038bf060a31 100644 (file)
@@ -21,7 +21,7 @@ project('elogind', 'c',
 libelogind_version = '0.22.0'
 #endif // 0
 
-# We need the same data in three different formats, ugh!
+# We need the same data in two different formats, ugh!
 # Also, for hysterical reasons, we use different variable
 # names, sometimes. Not all variables are included in every
 # set. Ugh, ugh, ugh!
@@ -37,8 +37,6 @@ substs.set('PACKAGE_URL',          'https://github.com/elogind/elogind')
 #endif // 0
 substs.set('PACKAGE_VERSION',      meson.project_version())
 
-m4_defines = []
-
 #####################################################################
 #if 0 /// elogind does not need this
 # 
@@ -84,10 +82,8 @@ endif
 #if 0 /// UNNEEDED by elogind
 # sysvinit_path = get_option('sysvinit-path')
 # sysvrcnd_path = get_option('sysvrcnd-path')
-# have = sysvinit_path != '' and sysvrcnd_path != ''
-# conf.set10('HAVE_SYSV_COMPAT', have,
+# conf.set10('HAVE_SYSV_COMPAT', sysvinit_path != '' and sysvrcnd_path != '',
 #            description : 'SysV init scripts and rcN.d links are supported')
-# m4_defines += have ? ['-DHAVE_SYSV_COMPAT'] : []
 #endif // 0
 
 # join_paths ignore the preceding arguments if an absolute component is
@@ -870,13 +866,8 @@ substs.set('TTY_GID', tty_gid)
 # endif
 # substs.set('USERS_GID', users_gid)
 # 
-# if get_option('adm-group')
-#         m4_defines += ['-DENABLE_ADM_GROUP']
-# endif
-# 
-# if get_option('wheel-group')
-#         m4_defines += ['-DENABLE_WHEEL_GROUP']
-# endif
+# conf.set10('ENABLE_ADM_GROUP', get_option('adm-group'))
+# conf.set10('ENABLE_WHEEL_GROUP', get_option('wheel-group'))
 # 
 # substs.set('DEV_KVM_MODE', get_option('dev-kvm-mode'))
 # substs.set('GROUP_RENDER_MODE', get_option('group-render-mode'))
@@ -963,7 +954,6 @@ endif
 libseccomp = []
 #endif // 0
 conf.set10('HAVE_SECCOMP', have)
-m4_defines += have ? ['-DHAVE_SECCOMP'] : []
 
 want_selinux = get_option('selinux')
 if want_selinux != 'false' and not fuzzer_build
@@ -976,7 +966,6 @@ else
         libselinux = []
 endif
 conf.set10('HAVE_SELINUX', have)
-m4_defines += have ? ['-DHAVE_SELINUX'] : []
 
 #if 0 /// UNNEEDED by elogind
 # want_apparmor = get_option('apparmor')
@@ -992,12 +981,10 @@ m4_defines += have ? ['-DHAVE_SELINUX'] : []
 libapparmor = []
 #endif // 0
 conf.set10('HAVE_APPARMOR', have)
-m4_defines += have ? ['-DHAVE_APPARMOR'] : []
 
 smack_run_label = get_option('smack-run-label')
 if smack_run_label != ''
         conf.set_quoted('SMACK_RUN_LABEL', smack_run_label)
-        m4_defines += ['-DHAVE_SMACK_RUN_LABEL']
 endif
 
 want_polkit = get_option('polkit')
@@ -1024,7 +1011,6 @@ else
         libacl = []
 endif
 conf.set10('HAVE_ACL', have)
-m4_defines += have ? ['-DHAVE_ACL'] : []
 
 want_audit = get_option('audit')
 if want_audit != 'false' and not fuzzer_build
@@ -1074,7 +1060,6 @@ else
         libpam_misc = []
 endif
 conf.set10('HAVE_PAM', have)
-m4_defines += have ? ['-DHAVE_PAM'] : []
 
 #if 0 /// UNNEEDED by elogind
 # want_microhttpd = get_option('microhttpd')
@@ -1088,7 +1073,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libmicrohttpd = []
 # endif
 # conf.set10('HAVE_MICROHTTPD', have)
-# m4_defines += have ? ['-DHAVE_MICROHTTPD'] : []
 # 
 # want_libcryptsetup = get_option('libcryptsetup')
 # if want_libcryptsetup != 'false' and not fuzzer_build
@@ -1113,7 +1097,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libcurl = []
 # endif
 # conf.set10('HAVE_LIBCURL', have)
-# m4_defines += have ? ['-DHAVE_LIBCURL'] : []
 # 
 # want_libidn = get_option('libidn')
 # want_libidn2 = get_option('libidn2')
@@ -1130,7 +1113,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libidn = []
 # endif
 # conf.set10('HAVE_LIBIDN', have)
-# m4_defines += have ? ['-DHAVE_LIBIDN'] : []
 # if not have and want_libidn2 != 'false' and not fuzzer_build
 #         # libidn is used for both libidn and libidn2 objects
 #         libidn = dependency('libidn2',
@@ -1140,7 +1122,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         have = false
 # endif
 # conf.set10('HAVE_LIBIDN2', have)
-# m4_defines += have ? ['-DHAVE_LIBIDN2'] : []
 # 
 # want_libiptc = get_option('libiptc')
 # if want_libiptc != 'false' and not fuzzer_build
@@ -1152,7 +1133,6 @@ m4_defines += have ? ['-DHAVE_PAM'] : []
 #         libiptc = []
 # endif
 # conf.set10('HAVE_LIBIPTC', have)
-# m4_defines += have ? ['-DHAVE_LIBIPTC'] : []
 # 
 # want_qrencode = get_option('qrencode')
 # if want_qrencode != 'false' and not fuzzer_build
@@ -1402,15 +1382,9 @@ foreach term : ['utmp',
         have = get_option(term)
         name = 'ENABLE_' + term.underscorify().to_upper()
         conf.set10(name, have)
-        m4_defines += have ? ['-D' + name] : []
 endforeach
 
-if get_option('timedated') or get_option('timesyncd')
-        conf.set10('ENABLE_TIMEDATECTL', true)
-        m4_defines += ['-DENABLE_TIMEDATECTL']
-else
-        conf.set10('ENABLE_TIMEDATECTL', false)
-endif
+conf.set10('ENABLE_TIMEDATECTL', get_option('timedated') or get_option('timesyncd'))
 
 want_tests = get_option('tests')
 install_tests = get_option('install-tests')
@@ -1459,6 +1433,8 @@ config_h = configure_file(
         output : 'config.h',
         configuration : conf)
 
+meson_apply_m4 = find_program('tools/meson-apply-m4.sh')
+
 includes = include_directories('src/basic',
                                'src/shared',
                                'src/systemd',
index bfad33b48653143d1c7181fef84fcfb38c23f759..ed4b1e0f061c29e3e5b5e499bd72d7376ad031c0 100644 (file)
@@ -137,7 +137,7 @@ libcore_la_sources = files('''
 #         'load-fragment-gperf.gperf',
 #         input : 'load-fragment-gperf.gperf.m4',
 #         output: 'load-fragment-gperf.gperf',
-#         command : [m4, '-P'] + m4_defines + ['@INPUT@'],
+#         command : [meson_apply_m4, config_h, '@INPUT@'],
 #         capture : true)
 # 
 # load_fragment_gperf_c = custom_target(
index af58bb11a565ad3cbbc19ac43a6d73897d6cd412..e0ba820369428663b8be5c6fe70d5f61a4b0d29a 100644 (file)
@@ -131,7 +131,7 @@ user_runtime_dir_sources = files('''
 #                 '73-seat-late.rules',
 #                 input : '73-seat-late.rules.m4',
 #                 output: '73-seat-late.rules',
-#                 command : [m4, '-P'] + m4_defines + ['@INPUT@'],
+#                 command : [meson_apply_m4, config_h, '@INPUT@'],
 #                 capture : true,
 #                 install : true,
 #                 install_dir : udevrulesdir)
@@ -140,7 +140,7 @@ user_runtime_dir_sources = files('''
 #                 'systemd-user',
 #                 input : 'systemd-user.m4',
 #                 output: 'systemd-user',
-#                 command : [m4, '-P'] + m4_defines + ['@INPUT@'],
+#                 command : [meson_apply_m4, config_h, '@INPUT@'],
 #                 capture : true,
 #                 install : pamconfdir != 'no',
 #                 install_dir : pamconfdir)
diff --git a/tools/meson-apply-m4.sh b/tools/meson-apply-m4.sh
new file mode 100644 (file)
index 0000000..6abe177
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+set -eu
+
+CONFIG=$1
+TARGET=$2
+
+if [ $# -ne 2 ]; then
+        echo 'Invalid number of arguments.'
+        exit 1
+fi
+
+if [ ! -f $CONFIG ]; then
+        echo "$CONFIG not found."
+        exit 2
+fi
+
+if [ ! -f $TARGET ]; then
+        echo "$TARGET not found."
+        exit 3
+fi
+
+DEFINES=$(awk '$1 == "#define" && $3 == "1" { printf "-D%s ", $2 }' $CONFIG)
+
+m4 -P $DEFINES $TARGET