b4abc32f7394c0969827f060ff8a2f12478c13ef
[dpdk.git] / drivers / meson.build
1 #   BSD LICENSE
2 #
3 #   Copyright(c) 2017 Intel Corporation.
4 #   All rights reserved.
5 #
6 #   Redistribution and use in source and binary forms, with or without
7 #   modification, are permitted provided that the following conditions
8 #   are met:
9 #
10 #     * Redistributions of source code must retain the above copyright
11 #       notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above copyright
13 #       notice, this list of conditions and the following disclaimer in
14 #       the documentation and/or other materials provided with the
15 #       distribution.
16 #     * Neither the name of Intel Corporation nor the names of its
17 #       contributors may be used to endorse or promote products derived
18 #       from this software without specific prior written permission.
19 #
20 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 driver_classes = ['bus', 'crypto', 'mempool', 'net']
33
34 foreach class:driver_classes
35         drivers = []
36         std_deps = []
37         config_flag_fmt = '' # format string used to set the value in dpdk_conf
38         driver_name_fmt = '' # format string for driver name, used to name
39                              # the library, the dependency and to find the
40                              # version file for linking
41
42         subdir(class)
43
44         foreach drv:drivers
45                 drv_path = join_paths(class, drv)
46
47                 # set up empty variables used for build
48                 build = true # set to false to disable, e.g. missing deps
49                 name = drv
50                 version = 1
51                 allow_experimental_apis = false
52                 sources = []
53                 objs = []
54                 cflags = []
55                 includes = [include_directories(drv_path)]
56                 # set up internal deps. Drivers can append/override as necessary
57                 deps = std_deps
58                 # ext_deps: Stores external library dependency got
59                 # using dependency() or cc.find_library(). For most cases, we
60                 # probably also need to specify the "-l" flags in
61                 # pkgconfig_extra_libs variable too, so that it can be reflected
62                 # in the pkgconfig output for static builds
63                 ext_deps = []
64                 pkgconfig_extra_libs = []
65
66                 # pull in driver directory which should assign to each of the above
67                 subdir(drv_path)
68
69                 if build
70                         dpdk_conf.set(config_flag_fmt.format(name.to_upper()),1)
71
72                         if allow_experimental_apis
73                                 cflags += '-DALLOW_EXPERIMENTAL_API'
74                         endif
75
76                         # get dependency objs from strings
77                         dep_objs = []
78                         foreach d:deps
79                                 dep_objs += [get_variable('dep_rte_' + d)]
80                         endforeach
81                         dep_objs += ext_deps
82                         dpdk_extra_ldflags += pkgconfig_extra_libs
83
84                         # generate pmdinfo sources
85                         pmdinfogen_srcs = run_command('grep', '--files-with-matches',
86                                 'RTE_PMD_REGISTER_.*(.*)', sources).stdout().strip().split()
87                         foreach src: pmdinfogen_srcs
88                                 out_filename = '@0@.pmd.c'.format(src.split('/')[-1])
89                                 tmp_lib = static_library('tmp_@0@'.format(src.underscorify()),
90                                         src, include_directories: includes,
91                                         dependencies: dep_objs,
92                                         c_args: cflags)
93                                 sources += custom_target(out_filename,
94                                                 command: [pmdinfo, tmp_lib.full_path(),
95                                                         '@OUTPUT@', pmdinfogen],
96                                                 output: out_filename,
97                                                 depends: [pmdinfogen, tmp_lib])
98                         endforeach
99
100                         # now build the driver itself, and add to the drivers list
101                         lib_name = driver_name_fmt.format(name)
102                         version_map = '@0@/@1@/@2@_version.map'.format(
103                                         meson.current_source_dir(),
104                                         drv_path, lib_name)
105                         lib = library(lib_name,
106                                 sources,
107                                 objects: objs,
108                                 include_directories: includes,
109                                 dependencies: dep_objs,
110                                 c_args: cflags,
111                                 link_args: '-Wl,--version-script=' + version_map,
112                                 link_depends: version_map,
113                                 version: '@0@.1'.format(version),
114                                 install: true,
115                                 install_dir: driver_install_path)
116
117                         dpdk_drivers += lib
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                         set_variable('dep_@0@'.format(lib_name),
122                                         declare_dependency(link_with: lib,
123                                         include_directories: includes,
124                                         dependencies: dep_objs))
125                 endif # build
126         endforeach
127 endforeach