build: detect micro-arch on ARM
[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
49                         if allow_experimental_apis
50                                 cflags += '-DALLOW_EXPERIMENTAL_API'
51                         endif
52
53                         # get dependency objs from strings
54                         shared_objs = []
55                         static_objs = []
56                         foreach d:deps
57                                 shared_objs += [get_variable('shared_rte_' + d)]
58                                 static_objs += [get_variable('static_rte_' + d)]
59                         endforeach
60                         shared_objs += ext_deps
61                         static_objs += ext_deps
62                         dpdk_extra_ldflags += pkgconfig_extra_libs
63
64                         # generate pmdinfo sources
65                         pmdinfogen_srcs = run_command('grep', '--files-with-matches',
66                                 'RTE_PMD_REGISTER_.*(.*)', sources).stdout().strip().split()
67                         foreach src: pmdinfogen_srcs
68                                 out_filename = '@0@.pmd.c'.format(src.split('/')[-1])
69                                 tmp_lib = static_library('tmp_@0@'.format(src.underscorify()),
70                                         src, include_directories: includes,
71                                         dependencies: static_objs,
72                                         c_args: cflags)
73                                 sources += custom_target(out_filename,
74                                                 command: [pmdinfo, tmp_lib.full_path(),
75                                                         '@OUTPUT@', pmdinfogen],
76                                                 output: out_filename,
77                                                 depends: [pmdinfogen, tmp_lib])
78                         endforeach
79
80                         if get_option('per_library_versions')
81                                 lib_version = '@0@.1'.format(version)
82                                 so_version = '@0@'.format(version)
83                         else
84                                 pver = meson.project_version().split('.')
85                                 lib_version = '@0@.@1@'.format(pver.get(0),
86                                                 pver.get(1))
87                                 so_version = lib_version
88                         endif
89
90                         # now build the static driver
91                         lib_name = driver_name_fmt.format(name)
92                         static_lib = static_library(lib_name,
93                                 sources,
94                                 objects: objs,
95                                 include_directories: includes,
96                                 dependencies: static_objs,
97                                 c_args: cflags,
98                                 install: true)
99
100                         # now build the shared driver
101                         sources = []
102                         objs += static_lib.extract_all_objects()
103                         version_map = '@0@/@1@/@2@_version.map'.format(
104                                         meson.current_source_dir(),
105                                         drv_path, lib_name)
106                         shared_lib = shared_library(lib_name,
107                                 sources,
108                                 objects: objs,
109                                 include_directories: includes,
110                                 dependencies: shared_objs,
111                                 c_args: cflags,
112                                 link_args: '-Wl,--version-script=' + version_map,
113                                 link_depends: version_map,
114                                 version: lib_version,
115                                 soversion: so_version,
116                                 install: true,
117                                 install_dir: driver_install_path)
118
119                         # create a dependency object and add it to the global dictionary so
120                         # testpmd or other built-in apps can find it if necessary
121                         shared_dep = declare_dependency(link_with: shared_lib,
122                                         include_directories: includes,
123                                         dependencies: shared_objs)
124                         static_dep = declare_dependency(link_with: static_lib,
125                                         include_directories: includes,
126                                         dependencies: static_objs)
127
128                         dpdk_drivers += static_lib
129
130                         set_variable('shared_@0@'.format(lib_name), shared_dep)
131                         set_variable('static_@0@'.format(lib_name), static_dep)
132                 endif # build
133         endforeach
134 endforeach