1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright(c) 2018 Intel Corporation 3 4subdirs = ['kni'] 5 6kernel_build_dir = get_option('kernel_dir') 7kernel_source_dir = get_option('kernel_dir') 8kernel_install_dir = '' 9install = not meson.is_cross_build() 10cross_args = [] 11 12if not meson.is_cross_build() 13 # native 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() 20 endif 21 else 22 # use default path for native builds 23 kernel_source_dir = '/lib/modules/' + kernel_version + '/source' 24 endif 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' 29 endif 30 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() 41 endif 42 endif 43 44 if make_returncode != 0 45 error('Cannot compile kernel modules as requested - are kernel headers installed?') 46 endif 47 48 # DO ACTUAL MODULE BUILDING 49 foreach d:subdirs 50 subdir(d) 51 endforeach 52 53 subdir_done() 54endif 55 56# cross build 57# if we are cross-compiling we need kernel_build_dir specified 58if kernel_build_dir == '' 59 error('Need "kernel_dir" option for kmod compilation when cross-compiling') 60endif 61cross_compiler = find_program('c').path() 62if cross_compiler.endswith('gcc') 63 cross_prefix = run_command([py3, '-c', 'print("' + cross_compiler + '"[:-3])'], 64 check: true).stdout().strip() 65elif cross_compiler.endswith('clang') 66 cross_prefix = '' 67 found_target = false 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 73 endif 74 if cross_c_arg == '-target' 75 found_target = true 76 endif 77 endforeach 78 if cross_prefix == '' 79 error('Did not find -target and its value in c_args in input cross-file.') 80 endif 81 linker = 'lld' 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] 85 endif 86 endforeach 87 cross_args += ['CC=@0@'.format(cross_compiler), 'LD=ld.@0@'.format(linker)] 88else 89 error('Unsupported cross compiler: @0@'.format(cross_compiler)) 90endif 91 92cross_arch = host_machine.cpu_family() 93if host_machine.cpu_family() == 'aarch64' 94 cross_arch = 'arm64' 95endif 96 97cross_args += ['ARCH=@0@'.format(cross_arch), 98 'CROSS_COMPILE=@0@'.format(cross_prefix)] 99 100# DO ACTUAL MODULE BUILDING 101foreach d:subdirs 102 subdir(d) 103endforeach 104