fbarray: improve musl compatibility
[dpdk.git] / drivers / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017 Intel Corporation
3
4 # Defines the order in which the drivers are buit.
5 driver_classes = ['common',
6                'bus',
7                'mempool', # depends on common and bus.
8                'net',     # depends on common, bus and mempool.
9                'crypto',  # depends on common, bus and mempool (net in future).
10                'compress', # depends on common, bus, mempool.
11                'event',   # depends on common, bus, mempool and net.
12                'baseband', # depends on common and bus.
13                'raw']     # depends on common, bus, mempool, net and event.
14
15 default_cflags = machine_args
16 if cc.has_argument('-Wno-format-truncation')
17         default_cflags += '-Wno-format-truncation'
18 endif
19
20 # specify -D_GNU_SOURCE unconditionally
21 default_cflags += '-D_GNU_SOURCE'
22
23 foreach class:driver_classes
24         drivers = []
25         std_deps = []
26         config_flag_fmt = '' # format string used to set the value in dpdk_conf
27         driver_name_fmt = '' # format string for driver name, used to name
28                              # the library, the dependency and to find the
29                              # version file for linking
30
31         subdir(class)
32         class_drivers = []
33
34         foreach drv:drivers
35                 drv_path = join_paths(class, drv)
36
37                 # set up empty variables used for build
38                 build = true # set to false to disable, e.g. missing deps
39                 name = drv
40                 version = 1
41                 allow_experimental_apis = false
42                 sources = []
43                 objs = []
44                 cflags = default_cflags
45                 includes = [include_directories(drv_path)]
46                 # set up internal deps. Drivers can append/override as necessary
47                 deps = std_deps
48                 # ext_deps: Stores external library dependency got
49                 # using dependency() or cc.find_library(). For most cases, we
50                 # probably also need to specify the "-l" flags in
51                 # pkgconfig_extra_libs variable too, so that it can be reflected
52                 # in the pkgconfig output for static builds
53                 ext_deps = []
54                 pkgconfig_extra_libs = []
55
56                 # pull in driver directory which should assign to each of the above
57                 subdir(drv_path)
58
59                 if build
60                         class_drivers += name
61
62                         dpdk_conf.set(config_flag_fmt.format(name.to_upper()),1)
63                         lib_name = driver_name_fmt.format(name)
64
65                         if allow_experimental_apis
66                                 cflags += '-DALLOW_EXPERIMENTAL_API'
67                         endif
68
69                         # get dependency objs from strings
70                         shared_objs = []
71                         static_objs = []
72                         foreach d:deps
73                                 if not is_variable('shared_rte_' + d)
74                                         error('Missing dependency ' + d +
75                                                 ' for driver ' + lib_name)
76                                 endif
77                                 shared_objs += [get_variable('shared_rte_' + d)]
78                                 static_objs += [get_variable('static_rte_' + d)]
79                         endforeach
80                         shared_objs += ext_deps
81                         static_objs += ext_deps
82                         dpdk_extra_ldflags += pkgconfig_extra_libs
83
84                         # generate pmdinfo sources by building a temporary
85                         # lib and then running pmdinfogen on the contents of
86                         # that lib. The final lib reuses the object files and
87                         # adds in the new source file.
88                         out_filename = lib_name + '.pmd.c'
89                         tmp_lib = static_library('tmp_' + lib_name,
90                                         sources,
91                                         include_directories: includes,
92                                         dependencies: static_objs,
93                                         c_args: cflags)
94                         objs += tmp_lib.extract_all_objects()
95                         sources = custom_target(out_filename,
96                                         command: [pmdinfo, tmp_lib.full_path(),
97                                                 '@OUTPUT@', pmdinfogen],
98                                         output: out_filename,
99                                         depends: [pmdinfogen, tmp_lib])
100
101                         if get_option('per_library_versions')
102                                 lib_version = '@0@.1'.format(version)
103                                 so_version = '@0@'.format(version)
104                         else
105                                 pver = meson.project_version().split('.')
106                                 lib_version = '@0@.@1@'.format(pver.get(0),
107                                                 pver.get(1))
108                                 so_version = lib_version
109                         endif
110
111                         # now build the static driver
112                         static_lib = static_library(lib_name,
113                                 sources,
114                                 objects: objs,
115                                 include_directories: includes,
116                                 dependencies: static_objs,
117                                 c_args: cflags,
118                                 install: true)
119
120                         # now build the shared driver
121                         version_map = '@0@/@1@/@2@_version.map'.format(
122                                         meson.current_source_dir(),
123                                         drv_path, lib_name)
124                         shared_lib = shared_library(lib_name,
125                                 sources,
126                                 objects: objs,
127                                 include_directories: includes,
128                                 dependencies: shared_objs,
129                                 c_args: cflags,
130                                 link_args: '-Wl,--version-script=' + version_map,
131                                 link_depends: version_map,
132                                 version: lib_version,
133                                 soversion: so_version,
134                                 install: true,
135                                 install_dir: driver_install_path)
136
137                         # create a dependency object and add it to the global dictionary so
138                         # testpmd or other built-in apps can find it if necessary
139                         shared_dep = declare_dependency(link_with: shared_lib,
140                                         include_directories: includes,
141                                         dependencies: shared_objs)
142                         static_dep = declare_dependency(link_with: static_lib,
143                                         include_directories: includes,
144                                         dependencies: static_objs)
145
146                         dpdk_drivers += static_lib
147
148                         set_variable('shared_@0@'.format(lib_name), shared_dep)
149                         set_variable('static_@0@'.format(lib_name), static_dep)
150                 endif # build
151         endforeach
152
153         if meson.version().version_compare('>=0.47')
154                 # prior to 0.47, set_variable can't take array params
155                 set_variable(class + '_drivers', class_drivers)
156         endif
157 endforeach