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