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