From 15e7a61aa7090942cc7714da4db6ff46bc9b8d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 3 Feb 2022 18:52:54 +0100 Subject: [PATCH] treewide: only define feature macros when the feature is available Most feature checks already use #ifdef, and do not care about the value of the macro. Convert all feature checks to do that, and simplify the meson build scripts by replacing if cond cdata.set('X', 1) endif with cdata.set('X', cond) --- meson.build | 68 ++++++------------- spa/plugins/bluez5/backend-native.c | 2 +- spa/plugins/bluez5/meson.build | 26 +++---- src/gst/gstpipewire.c | 2 +- src/modules/meson.build | 2 +- src/modules/module-access.c | 4 +- src/modules/module-protocol-native.c | 2 +- .../module-protocol-native/local-socket.c | 2 +- .../module-protocol-pulse/pulse-server.c | 4 +- src/pipewire/conf.c | 2 +- src/pipewire/utils.c | 2 +- test/pwtest-compat.c | 2 +- test/pwtest.c | 10 +-- test/test-context.c | 2 +- test/test-pwtest.c | 2 +- 15 files changed, 49 insertions(+), 83 deletions(-) diff --git a/meson.build b/meson.build index 6f723df7f..2f6dc233b 100644 --- a/meson.build +++ b/meson.build @@ -218,38 +218,29 @@ check_headers = [ ] foreach h : check_headers - if cc.has_header(h.get(0)) - cdata.set(h.get(1), 1) - endif + cdata.set(h.get(1), cc.has_header(h.get(0))) endforeach -if cc.has_function('gettid', prefix : '#include', args: [ '-D_GNU_SOURCE' ]) - cdata.set('HAVE_GETTID', 1) -endif +check_functions = [ + ['gettid', '#include ', ['-D_GNU_SOURCE']], + ['memfd_create', '#include ', ['-D_GNU_SOURCE']], + ['getrandom', '#include \n#include ', ['-D_GNU_SOURCE']], + ['sigabbrev_np', '#include ', ['-D_GNU_SOURCE']], +] -if cc.has_function('memfd_create', prefix : '#include ', args : [ '-D_GNU_SOURCE' ]) - cdata.set('HAVE_MEMFD_CREATE', 1) -endif +foreach f : check_functions + cdata.set('HAVE_' + f.get(0).to_upper(), + cc.has_function(f.get(0), prefix: f.get(1), args: f.get(2))) +endforeach -if cc.has_function('getrandom', prefix : '#include \n#include ', args : [ '-D_GNU_SOURCE' ]) - cdata.set('HAVE_GETRANDOM', 1) -endif - -if cc.has_function('sigabbrev_np', prefix : '#include ', args : [ '-D_GNU_SOURCE' ]) - cdata.set('HAVE_SIGABBREV_NP', 1) -endif - -if cc.get_define('SYS_pidfd_open', prefix : '#include ') != '' - cdata.set('HAVE_PIDFD_OPEN', 1) -endif +cdata.set('HAVE_PIDFD_OPEN', + cc.get_define('SYS_pidfd_open', prefix: '#include ') != '') systemd = dependency('systemd', required: get_option('systemd')) systemd_dep = dependency('libsystemd',required: get_option('systemd')) summary({'systemd conf data': systemd.found()}, bool_yn: true) summary({'libsystemd': systemd_dep.found()}, bool_yn: true) -if systemd.found() and systemd_dep.found() - cdata.set('HAVE_SYSTEMD', 1) -endif +cdata.set('HAVE_SYSTEMD', systemd.found() and systemd_dep.found()) configinc = include_directories('.') includes_inc = include_directories('include') @@ -276,9 +267,7 @@ dl_lib = cc.find_library('dl', required : false) pthread_lib = dependency('threads') dbus_dep = dependency('dbus-1', required : get_option('dbus')) summary({'dbus (Bluetooth, rt, portal, pw-reserve)': dbus_dep.found()}, bool_yn: true, section: 'Misc dependencies') -if dbus_dep.found() - cdata.set('HAVE_DBUS', 1) -endif +cdata.set('HAVE_DBUS', dbus_dep.found()) sdl_dep = dependency('sdl2', required : get_option('sdl2')) summary({'SDL2 (video examples)': sdl_dep.found()}, bool_yn: true, section: 'Misc dependencies') drm_dep = dependency('libdrm', required : false) @@ -292,9 +281,7 @@ summary({'readline (for pw-cli)': readline_dep.found()}, bool_yn: true, section: ncurses_dep = dependency('ncursesw', required : false) sndfile_dep = dependency('sndfile', version : '>= 1.0.20', required : get_option('sndfile')) summary({'sndfile': sndfile_dep.found()}, bool_yn: true, section: 'pw-cat/pw-play/pw-dump/filter-chain') -if sndfile_dep.found() - cdata.set('HAVE_SNDFILE', 1) -endif +cdata.set('HAVE_SNDFILE', sndfile_dep.found()) pulseaudio_dep = dependency('libpulse', required : get_option('libpulse')) summary({'libpulse': pulseaudio_dep.found()}, bool_yn: true, section: 'Streaming between daemons') avahi_dep = dependency('avahi-client', required : get_option('avahi')) @@ -311,14 +298,10 @@ summary({'libcanberra (x11-bell)': canberra_dep.found()}, bool_yn: true, libusb_dep = dependency('libusb-1.0', required : get_option('libusb')) summary({'libusb (Bluetooth quirks)': libusb_dep.found()}, bool_yn: true, section: 'Backend') -if libusb_dep.found() - cdata.set('HAVE_LIBUSB', 1) -endif +cdata.set('HAVE_LIBUSB', libusb_dep.found()) cap_lib = dependency('libcap', required : false) -if cap_lib.found() - cdata.set('HAVE_LIBCAP', 1) -endif +cdata.set('HAVE_LIBCAP', cap_lib.found()) gst_option = get_option('gstreamer') gst_deps_def = { @@ -353,18 +336,13 @@ endforeach gst_dp_found = gst_dep.length() > 0 summary({'gstreamer-device-provider': gst_dp_found}, bool_yn: true, section: 'Backend') -if not get_option('gstreamer-device-provider').disabled() - cdata.set('HAVE_GSTREAMER_DEVICE_PROVIDER', 1) -endif +cdata.set('HAVE_GSTREAMER_DEVICE_PROVIDER', not get_option('gstreamer-device-provider').disabled()) webrtc_dep = dependency('webrtc-audio-processing', version : ['>= 0.2', '< 1.0'], required : get_option('echo-cancel-webrtc')) summary({'WebRTC Echo Canceling': webrtc_dep.found()}, bool_yn: true, section: 'Misc dependencies') - -if webrtc_dep.found() - cdata.set('HAVE_WEBRTC', 1) -endif +cdata.set('HAVE_WEBRTC', webrtc_dep.found()) # On FreeBSD, epoll-shim library is required for eventfd() and timerfd() epoll_shim_dep = (build_machine.system() == 'freebsd' @@ -400,9 +378,7 @@ summary({'OpenSSL (for raop-sink)': openssl_lib.found()}, bool_yn: true) lilv_lib = dependency('lilv-0', required: get_option('lv2')) summary({'lilv (for lv2 plugins)': lilv_lib.found()}, bool_yn: true) -if lilv_lib.found() - cdata.set('HAVE_LILV', 1) -endif +cdata.set('HAVE_LILV', lilv_lib.found()) installed_tests_metadir = pipewire_datadir / 'installed-tests' / pipewire_name installed_tests_execdir = pipewire_libexecdir / 'installed-tests' / pipewire_name @@ -411,7 +387,7 @@ installed_tests_template = files('template.test.in') if not get_option('tests').disabled() gstack = find_program('gstack', required : false) - cdata.set10('HAVE_GSTACK', gstack.found()) + cdata.set('HAVE_GSTACK', gstack.found()) endif subdir('po') diff --git a/spa/plugins/bluez5/backend-native.c b/spa/plugins/bluez5/backend-native.c index af789b704..28885e88e 100644 --- a/spa/plugins/bluez5/backend-native.c +++ b/spa/plugins/bluez5/backend-native.c @@ -594,7 +594,7 @@ static bool device_supports_required_mSBC_transport_modes( /* Check if USB ALT6 is really available on the device */ if (device->adapter->bus_type == BUS_TYPE_USB && !msbc_alt1_ok && msbc_ok) { -#if HAVE_LIBUSB +#ifdef HAVE_LIBUSB if (device->adapter->source_id == SOURCE_ID_USB) { msbc_ok = check_usb_altsetting_6(backend, device->adapter->vendor_id, device->adapter->product_id); diff --git a/spa/plugins/bluez5/meson.build b/spa/plugins/bluez5/meson.build index 4ae169771..7a1e12ec7 100644 --- a/spa/plugins/bluez5/meson.build +++ b/spa/plugins/bluez5/meson.build @@ -5,24 +5,14 @@ foreach dep: bluez5_deps endif endforeach -if not get_option('bluez5-backend-hsp-native').disabled() - cdata.set('HAVE_BLUEZ_5_BACKEND_HSP_NATIVE', 1) - cdata.set('HAVE_BLUEZ_5_BACKEND_NATIVE', 1) -endif -if not get_option('bluez5-backend-hfp-native').disabled() - cdata.set('HAVE_BLUEZ_5_BACKEND_HFP_NATIVE', 1) - cdata.set('HAVE_BLUEZ_5_BACKEND_NATIVE', 1) -endif -if not get_option('bluez5-backend-ofono').disabled() - cdata.set('HAVE_BLUEZ_5_BACKEND_OFONO', 1) -endif -if not get_option('bluez5-backend-hsphfpd').disabled() - cdata.set('HAVE_BLUEZ_5_BACKEND_HSPHFPD', 1) -endif - -if dependency('bluez', version: '< 6', required: false).found() - cdata.set('HAVE_BLUEZ_5_HCI', 1) -endif +cdata.set('HAVE_BLUEZ_5_BACKEND_NATIVE', + not get_option('bluez5-backend-hsp-native').disabled() or + not get_option('bluez5-backend-hfp-native').disabled()) +cdata.set('HAVE_BLUEZ_5_BACKEND_HSP_NATIVE', not get_option('bluez5-backend-hsp-native').disabled()) +cdata.set('HAVE_BLUEZ_5_BACKEND_HFP_NATIVE', not get_option('bluez5-backend-hfp-native').disabled()) +cdata.set('HAVE_BLUEZ_5_BACKEND_OFONO', not get_option('bluez5-backend-ofono').disabled()) +cdata.set('HAVE_BLUEZ_5_BACKEND_HSPHFPD', not get_option('bluez5-backend-hsphfpd').disabled()) +cdata.set('HAVE_BLUEZ_5_HCI', dependency('bluez', version: '< 6', required: false).found()) bluez5_sources = [ 'plugin.c', diff --git a/src/gst/gstpipewire.c b/src/gst/gstpipewire.c index 56b864dee..b87f8a366 100644 --- a/src/gst/gstpipewire.c +++ b/src/gst/gstpipewire.c @@ -51,7 +51,7 @@ plugin_init (GstPlugin *plugin) gst_element_register (plugin, "pipewiresink", GST_RANK_NONE, GST_TYPE_PIPEWIRE_SINK); -#if HAVE_GSTREAMER_DEVICE_PROVIDER +#ifdef HAVE_GSTREAMER_DEVICE_PROVIDER if (!gst_device_provider_register (plugin, "pipewiredeviceprovider", GST_RANK_PRIMARY + 1, GST_TYPE_PIPEWIRE_DEVICE_PROVIDER)) return FALSE; diff --git a/src/modules/meson.build b/src/modules/meson.build index 5000b9104..69839f124 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -273,7 +273,7 @@ if avahi_dep.found() 'module-zeroconf-discover/avahi-poll.c', ] pipewire_module_protocol_pulse_deps += avahi_dep - cdata.set('HAVE_AVAHI', 1) + cdata.set('HAVE_AVAHI', true) endif pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse', diff --git a/src/modules/module-access.c b/src/modules/module-access.c index ceb10b7ea..a5df8aa5e 100644 --- a/src/modules/module-access.c +++ b/src/modules/module-access.c @@ -32,10 +32,10 @@ #include "config.h" -#if HAVE_SYS_VFS_H +#ifdef HAVE_SYS_VFS_H #include #endif -#if HAVE_SYS_MOUNT_H +#ifdef HAVE_SYS_MOUNT_H #include #endif diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 9b1180b1b..b2874b592 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -35,7 +35,7 @@ #include #include #include -#if HAVE_PWD_H +#ifdef HAVE_PWD_H #include #endif #if defined(__FreeBSD__) diff --git a/src/modules/module-protocol-native/local-socket.c b/src/modules/module-protocol-native/local-socket.c index 4b5bcd161..a21636c12 100644 --- a/src/modules/module-protocol-native/local-socket.c +++ b/src/modules/module-protocol-native/local-socket.c @@ -35,7 +35,7 @@ #include #include #include -#if HAVE_PWD_H +#ifdef HAVE_PWD_H #include #endif diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index eedb23901..3c8a39971 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -5105,7 +5105,7 @@ static void impl_clear(struct impl *impl) pw_map_for_each(&impl->modules, impl_unload_module, impl); pw_map_clear(&impl->modules); -#if HAVE_DBUS +#ifdef HAVE_DBUS if (impl->dbus_name) { dbus_release_name(impl->dbus_name); impl->dbus_name = NULL; @@ -5276,7 +5276,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, pw_context_add_listener(context, &impl->context_listener, &context_events, impl); -#if HAVE_DBUS +#ifdef HAVE_DBUS impl->dbus_name = dbus_request_name(context, "org.pulseaudio.Server"); #endif diff --git a/src/pipewire/conf.c b/src/pipewire/conf.c index d85ab861e..85287eefa 100644 --- a/src/pipewire/conf.c +++ b/src/pipewire/conf.c @@ -34,7 +34,7 @@ #include #include #include -#if HAVE_PWD_H +#ifdef HAVE_PWD_H #include #endif #ifdef __FreeBSD__ diff --git a/src/pipewire/utils.c b/src/pipewire/utils.c index e69ea2147..2f3240faf 100644 --- a/src/pipewire/utils.c +++ b/src/pipewire/utils.c @@ -27,7 +27,7 @@ #include #include #include -#if HAVE_SYS_RANDOM_H +#ifdef HAVE_SYS_RANDOM_H #include #endif #include diff --git a/test/pwtest-compat.c b/test/pwtest-compat.c index b10d04ec1..fa8975698 100644 --- a/test/pwtest-compat.c +++ b/test/pwtest-compat.c @@ -24,7 +24,7 @@ #include "config.h" -#if !HAVE_SIGABBREV_NP +#ifndef HAVE_SIGABBREV_NP #include #include diff --git a/test/pwtest.c b/test/pwtest.c index 5641c9ae4..3588c88af 100644 --- a/test/pwtest.c +++ b/test/pwtest.c @@ -36,10 +36,10 @@ #include #include #include -#if HAVE_PIDFD_OPEN +#ifdef HAVE_PIDFD_OPEN #include #endif -#if HAVE_LIBCAP +#ifdef HAVE_LIBCAP #include #endif #include @@ -177,7 +177,7 @@ static void restore_env(struct pwtest_test *t) static void pwtest_backtrace(pid_t p) { -#if HAVE_GSTACK +#ifdef HAVE_GSTACK char pid[11]; pid_t parent, child; int status; @@ -820,7 +820,7 @@ static int monitor_test_forked(struct pwtest_test *t, pid_t pid, int read_fds[_F size_t nevents = 0; int r; -#if HAVE_PIDFD_OPEN +#ifdef HAVE_PIDFD_OPEN pidfd = syscall(SYS_pidfd_open, pid, 0); #else errno = ENOSYS; @@ -1168,7 +1168,7 @@ static void list_tests(struct pwtest_context *ctx) static bool is_debugger_attached(void) { bool rc = false; -#if HAVE_LIBCAP +#ifdef HAVE_LIBCAP int status; int pid = fork(); diff --git a/test/test-context.c b/test/test-context.c index f3e5a63d8..3625d35a0 100644 --- a/test/test-context.c +++ b/test/test-context.c @@ -233,7 +233,7 @@ PWTEST(context_support) SPA_TYPE_INTERFACE_Loop, SPA_TYPE_INTERFACE_LoopUtils, SPA_TYPE_INTERFACE_Log, -#if HAVE_DBUS +#ifdef HAVE_DBUS SPA_TYPE_INTERFACE_DBus, #endif SPA_TYPE_INTERFACE_CPU diff --git a/test/test-pwtest.c b/test/test-pwtest.c index 03cad70cd..9242d4c19 100644 --- a/test/test-pwtest.c +++ b/test/test-pwtest.c @@ -32,7 +32,7 @@ PWTEST(compat_sigabbrev_np) { -#if !HAVE_SIGABBREV_NP +#ifndef HAVE_SIGABBREV_NP pwtest_str_eq(sigabbrev_np(SIGABRT), "ABRT"); pwtest_str_eq(sigabbrev_np(SIGSEGV), "SEGV"); pwtest_str_eq(sigabbrev_np(SIGSTOP), "STOP");