bus/pci: build with meson
[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']
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                 version = 1
50                 allow_experimental_apis = false
51                 sources = []
52                 objs = []
53                 cflags = []
54                 includes = [include_directories(drv_path)]
55                 # set up internal deps. Drivers can append/override as necessary
56                 deps = std_deps
57                 # ext_deps: Stores external library dependency got
58                 # using dependency() or cc.find_library(). For most cases, we
59                 # probably also need to specify the "-l" flags in
60                 # pkgconfig_extra_libs variable too, so that it can be reflected
61                 # in the pkgconfig output for static builds
62                 ext_deps = []
63                 pkgconfig_extra_libs = []
64
65                 # pull in driver directory which should assign to each of the above
66                 subdir(drv_path)
67
68                 if build
69                         dpdk_conf.set(config_flag_fmt.format(drv.to_upper()),1)
70
71                         if allow_experimental_apis
72                                 cflags += '-DALLOW_EXPERIMENTAL_API'
73                         endif
74
75                         # get dependency objs from strings
76                         dep_objs = []
77                         foreach d:deps
78                                 dep_objs += [get_variable('dep_rte_' + d)]
79                         endforeach
80                         dep_objs += ext_deps
81                         dpdk_extra_ldflags += pkgconfig_extra_libs
82
83                         # generate pmdinfo sources
84                         pmdinfogen_srcs = run_command('grep', '--files-with-matches',
85                                 'RTE_PMD_REGISTER_.*(.*)', sources).stdout().strip().split()
86                         foreach src: pmdinfogen_srcs
87                                 out_filename = '@0@.pmd.c'.format(src.split('/')[-1])
88                                 tmp_lib = static_library('tmp_@0@'.format(src.underscorify()),
89                                         src, include_directories: includes,
90                                         dependencies: dep_objs,
91                                         c_args: cflags)
92                                 sources += custom_target(out_filename,
93                                                 command: [pmdinfo, tmp_lib.full_path(),
94                                                         '@OUTPUT@', pmdinfogen],
95                                                 output: out_filename,
96                                                 depends: [pmdinfogen, tmp_lib])
97                         endforeach
98
99                         # now build the driver itself, and add to the drivers list
100                         drv_name = driver_name_fmt.format(drv)
101                         version_map = '@0@/@1@/@2@_version.map'.format(
102                                         meson.current_source_dir(),
103                                         drv_path, drv_name)
104                         lib = library(drv_name,
105                                 sources,
106                                 objects: objs,
107                                 include_directories: includes,
108                                 dependencies: dep_objs,
109                                 c_args: cflags,
110                                 link_args: '-Wl,--version-script=' + version_map,
111                                 link_depends: version_map,
112                                 version: '@0@.1'.format(version),
113                                 install: true,
114                                 install_dir: driver_install_path)
115
116                         dpdk_drivers += lib
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                         set_variable('dep_@0@'.format(drv_name),
121                                         declare_dependency(link_with: lib,
122                                         include_directories: includes,
123                                         dependencies: dep_objs))
124                 endif # build
125         endforeach
126 endforeach