Skip to content

Commit 4c77378

Browse files
bruce-richardsontmonjalo
authored andcommitted
build: generate Windows exports file
Rather than having a separate version.map file for linux/BSD and an exports definition file for windows for each library, generate the latter from the former automatically at build time. Signed-off-by: Bruce Richardson <[email protected]>
1 parent 8cb511b commit 4c77378

File tree

6 files changed

+64
-18
lines changed

6 files changed

+64
-18
lines changed

buildtools/map_to_def.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright(c) 2019 Intel Corporation
4+
5+
from __future__ import print_function
6+
import sys
7+
from os.path import dirname, basename, join, exists
8+
9+
10+
def is_function_line(ln):
11+
return ln.startswith('\t') and ln.endswith(';\n') and ":" not in ln
12+
13+
14+
def main(args):
15+
if not args[1].endswith('version.map') or \
16+
not args[2].endswith('exports.def'):
17+
return 1
18+
19+
# special case, allow override if an def file already exists alongside map file
20+
override_file = join(dirname(args[1]), basename(args[2]))
21+
if exists(override_file):
22+
with open(override_file) as f_in:
23+
functions = f_in.readlines()
24+
25+
# generate def file from map file.
26+
# This works taking indented lines only which end with a ";" and which don't
27+
# have a colon in them, i.e. the lines defining functions only.
28+
else:
29+
with open(args[1]) as f_in:
30+
functions = [ln[:-2] + '\n' for ln in sorted(f_in.readlines())
31+
if is_function_line(ln)]
32+
functions = ["EXPORTS\n"] + functions
33+
34+
with open(args[2], 'w') as f_out:
35+
f_out.writelines(functions)
36+
return 0
37+
38+
39+
if __name__ == "__main__":
40+
sys.exit(main(sys.argv))

buildtools/meson.build

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright(c) 2017-2019 Intel Corporation
33

4-
if is_windows
5-
subdir_done()
6-
endif
7-
84
subdir('pmdinfogen')
95

106
pmdinfo = find_program('gen-pmdinfo-cfile.sh')
7+
8+
# set up map-to-def script using python, either built-in or external
9+
python3 = import('python').find_installation(required: false)
10+
if python3.found()
11+
map_to_def_cmd = [python3, files('map_to_def.py')]
12+
else
13+
map_to_def_cmd = ['meson', 'runpython', files('map_to_def.py')]
14+
endif

buildtools/pmdinfogen/meson.build

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright(c) 2017 Intel Corporation
33

4-
pmdinfogen_inc = eal_inc
4+
if host_machine.system() == 'windows'
5+
subdir_done()
6+
endif
7+
8+
pmdinfogen_inc = [global_inc]
9+
pmdinfogen_inc += include_directories('../../lib/librte_eal/common/include')
510
pmdinfogen_inc += include_directories('../../lib/librte_pci')
611
pmdinfogen = executable('pmdinfogen',
712
'pmdinfogen.c',

lib/librte_kvargs/rte_kvargs_exports.def

-7
This file was deleted.

lib/meson.build

+9-5
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,27 @@ foreach l:libraries
121121
objs += static_lib.extract_all_objects(recursive: false)
122122
version_map = '@0@/@1@/rte_@2@_version.map'.format(
123123
meson.current_source_dir(), dir_name, name)
124-
exports = []
125124
implib = dir_name + '.dll.a'
125+
126+
def_file = custom_target(name + '_def',
127+
command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'],
128+
input: version_map,
129+
output: 'rte_@0@_exports.def'.format(name))
126130
if is_windows
127-
exports = '@0@/@1@/rte_@2@_exports.def'.format(
128-
meson.current_source_dir(), dir_name, name)
129-
lk_args = ['-Wl,/def:' + exports, '-Wl,/implib:lib\\' + implib]
131+
lk_args = ['-Wl,/def:' + def_file.full_path(),
132+
'-Wl,/implib:lib\\' + implib]
130133
else
131134
lk_args = ['-Wl,--version-script=' + version_map]
132135
endif
136+
133137
shared_lib = shared_library(libname,
134138
sources,
135139
objects: objs,
136140
c_args: cflags,
137141
dependencies: shared_deps,
138142
include_directories: includes,
139143
link_args: lk_args,
140-
link_depends: [version_map, exports],
144+
link_depends: [version_map, def_file],
141145
version: lib_version,
142146
soversion: so_version,
143147
install: true)

meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ global_inc = include_directories('.', 'config',
3131
subdir('config')
3232

3333
# build libs and drivers
34-
subdir('lib')
3534
subdir('buildtools')
35+
subdir('lib')
3636
subdir('drivers')
3737

3838
# build binaries and installable tools

0 commit comments

Comments
 (0)