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