Commit a75ab799 authored by Thomas Haller's avatar Thomas Haller

build: create "config-extra.h" header instead of passing directory variables via CFLAGS

1) the command line gets shorter. I frequently run `make V=1` to see
   the command line arguments for the compiler, and there is a lot
   of noise.

2) define each of these variables at one place. This makes it easy
   to verify that for all compilation units, a particular
   define has the same value. Previously that was not obvious or
   even not the case (see commit e5d1a713
   and commit d63cf1ef).
   The point is to avoid redundancy.

3) not all compilation units need all defines. In fact, most modules
   would only need a few of these defines. We aimed to pass the necessary
   minium of defines to each compilation unit, but that was non-obvious
   to get right and often we set a define that wasn't used. See for example
   "src_settings_plugins_ibft_cppflags" which needlessly had "-DSYSCONFDIR".
   This question is now entirely avoided by just defining all variables in
   a header. We don't care to find the minimum, because every component
   gets anyway all defines from the header.

4) this also avoids the situation, where a module that previously did
   not use a particular define gets modified to require it. Previously,
   that would have required to identify the missing define, and add
   it to the CFLAGS of the complation unit. Since every compilation
   now includes "config-extra.h", all defines are available everywhere.

5) the fact that each define is now available in all compilation units
   could be perceived as a downside. But it isn't, because these defines
   should have a unique name and one specific value. Defining the same
   name with different values, or refer to the same value by different
   names is a bug, not a desirable feature. Since these defines should
   be unique accross the entire tree, there is no problem in providing
   them to every compilation unit.

6) the reason why we generate "config-extra.h" this way, instead of using
   AC_DEFINE() in configure.ac, is due to the particular handling of
   autoconf for directory variables. See [1].
   With meson, it would be trivial to put them into "config.h.meson".
   While that is not easy with autoconf, the "config-extra.h" workaround
   seems still preferable to me.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
parent 1c203330
......@@ -47,6 +47,7 @@ test-*.trs
/autom4te.cache
/build-aux
/config.*
/config-extra.h
/configure
/intltool-*
......
This diff is collapsed.
......@@ -27,9 +27,7 @@ deps = [
]
cflags = clients_cflags + [
'-DSYSCONFDIR="@0@"'.format(nm_sysconfdir),
'-DG_LOG_DOMAIN="@0@"'.format(name),
'-DNMLOCALEDIR="@0@"'.format(nm_localedir)
]
if enable_polkit_agent
......
......@@ -7,7 +7,6 @@ deps = [
clients_cflags = [
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT',
'-DNMLOCALEDIR="@0@"'.format(nm_localedir),
]
cflags = clients_cflags + [
......
......@@ -7,7 +7,6 @@ deps = [
cflags = clients_cflags + [
'-DG_LOG_DOMAIN="@0@"'.format(name),
'-DNMLOCALEDIR="@0@"'.format(nm_localedir)
]
subdir('newt')
......
#mesondefine BINDIR
#mesondefine DATADIR
#mesondefine DHCLIENT_PATH
#mesondefine DHCPCANON_PATH
#mesondefine DHCPCD_PATH
#mesondefine LIBEXECDIR
#mesondefine LOCALSTATEDIR
#mesondefine NMCONFDIR
#mesondefine NMLIBDIR
#mesondefine NMLOCALEDIR
#mesondefine NMPLUGINDIR
#mesondefine NMRUNDIR
#mesondefine NMSTATEDIR
#mesondefine NMVPNDIR
#mesondefine NM_BUILD_BUILDDIR
#mesondefine NM_BUILD_SRCDIR
#mesondefine PPPD_PLUGIN_DIR
#mesondefine PREFIX
#mesondefine RUNDIR
#mesondefine RUNSTATEDIR
#mesondefine SYSCONFDIR
......@@ -31,9 +31,6 @@ deps = [
]
cflags = [
'-DLIBEXECDIR="@0@"'.format(nm_libexecdir),
'-DSYSCONFDIR="@0@"'.format(nm_sysconfdir),
'-DNMCONFDIR="@0@"'.format(nm_pkgconfdir),
'-DG_LOG_DOMAIN="@0@"'.format(name),
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT',
]
......
......@@ -13,8 +13,7 @@ exe = executable(
c_args: [
'-DNETWORKMANAGER_COMPILATION_TEST',
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT',
] +
nm_build_cflags,
],
link_with: libnm_dispatcher_core
)
......
......@@ -144,12 +144,6 @@ deps = [
cflags = [
'-DG_LOG_DOMAIN="@0@"'.format(libnm_name),
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE',
'-DLIBEXECDIR="@0@"'.format(nm_libexecdir),
'-DNMLOCALEDIR="@0@"'.format(nm_localedir),
'-DNMCONFDIR="@0@"'.format(nm_pkgconfdir),
'-DNMLIBDIR="@0@"'.format(nm_pkglibdir),
'-DNMPLUGINDIR="@0@"'.format(nm_plugindir),
'-DNMVPNDIR="@0@"'.format(nm_vpndir)
]
if enable_json_validation
......
......@@ -37,8 +37,7 @@ foreach test_unit: test_units
c_args: [
'-DNETWORKMANAGER_COMPILATION_TEST',
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE',
] +
nm_build_cflags,
],
link_with: libnm_core
)
test(
......
......@@ -19,8 +19,7 @@ foreach test_unit: test_units
c_args:
common_cflags + [
'-DNETWORKMANAGER_COMPILATION_TEST',
] +
nm_build_cflags,
],
)
test(
......
......@@ -102,7 +102,6 @@ deps = [
common_cflags = [
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM_UTIL',
'-DNMLOCALEDIR="@0@"'.format(nm_localedir),
]
cflags = common_cflags + [
......
......@@ -7,7 +7,7 @@ deps = [
cflags = common_cflags + [
'-DNETWORKMANAGER_COMPILATION_TEST',
] + nm_build_cflags
]
test = 'test-libnm-linking'
......
......@@ -8,7 +8,7 @@ test_units = [
cflags = [
'-DNETWORKMANAGER_COMPILATION_TEST',
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM',
] + nm_build_cflags
]
foreach test_unit: test_units
exe = executable(
......
......@@ -54,11 +54,6 @@ nm_pkgstatedir = join_paths(nm_localstatedir, nm_name)
nm_vpndir = join_paths(nm_libdir, nm_name)
nm_plugindir = join_paths(nm_libdir, nm_name, dist_version)
nm_build_cflags = [
'-DNM_BUILD_SRCDIR="@0@"'.format(meson.source_root()),
'-DNM_BUILD_BUILDDIR="@0@"'.format(meson.build_root()),
]
libnm_name = 'libnm'
current = 1
......@@ -874,6 +869,44 @@ configure_file(
configuration: config_h
)
config_extra_h = configuration_data()
config_extra_h.set_quoted('BINDIR', nm_bindir)
config_extra_h.set_quoted('DATADIR', nm_datadir)
if enable_dhclient
config_extra_h.set_quoted('DHCLIENT_PATH', dhclient.path())
endif
if enable_dhcpcanon
config_extra_h.set_quoted('DHCPCANON_PATH', dhcpcanon.path())
endif
if enable_dhcpcd
config_extra_h.set_quoted('DHCPCD_PATH', dhcpcd.path())
endif
config_extra_h.set_quoted('LIBEXECDIR', nm_libexecdir)
config_extra_h.set_quoted('LOCALSTATEDIR', nm_localstatedir)
config_extra_h.set_quoted('NMCONFDIR', nm_pkgconfdir)
config_extra_h.set_quoted('NMLIBDIR', nm_pkglibdir)
config_extra_h.set_quoted('NMLIBDIR', nm_pkglibdir)
config_extra_h.set_quoted('NMLOCALEDIR', nm_localedir)
config_extra_h.set_quoted('NMPLUGINDIR', nm_plugindir)
config_extra_h.set_quoted('NMRUNDIR', nm_pkgrundir)
config_extra_h.set_quoted('NMSTATEDIR', nm_pkgstatedir)
config_extra_h.set_quoted('NMVPNDIR', nm_vpndir)
config_extra_h.set_quoted('NM_BUILD_BUILDDIR', meson.build_root())
config_extra_h.set_quoted('NM_BUILD_SRCDIR', meson.source_root())
config_extra_h.set_quoted('PPPD_PLUGIN_DIR', pppd_plugin_dir)
config_extra_h.set_quoted('PREFIX', nm_prefix)
config_extra_h.set_quoted('RUNDIR', nm_pkgrundir)
config_extra_h.set_quoted('RUNSTATEDIR', nm_runstatedir)
config_extra_h.set_quoted('SBINDIR', nm_sbindir)
config_extra_h.set_quoted('SYSCONFDIR', nm_sysconfdir)
configure_file(
input: 'config-extra.h.meson',
output: 'config-extra.h',
configuration: config_extra_h
)
meson.add_install_script(
'meson_post_install.py',
nm_datadir,
......
......@@ -112,6 +112,8 @@
#include <config.h>
#endif
#include "config-extra.h"
/* for internal compilation we don't want the deprecation macros
* to be in effect. Define the widest range of versions to effectively
* disable deprecation checks */
......
......@@ -15,7 +15,6 @@ libnm_device_plugin_ovs = shared_module(
'nm-device-plugin-ovs',
sources: sources,
dependencies: deps,
c_args: '-DRUNSTATEDIR="@0@"'.format(nm_runstatedir),
link_args: ldflags_linker_script_devices,
link_depends: linker_script_devices,
install: true,
......
......@@ -3,7 +3,6 @@ name = 'nm-dhcp-helper'
cflags = [
'-DG_LOG_DOMAIN="@0@"'.format(name),
'-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_GLIB',
'-DNMRUNDIR="@0@"'.format(nm_pkgrundir),
]
executable(
......
......@@ -8,7 +8,6 @@ foreach test_unit: test_units
test_unit,
test_unit + '.c',
dependencies: test_nm_dep,
c_args: nm_build_cflags,
)
test(
......
......@@ -17,35 +17,7 @@ nm_dep = declare_dependency(
compile_args: nm_cflags
)
cflags = nm_cflags + [
'-DPREFIX="@0@"'.format(nm_prefix),
'-DBINDIR="@0@"'.format(nm_bindir),
'-DDATADIR="@0@"'.format(nm_datadir),
'-DLIBEXECDIR="@0@"'.format(nm_libexecdir),
'-DLOCALSTATEDIR="@0@"'.format(nm_localstatedir),
'-DRUNSTATEDIR="@0@"'.format(nm_runstatedir),
'-DSBINDIR="@0@"'.format(nm_sbindir),
'-DSYSCONFDIR="@0@"'.format(nm_sysconfdir),
'-DRUNDIR="@0@"'.format(nm_pkgrundir),
'-DNMCONFDIR="@0@"'.format(nm_pkgconfdir),
'-DNMLOCALEDIR="@0@"'.format(nm_localedir),
'-DNMPLUGINDIR="@0@"'.format(nm_plugindir),
'-DNMRUNDIR="@0@"'.format(nm_pkgrundir),
'-DNMSTATEDIR="@0@"'.format(nm_pkgstatedir),
'-DNMLIBDIR="@0@"'.format(nm_pkglibdir)
]
if enable_dhcpcanon
cflags += '-DDHCPCANON_PATH="@0@"'.format(dhcpcanon.path())
endif
if enable_dhclient
cflags += '-DDHCLIENT_PATH="@0@"'.format(dhclient.path())
endif
if enable_dhcpcd
cflags += '-DDHCPCD_PATH="@0@"'.format(dhcpcd.path())
endif
cflags = nm_cflags
sources = files(
'dhcp/nm-dhcp-client.c',
......
......@@ -31,7 +31,6 @@ core_plugins += shared_module(
name,
sources: 'nm-ppp-manager.c',
dependencies: deps,
c_args: '-DPPPD_PLUGIN_DIR="@0@"'.format(pppd_plugin_dir),
link_args: [
'-Wl,--version-script,@0@'.format(linker_script),
],
......
name = 'nm-settings-plugin-ibft'
cflags = [
'-DSBINDIR="@0@"'.format(nm_sbindir),
'-DSYSCONFDIR="@0@"'.format(nm_sysconfdir)
]
libnms_ibft_core = static_library(
'nms-ibft-core',
'nms-ibft-reader.c',
dependencies: nm_dep,
c_args: cflags
)
sources = files(
......@@ -21,7 +15,6 @@ libnm_settings_plugin_ibft = shared_module(
name,
sources: sources,
dependencies: nm_dep,
c_args: cflags,
link_with: libnms_ibft_core,
link_args: ldflags_linker_script_settings,
link_depends: linker_script_settings,
......
......@@ -6,7 +6,6 @@ exe = executable(
test_unit,
test_unit + '.c',
dependencies: test_nm_dep,
c_args: nm_build_cflags,
link_with: libnms_ibft_core
)
......
......@@ -3,11 +3,6 @@ install_data(
install_dir: dbus_conf_dir
)
cflags = [
'-DSBINDIR="@0@"'.format(nm_sbindir),
'-DSYSCONFDIR="@0@"'.format(nm_sysconfdir)
]
name = 'nmdbus-ifcfg-rh'
dbus_sources = gnome.gdbus_codegen(
......@@ -21,7 +16,6 @@ libnmdbus_ifcfg_rh = static_library(
name,
sources: dbus_sources,
dependencies: glib_dep,
c_args: cflags
)
sources = files(
......@@ -41,7 +35,6 @@ libnms_ifcfg_rh_core = static_library(
'nms-ifcfg-rh-core',
sources: sources,
dependencies: deps,
c_args: cflags
)
sources = [dbus_sources] + files('nms-ifcfg-rh-connection.c')
......@@ -50,7 +43,6 @@ libnm_settings_plugin_ifcfg_rh = shared_module(
'nm-settings-plugin-ifcfg-rh',
sources: sources,
dependencies: deps,
c_args: cflags,
link_with: [libnms_ifcfg_rh_core],
link_args: ldflags_linker_script_settings,
link_depends: linker_script_settings,
......
......@@ -6,7 +6,6 @@ exe = executable(
test_unit,
test_unit + '.c',
dependencies: test_nm_dep,
c_args: nm_build_cflags,
link_with: libnms_ifcfg_rh_core
)
......
......@@ -8,13 +8,10 @@ deps = [
nm_dep
]
cflags = '-DSYSCONFDIR="@0@"'.format(nm_sysconfdir)
libnms_ifupdown_core = static_library(
'nms-ifupdown-core',
sources: sources,
dependencies: deps,
c_args: cflags
)
sources = files(
......@@ -26,7 +23,6 @@ libnm_settings_plugin_ifupdown = shared_module(
'nm-settings-plugin-ifupdown',
sources: sources,
dependencies: deps,
c_args: cflags,
link_with: libnms_ifupdown_core,
link_args: ldflags_linker_script_settings,
link_depends: linker_script_settings,
......
......@@ -4,7 +4,6 @@ exe = executable(
test_unit,
test_unit + '.c',
dependencies: test_nm_dep,
c_args: nm_build_cflags,
link_with: libnms_ifupdown_core
)
......
......@@ -6,7 +6,6 @@ exe = executable(
test_unit,
test_unit + '.c',
dependencies: test_nm_dep,
c_args: nm_build_cflags,
)
test(
......
......@@ -4,7 +4,6 @@ exe = executable(
test_unit,
test_unit + '.c',
dependencies: test_nm_dep,
c_args: nm_build_cflags,
)
test(
......
......@@ -11,7 +11,6 @@ exe = executable(
test_unit,
sources,
dependencies: test_nm_dep,
c_args: nm_build_cflags,
)
test(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment