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