summaryrefslogtreecommitdiffstats
path: root/src/core/bpf/meson.build
blob: 57a4c5393c90737bbb7888473f1dde789db4e050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# SPDX-License-Identifier: LGPL-2.1+

if conf.get('BPF_FRAMEWORK') != 1
        subdir_done()
endif

clang_flags = [
        '-Wno-compare-distinct-pointer-types',
        '-O2',
        '-target',
        'bpf',
        '-g',
        '-c',
]

# Generate defines that are appropriate to tell the compiler what architecture
# we're compiling for. By default we just map meson's cpu_family to __<cpu_family>__.
# This dictionary contains the exceptions where this doesn't work.
#
# C.f. https://mesonbuild.com/Reference-tables.html#cpu-families
# and src/basic/missing_syscall_def.h.
cpu_arch_defines = {
        'ppc'     : ['-D__powerpc__'],
        'ppc64'   : ['-D__powerpc64__', '-D_CALL_ELF=2'],
        'riscv32' : ['-D__riscv', '-D__riscv_xlen=32'],
        'riscv64' : ['-D__riscv', '-D__riscv_xlen=64'],
        'x86'     : ['-D__i386__'],

        # For arm, assume hardware fp is available.
        'arm'     : ['-D__arm__', '-D__ARM_PCS_VFP'],
}

clang_arch_flags = cpu_arch_defines.get(host_machine.cpu_family(),
                                        ['-D__@0@__'.format(host_machine.cpu_family())])

if meson.version().version_compare('>= 0.58')
        libbpf_include_dir = libbpf.get_variable('includedir')
else
        libbpf_include_dir = libbpf.get_variable(pkgconfig : 'includedir')
endif

bpf_o_unstripped_cmd = [
        clang,
        clang_flags,
        clang_arch_flags,
        '-I.'
]

if not meson.is_cross_build()
        target_triplet_cmd = run_command('gcc', '-dumpmachine', check: false)
        if target_triplet_cmd.returncode() == 0
                target_triplet = target_triplet_cmd.stdout().strip()
                bpf_o_unstripped_cmd += [
                        '-isystem',
                        '/usr/include/@0@'.format(target_triplet)
                ]
        endif
endif

bpf_o_unstripped_cmd += [
        '-idirafter',
        libbpf_include_dir,
        '@INPUT@',
        '-o',
        '@OUTPUT@'
]

if bpftool_strip
        bpf_o_cmd = [
                bpftool,
                'g',
                'o',
                '@OUTPUT@',
                '@INPUT@'
        ]
else
        bpf_o_cmd = [
                llvm_strip,
                '-g',
                '@INPUT@',
                '-o',
                '@OUTPUT@'
        ]
endif

skel_h_cmd = [
        bpftool,
        'g',
        's',
        '@INPUT@'
]