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