From 3282fc4322f0bc3a70d786cacb43975f1897861c Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 17 Dec 2020 11:27:11 +0200 Subject: [PATCH] build script: add function to create .pc file --- build.py | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/build.py b/build.py index c3926306..408ac703 100755 --- a/build.py +++ b/build.py @@ -197,6 +197,37 @@ class Target(BaseTarget): assert pcfile return line + def write_pc_file(self, filename=None, name=None, description=None, version='', + requires='', requires_private='', libs='', libs_private='', cflags=''): + pkgconfig_path = self.prefix + '/lib/pkgconfig/' + os.makedirs(pkgconfig_path, exist_ok=True) + + if not filename: + filename = self.name + '.pc' + if not name: + name = self.name + if not description: + description = self.name + if not libs: + libs = '-l' + self.name + + pc_content = f'''prefix= +exec_prefix=${{prefix}} +libdir=${{exec_prefix}}/lib +includedir=${{prefix}}/include + +Name: {name} +Description: {description} +Version: {version} +Requires: {requires} +Requires.private: {requires_private} +Libs: -L${{libdir}} {libs} +Libs.private: {libs_private} +Cflags: -I${{includedir}} {cflags} +''' + with open(pkgconfig_path + filename, 'w') as f: + f.write(pc_content) + class MakeTarget(Target): def __init__(self, name=None): @@ -686,23 +717,7 @@ class Bzip2Target(MakeTarget): self.options['PREFIX'] = self.prefix self.install(builder, self.options) - # Write .pc file - pkgconfig_path = self.prefix + '/lib/pkgconfig/' - os.makedirs(pkgconfig_path, exist_ok=True) - - pc_content = '''prefix= -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: bzip2 -Description: bzip2 compression library -Version: 1.0.8 -Libs: -L${libdir} -lbz2 -Cflags: -I${includedir} -''' - with open(pkgconfig_path + 'bzip2.pc', 'w') as f: - f.write(pc_content) + self.write_pc_file(description='bzip2 compression library', version='1.0.8', libs='-lbz2') class DumbTarget(CMakeStaticDependencyTarget):