kni: fix build for SLES15-SP3
[dpdk.git] / kernel / linux / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2018 Intel Corporation
3
4 subdirs = ['kni']
5
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()
10 cross_args = []
11
12 if not meson.is_cross_build()
13     # native build
14     kernel_version = run_command('uname', '-r').stdout().strip()
15     kernel_install_dir = '/lib/modules/' + kernel_version + '/extra/dpdk'
16     if kernel_build_dir == ''
17         # use default path for native builds
18         kernel_build_dir = '/lib/modules/' + kernel_version + '/build'
19     endif
20     if kernel_source_dir == ''
21         # use default path for native builds
22         kernel_source_dir = '/lib/modules/' + kernel_version + '/source'
23     endif
24
25     # test running make in kernel directory, using "make kernelversion"
26     make_returncode = run_command('make', '-sC', kernel_build_dir,
27             'kernelversion').returncode()
28     if make_returncode != 0
29         # backward compatibility:
30         # the headers could still be in the 'build' subdir
31         if not kernel_build_dir.endswith('build') and not kernel_build_dir.endswith('build/')
32             kernel_build_dir = join_paths(kernel_build_dir, 'build')
33             make_returncode = run_command('make', '-sC', kernel_build_dir,
34                     'kernelversion').returncode()
35         endif
36     endif
37
38     if make_returncode != 0
39         error('Cannot compile kernel modules as requested - are kernel headers installed?')
40     endif
41
42     # DO ACTUAL MODULE BUILDING
43     foreach d:subdirs
44         subdir(d)
45     endforeach
46
47     subdir_done()
48 endif
49
50 # cross build
51 # if we are cross-compiling we need kernel_build_dir specified
52 if kernel_build_dir == ''
53     error('Need "kernel_dir" option for kmod compilation when cross-compiling')
54 endif
55 cross_compiler = find_program('c').path()
56 if cross_compiler.endswith('gcc')
57     cross_prefix = run_command([py3, '-c', 'print("' + cross_compiler + '"[:-3])']).stdout().strip()
58 elif cross_compiler.endswith('clang')
59     cross_prefix = ''
60     found_target = false
61     # search for '-target' and use the arg that follows
62     # (i.e. the value of '-target') as cross_prefix
63     foreach cross_c_arg : meson.get_cross_property('c_args')
64         if found_target and cross_prefix == ''
65             cross_prefix = cross_c_arg
66         endif
67         if cross_c_arg == '-target'
68             found_target = true
69         endif
70     endforeach
71     if cross_prefix == ''
72         error('Did not find -target and its value in c_args in input cross-file.')
73     endif
74     linker = 'lld'
75     foreach cross_c_link_arg : meson.get_cross_property('c_link_args')
76         if cross_c_link_arg.startswith('-fuse-ld')
77             linker = cross_c_link_arg.split('=')[1]
78         endif
79     endforeach
80     cross_args += ['CC=@0@'.format(cross_compiler), 'LD=ld.@0@'.format(linker)]
81 else
82     error('Unsupported cross compiler: @0@'.format(cross_compiler))
83 endif
84
85 cross_arch = host_machine.cpu_family()
86 if host_machine.cpu_family() == 'aarch64'
87     cross_arch = 'arm64'
88 endif
89
90 cross_args += ['ARCH=@0@'.format(cross_arch),
91         'CROSS_COMPILE=@0@'.format(cross_prefix)]
92
93 # DO ACTUAL MODULE BUILDING
94 foreach d:subdirs
95     subdir(d)
96 endforeach