1# #############################################################################
2# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
3#                                lzutao <taolzu(at)gmail.com>
4# All rights reserved.
5#
6# This source code is licensed under both the BSD-style license (found in the
7# LICENSE file in the root directory of this source tree) and the GPLv2 (found
8# in the COPYING file in the root directory of this source tree).
9# #############################################################################
10
11zstd_rootdir = '../../..'
12
13zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
14  join_paths(zstd_rootdir, 'programs/util.c'),
15  join_paths(zstd_rootdir, 'programs/timefn.c'),
16  join_paths(zstd_rootdir, 'programs/fileio.c'),
17  join_paths(zstd_rootdir, 'programs/benchfn.c'),
18  join_paths(zstd_rootdir, 'programs/benchzstd.c'),
19  join_paths(zstd_rootdir, 'programs/datagen.c'),
20  join_paths(zstd_rootdir, 'programs/dibio.c'),
21  join_paths(zstd_rootdir, 'programs/zstdcli_trace.c')]
22
23zstd_c_args = libzstd_debug_cflags
24if use_multi_thread
25  zstd_c_args += [ '-DZSTD_MULTITHREAD' ]
26endif
27
28zstd_deps = [ libzstd_dep ]
29if use_zlib
30  zstd_deps += [ zlib_dep ]
31  zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ]
32endif
33
34if use_lzma
35  zstd_deps += [ lzma_dep ]
36  zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ]
37endif
38
39if use_lz4
40  zstd_deps += [ lz4_dep ]
41  zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ]
42endif
43
44export_dynamic_on_windows = false
45# explicit backtrace enable/disable for Linux & Darwin
46if not use_backtrace
47  zstd_c_args += '-DBACKTRACE_ENABLE=0'
48elif use_debug and host_machine_os == os_windows  # MinGW target
49  zstd_c_args += '-DBACKTRACE_ENABLE=1'
50  export_dynamic_on_windows = true
51endif
52
53if cc_id == compiler_msvc
54  if default_library_type != 'static'
55    zstd_programs_sources += [windows_mod.compile_resources(
56      join_paths(zstd_rootdir, 'build/VS2010/zstd/zstd.rc'))]
57  endif
58endif
59
60zstd = executable('zstd',
61  zstd_programs_sources,
62  c_args: zstd_c_args,
63  dependencies: zstd_deps,
64  export_dynamic: export_dynamic_on_windows, # Since Meson 0.45.0
65  install: true)
66
67zstd_frugal_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
68  join_paths(zstd_rootdir, 'programs/timefn.c'),
69  join_paths(zstd_rootdir, 'programs/util.c'),
70  join_paths(zstd_rootdir, 'programs/fileio.c')]
71
72# Minimal target, with only zstd compression and decompression.
73# No bench. No legacy.
74executable('zstd-frugal',
75  zstd_frugal_sources,
76  dependencies: libzstd_dep,
77  c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT', '-DZSTD_NOTRACE' ],
78  install: true)
79
80install_data(join_paths(zstd_rootdir, 'programs/zstdgrep'),
81  join_paths(zstd_rootdir, 'programs/zstdless'),
82  install_dir: zstd_bindir)
83
84# =============================================================================
85# Programs and manpages installing
86# =============================================================================
87
88install_man(join_paths(zstd_rootdir, 'programs/zstd.1'),
89  join_paths(zstd_rootdir, 'programs/zstdgrep.1'),
90  join_paths(zstd_rootdir, 'programs/zstdless.1'))
91
92InstallSymlink_py = '../InstallSymlink.py'
93zstd_man1_dir = join_paths(zstd_mandir, 'man1')
94bin_EXT = host_machine_os == os_windows ? '.exe' : ''
95man1_EXT = meson.version().version_compare('>=0.49.0') ? '.1' : '.1.gz'
96
97foreach f : ['zstdcat', 'unzstd']
98  meson.add_install_script(InstallSymlink_py, 'zstd' + bin_EXT, f + bin_EXT, zstd_bindir)
99  meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, f + man1_EXT, zstd_man1_dir)
100endforeach
101
102if use_multi_thread
103  meson.add_install_script(InstallSymlink_py, 'zstd' + bin_EXT, 'zstdmt' + bin_EXT, zstd_bindir)
104  meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, 'zstdmt' + man1_EXT, zstd_man1_dir)
105endif
106