build script: add function to create .pc file

This commit is contained in:
alexey.lysiuk 2020-12-17 11:27:11 +02:00
parent 07d0d4bd04
commit 3282fc4322

View file

@ -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):