Merge pull request #1447 from lzutao/meson_symlink_soversion
meson: More accurate Windows build support
This commit is contained in:
commit
d4698424ce
@ -1,70 +1,54 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
|
# Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# This source code is licensed under both the BSD-style license (found in the
|
# This source code is licensed under both the BSD-style license (found in the
|
||||||
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
# in the COPYING file in the root directory of this source tree).
|
# in the COPYING file in the root directory of this source tree).
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
import errno
|
# This file should be synced with https://github.com/lzutao/meson-symlink
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import pathlib # since Python 3.4
|
||||||
|
|
||||||
def mkdir_p(path, dir_mode=0o777):
|
|
||||||
try:
|
|
||||||
os.makedirs(path, mode=dir_mode)
|
|
||||||
except OSError as exc: # Python >2.5
|
|
||||||
if exc.errno == errno.EEXIST and os.path.isdir(path):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def install_symlink(src, dst, install_dir, dst_is_dir=False, dir_mode=0o777):
|
def install_symlink(src, dst, install_dir, dst_is_dir=False, dir_mode=0o777):
|
||||||
if not os.path.exists(install_dir):
|
if not install_dir.exists():
|
||||||
mkdir_p(install_dir, dir_mode)
|
install_dir.mkdir(mode=dir_mode, parents=True, exist_ok=True)
|
||||||
if not os.path.isdir(install_dir):
|
if not install_dir.is_dir():
|
||||||
raise NotADirectoryError(install_dir)
|
raise NotADirectoryError(install_dir)
|
||||||
|
|
||||||
new_dst = os.path.join(install_dir, dst)
|
new_dst = install_dir.joinpath(dst)
|
||||||
if os.path.islink(new_dst) and os.readlink(new_dst) == src:
|
if new_dst.is_symlink() and os.readlink(new_dst) == src:
|
||||||
print('File exists: {!r} -> {!r}'.format(new_dst, src))
|
print('File exists: {!r} -> {!r}'.format(new_dst, src))
|
||||||
return
|
return
|
||||||
print('Installing symlink {!r} -> {!r}'.format(new_dst, src))
|
print('Installing symlink {!r} -> {!r}'.format(new_dst, src))
|
||||||
os.symlink(src, new_dst, dst_is_dir)
|
new_dst.symlink_to(src, target_is_directory=dst_is_dir)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser(description='Install a symlink',
|
parser = argparse.ArgumentParser(description='Install a symlink',
|
||||||
usage='InstallSymlink.py [-h] [-d] [-m MODE] src dst install_dir\n\n'
|
usage='{0} [-h] [-d] [-m MODE] source dest install_dir\n\n'
|
||||||
'example:\n'
|
'example:\n'
|
||||||
'\tInstallSymlink.py dash sh /bin\n'
|
' {0} dash sh /bin'.format(pathlib.Path(__file__).name))
|
||||||
'\tDESTDIR=./staging InstallSymlink.py dash sh /bin')
|
parser.add_argument('source', help='target to link')
|
||||||
parser.add_argument('src', help='target to link')
|
parser.add_argument('dest', help='link name')
|
||||||
parser.add_argument('dst', help='link name')
|
|
||||||
parser.add_argument('install_dir', help='installation directory')
|
parser.add_argument('install_dir', help='installation directory')
|
||||||
parser.add_argument('-d', '--isdir',
|
parser.add_argument('-d', '--isdir',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='dst is a directory')
|
help='dest is a directory')
|
||||||
parser.add_argument('-m', '--mode',
|
parser.add_argument('-m', '--mode',
|
||||||
help='directory mode on creating if not exist',
|
help='directory mode on creating if not exist',
|
||||||
default='0o777')
|
default='0o755')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
src = args.src
|
|
||||||
dst = args.dst
|
|
||||||
install_dir = args.install_dir
|
|
||||||
dst_is_dir = args.isdir
|
|
||||||
dir_mode = int(args.mode, 8)
|
dir_mode = int(args.mode, 8)
|
||||||
|
|
||||||
DESTDIR = os.environ.get('DESTDIR')
|
meson_destdir = os.environ.get('MESON_INSTALL_DESTDIR_PREFIX', default='')
|
||||||
if DESTDIR:
|
install_dir = pathlib.Path(meson_destdir, args.install_dir)
|
||||||
install_dir = DESTDIR + install_dir if os.path.isabs(install_dir) \
|
install_symlink(args.source, args.dest, install_dir, args.isdir, dir_mode)
|
||||||
else os.path.join(DESTDIR, install_dir)
|
|
||||||
|
|
||||||
install_symlink(src, dst, install_dir, dst_is_dir, dir_mode)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -111,8 +111,7 @@ libzstd = library('zstd',
|
|||||||
c_args: libzstd_c_args,
|
c_args: libzstd_c_args,
|
||||||
dependencies: libzstd_deps,
|
dependencies: libzstd_deps,
|
||||||
install: true,
|
install: true,
|
||||||
version: zstd_libversion,
|
version: zstd_libversion)
|
||||||
soversion: '1')
|
|
||||||
|
|
||||||
libzstd_dep = declare_dependency(link_with: libzstd,
|
libzstd_dep = declare_dependency(link_with: libzstd,
|
||||||
include_directories: libzstd_includes)
|
include_directories: libzstd_includes)
|
||||||
|
@ -36,30 +36,30 @@ compiler_clang = 'clang'
|
|||||||
compiler_msvc = 'msvc'
|
compiler_msvc = 'msvc'
|
||||||
|
|
||||||
zstd_version = meson.project_version()
|
zstd_version = meson.project_version()
|
||||||
zstd_libversion = ''
|
|
||||||
|
|
||||||
# =============================================================================
|
zstd_h_file = join_paths(meson.current_source_dir(), '../../lib/zstd.h')
|
||||||
# Project directories
|
GetZstdLibraryVersion_py = files('GetZstdLibraryVersion.py')
|
||||||
# =============================================================================
|
r = run_command(python3, GetZstdLibraryVersion_py, zstd_h_file)
|
||||||
|
if r.returncode() == 0
|
||||||
|
output = r.stdout().strip()
|
||||||
|
if output.version_compare('>@0@'.format(zstd_version))
|
||||||
|
zstd_version = output
|
||||||
|
message('Project version is now: @0@'.format(zstd_version))
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
message('Cannot find project version in @0@'.format(zstd_h_file))
|
||||||
|
endif
|
||||||
|
|
||||||
zstd_rootdir = '../..'
|
zstd_libversion = zstd_version
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Installation directories
|
# Installation directories
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
if host_machine_os == os_windows
|
zstd_prefix = get_option('prefix')
|
||||||
zstd_prefix = '.'
|
zstd_bindir = get_option('bindir')
|
||||||
zstd_bindir = 'bin'
|
zstd_datadir = get_option('datadir')
|
||||||
zstd_datadir = 'share'
|
zstd_mandir = get_option('mandir')
|
||||||
zstd_mandir = join_paths(zstd_datadir, 'man')
|
|
||||||
else
|
|
||||||
zstd_prefix = get_option('prefix')
|
|
||||||
zstd_bindir = join_paths(zstd_prefix, get_option('bindir'))
|
|
||||||
zstd_datadir = join_paths(zstd_prefix, get_option('datadir'))
|
|
||||||
zstd_mandir = join_paths(zstd_prefix, get_option('mandir'))
|
|
||||||
endif
|
|
||||||
|
|
||||||
zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
|
zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@ -85,30 +85,6 @@ feature_zlib = get_option('zlib')
|
|||||||
feature_lzma = get_option('lzma')
|
feature_lzma = get_option('lzma')
|
||||||
feature_lz4 = get_option('lz4')
|
feature_lz4 = get_option('lz4')
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Helper scripts for Meson
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
GetZstdLibraryVersion_py = files('GetZstdLibraryVersion.py')
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Getting project version from zstd.h
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
zstd_h_file = join_paths(meson.current_source_dir(), zstd_rootdir, 'lib/zstd.h')
|
|
||||||
r = run_command(python3, GetZstdLibraryVersion_py, zstd_h_file)
|
|
||||||
if r.returncode() == 0
|
|
||||||
output = r.stdout().strip()
|
|
||||||
if output.version_compare('>@0@'.format(zstd_version))
|
|
||||||
zstd_version = output
|
|
||||||
message('Project version is now: @0@'.format(zstd_version))
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if host_machine_os != os_windows
|
|
||||||
zstd_libversion = zstd_version
|
|
||||||
endif
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
@ -88,14 +88,15 @@ install_man(join_paths(zstd_rootdir, 'programs/zstd.1'),
|
|||||||
|
|
||||||
InstallSymlink_py = '../InstallSymlink.py'
|
InstallSymlink_py = '../InstallSymlink.py'
|
||||||
zstd_man1_dir = join_paths(zstd_mandir, 'man1')
|
zstd_man1_dir = join_paths(zstd_mandir, 'man1')
|
||||||
man1_EXT = host_machine_os != os_windows ? '.1.gz' : '.1'
|
bin_EXT = host_machine_os == os_windows ? '.exe' : ''
|
||||||
|
man1_EXT = meson.version().version_compare('>=0.49.0') ? '.1' : '.1.gz'
|
||||||
|
|
||||||
foreach f : ['zstdcat', 'unzstd']
|
foreach f : ['zstdcat', 'unzstd']
|
||||||
meson.add_install_script(InstallSymlink_py, 'zstd', f, zstd_bindir)
|
meson.add_install_script(InstallSymlink_py, 'zstd' + bin_EXT, f + bin_EXT, zstd_bindir)
|
||||||
meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, f + man1_EXT, zstd_man1_dir)
|
meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, f + man1_EXT, zstd_man1_dir)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
if use_multi_thread
|
if use_multi_thread
|
||||||
meson.add_install_script(InstallSymlink_py, 'zstd', 'zstdmt', zstd_bindir)
|
meson.add_install_script(InstallSymlink_py, 'zstd' + bin_EXT, 'zstdmt' + bin_EXT, zstd_bindir)
|
||||||
meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, 'zstdmt' + man1_EXT, zstd_man1_dir)
|
meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, 'zstdmt' + man1_EXT, zstd_man1_dir)
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user