f3dd23dd43fb2cf12799a60c117c431357457014
[dpdk.git] / drivers / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017-2019 Intel Corporation
3
4 if is_windows
5         subdir_done()
6 endif
7
8 # Defines the order in which the drivers are buit.
9 dpdk_driver_classes = ['common',
10                'bus',
11                'mempool', # depends on common and bus.
12                'net',     # depends on common, bus, mempool
13                'raw',     # depends on common, bus and net.
14                'crypto',  # depends on common, bus and mempool (net in future).
15                'compress', # depends on common, bus, mempool.
16                'vdpa',    # depends on common, bus and mempool.
17                'event',   # depends on common, bus, mempool and net.
18                'baseband'] # depends on common and bus.
19
20 disabled_drivers = run_command(list_dir_globs, get_option('disable_drivers'),
21                 ).stdout().split()
22
23 default_cflags = machine_args
24 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
25 default_cflags += ['-DALLOW_INTERNAL_API']
26
27 if cc.has_argument('-Wno-format-truncation')
28         default_cflags += '-Wno-format-truncation'
29 endif
30
31 foreach class:dpdk_driver_classes
32         drivers = []
33         std_deps = []
34         config_flag_fmt = '' # format string used to set the value in dpdk_conf
35         driver_name_fmt = '' # format string for driver name, used to name
36                              # the library, the dependency and to find the
37                              # version file for linking
38
39         subdir(class)
40         class_drivers = []
41
42         foreach drv:drivers
43                 drv_path = join_paths(class, drv)
44
45                 # set up empty variables used for build
46                 build = true # set to false to disable, e.g. missing deps
47                 reason = '<unknown reason>' # set if build == false to explain
48                 name = drv
49                 fmt_name = ''
50                 sources = []
51                 objs = []
52                 cflags = default_cflags
53                 includes = [include_directories(drv_path)]
54                 # set up internal deps. Drivers can append/override as necessary
55                 deps = std_deps
56                 # ext_deps: Stores external library dependency got
57                 # using dependency() (preferred) or find_library().
58                 # For the find_library() case (but not with dependency()) we also
59                 # need to specify the "-l" flags in pkgconfig_extra_libs variable
60                 # too, so that it can be reflected in the pkgconfig output for
61                 # static builds.
62                 ext_deps = []
63                 pkgconfig_extra_libs = []
64
65                 # pull in driver directory which should assign to each of the above
66                 subdir(drv_path)
67
68                 # skip disabled drivers. For meson 0.49 change this to use
69                 # "in" keyword
70                 foreach disable_path: disabled_drivers
71                         if drv_path == disable_path
72                                 build = false
73                                 reason = 'Explicitly disabled via build config'
74                         endif
75                 endforeach
76                 if build
77                         # get dependency objs from strings
78                         shared_deps = ext_deps
79                         static_deps = ext_deps
80                         foreach d:deps
81                                 if not is_variable('shared_rte_' + d)
82                                         build = false
83                                         reason = 'Missing internal dependency, "@0@"'.format(d)
84                                         message('Disabling @1@ [@2@]: missing internal dependency "@0@"'
85                                                         .format(d, name, 'drivers/' + drv_path))
86                                 else
87                                         shared_deps += [get_variable('shared_rte_' + d)]
88                                         static_deps += [get_variable('static_rte_' + d)]
89                                 endif
90                         endforeach
91                 endif
92
93                 if not build
94                         # some driver directories are placeholders which
95                         # are never built, so we allow suppression of the
96                         # component disable printout in those cases
97                         if reason != ''
98                                 dpdk_drvs_disabled += drv_path
99                                 set_variable(drv_path.underscorify() +
100                                                 '_disable_reason', reason)
101                         endif
102                 else
103                         class_drivers += name
104
105                         if fmt_name == ''
106                                 fmt_name = name
107                         endif
108                         dpdk_conf.set(config_flag_fmt.format(fmt_name.to_upper()),1)
109                         lib_name = driver_name_fmt.format(fmt_name)
110
111                         dpdk_extra_ldflags += pkgconfig_extra_libs
112
113                         # generate pmdinfo sources by building a temporary
114                         # lib and then running pmdinfogen on the contents of
115                         # that lib. The final lib reuses the object files and
116                         # adds in the new source file.
117                         out_filename = lib_name + '.pmd.c'
118                         tmp_lib = static_library('tmp_' + lib_name,
119                                         sources,
120                                         include_directories: includes,
121                                         dependencies: static_deps,
122                                         c_args: cflags)
123                         objs += tmp_lib.extract_all_objects()
124                         sources = custom_target(out_filename,
125                                         command: [pmdinfo, tmp_lib.full_path(),
126                                                 '@OUTPUT@', pmdinfogen],
127                                         output: out_filename,
128                                         depends: [pmdinfogen, tmp_lib])
129
130                         version_map = '@0@/@1@/@2@_version.map'.format(
131                                         meson.current_source_dir(),
132                                         drv_path, lib_name)
133
134                         is_experimental = run_command(is_experimental_cmd,
135                                 files(version_map)).returncode()
136
137                         if is_experimental != 0
138                                 lib_version = experimental_abi_version
139                                 so_version = experimental_so_version
140                         else
141                                 lib_version = abi_version
142                                 so_version = stable_so_version
143                         endif
144
145                         # now build the static driver
146                         static_lib = static_library(lib_name,
147                                 sources,
148                                 objects: objs,
149                                 include_directories: includes,
150                                 dependencies: static_deps,
151                                 c_args: cflags,
152                                 install: true)
153
154                         # now build the shared driver
155                         version_map = '@0@/@1@/@2@_version.map'.format(
156                                         meson.current_source_dir(),
157                                         drv_path, lib_name)
158                         implib = dir_name + '.dll.a'
159
160                         def_file = custom_target(lib_name + '_def',
161                                 command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'],
162                                 input: version_map,
163                                 output: '@0@_exports.def'.format(lib_name))
164                         lk_deps = [version_map, def_file]
165                         if is_windows
166                                 lk_args = ['-Wl,/def:' + def_file.full_path(),
167                                         '-Wl,/implib:lib\\' + implib]
168                         else
169                                 lk_args = ['-Wl,--version-script=' + version_map]
170                                 # on unix systems check the output of the
171                                 # experimental syms script, using it as a
172                                 # dependency of the .so build
173                                 lk_deps += custom_target(lib_name + '.exp_chk',
174                                         command: [check_experimental_syms,
175                                                 version_map, '@INPUT@'],
176                                         capture: true,
177                                         input: static_lib,
178                                         output: lib_name + '.exp_chk')
179                         endif
180
181                         shared_lib = shared_library(lib_name,
182                                 sources,
183                                 objects: objs,
184                                 include_directories: includes,
185                                 dependencies: shared_deps,
186                                 c_args: cflags,
187                                 link_args: lk_args,
188                                 link_depends: lk_deps,
189                                 version: lib_version,
190                                 soversion: so_version,
191                                 install: true,
192                                 install_dir: driver_install_path)
193
194                         # create a dependency object and add it to the global dictionary so
195                         # testpmd or other built-in apps can find it if necessary
196                         shared_dep = declare_dependency(link_with: shared_lib,
197                                         include_directories: includes,
198                                         dependencies: shared_deps)
199                         static_dep = declare_dependency(link_with: static_lib,
200                                         include_directories: includes,
201                                         dependencies: static_deps)
202
203                         dpdk_drivers += static_lib
204
205                         set_variable('shared_@0@'.format(lib_name), shared_dep)
206                         set_variable('static_@0@'.format(lib_name), static_dep)
207                         dependency_name = ''.join(lib_name.split('rte_'))
208                         message('drivers/@0@: Defining dependency "@1@"'.format(
209                                         drv_path, dependency_name))
210                 endif # build
211         endforeach
212
213         set_variable(class + '_drivers', class_drivers)
214 endforeach