1
0
Fork 0
forked from hanez/xtc
xtc/tools/pkgconfig.py

25 lines
1.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""Generate pkg-config metadata without shell/sed interpolation of paths."""
import argparse
from pathlib import Path
from dist import version
from install_layout import directory
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--prefix', required=True)
parser.add_argument('--exec-prefix')
parser.add_argument('--libdir')
parser.add_argument('--includedir')
parser.add_argument('--jack', default='')
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
prefix = directory(args.prefix)
exec_prefix = directory(args.exec_prefix or prefix)
libdir = directory(args.libdir or exec_prefix / 'lib')
includedir = directory(args.includedir or prefix / 'include')
def reference(path):
return '${prefix}/' + str(path.relative_to(prefix)) if path != prefix and prefix in path.parents else str(path)
text = Path('packaging/xtc.pc.in').read_text().replace('@PREFIX@', str(prefix))
text = text.replace('@EXEC_PREFIX@', reference(exec_prefix)).replace('@LIBDIR@', reference(libdir)).replace('@INCLUDEDIR@', reference(includedir))
text = text.replace('@VERSION@', version(Path.cwd())).replace('@JACK@', args.jack)
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(text)