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