build/pkg-config: improve static linking flags
[dpdk.git] / buildtools / pkg-config / set-static-linker-flags.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2020 Intel Corporation
4
5 # Script to fix flags for static linking in pkgconfig files from meson
6 # Should be called from meson build itself
7 import os
8 import sys
9
10
11 def fix_ldflag(f):
12     if not f.startswith('-lrte_'):
13         return f
14     return '-l:lib' + f[2:] + '.a'
15
16
17 def fix_libs_private(line):
18     if not line.startswith('Libs.private'):
19         return line
20     ldflags = [fix_ldflag(flag) for flag in line.split()]
21     return ' '.join(ldflags) + '\n'
22
23
24 def process_pc_file(filepath):
25     print('Processing', filepath)
26     with open(filepath) as src:
27         lines = src.readlines()
28     with open(filepath, 'w') as dst:
29         dst.writelines([fix_libs_private(line) for line in lines])
30
31
32 if 'MESON_BUILD_ROOT' not in os.environ:
33     print('This script must be called from a meson build environment')
34     sys.exit(1)
35 for root, dirs, files in os.walk(os.environ['MESON_BUILD_ROOT']):
36     pc_files = [f for f in files if f.endswith('.pc')]
37     for f in pc_files:
38         process_pc_file(os.path.join(root, f))