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