This commit is contained in:
alb3e3 2026-08-03 15:04:26 +04:00 committed by GitHub
commit dbfebde847
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 103 deletions

View file

@ -1,39 +0,0 @@
#!/usr/bin/env python3
# #############################################################################
# Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
# All rights reserved.
#
# 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
# in the COPYING file in the root directory of this source tree).
# #############################################################################
import re
def find_version_tuple(filepath):
version_file_data = None
with open(filepath) as fd:
version_file_data = fd.read()
patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
#\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
#\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
"""
regex = re.compile(patterns, re.MULTILINE)
version_match = regex.search(version_file_data)
if version_match:
return version_match.groups()
raise Exception("Unable to find version string")
def main():
import argparse
parser = argparse.ArgumentParser(description='Print zstd version from lib/zstd.h')
parser.add_argument('file', help='path to lib/zstd.h')
args = parser.parse_args()
version_tuple = find_version_tuple(args.file)
print('.'.join(version_tuple))
if __name__ == '__main__':
main()

View file

@ -1,55 +0,0 @@
#!/usr/bin/env python3
# #############################################################################
# Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
# All rights reserved.
#
# 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
# in the COPYING file in the root directory of this source tree).
# #############################################################################
# This file should be synced with https://github.com/lzutao/meson-symlink
import os
import pathlib # since Python 3.4
def install_symlink(src, dst, install_dir, dst_is_dir=False, dir_mode=0o777):
if not install_dir.exists():
install_dir.mkdir(mode=dir_mode, parents=True, exist_ok=True)
if not install_dir.is_dir():
raise NotADirectoryError(install_dir)
new_dst = install_dir.joinpath(dst)
if new_dst.is_symlink() and os.readlink(new_dst) == src:
print('File exists: {!r} -> {!r}'.format(new_dst, src))
return
print('Installing symlink {!r} -> {!r}'.format(new_dst, src))
new_dst.symlink_to(src, target_is_directory=dst_is_dir)
def main():
import argparse
parser = argparse.ArgumentParser(description='Install a symlink',
usage='{0} [-h] [-d] [-m MODE] source dest install_dir\n\n'
'example:\n'
' {0} dash sh /bin'.format(pathlib.Path(__file__).name))
parser.add_argument('source', help='target to link')
parser.add_argument('dest', help='link name')
parser.add_argument('install_dir', help='installation directory')
parser.add_argument('-d', '--isdir',
action='store_true',
help='dest is a directory')
parser.add_argument('-m', '--mode',
help='directory mode on creating if not exist',
default='0o755')
args = parser.parse_args()
dir_mode = int(args.mode, 8)
meson_destdir = os.environ.get('MESON_INSTALL_DESTDIR_PREFIX', default='')
install_dir = pathlib.Path(meson_destdir, args.install_dir)
install_symlink(args.source, args.dest, install_dir, args.isdir, dir_mode)
if __name__ == '__main__':
main()

View file

@ -11,6 +11,7 @@
project('zstd',
['c', 'cpp'],
license: 'BSD-3-Clause OR GPL-2.0-only',
version: '1.6.0',
default_options : [
# There shouldn't be any need to force a C standard convention for zstd
# but in case one would want that anyway, this can be done here.
@ -23,13 +24,11 @@ project('zstd',
# so this isn't safe
#'werror=true'
],
version: run_command(
find_program('GetZstdLibraryVersion.py'), '../../lib/zstd.h',
check: true).stdout().strip(),
meson_version: '>=0.50.0')
meson_version: '>=0.61.0')
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
fs = import('fs')
pkgconfig = import('pkgconfig')
windows_mod = import('windows')
@ -46,6 +45,30 @@ compiler_clang = 'clang'
compiler_msvc = 'msvc'
zstd_version = meson.project_version()
zstd_h = fs.read('../../lib/zstd.h')
zstd_version_major = ''
zstd_version_minor = ''
zstd_version_release = ''
foreach line : zstd_h.split('\n')
line_parts = line.strip().split()
if line_parts.length() == 3 and line_parts[0] == '#define'
if line_parts[1] == 'ZSTD_VERSION_MAJOR'
zstd_version_major = line_parts[2]
elif line_parts[1] == 'ZSTD_VERSION_MINOR'
zstd_version_minor = line_parts[2]
elif line_parts[1] == 'ZSTD_VERSION_RELEASE'
zstd_version_release = line_parts[2]
endif
endif
endforeach
assert(zstd_version_major != '' and zstd_version_minor != '' and zstd_version_release != '',
'Unable to read zstd version from lib/zstd.h')
zstd_h_version = zstd_version_major + '.' + zstd_version_minor + '.' + zstd_version_release
assert(zstd_version == zstd_h_version,
'Meson project version @0@ does not match lib/zstd.h version @1@'.format(zstd_version, zstd_h_version))
zstd_libversion = zstd_version

View file

@ -108,17 +108,16 @@ install_man(join_paths(zstd_rootdir, 'programs/zstd.1'),
join_paths(zstd_rootdir, 'programs/zstdgrep.1'),
join_paths(zstd_rootdir, 'programs/zstdless.1'))
InstallSymlink_py = '../InstallSymlink.py'
zstd_man1_dir = join_paths(zstd_mandir, 'man1')
bin_EXT = host_machine_os == os_windows ? '.exe' : ''
man1_EXT = meson.version().version_compare('>=0.49.0') ? '.1' : '.1.gz'
foreach f : ['zstdcat', 'unzstd']
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)
install_symlink(f + bin_EXT, pointing_to: 'zstd' + bin_EXT, install_dir: zstd_bindir)
install_symlink(f + man1_EXT, pointing_to: 'zstd' + man1_EXT, install_dir: zstd_man1_dir)
endforeach
if use_multi_thread
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)
install_symlink('zstdmt' + bin_EXT, pointing_to: 'zstd' + bin_EXT, install_dir: zstd_bindir)
install_symlink('zstdmt' + man1_EXT, pointing_to: 'zstd' + man1_EXT, install_dir: zstd_man1_dir)
endif