• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# meson-pkg-config-file-fixup.py PC_FILE VAR1,VAR2,VAR3
4#
5# Fix up escaping of custom variables in meson-generated .pc file
6#
7# Copyright (C) 2021 Tim-Philipp Müller <tim centricular com>
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Library General Public
11# License as published by the Free Software Foundation; either
12# version 2 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17# Library General Public License for more details.
18#
19# You should have received a copy of the GNU Library General Public
20# License along with this library; if not, write to the
21# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22# Boston, MA 02110-1301, USA.
23
24import os
25import sys
26
27if len(sys.argv) < 3:
28  sys.exit('Usage: {} PC_FILE_BASE_NAME VAR1 [VAR2 [VAR3 ..]]'.format(sys.argv[0]))
29
30pc_name = sys.argv[1]
31pc_vars = sys.argv[2:]
32
33build_root = os.environ['MESON_BUILD_ROOT']
34
35# Poking into the private dir is not entirely kosher of course..
36pc_files = [
37  os.path.join(build_root, 'meson-private', pc_name + '.pc'),
38  os.path.join(build_root, 'meson-uninstalled', pc_name + '-uninstalled.pc')
39]
40
41for pc_file in pc_files:
42  out_lines = ''
43
44  with open(pc_file, 'r') as f:
45    for line in f:
46      r = line.strip().split('=', 1)
47      if len(r) == 2 and r[0] in pc_vars:
48        out_lines += '{}={}\n'.format(r[0], r[1].replace('\\ ', ' '))
49      else:
50        out_lines += line
51
52  with open(pc_file, 'w') as f_new:
53      f_new.write(out_lines)
54
55sys.exit(0)
56