• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2#
3# Copyright (c) 2023 Daniel Wagner, SUSE LLC
4
5project(
6    'trace-cmd', ['c'],
7    meson_version: '>= 0.50.0',
8    license: 'GPL-2.0',
9    version: '3.3.1',
10    default_options: [
11        'c_std=gnu99',
12        'buildtype=debug',
13        'default_library=both',
14        'prefix=/usr/local',
15        'warning_level=1'])
16
17cc = meson.get_compiler('c')
18
19prefixdir = get_option('prefix')
20datadir = join_paths(prefixdir, get_option('datadir'))
21bindir = join_paths(prefixdir, get_option('bindir'))
22mandir = join_paths(prefixdir, get_option('mandir'))
23htmldir = join_paths(prefixdir, get_option('htmldir'))
24
25conf = configuration_data()
26
27libtraceevent_dep = dependency('libtraceevent', version: '>= 1.5.0', required: true)
28libtracefs_dep = dependency('libtracefs', version: '>= 1.8.0', required: true)
29
30threads_dep = dependency('threads', required: true)
31dl_dep = cc.find_library('dl', required : false)
32
33zlib_dep = dependency('zlib', required: false)
34conf.set('HAVE_ZLIB', zlib_dep.found(), description: 'Is zlib avialable?')
35
36libzstd_dep = dependency('libzstd', version: '>= 1.4.0', required: false)
37conf.set('HAVE_ZSTD', libzstd_dep.found(), description: 'Is libzstd available?')
38
39cunit_dep = dependency('cunit', required : false)
40
41vsock_defined = get_option('vsock') and cc.has_header('linux/vm_sockets.h')
42conf.set('VSOCK', vsock_defined, description: 'Is vsock available?')
43
44perf_defined = cc.has_header('linux/perf_event.h')
45conf.set('PERF', perf_defined, description: 'Is perf available?')
46
47have_ptrace = get_option('ptrace') and cc.compiles(
48    '''
49    #include <stdio.h>
50    #include <sys/ptrace.h>
51
52    int main (void)
53    {
54            int ret;
55            ret = ptrace(PTRACE_ATTACH, 0, NULL, 0);
56            ptrace(PTRACE_TRACEME, 0, NULL, 0);
57            ptrace(PTRACE_GETSIGINFO, 0, NULL, NULL);
58            ptrace(PTRACE_GETEVENTMSG, 0, NULL, NULL);
59            ptrace(PTRACE_SETOPTIONS, NULL, NULL,
60                           PTRACE_O_TRACEFORK |
61                           PTRACE_O_TRACEVFORK |
62                           PTRACE_O_TRACECLONE |
63                           PTRACE_O_TRACEEXIT);
64            ptrace(PTRACE_CONT, NULL, NULL, 0);
65            ptrace(PTRACE_DETACH, 0, NULL, NULL);
66            ptrace(PTRACE_SETOPTIONS, 0, NULL,
67                   PTRACE_O_TRACEFORK |
68                   PTRACE_O_TRACEVFORK |
69                   PTRACE_O_TRACECLONE |
70                   PTRACE_O_TRACEEXIT);
71            return ret;
72    }
73    ''',
74    name: 'ptrace')
75if not have_ptrace
76    conf.set10('NO_PTRACE', true, description: 'Is ptrace missing?')
77    conf.set('WARN_NO_PTRACE', true, description: 'Issue no ptrace warning?')
78endif
79
80audit_dep = dependency('audit', required: false)
81if not audit_dep.found()
82    conf.set10('NO_AUDIT', true, description: 'Is audit missing?')
83    conf.set('WARN_NO_AUDIT', true, description: 'Issue no audit warning?')
84endif
85
86config_h = configure_file(
87    output: 'config.h',
88    configuration: conf
89)
90
91version = meson.project_version().split('.')
92
93vconf = configuration_data()
94vconf.set('VERSION_CODE', version[0].to_int() * 256 + version[1].to_int())
95vconf.set('EXTRAVERSION', '"@0@"'.format(version[2]))
96vconf.set('FILE_VERSION', '""')
97vconf.set('VERSION_STRING', '"@0@"'.format(meson.project_version()))
98
99version_tag = get_option('version-tag')
100if version_tag != ''
101    vconf.set('VERSION_GIT', '"@0@"'.format(version_tag))
102else
103    r = run_command(
104        'meson-vcs-tag.sh',
105        meson.current_source_dir(),
106        meson.project_version(),
107        check: true)
108    vconf.set('VERSION_GIT', '"@0@"'.format(r.stdout().strip()))
109endif
110version_h = configure_file(
111    output: 'tc_version.h',
112    configuration: vconf)
113
114add_project_arguments(
115    [
116      '-D_GNU_SOURCE',
117      '-include', 'config.h',
118    ],
119    language : 'c')
120
121incdir = include_directories(['.', 'include'])
122
123# libtracecmd: trace-cmd currently depends on a statically linked
124# libtracecmd.  libtracecmd is sill very strongly coupled with
125# trace-cmd (or the other way around). To reduce the development setup
126# complexity we add some of the 'top meson.build' from libtracecmd and
127# make it simpler to use.
128library_version = '1.5.1'
129libtracecmd_standalone_build = false
130libtracecmd_ext_incdir = include_directories(
131    [
132        'include',
133        'include/trace-cmd',
134        'tracecmd/include'
135    ])
136subdir('lib/trace-cmd/include')
137subdir('lib/trace-cmd/include/private')
138subdir('lib/trace-cmd')
139
140# trace-cmd
141subdir('tracecmd')
142subdir('python')
143if cunit_dep.found()
144    subdir('utest')
145endif
146subdir('Documentation/trace-cmd')
147
148custom_target(
149    'docs',
150    output: 'docs',
151    depends: [html, man],
152    command: ['echo'])
153