1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2018 Intel Corporation
6 kernel_build_dir = get_option('kernel_dir')
7 kernel_source_dir = get_option('kernel_dir')
8 kernel_install_dir = ''
9 install = not meson.is_cross_build()
12 if not meson.is_cross_build()
14 kernel_version = run_command('uname', '-r', check: true).stdout().strip()
15 if kernel_source_dir != ''
16 # Try kernel release from sources first
17 r = run_command('make', '-s', '-C', kernel_source_dir, 'kernelrelease', check: false)
18 if r.returncode() == 0
19 kernel_version = r.stdout().strip()
22 # use default path for native builds
23 kernel_source_dir = '/lib/modules/' + kernel_version + '/source'
25 kernel_install_dir = '/lib/modules/' + kernel_version + '/extra/dpdk'
26 if kernel_build_dir == ''
27 # use default path for native builds
28 kernel_build_dir = '/lib/modules/' + kernel_version + '/build'
31 # test running make in kernel directory, using "make kernelversion"
32 make_returncode = run_command('make', '-sC', kernel_build_dir,
33 'kernelversion', check: true).returncode()
34 if make_returncode != 0
35 # backward compatibility:
36 # the headers could still be in the 'build' subdir
37 if not kernel_build_dir.endswith('build') and not kernel_build_dir.endswith('build/')
38 kernel_build_dir = join_paths(kernel_build_dir, 'build')
39 make_returncode = run_command('make', '-sC', kernel_build_dir,
40 'kernelversion', check: true).returncode()
44 if make_returncode != 0
45 error('Cannot compile kernel modules as requested - are kernel headers installed?')
48 # DO ACTUAL MODULE BUILDING
57 # if we are cross-compiling we need kernel_build_dir specified
58 if kernel_build_dir == ''
59 error('Need "kernel_dir" option for kmod compilation when cross-compiling')
61 cross_compiler = find_program('c').path()
62 if cross_compiler.endswith('gcc')
63 cross_prefix = run_command([py3, '-c', 'print("' + cross_compiler + '"[:-3])'],
64 check: true).stdout().strip()
65 elif cross_compiler.endswith('clang')
68 # search for '-target' and use the arg that follows
69 # (i.e. the value of '-target') as cross_prefix
70 foreach cross_c_arg : meson.get_cross_property('c_args')
71 if found_target and cross_prefix == ''
72 cross_prefix = cross_c_arg
74 if cross_c_arg == '-target'
79 error('Did not find -target and its value in c_args in input cross-file.')
82 foreach cross_c_link_arg : meson.get_cross_property('c_link_args')
83 if cross_c_link_arg.startswith('-fuse-ld')
84 linker = cross_c_link_arg.split('=')[1]
87 cross_args += ['CC=@0@'.format(cross_compiler), 'LD=ld.@0@'.format(linker)]
89 error('Unsupported cross compiler: @0@'.format(cross_compiler))
92 cross_arch = host_machine.cpu_family()
93 if host_machine.cpu_family() == 'aarch64'
97 cross_args += ['ARCH=@0@'.format(cross_arch),
98 'CROSS_COMPILE=@0@'.format(cross_prefix)]
100 # DO ACTUAL MODULE BUILDING