From ab22254684d0a24339ebe8f8ff2cfd88a7b7eb95 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 28 Jun 2019 10:04:10 -0700 Subject: [PATCH] Meson: install symlinks or copies of binaries On most system symlinks are fine, but on windows symlinks are tricky at best, or unsupported for older versions of windows. To avoid those problems we'll just copy the binary if the host or build machine is windows. This uses a small helper python script to make this all easier to use and understand. --- install_links.py | 41 +++++++++++++++++++++++++++++++++++++++++ meson.build | 13 +++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 install_links.py diff --git a/install_links.py b/install_links.py new file mode 100755 index 0000000..c17b697 --- /dev/null +++ b/install_links.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +"""Create a symlink or a copy of an installed file.""" + +import argparse +import os +import shutil + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('bindir') + parser.add_argument('source') + parser.add_argument('dest', nargs='+') + parser.add_argument('--use-links', action='store_true') + args = parser.parse_args() + + os.chdir(os.environ['MESON_INSTALL_DESTDIR_PREFIX']) + os.chdir(args.bindir) + + # Windows doesn't really use symlinks, just copy in that case. Windows + # before vista (xp) doesn't have symlinks at all. + if args.use_links: + func = os.symlink + verb = 'Linking' + else: + func = shutil.copy + verb = 'Copying' + + # at least os.symlink will fail if the destination already exists, just + # remove the dest if it already exists. + for dest in args.dest: + if os.path.exists(dest): + os.unlink(dest) + + func(args.source, dest) + print('{} {} to {}'.format(verb, args.source, dest)) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/meson.build b/meson.build index 684d1ad..96d5a06 100644 --- a/meson.build +++ b/meson.build @@ -101,6 +101,19 @@ install_data( install_mode : 'rwxr-xr-x', ) +## Create aliases. Use links if possible, but copies if not. +# Copies are mainly meant for windows, which doesn't have symlinks. +bindir = get_option('bindir') +targets = [['bzmore', 'bzless'], ['bzdiff', 'bzcmp'], ['bzgrep', 'bzegrep', 'bzfgrep'], + ['bzip2', 'bunzip2', 'bzcat']] +extra_args = [] +if host_machine.system() != 'windows' and build_machine.system() != 'windows' + extra_args = '--use-links' +endif +foreach t : targets + meson.add_install_script('install_links.py', get_option('bindir'), t, extra_args) +endforeach + ## Generate pkg-config automaically from built library information pkg = import('pkgconfig') pkg.generate(