libtraceevent: Add initial support for meson
RFC v2 1/1 libtraceevent: Add initial support for meson
Add support for building the project with meson. It's not complete yet, for example building and installing the documentation is missing.
The rest should work as expected. The only thing I was not really clear what the purpose is the libtraceevent-dynamic-list which seems not be used or installed. The meson build will also generate the file but using the host nm and not the cross tool chain if any is used. I didn't want to invest too much time figuring out this detail if it is actually not used.
Obviously, meson is not make and there are some changes in how to use this build system. The meson documentation is outstanding good and usually has good tips and tricks to solve problems. But sure there is learning curve but hopefully not so step.
Anyway, as pure user the build steps are (in source tree builds are not supported):
# configure using .build as build directory and install destination # /tmp/test meson .build --prefix=/tmp/test
# trigger the build ninja -C .build
# install the library ninja -C .build install
I am using an alias for 'ninja -C .build' which is called 'ni'. This makes way more convenient to use.
---
v2:
- changed include path exported in pkg-config
exports the same paths as per Makefile
v1:
- initial version
include/traceevent/meson.build | 12 ++++++++++ meson.build | 38 ++++++++++++++++++++++++++++++++ meson_options.txt | 2 ++ plugins/dynamic_list.sh | 14 ++++++++++++ plugins/meson.build | 40 ++++++++++++++++++++++++++++++++++ src/meson.build | 35 +++++++++++++++++++++++++++++ utest/meson.build | 14 ++++++++++++ 7 files changed, 155 insertions(+) create mode 100644 include/traceevent/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100755 plugins/dynamic_list.sh create mode 100644 plugins/meson.build create mode 100644 src/meson.build create mode 100644 utest/meson.build
include/traceevent/meson.build new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1 + +headers = [ + 'event-parse.h', + 'event-utils.h', + 'kbuffer.h', + 'trace-seq.h', +] + +foreach h : headers + install_headers(h, subdir : 'traceevent') +endforeach
meson.build new file +38 -0
@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: LGPL-2.1 + +project( + 'libtraceevent', ['c'], + meson_version: '>= 0.47.0', + license: 'LGPL-2.1', + version: '1.5.3', + default_options: [ + 'c_std=gnu99', + 'buildtype=release', + 'prefix=/usr', + 'warning_level=1', + ] +) + +library_version = meson.project_version() + +cunit_dep = dependency('cunit', required : false) + +prefixdir = get_option('prefix') +libdir = join_paths(prefixdir, get_option('libdir')) + +plugindir = get_option('plugindir') == '' ? join_paths(libdir, 'libtraceevent/plugins') : get_option('plugindir') + +add_project_arguments( + [ + '-D_GNU_SOURCE', + '-DPLUGIN_DIR="@0@"'.format(plugindir), + ], + language : 'c', +) + +incdir = include_directories(['include', 'include/traceevent']) + +subdir('src') +subdir('include/traceevent') +subdir('plugins') +subdir('utest')
meson_options.txt new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: LGPL-2.1 +option('plugindir', type : 'string', description : 'set the plugin dir')
plugins/dynamic_list.sh new file +14 -0
@@ -0,0 +1,14 @@ +#!/bin/sh +# SPDX-License-Identifier: LGPL-2.1 + +symbol_type=$(nm -u -D $@ | awk 'NF>1 {print $1}' | xargs echo "U w W" | + tr 'w ' 'W\n' | sort -u | xargs echo) + +if [ "$symbol_type" = "U W" ]; then + echo '{' + + nm -u -D $@ | awk 'NF>1 {sub("@.*", "", $2); print "\t"$2";"}' | + sort -u + + echo '};' +fi
plugins/meson.build new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: LGPL-2.1 + +plugins = [ + 'plugin_jbd2.c', + 'plugin_hrtimer.c', + 'plugin_kmem.c', + 'plugin_kvm.c', + 'plugin_mac80211.c', + 'plugin_sched_switch.c', + 'plugin_function.c', + 'plugin_futex.c', + 'plugin_xen.c', + 'plugin_scsi.c', + 'plugin_cfg80211.c', + 'plugin_tlb.c', +] + +pdeps = [] +foreach plugin : plugins + pdeps += library( + plugin.replace('.c', ''), + plugin, + name_prefix: '', + version: library_version, + dependencies: [libtraceevent_dep], + include_directories: [incdir], + install: true, + install_dir: plugindir) +endforeach + +# not used? +dynamic_list_file = find_program('dynamic_list.sh') +custom_target( + 'dynamic_list', + depends: pdeps, + input: pdeps, + output: 'libtraceevent-dynamic-list', + command: [dynamic_list_file, '@INPUT@'], + capture: true, + build_by_default: true)
src/meson.build new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: LGPL-2.1 + +sources= [ + 'event-parse-api.c', + 'event-parse.c', + 'event-plugin.c', + 'kbuffer-parse.c', + 'parse-filter.c', + 'parse-utils.c', + 'tep_strerror.c', + 'trace-seq.c', +] + +libtraceevent = library( + 'traceevent', + sources, + version: library_version, + include_directories: [incdir], + install: true, +) + +pkg = import('pkgconfig') +pkg.generate(libtraceevent, + subdirs: 'traceevent', + filebase: meson.project_name(), + name: meson.project_name(), + version: meson.project_version(), + description: 'Manage trace event', + url: 'https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/', +) + +libtraceevent_dep = declare_dependency( + include_directories: ['.'], + link_with: libtraceevent, +)
utest/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: LGPL-2.1 + +source = [ + 'trace-utest.c', + 'traceevent-utest.c', +] + +e = executable( + 'trace-utest', + source, + include_directories: [incdir], + dependencies: [libtraceevent_dep, cunit_dep]) + +test('trace-utest', e)
Signature · 1 line
2.36.1
Quoted 9 lines · On Thu, 7 Jul 2022 16:27:23 +0200 Daniel Wagner <[email protected]> wrote:
Add support for building the project with meson. It's not complete yet, for example building and installing the documentation is missing.
The rest should work as expected. The only thing I was not really clear what the purpose is the libtraceevent-dynamic-list which seems not be used or installed. The meson build will also generate the file but using the host nm and not the cross tool chain if any is used. I didn't want to invest too much time figuring out this detail if it is actually not used.
It came over from the perf update. See:
f1489e5dce74a ("tools lib traceevent: Export dynamic symbols used by traceevent plugins")
Not sure it's still needed or not.
Quoted 13 lines
Obviously, meson is not make and there are some changes in how to use this build system. The meson documentation is outstanding good and usually has good tips and tricks to solve problems. But sure there is learning curve but hopefully not so step.
Anyway, as pure user the build steps are (in source tree builds are not supported):
# configure using .build as build directory and install destination # /tmp/test meson .build --prefix=/tmp/test
Quoted 5 lines
# trigger the build ninja -C .build# install the library ninja -C .build install
When this is all and done, it should still be part of "make".
That is, make could do the above for the user.
Quoted 54 lines
I am using an alias for 'ninja -C .build' which is called 'ni'. This makes way more convenient to use.
Signed-off-by Daniel Wagner <[email protected]>---
v2:
- changed include path exported in pkg-config
exports the same paths as perMakefilev1:
- initial versioninclude/traceevent/meson.build | 12 ++++++++++ meson.build | 38 ++++++++++++++++++++++++++++++++ meson_options.txt | 2 ++ plugins/dynamic_list.sh | 14 ++++++++++++ plugins/meson.build | 40 ++++++++++++++++++++++++++++++++++ src/meson.build | 35 +++++++++++++++++++++++++++++ utest/meson.build | 14 ++++++++++++ 7 files changed, 155 insertions(+) create mode 100644 include/traceevent/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100755 plugins/dynamic_list.sh create mode 100644 plugins/meson.build create mode 100644 src/meson.build create mode 100644 utest/meson.buildinclude/traceevent/meson.build new file +12
-0@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1 + +headers = [ + 'event-parse.h', + 'event-utils.h', + 'kbuffer.h', + 'trace-seq.h', +] + +foreach h : headers + install_headers(h, subdir : 'traceevent') +endforeachmeson.build new file +0
-0
meson.build line 5
Quoted 5 lines
meson.build new file +5
-0@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: LGPL-2.1 + +project( + 'libtraceevent', ['c'], + meson_version: '>= 0.47.0',
I get a warning:
WARNING: Project specifies a minimum meson_version '>= 0.47.0' but uses features which were added in newer versions:
* 0.50.0: {'include_directories kwarg of type string'}
meson.build line 11
Quoted 6 lines
meson.build new file +6
-0+ license: 'LGPL-2.1', + version: '1.5.3', + default_options: [ + 'c_std=gnu99', + 'buildtype=release', + 'prefix=/usr',
default should be in /usr/local
-- Steve
Quoted 162 lines
meson.build new file +27
-0+ 'warning_level=1', + ] +) + +library_version = meson.project_version() + +cunit_dep = dependency('cunit', required : false) + +prefixdir = get_option('prefix') +libdir = join_paths(prefixdir, get_option('libdir')) + +plugindir = get_option('plugindir') == '' ? join_paths(libdir, 'libtraceevent/plugins') : get_option('plugindir') + +add_project_arguments( + [ + '-D_GNU_SOURCE', + '-DPLUGIN_DIR="@0@"'.format(plugindir), + ], + language : 'c', +) + +incdir = include_directories(['include', 'include/traceevent']) + +subdir('src') +subdir('include/traceevent') +subdir('plugins') +subdir('utest')meson_options.txt new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: LGPL-2.1 +option('plugindir', type : 'string', description : 'set the plugin dir')plugins/dynamic_list.sh new file +14
-0@@ -0,0 +1,14 @@ +#!/bin/sh +# SPDX-License-Identifier: LGPL-2.1 + +symbol_type=$(nm -u -D $@ | awk 'NF>1 {print $1}' | xargs echo "U w W" | + tr 'w ' 'W\n' | sort -u | xargs echo) + +if [ "$symbol_type" = "U W" ]; then + echo '{' + + nm -u -D $@ | awk 'NF>1 {sub("@.*", "", $2); print "\t"$2";"}' | + sort -u + + echo '};' +fiplugins/meson.build new file +40
-0@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: LGPL-2.1 + +plugins = [ + 'plugin_jbd2.c', + 'plugin_hrtimer.c', + 'plugin_kmem.c', + 'plugin_kvm.c', + 'plugin_mac80211.c', + 'plugin_sched_switch.c', + 'plugin_function.c', + 'plugin_futex.c', + 'plugin_xen.c', + 'plugin_scsi.c', + 'plugin_cfg80211.c', + 'plugin_tlb.c', +] + +pdeps = [] +foreach plugin : plugins + pdeps += library( + plugin.replace('.c', ''), + plugin, + name_prefix: '', + version: library_version, + dependencies: [libtraceevent_dep], + include_directories: [incdir], + install: true, + install_dir: plugindir) +endforeach + +# not used? +dynamic_list_file = find_program('dynamic_list.sh') +custom_target( + 'dynamic_list', + depends: pdeps, + input: pdeps, + output: 'libtraceevent-dynamic-list', + command: [dynamic_list_file, '@INPUT@'], + capture: true, + build_by_default: true)src/meson.build new file +35
-0@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: LGPL-2.1 + +sources= [ + 'event-parse-api.c', + 'event-parse.c', + 'event-plugin.c', + 'kbuffer-parse.c', + 'parse-filter.c', + 'parse-utils.c', + 'tep_strerror.c', + 'trace-seq.c', +] + +libtraceevent = library( + 'traceevent', + sources, + version: library_version, + include_directories: [incdir], + install: true, +) + +pkg = import('pkgconfig') +pkg.generate(libtraceevent, + subdirs: 'traceevent', + filebase: meson.project_name(), + name: meson.project_name(), + version: meson.project_version(), + description: 'Manage trace event', + url: 'https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/', +) + +libtraceevent_dep = declare_dependency( + include_directories: ['.'], + link_with: libtraceevent, +)utest/meson.build new file +14
-0@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: LGPL-2.1 + +source = [ + 'trace-utest.c', + 'traceevent-utest.c', +] + +e = executable( + 'trace-utest', + source, + include_directories: [incdir], + dependencies: [libtraceevent_dep, cunit_dep]) + +test('trace-utest', e)
Hi Steven
Sorry for the late response, just got back from my vacation.
Quoted 13 lines · Steven Rostedt
Quoted 9 lines · On Thu, 7 Jul 2022 16:27:23 +0200 Daniel Wagner <[email protected]> wrote:
Add support for building the project with meson. It's not complete yet, for example building and installing the documentation is missing.
The rest should work as expected. The only thing I was not really clear what the purpose is the libtraceevent-dynamic-list which seems not be used or installed. The meson build will also generate the file but using the host nm and not the cross tool chain if any is used. I didn't want to invest too much time figuring out this detail if it is actually not used.
Quoted 5 lines
It came over from the perf update. See:
f1489e5dce74a("tools lib traceevent: Export dynamic symbols used by traceevent plugins")Not sure it's still needed or not.
After looking a bit closer, libtraceevent is not using this information itself, it's perf which uses this:
tools/perf/Makefile.perf
# # The static build has no dynsym table, so this does not work for # static build. Looks like linker starts to scream about that now # (in Fedora 26) so we need to switch it off for static build. DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST) LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = $(if $(findstring -static,$(LDFLAGS)),,$(DYNAMIC_LIST_LDFLAGS))
Right so the kernel has a copy of libtraceevent under tools/lib/traceevent. But I haven't really understood when this version of libtraceevent is used. I see in
tools/perf/Makefile.config
ifdef LIBTRACEEVENT_DYNAMIC
$(call feature_check,libtraceevent)
ifeq ($(feature-libtraceevent), 1)
EXTLIBS += -ltraceevent
LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent)
LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
else
dummy := $(error Error: No libtraceevent devel library found, please install libtraceevent-devel);
endif
endifSo this clearly searches for the installed version of the library, but the
tools/perf/Makefile.perf
$(LIBTRACEEVENT_DYNAMIC_LIST): libtraceevent_plugins
$(Q)$(MAKE) -C $(TRACE_EVENT_DIR)plugins $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent-dynamic-listis creating the list from the sources shipped with the kernel? I suspect the idea here is to create this list and also install it and let the kernel use libtraceevent list. Unless I am completely confused.
Quoted 15 lines
Quoted 15 lines
Obviously, meson is not make and there are some changes in how to use this build system. The meson documentation is outstanding good and usually has good tips and tricks to solve problems. But sure there is learning curve but hopefully not so step.
Anyway, as pure user the build steps are (in source tree builds are not supported):
# configure using .build as build directory and install destination # /tmp/test meson .build --prefix=/tmp/test# trigger the build ninja -C .build
Quoted 6 lines
Quoted 2 lines
# install the library ninja -C .build installWhen this is all and done, it should still be part of "make".
That is, make could do the above for the user.
Sure, this shouldn't be a big issue. Many project ship a simple Makefile for convenience. Though it should be kept simple and should not aim to support all features IMO.
But given that we currently have a copy of libtraceevent in the kernel, I think we can't really ditch the Makefile unless we also could drop the copy in tools/lib/traceevent.
Quoted 8 lines
meson.build line 5
Quoted 3 lines
meson.build new file +3
-0+project( + 'libtraceevent', ['c'], + meson_version: '>= 0.47.0',I get a warning:
WARNING: Project specifies a minimum
meson_version'>= 0.47.0' but uses features which were added in newer versions:
* 0.50.0: {'include_directorieskwarg of type string'}
Meson 0.64.0 add a new warning. For libnvme I opted to update the minimum version requirement to 0.50.0.
Version 0.47.0 was released on 2018-07-02
Version 0.50.0 was released on 2019-03-10
As reference Debian oldstable ships 0.49.0. Debian oldstable is not likely to update the libtracevent library, so I think it's also okay for the trace-cmd and it's library to depend on 0.50.0
Quoted 8 lines
meson.build line 11
Quoted 6 lines
meson.build new file +6
-0+ license: 'LGPL-2.1', + version: '1.5.3', + default_options: [ + 'c_std=gnu99', + 'buildtype=release', + 'prefix=/usr',default should be in
/usr/local
Sure.
Thanks,
Daniel