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