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
22zstd_c_args = libzstd_debug_cflags
23if use_multi_thread
24  zstd_c_args += [ '-DZSTD_MULTITHREAD' ]
25endif
26
27zstd_deps = [ libzstd_dep ]
28if use_zlib
29  zstd_deps += [ zlib_dep ]
30  zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ]
31endif
32
33if use_lzma
34  zstd_deps += [ lzma_dep ]
35  zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ]
36endif
37
38if use_lz4
39  zstd_deps += [ lz4_dep ]
40  zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ]
41endif
42
43export_dynamic_on_windows = false
44# explicit backtrace enable/disable for Linux & Darwin
45if not use_backtrace
46  zstd_c_args += '-DBACKTRACE_ENABLE=0'
47elif use_debug and host_machine_os == os_windows  # MinGW target
48  zstd_c_args += '-DBACKTRACE_ENABLE=1'
49  export_dynamic_on_windows = true
50endif
51
52if cc_id == compiler_msvc
53  if default_library_type != 'static'
54    zstd_programs_sources += [windows_mod.compile_resources(
55      join_paths(zstd_rootdir, 'build/VS2010/zstd/zstd.rc'))]
56  endif
57endif
58
59zstd = executable('zstd',
60  zstd_programs_sources,
61  c_args: zstd_c_args,
62  dependencies: zstd_deps,
63  export_dynamic: export_dynamic_on_windows, # Since Meson 0.45.0
64  install: true)
65
66zstd_frugal_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
67  join_paths(zstd_rootdir, 'programs/timefn.c'),
68  join_paths(zstd_rootdir, 'programs/util.c'),
69  join_paths(zstd_rootdir, 'programs/fileio.c')]
70
71# Minimal target, with only zstd compression and decompression.
72# No bench. No legacy.
73executable('zstd-frugal',
74  zstd_frugal_sources,
75  dependencies: libzstd_dep,
76  c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ],
77  install: true)
78
79install_data(join_paths(zstd_rootdir, 'programs/zstdgrep'),
80  join_paths(zstd_rootdir, 'programs/zstdless'),
81  install_dir: zstd_bindir)
82
83# =============================================================================
84# Programs and manpages installing
85# =============================================================================
86
87install_man(join_paths(zstd_rootdir, 'programs/zstd.1'),
88  join_paths(zstd_rootdir, 'programs/zstdgrep.1'),
89  join_paths(zstd_rootdir, 'programs/zstdless.1'))
90
91InstallSymlink_py = '../InstallSymlink.py'
92zstd_man1_dir = join_paths(zstd_mandir, 'man1')
93bin_EXT = host_machine_os == os_windows ? '.exe' : ''
94man1_EXT = meson.version().version_compare('>=0.49.0') ? '.1' : '.1.gz'
95
96foreach f : ['zstdcat', 'unzstd']
97  meson.add_install_script(InstallSymlink_py, 'zstd' + bin_EXT, f + bin_EXT, zstd_bindir)
98  meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, f + man1_EXT, zstd_man1_dir)
99endforeach
100
101if use_multi_thread
102  meson.add_install_script(InstallSymlink_py, 'zstd' + bin_EXT, 'zstdmt' + bin_EXT, zstd_bindir)
103  meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, 'zstdmt' + man1_EXT, zstd_man1_dir)
104endif
105