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