-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpkg_config_builder.py
More file actions
84 lines (64 loc) · 2.57 KB
/
Copy pathpkg_config_builder.py
File metadata and controls
84 lines (64 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
import os
import sys
import re
from jinja2 import Template
import subprocess
if os.path.exists("/usr/lib64"):
# Rhel/CentOS/Fedora
library_path = "/usr/lib64"
dpdk_version = subprocess.check_output(
['rpm', '-q', '--qf', '%{VERSION}', 'dpdk']).decode('UTF-8')
else:
# Ubuntu/Debian
library_path = "/usr/lib"
dpkg_query_out = subprocess.check_output(
['dpkg-query', '-f', '${Version}', '-W', 'dpdk']).decode('UTF-8')
dpdk_version = dpkg_query_outplit('-')[0]
if (dpdk_version == ''):
print("Could not find DPDK package", file=sys.stderr)
exit(1)
# Write the .pc file to a place that all users have access to.
pkg_config_path = "/tmp/pkgconfig"
dpdk_libraries = []
# Order is important here
dpdk_libraries.append('-Wl,--whole-archive -L${libdir}')
dpdk_libraries += [os.path.splitext(lib)[0] for lib in os.listdir(library_path)
if re.search(r'librte_common.*\.so$', lib)]
dpdk_libraries += [os.path.splitext(lib)[0] for lib in os.listdir(library_path)
if re.search(r'librte_bus.*\.so$', lib)]
dpdk_libraries += [os.path.splitext(lib)[0] for lib in os.listdir(library_path)
if re.search(r'librte_mempool.*\.so$', lib)]
dpdk_libraries += [os.path.splitext(lib)[0] for lib in os.listdir(library_path)
if re.search(r'librte_raw.*\.so$', lib)]
dpdk_libraries += [os.path.splitext(lib)[0] for lib in os.listdir(library_path)
if re.search(r'librte_pmd.*\.so$', lib)]
dpdk_libraries.append('-Wl,--no-whole-archive')
dpdk_libraries += [os.path.splitext(lib)[0] for lib in os.listdir(library_path)
if re.search(r'librte_(?!common|bus|mempool|raw|pmd).*\.so$', lib)]
dpdk_libraries = [x.replace('librte', '-lrte') for x in dpdk_libraries]
template = """prefix={{ prefix }}
libdir=${prefix}/{{ os_lib_path }}
includedir=${prefix}/include/dpdk
Name: {{ name }}
Description: {{ description }}
Version: {{ version }}
Libs: {{ libraries }}
Cflags: -I${includedir} -include rte_config.h -march=corei7"""
config_data = {
"prefix": "/usr",
"os_lib_path": os.path.split(library_path)[1],
"name": "DPDK",
"description" : "Manually built libdpdk.pc file",
"version" : dpdk_version,
"libraries": " ".join(dpdk_libraries)
}
j2_template = Template(template)
if not os.path.exists(pkg_config_path):
os.makedirs(pkg_config_path)
with open(os.path.join(pkg_config_path, "libdpdk.pc"), "w") as f:
f.write(j2_template.render(config_data))
f.flush()
os.fsync(f)
print("Wrote {}".format(os.path.join(pkg_config_path, "libdpdk.pc")))
exit(0)