xref: /dpdk/drivers/net/tap/bpf/meson.build (revision fa6cbff5b6c249280589c5286f62d6a107d0af34)
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright 2024 Stephen Hemminger <stephen@networkplumber.org>
3
4# Loading BPF requires libbpf
5# and the bpf_map__XXX API's were introduced in 0.8.0
6libbpf = dependency('libbpf', version: '>= 1.0',
7                    required: false, method: 'pkg-config')
8if not libbpf.found()
9    message('net/tap: no RSS support missing libbpf')
10    subdir_done()
11endif
12
13# Making skeleton needs bpftool
14# Debian install this in /usr/sbin which is not in $PATH
15bpftool_supports_skel = false
16bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false)
17if bpftool.found()
18    # Some Ubuntu versions have non-functional bpftool
19    bpftool_supports_skel = run_command(bpftool, 'gen', 'help',
20                                        check:false).returncode() == 0
21endif
22
23if not bpftool_supports_skel
24    message('net/tap: no RSS support missing bpftool')
25    subdir_done()
26endif
27
28clang_supports_bpf = false
29clang = find_program('clang', required: false)
30if clang.found()
31    clang_supports_bpf = run_command(clang, '-target', 'bpf', '--print-supported-cpus',
32                                     check: false).returncode() == 0
33endif
34
35if not clang_supports_bpf
36    message('net/tap: no RSS support missing clang BPF')
37    subdir_done()
38endif
39
40enable_tap_rss = true
41
42libbpf_include_dir = libbpf.get_variable(pkgconfig : 'includedir')
43
44# The include files <linux/bpf.h> and others include <asm/types.h>
45# but <asm/types.h> is not defined for multi-lib environment target.
46# Workaround by using include directoriy from the host build environment.
47machine_name = run_command('uname', '-m', check: true).stdout().strip()
48march_include_dir = '/usr/include/' + machine_name + '-linux-gnu'
49
50clang_flags = [
51        # these are flags used to build the BPF code
52        '-O2',
53        '-Wall',
54        '-Wextra',
55        max_queues,
56        '-target',
57        'bpf',
58        '-g',
59        '-c',
60]
61
62# Command used to compile BPF pgrograme
63bpf_o_cmd = [
64        clang,
65        clang_flags,
66        '-idirafter',
67        libbpf_include_dir,
68        '-idirafter',
69        march_include_dir,
70        '@INPUT@',
71        '-o',
72        '@OUTPUT@',
73]
74
75# Command used to generate header file from BPF object
76skel_h_cmd = [
77        bpftool,
78        'gen',
79        'skeleton',
80        '@INPUT@',
81]
82
83tap_rss_o = custom_target(
84        'tap_rss.bpf.o',
85        input: 'tap_rss.c',
86        output: 'tap_rss.o',
87        command: bpf_o_cmd)
88
89tap_rss_skel_h = custom_target(
90        'tap_rss.skel.h',
91        input: tap_rss_o,
92        output: 'tap_rss.skel.h',
93        command: skel_h_cmd,
94        capture: true)
95