diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..5b1552042 --- /dev/null +++ b/meson.build @@ -0,0 +1,362 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +project( + 'xz', + 'c', + version: '5.6.99', + license: '0BSD', + license_files: [ + 'COPYING', + 'COPYING.0BSD', + 'COPYING.GPLv2', + 'COPYING.GPLv3', + 'COPYING.LGPLv2.1' + ], + default_options: [ + 'b_ndebug=if-release', + 'c_std=c11', + 'warning_level=3', + ], + meson_version: '>= 1.1.0', +) + +v_array = meson.project_version().split('.') +v_maj = v_array[0] + +# config.h + +config_dir = [include_directories('.')] + +config_h = configuration_data() +config_h.set_quoted('PACKAGE', 'xz') +config_h.set_quoted('PACKAGE_BUGREPORT', 'xz@tukaani.org') +config_h.set_quoted('PACKAGE_NAME', meson.project_name()) +config_h.set_quoted('PACKAGE_URL', 'https://tukaani.org/xz/') + +# host + +config_h.set('WORDS_BIGENDIAN', + host_machine.endian() == 'big', + description: 'Defined if the processor stores words with the most significant byte first.' +) + +host_os = host_machine.system() + +cygwin = 'cygwin' +windows = 'windows' +linux = 'linux' +sunos = 'sunos' +asm_os = [ 'linux', 'dragonfly', 'freebsd', 'netbsd', 'openbsd', 'windows', 'cygwin' ] +sys_cygwin = cygwin.contains(host_os) +sys_windows = windows.contains(host_os) +sys_sunos = sunos.contains(host_os) + +COND_W32 = sys_cygwin or sys_windows + +# binaries +cc = meson.get_compiler('c') + +# try mimic AC_USE_SYSTEM_EXTENSIONS +add_project_arguments('-D_GNU_SOURCE', language: 'c') +add_project_arguments('-D__EXTENSIONS__', language: 'c') +if host_machine.system() == 'sunos' + add_project_arguments('-D_POSIX_PTHREAD_SEMANTICS', language: 'c') +else + add_project_arguments('-D_TANDEM_SOURCE', language: 'c') + add_project_arguments('-D_ALL_SOURCE', language: 'c') +endif + +# unconditionally define macro for C99 headers +add_project_arguments('-DHAVE_INTTYPES_H', language: 'c') +add_project_arguments('-DHAVE_STDBOOL_H', language: 'c') +add_project_arguments('-DHAVE_STDINT_H', language: 'c') +# unconditionally define macro for C99 functions +add_project_arguments('-DHAVE_MBRTOWC', language: 'c') + +lzma_c_args = [] +cflags_try = [] + +if cc.get_argument_syntax() == 'gcc' + cflags_try += [ + '-Wvla', + '-Wformat=2', + '-Winit-self', + '-Wmissing-include-dirs', + '-Wshift-overflow=2', + '-Wstrict-overflow=3', + '-Walloc-zero', + '-Wduplicated-cond', + '-Wfloat-equal', + '-Wundef', + '-Wshadow', + '-Wpointer-arith', + '-Wbad-function-cast', + '-Wwrite-strings', + '-Wdate-time', + '-Wsign-conversion', + '-Wfloat-conversion', + '-Wlogical-op', + '-Waggregate-return', + '-Wstrict-prototypes', + '-Wold-style-definition', + '-Wmissing-prototypes', + '-Wmissing-declarations', + '-Wredundant-decls', + # + '-Wc99-compat', + '-Wc11-extensions', + '-Wc2x-compat', + '-Wc2x-extensions', + '-Wpre-c2x-compat', + '-Warray-bounds-pointer-arithmetic', + '-Wassign-enum', + '-Wconditional-uninitialized', + '-Wdocumentation', + '-Wduplicate-enum', + '-Wempty-translation-unit', + '-Wflexible-array-extensions', + '-Wmissing-variable-declarations', + '-Wnewline-eof', + '-Wshift-sign-overflow', + '-Wstring-conversion', + ] + + lzma_c_args += cc.get_supported_arguments(cflags_try) +endif + +config_h.set10('HAVE_VISIBILITY', + cc.has_function_attribute('visibility'), + description: 'Defined to 1 if the compiler supports simple visibility declarations.' +) + + +config_h.set('HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR', + cc.has_function_attribute('constructor'), + description: 'Defined if __attribute__((__constructor__)) is supported for functions.', +) + +time_fcts = [ + [ 'futimens', [ '#include ' ] ], + [ 'futimes', [ '#include ' ] ], + [ 'futimesat', [ '#include ', '#include ' ] ], + [ 'utimes', [ '#include ' ] ], + [ '_futime', [ '#include ' ] ], + [ 'utime', [ '#include ', '#include ' ] ], +] + +foreach f : time_fcts + res = cc.has_function(f[0], prefix : f[1]) + config_h.set('HAVE_' + f[0].to_upper(), + res, + description: 'Defined if the ' + f[0] + '() function is available.' + ) + if res + break + endif +endforeach + +config_h.set('HAVE_POSIX_FADVISE', + cc.has_function('posix_fadvise', prefix : '#include '), + description: 'Defined if the posix_fadvise() function is available.' +) + +### Filters + +## encoders +encoder_msg = '' +decoder_msg = '' + +simple_filters = [ + 'x86', + 'powerpc', + 'ia64', + 'arm', + 'armthumb', + 'arm64', + 'sparc', + 'riscv', +] + +# FIXME foreach i in array; set_variable(f'have_@i@', true) endforeach + +foreach f : get_option('encoders') + config_h.set('HAVE_ENCODER_' + f.underscorify().to_upper(), + true, + description: 'Defined if ' + f + ' encoder is enabled.' + ) + encoder_msg += f + ' ' +endforeach + +foreach f : get_option('decoders') + config_h.set('HAVE_DECODER_' + f.underscorify().to_upper(), + true, + description: 'Defined if ' + f + ' decoder is enabled.' + ) + decoder_msg += f + ' ' +endforeach + +have_encoder_simple_filters = false +have_decoder_simple_filters = false +foreach f : simple_filters + if f in get_option('encoders') + have_encoder_simple_filters = true + endif + if f in get_option('decoders') + have_decoder_simple_filters = true + endif +endforeach + +if ('lzma2' in get_option('encoders') and not ('lzma1' in get_option('encoders'))) or('lzma2' in get_option('decoders') and not ('lzma1' in get_option('decoders'))) + error('LZMA2 requires that LZMA1 is also enabled') +endif + +if get_option('encoders').length() > 0 + config_h.set('HAVE_ENCODERS', + true, + description: 'Defined if at least one encoder has been enabled.' + ) +endif + +if get_option('decoders').length() > 0 + config_h.set('HAVE_DECODERS', + true, + description: 'Defined if at least one decoder has been enabled.' + ) +endif + +### Match finders + +match_finder_msg = '' + +if 'lzma1' in get_option('encoders') or 'lzma2' in get_option('encoders') + if get_option('match-finders').length() == 0 + error('at least one match finder is required for an LZ-based encoder') + endif + + foreach m : get_option('match-finders') + config_h.set('HAVE_MF_' + m.underscorify().to_upper(), + true, + description: 'Defined to enable ' + m + ' match finder.' + ) + match_finder_msg += m + ' ' + endforeach +endif + +### Integrity checks + +check_msg = '' + +if not ('crc32' in get_option('checks')) + error('For now, the CRC32 check must always be enabled') +endif + +foreach c : get_option('checks') + config_h.set('HAVE_CHECK_' + c.underscorify().to_upper(), + true, + description: 'Define to 1 if ' + c + ' integrity check is enabled.' + ) + check_msg += c + ' ' +endforeach + +### microLZMA + +if get_option('microlzma') == true +endif + +### .lz (lzip) format support + +have_lzip = false +if not ('lzma1' in get_option('encoders')) + lzip_msg = 'no (LZMA1 disabled)' +elif get_option('lzip-decoder') + lzip_msg = 'yes' + have_lzip = true + config_h.set('HAVE_LZIP_DECODER', + true, + description: 'Defined if .lz (lzip) decompression support is enabled.' + ) +else + lzip_msg = 'no' +endif + +### assembler optimizations + +have_assembler_x86 = false +if get_option('assembler') + if host_os in asm_os and host_machine.cpu_family() == 'x86' + have_assembler_x86 = true + endif +endif + +### size optimization + +config_h.set('HAVE_SMALL', + get_option('small'), + description: 'Defined if optimizing for size.' +) + +### threading + +have_threads = false + +if get_option('threads') == true + if sys_windows == true + config_h.set('MYTHREAD_WIN95', + host_machine.cpu_family() == 'x86', + description: 'Defined when using Windows 95 (and thus XP) compatible threads. This avoids use of features that were added in Windows Vista.' + ) + config_h.set('MYTHREAD_VISTA', + host_machine.cpu_family() != 'x86', + description: 'Defined when using Windows Vista compatible threads. This uses features that are not available on Windows XP.' + ) + have_threads = true + else + # FIXME: pthread detection should be fixed + pthread_dep = dependency('threads', required : false) + config_h.set('MYTHREAD_POSIX', + pthread_dep.found(), + description: 'Defined when using POSIX threads (pthreads).' + ) + have_threads = pthread_dep.found() + endif +endif + + +### subdirectories + +subdir('src') +subdir('tests') + +configure_file(output: 'config.h', configuration: config_h) + +# summary + +summary( + { + 'OS': host_os, + 'endianness': host_machine.endian(), + 'assembler': get_option('assembler').to_string('yes', 'no'), + 'encoders': encoder_msg, + 'decoders': decoder_msg, + 'match finders': match_finder_msg, + 'checks': check_msg, + 'external sha256': get_option('external-sha256').to_string('yes', 'no'), + 'microLZMA': get_option('microlzma').to_string('yes', 'no'), + 'lzip decompression': lzip_msg, + 'small': get_option('small').to_string('yes', 'no'), + 'threads': have_threads.to_string('yes', 'no'), + 'fast unaligned access': fast_unaligned_access.to_string('yes', 'no'), + 'unsafe type punning': get_option('unsafe-type-punning').to_string('yes', 'no') + }, + section: 'Configuration Options Summary:', +) + +summary( + { + 'xzdec': get_option('xzdec').to_string('yes', 'no'), + 'lzmadec': get_option('lzmadec').to_string('yes', 'no'), + 'xz': get_option('xz').to_string('yes', 'no') + ((get_option('assume-ram') > 0) ? ' (' + get_option('assume-ram').to_string() + ' MiB)' : ''), + }, + section: 'Tools', +) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..26aea208d --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,188 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +# [ ] debug - not used : done by meson +# [ ] arm64-crc32 +# [X] assembler +# [X] assume-ram +# [X] checks +# [ ] clmul-crc +# [X] decoders +# [ ] doc +# [ ] doxygen +# [X] encoders +# [X] external-sha256 +# [X] lzip-decoder +# [X] lzmadec +# [X] lzmainfo +# [ ] lzma-links +# [X] match-finders +# [X] microlzma +# [X] path-for-scripts +# [ ] sandbox +# [X] small +# [ ] symbol-versions +# [ ] scripts +# [X] threads +# [X] unaligned-access +# [X] unsafe-type-punning +# [ ] werror - not used : done by meson +# [X] xz +# [X] xzdec + +option('arm64-crc32', + type : 'boolean', + value : true, + description : 'use ARM64 CRC32 instructions' +) + +option('assembler', + type : 'boolean', + value : true, + description : 'use assembler optimizations' +) + +option('assume-ram', + type : 'integer', + value : 128, + description : 'how much RAM in MiB to assume if the real amount is unknown' +) + +option('checks', + type : 'array', + choices : [ 'crc32', 'crc64', 'sha256' ], + value : [ 'crc32', 'crc64', 'sha256' ], + description : 'list of integrity checks to build' +) + +option('clmul-crc', + type : 'boolean', + value : true, + description : 'use carryless multiplication for CRC calculation' +) + +option('decoders', + type : 'array', + choices : [ 'lzma1', 'lzma2', 'delta', 'x86', 'powerpc', 'ia64', 'arm', 'armthumb', 'arm64', 'sparc', 'riscv' ], + value : [ 'lzma1', 'lzma2', 'delta', 'x86', 'powerpc', 'ia64', 'arm', 'armthumb', 'arm64', 'sparc', 'riscv' ], + description : 'list of decoders to build' +) + +option('doc', + type : 'boolean', + value : true, + description : 'install documentation files' +) + +option('encoders', + type : 'array', + choices : [ 'lzma1', 'lzma2', 'delta', 'x86', 'powerpc', 'ia64', 'arm', 'armthumb', 'arm64', 'sparc', 'riscv' ], + value : [ 'lzma1', 'lzma2', 'delta', 'x86', 'powerpc', 'ia64', 'arm', 'armthumb', 'arm64', 'sparc', 'riscv' ], + description : 'list of encoders to build' +) + +option('external-sha256', + type : 'boolean', + value : false, + description : 'use SHA-256 code from the operating system' +) + +option('lzip-decoder', + type : 'boolean', + value : true, + description : 'decompression support for .lz (lzip) files' +) + +option('lzmadec', + type : 'boolean', + value : true, + description : 'build lzmadec' +) + +option('lzmainfo', + type : 'boolean', + value : true, + description : 'build lzmainfo' +) + +option('lzma-links', + type : 'boolean', + value : true, + description : 'create symlinks for LZMA Utils compatibility' +) + +option('match-finders', + type : 'array', + choices : [ 'hc3', 'hc4', 'bt2', 'bt3', 'bt4' ], + value : [ 'hc3', 'hc4', 'bt2', 'bt3', 'bt4' ], + description : 'list of match finders to build' +) + +option('microlzma', + type : 'boolean', + value : true, + description : 'build MicroLZMA encoder and decoder, needed by specific applications' +) + +option('path-for-scripts', + type : 'string', + value : '', + description : 'if not empty, the path will be added to PATH. If empty and on solaris, the path is /usr/xpg4/bin' +) + +option('sandbox', + type : 'combo', + choices : [ 'auto', 'no', 'capsicum', 'pledge', 'landlock' ], + value : 'auto', + description : 'sandboxing method' +) + +option('scripts', + type : 'boolean', + value : true, + description : 'install the scripts xzdiff, xzgrep, xzless, xzmore, and their symlinks' +) + +option('small', + type : 'boolean', + value : false, + description : 'make liblzma smaller and a little slower' +) + +option( + 'symbol-versions', + type: 'feature', + value: 'auto', + description: 'use symbol versioning for liblzma. Enabled by default on GNU/Linux, other GNU-based systems, and FreeBSD', +) + +option('threads', + type : 'boolean', + value : true, + description : 'threading support' +) + +option( + 'unaligned-access', + type: 'feature', + value: 'auto', + description: '*fast* unaligned memory access with 16-bit, 32-bit, and 64-bit integers. Enabled by default on x86, x86-64, 32/64-bit big endian PowerPC, 64-bit little endian PowerPC and some ARM, ARM64, and RISC-V systems.' +) + +option('unsafe-type-punning', + type : 'boolean', + value : false, + description : 'use unsafe type punning' +) + +option('xz', + type : 'boolean', + value : true, + description : 'build the xz tool' +) + +option('xzdec', + type : 'boolean', + value : true, + description : 'build xzdec' +) diff --git a/src/common/meson.build b/src/common/meson.build new file mode 100644 index 000000000..f78d68d2b --- /dev/null +++ b/src/common/meson.build @@ -0,0 +1,367 @@ +# SPDX-License-Identifier: 0BSD + +# [X] tuklib_common.m4 +# [X] tuklib_cpucores.m4 +# [X] tuklib_integer.m4 +# [X] tuklib_mbstr.m4 +# [X] tuklib_physmem.m4 +# [X] tuklib_progname.m4 + +# tuklib_common.m4 + +## requires c99, host, AC_USE_SYSTEM_EXTENSIONS +## nothing to do, here (already in toplevel meson.build) + +# tuklib_cpucores.m4 + +have_sys_param_h = cc.has_header('sys/param.h') + +cpu_special_src = ''' +#if defined(_WIN32) || defined(__CYGWIN__) +int main(void) { return 0; } +#else +compile error +#endif +''' + +cpu_sched_getaffinity_src = ''' +#include +int +main(void) +{ + cpu_set_t cpu_mask; + sched_getaffinity(0, sizeof(cpu_mask), &cpu_mask); + return CPU_COUNT(&cpu_mask); +} +''' + +cpu_cpuset_src = ''' +#include +#include + +int +main(void) +{ + cpuset_t set; + cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, + sizeof(set), &set); + return 0; +} +''' + +cpu_sysctl_src = ''' +#ifdef __QNX__ +compile error +#endif +#ifdef HAVE_SYS_PARAM_H +# include +#endif +#include +int +main(void) +{ +#ifdef HW_NCPUONLINE + /* This is preferred on OpenBSD, see tuklib_cpucores.c. */ + int name[2] = { CTL_HW, HW_NCPUONLINE }; +#else + int name[2] = { CTL_HW, HW_NCPU }; +#endif + int cpus; + size_t cpus_size = sizeof(cpus); + sysctl(name, 2, &cpus, &cpus_size, NULL, 0); + return 0; +} +''' + +cpu_sysconf_src = ''' +#include +int +main(void) +{ + long i; +#ifdef _SC_NPROCESSORS_ONLN + /* Many systems using sysconf() */ + i = sysconf(_SC_NPROCESSORS_ONLN); +#else + /* IRIX */ + i = sysconf(_SC_NPROC_ONLN); +#endif + return 0; +} +''' + +cpu_pstat_getdynamic_src = ''' +#include +#include + +int +main(void) +{ + struct pst_dynamic pst; + pstat_getdynamic(&pst, sizeof(pst), 1, 0); + (void)pst.psd_proc_cnt; + return 0; +} +''' + +if cc.compiles(cpu_special_src, name : 'number of cpu cores on Windows or Cygwin') +# nothing to do, here +elif cc.compiles(cpu_sched_getaffinity_src, name : 'number of cpu cores with sched_getaffinity()') + config_h.set('TUKLIB_CPUCORES_SCHED_GETAFFINITY', true) +elif cc.compiles(cpu_cpuset_src, name : 'number of cpu cores with cpuset()') + config_h.set('TUKLIB_CPUCORES_CPUSET', true) +elif cc.compiles(cpu_sysctl_src, args : have_sys_param_h ? '-DHAVE_SYS_PARAM_H' : '', name : 'number of cpu cores with sysctl()') + config_h.set('TUKLIB_CPUCORES_SYSCTL', true) +elif cc.compiles(cpu_sysconf_src, name : 'number of cpu cores with sysconf()') + config_h.set('TUKLIB_CPUCORES_SYSCONF', true) +elif cc.compiles(cpu_pstat_getdynamic_src, name : 'number of cpu cores with pstat_getdynamic()') + config_h.set('TUKLIB_CPUCORES_PSTAT_GETDYNAMIC', true) +endif + +# tuklib_integer.m4 + +bswap_src = ''' +int main() +{ + __builtin_bswap16(1); + __builtin_bswap32(1); + __builtin_bswap64(1); + return 0; +} +''' +res = cc.links(bswap_src, name: '__builtin_bswap16/32/64') +if res + config_h.set('HAVE___BUILTIN_BSWAPXX', true, + description: 'Defined if the GNU C extensions __builtin_bswap16/32/64 are supported.' + ) +else + have_byteswap_h = false + have_sys_endian_h = false + have_sys_byteorder_h = false + bswap_headers = [ + 'byteswap.h', + 'sys/endian.h', + 'sys/byteorder.h' + ] + foreach h : bswap_headers + if cc.has_header(h) + config_h.set('HAVE_' + h.underscorify().to_upper(), true) + set_variable(f'have_' + h.underscorify(), true) + endif + endforeach + + if have_byteswap_h + bswap_fcts = [ + 'bswap_16', + 'bswap_32', + 'bswap_64' + ] + foreach f : bswap_fcts + bswap_src = ''' +#include +int main() +{ + @0@(42); + return 0; +} +''' + config_h.set('HAVE_' + f.to_upper(), + cc.links(bswap_src.format(f), name: f), + description: 'Defined if ' + f + '() is available.' + ) + endforeach + endif +endif + +fast_unaligned_access = false +if get_option('unaligned-access').auto() + unaligned_access_cpus = [ + 'ppc', + 'ppc64', + 'x86', + 'x86_64', + ] + if host_machine.cpu_family() in unaligned_access_cpus + config_h.set('TUKLIB_FAST_UNALIGNED_ACCESS', true, + description: 'Defined if the system supports fast unaligned access to 16-bit, 32-bit, and 64-bit integers.' + ) + fast_unaligned_access = true + endif + + if not fast_unaligned_access + unaligned_access_cpus = [ + 'aarch64', + 'arm', + 'riscv32', + 'riscv64', + ] + if host_machine.cpu_family() in unaligned_access_cpus + ua_src = ''' +#if !defined(__ARM_FEATURE_UNALIGNED) \ + && !defined(__riscv_misaligned_fast) \ + && !defined(_MSC_VER) +compile error +#endif +int main(void) { return 0; } +''' + if cc.compiles(ua_src, name: 'fast unaligned access for ' + host_machine.cpu_family()) + config_h.set('TUKLIB_FAST_UNALIGNED_ACCESS', true, + description: 'Defined if the system supports fast unaligned access to 16-bit, 32-bit, and 64-bit integers.' + ) + fast_unaligned_access = true + endif + endif + endif +elif get_option('unaligned-access').enabled() + config_h.set('TUKLIB_FAST_UNALIGNED_ACCESS', true, + description: 'Defined if the system supports fast unaligned access to 16-bit, 32-bit, and 64-bit integers.' + ) + fast_unaligned_access = true +endif + +if get_option('unsafe-type-punning') + config_h.set('HAVE___BUILTIN_ASSUME_ALIGNED', true, + description: 'Defined if the GNU C extension __builtin_assume_aligned is supported.' + ) +endif + +# tuklib_mbstr.m4 + +config_h.set('HAVE_WCWIDTH', + cc.has_function('wcwidth', prefix : '#include '), + description: 'Defined if the wcwidth() function is available.' +) + +# tuklib_physmem.m4 + + +physmem_special_src = ''' +#if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \ + || defined(__DJGPP__) || defined(__VMS) \ + || defined(AMIGA) || defined(__AROS__) || defined(__QNX__) +int main(void) { return 0; } +#else +compile error +#endif +''' + +physmem_aix_src = ''' +#include + +int +main(void) +{ + (void)_system_configuration.physmem; + return 0; +} +''' + +physmem_sysconf_src = ''' +#include +int +main(void) +{ + long i; + i = sysconf(_SC_PAGESIZE); + i = sysconf(_SC_PHYS_PAGES); + return 0; +} +''' + +physmem_sysctl_src = ''' +#ifdef HAVE_SYS_PARAM_H +# include +#endif +#include +int +main(void) +{ + int name[2] = { CTL_HW, HW_PHYSMEM }; + unsigned long mem; + size_t mem_ptr_size = sizeof(mem); + sysctl(name, 2, &mem, &mem_ptr_size, NULL, 0); + return 0; +} +''' + +physmem_getsysinfo_src = ''' +#include +#include + +int +main(void) +{ + int memkb; + int start = 0; + getsysinfo(GSI_PHYSMEM, (caddr_t)&memkb, sizeof(memkb), &start); + return 0; +} +''' + +physmem_pstat_getstatic_src = ''' +#include +#include + +int +main(void) +{ + struct pst_static pst; + pstat_getstatic(&pst, sizeof(pst), 1, 0); + (void)pst.physical_memory; + (void)pst.page_size; + return 0; +} +''' + +physmem_getinvent_r_src = ''' +#include +int +main(void) +{ + inv_state_t *st = NULL; + setinvent_r(&st); + getinvent_r(st); + endinvent_r(st); + return 0; +} +''' + +physmem_sysinfo_src = ''' +#include +int +main(void) +{ + struct sysinfo si; + sysinfo(&si); + return 0; +} +''' + +if cc.compiles(physmem_special_src, name : 'physical memory on some special OSes') +# nothing to do, here +elif cc.compiles(physmem_aix_src, name : 'physical memory on AIX') + config_h.set('TUKLIB_PHYSMEM_AIX', true) +elif cc.compiles(physmem_sysconf_src, name : 'physical memory with sysconf()') + config_h.set('TUKLIB_PHYSMEM_SYSCONF', true) +elif cc.compiles(physmem_sysctl_src, args : have_sys_param_h ? '-DHAVE_SYS_PARAM_H' : '', name : 'physical memory with sysctl()') + config_h.set('TUKLIB_PHYSMEM_SYSCTL', true) +elif cc.compiles(physmem_getsysinfo_src, name : 'physical memory with getsysinfo()') + config_h.set('TUKLIB_PHYSMEM_GETSYSINFO', true) +elif cc.compiles(physmem_pstat_getstatic_src, name : 'physical memory with pstat_getstatic()') + config_h.set('TUKLIB_PHYSMEM_PSTAT_GETSTATIC', true) +elif cc.compiles(physmem_getinvent_r_src, name : 'physical memory with getinvent_r()') + config_h.set('TUKLIB_PHYSMEM_GETINVENT_R', true) +elif cc.compiles(physmem_sysinfo_src, name : 'physical memory with sysinfo()') + config_h.set('TUKLIB_PHYSMEM_SYSINFO', true) +endif + +# tuklib_progname.m4 + +if cc.has_function('program_invocation_name', + args : '-D_GNU_SOURCE', + prefix : '#include ' + ) + config_h.set('HAVE_PROGRAM_INVOCATION_NAME', true, + description: 'Defined if the program_invocation_name() function is available.' + ) +endif diff --git a/src/liblzma/meson.build b/src/liblzma/meson.build new file mode 100644 index 000000000..f8865044a --- /dev/null +++ b/src/liblzma/meson.build @@ -0,0 +1,347 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +lzma_src = [ + '../common/tuklib_physmem.c', +] + +if have_threads + lzma_src += [ + '../common/tuklib_cpucores.c', + ] +endif + +# common/Makefile.inc + +lzma_src += [ + 'common/common.c', + 'common/block_util.c', + 'common/easy_preset.c', + 'common/filter_common.c', + 'common/hardware_physmem.c', + 'common/index.c', + 'common/stream_flags_common.c', + 'common/string_conversion.c', + 'common/vli_size.c', +] + +if have_threads + lzma_src += [ + 'common/hardware_cputhreads.c', + 'common/outqueue.c', + ] +endif + +if get_option('encoders').length() > 0 + lzma_src += [ + 'common/alone_encoder.c', + 'common/block_buffer_encoder.c', + 'common/block_encoder.c', + 'common/block_header_encoder.c', + 'common/easy_buffer_encoder.c', + 'common/easy_encoder.c', + 'common/easy_encoder_memusage.c', + 'common/filter_buffer_encoder.c', + 'common/filter_encoder.c', + 'common/filter_flags_encoder.c', + 'common/index_encoder.c', + 'common/stream_buffer_encoder.c', + 'common/stream_encoder.c', + 'common/stream_flags_encoder.c', + 'common/vli_encoder.c', + ] + + if have_threads + lzma_src += [ + 'common/stream_encoder_mt.c', + ] + endif + + if get_option('microlzma') + lzma_src += [ + 'common/microlzma_encoder.c', + ] + endif +endif + +if get_option('decoders').length() > 0 + lzma_src += [ + 'common/alone_decoder.c', + 'common/auto_decoder.c', + 'common/block_buffer_decoder.c', + 'common/block_decoder.c', + 'common/block_header_decoder.c', + 'common/easy_decoder_memusage.c', + 'common/file_info.c', + 'common/filter_buffer_decoder.c', + 'common/filter_decoder.c', + 'common/filter_flags_decoder.c', + 'common/index_decoder.c', + 'common/index_hash.c', + 'common/stream_buffer_decoder.c', + 'common/stream_decoder.c', + 'common/stream_flags_decoder.c', + 'common/vli_decoder.c' + ] + + if have_threads + lzma_src += [ + 'common/stream_decoder_mt.c', + ] + endif + + if get_option('microlzma') + lzma_src += [ + 'common/microlzma_decoder.c' + ] + endif + + if have_lzip + lzma_src += 'common/lzip_decoder.c' + endif +endif + +# check/Makefile.inc + +lzma_src += [ + 'check/check.c' +] + +if get_option('small') + lzma_src += [ + 'check/crc32_small.c' + ] +else + lzma_src += [ + 'check/crc32_table.c' + ] + + if have_assembler_x86 + lzma_src += [ + 'check/crc32_x86.S' + ] + else + lzma_src += [ + 'check/crc32_fast.c' + ] + endif +endif + +if 'crc64' in get_option('checks') + if get_option('small') + lzma_src += [ + 'check/crc64_small.c' + ] + else + lzma_src += [ + 'check/crc64_table.c' + ] + + if have_assembler_x86 + lzma_src += [ + 'check/crc64_x86.S' + ] + else + lzma_src += [ + 'check/crc64_fast.c' + ] + endif + endif +endif + +if ('sha256' in get_option('checks')) and (not get_option('external-sha256')) + lzma_src += [ + 'check/sha256.c' + ] +endif + +# lz/Makefile.inc +if ('lzma1' in get_option('encoders')) or ('lzma2' in get_option('encoders')) + lzma_src += [ + 'lz/lz_encoder.c', + 'lz/lz_encoder_mf.c' + ] + endif + +if ('lzma1' in get_option('decoders')) or ('lzma2' in get_option('decoders')) + lzma_src += [ + 'lz/lz_decoder.c' + ] +endif + +if ('lzma1' in get_option('encoders')) or ('lzma1' in get_option('decoders')) + + # lzma/Makefile.inc + lzma_src += [ + 'lzma/lzma_encoder_presets.c' + ] + + if 'lzma1' in get_option('encoders') + lzma_src += [ + 'lzma/lzma_encoder.c', + 'lzma/lzma_encoder_optimum_fast.c', + 'lzma/lzma_encoder_optimum_normal.c' + ] + + if not get_option('small') + lzma_src += [ + 'lzma/fastpos_table.c' + ] + endif + endif + + if 'lzma1' in get_option('decoders') + lzma_src += [ + 'lzma/lzma_decoder.c' + ] + endif + + if 'lzma2' in get_option('encoders') + lzma_src += [ + 'lzma/lzma2_encoder.c' + ] + endif + + if 'lzma2' in get_option('decoders') + lzma_src += [ + 'lzma/lzma2_decoder.c' + ] + endif + + # rangecoder/Makefile.inc + if 'lzma1' in get_option('encoders') + lzma_src += [ + 'rangecoder/price_table.c' + ] + endif +endif + +if ('delta' in get_option('encoders')) or ('delta' in get_option('decoders')) + + # delta/Makefile.inc + lzma_src += [ + 'delta/delta_common.c' + ] + + if 'delta' in get_option('encoders') + lzma_src += [ + 'delta/delta_encoder.c' + ] + endif + + if 'delta' in get_option('decoders') + lzma_src += [ + 'delta/delta_decoder.c' + ] + endif +endif + +if have_encoder_simple_filters or have_decoder_simple_filters + + # simple/Makefile.inc + lzma_src += [ + 'simple/simple_coder.c' + ] + + if have_encoder_simple_filters + lzma_src += [ + 'simple/simple_encoder.c' + ] + endif + + if have_decoder_simple_filters + lzma_src += [ + 'simple/simple_decoder.c' + ] + endif + + foreach f : simple_filters + if (f in get_option('encoders')) or + (f in get_option('decoders')) + lzma_src += [ + 'simple/' + f + '.c' + ] + endif + endforeach +endif + +# resource file + +win_mod = import('windows') + +if sys_windows + liblzma_rc = win_mod.compile_resources(files('liblzma_w32res.rc'), + args : [ '-DHAVE_CONFIG_H', '-DTUKLIB_SYMBOL_PREFIX=lzma_' ], + depend_files : files('../common/common_w32res.rc'), + include_directories : [ '../src/common/', config_dir ] + ) + lzma_src += [ liblzma_rc ] +endif + +lzma_c_args += [ + '-DHAVE_CONFIG_H', +] + +lzma_incdir = [ + config_dir, + '../common', + 'api', + 'check', + 'common', + 'delta', + 'lz', + 'lzma', + 'rangecoder', + 'simple', +] + +lzma_deps = [] + +if (not sys_windows) and have_threads + lzma_deps += pthread_dep +endif + +lzma_lib = library('lzma', lzma_src, + c_args : lzma_c_args, + dependencies : lzma_deps, + gnu_symbol_visibility : 'hidden', + include_directories : lzma_incdir, + install : true, + link_args : sys_windows ? '-Wl,--output-def,liblzma.def.in' : '', + version : meson.project_version(), +) + +lzma_dep = declare_dependency(link_with: lzma_lib) + +# pc file + +pkg_mod = import('pkgconfig') + +pkg_mod.generate( + lzma_lib, + description : 'General purpose data compression library', + name : 'liblzma', + url : 'https://tukaani.org/xz/', +) + +install_headers('api/lzma.h') + +lzma_headers = files([ + 'api/lzma/base.h', + 'api/lzma/bcj.h', + 'api/lzma/block.h', + 'api/lzma/check.h', + 'api/lzma/container.h', + 'api/lzma/delta.h', + 'api/lzma/filter.h', + 'api/lzma/hardware.h', + 'api/lzma/index.h', + 'api/lzma/index_hash.h', + 'api/lzma/lzma12.h', + 'api/lzma/stream_flags.h', + 'api/lzma/version.h', + 'api/lzma/vli.h', +]) + +install_headers(lzma_headers, subdir: 'lzma' +) diff --git a/src/lzmainfo/meson.build b/src/lzmainfo/meson.build new file mode 100644 index 000000000..7e7f4b0b1 --- /dev/null +++ b/src/lzmainfo/meson.build @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +lzmainfo_cargs = [ + '-DHAVE_CONFIG_H', +] + +lzmainfo_incdir = [ + '../common', + config_dir, +] + +lzmainfo_src = [ + 'lzmainfo.c', + '../common/tuklib_progname.c', + '../common/tuklib_exit.c', +] + +if sys_windows + lzmainfo_rc = win_mod.compile_resources(files('lzmainfo_w32res.rc'), + args : lzmainfo_cargs, + depend_files : files('../common/common_w32res.rc'), + include_directories : [ '../src/common/', config_dir ] + ) + lzmainfo_src += [ lzmainfo_rc ] +endif + +executable('lzmainfo', lzmainfo_src, + c_args: lzmainfo_cargs, + dependencies: lzma_dep, + include_directories : lzmainfo_incdir, + install: true, +) + +install_man(files('lzmainfo.1')) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 000000000..b7a3017ee --- /dev/null +++ b/src/meson.build @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +subdir('common') +subdir('liblzma') +subdir('xzdec') + +if get_option('xz') + subdir('xz') +endif + +if 'lzma1' in get_option('decoders') and get_option('lzmainfo') + subdir('lzmainfo') +endif + +if get_option('scripts') + subdir('scripts') +endif \ No newline at end of file diff --git a/src/scripts/meson.build b/src/scripts/meson.build new file mode 100644 index 000000000..3e1c4419d --- /dev/null +++ b/src/scripts/meson.build @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +path_for_script = '' +if get_option('path-for-scripts') == '' + if sys_sunos + path_for_script = '/usr/xpg4/bin' + endif +else + path_for_script = 'PATH=' + get_option('path-for-scripts') + ':$PATH' +endif + +# As discussed on IRC, @xz@ is transformed to 'xz' + +scriptconf = configuration_data() + +scriptconf.set('PACKAGE_NAME', meson.project_name()) +scriptconf.set('PACKAGE_VERSION', meson.project_version()) +scriptconf.set('PACKAGE_BUGREPORT', meson.project_version()) +scriptconf.set('enable_path_for_scripts', path_for_script) +scriptconf.set('xz', 'xz') + +scripts = [ + 'xzdiff', + 'xzgrep', + 'xzmore', + 'xzless', +] + +foreach s : scripts + configure_file( + input : s + '.in', + output : s, + configuration : scriptconf, + install_dir : get_option('bindir') + ) +endforeach + +links = [ + [ 'xzdiff', 'xzcmp' ], + [ 'xzgrep', 'xzegrep' ], + [ 'xzgrep', 'xzfgrep' ], +] + +if get_option('lzma-links') + links += [ + [ 'xzdiff', 'lzdiff' ], + [ 'xzdiff', 'lzcmp' ], + [ 'xzgrep', 'lzgrep' ], + [ 'xzgrep', 'lzegrep' ], + [ 'xzgrep', 'lzfgrep' ], + [ 'xzmore', 'lzmore' ], + [ 'xzless', 'lzless' ], + ] +endif + +foreach l : links + install_symlink(l[1], + install_dir: get_option('bindir'), + pointing_to: l[0], + ) +endforeach + +install_man(files([ 'xzdiff.1', 'xzgrep.1', 'xzless.1', 'xzmore.1' ])) diff --git a/src/xz/meson.build b/src/xz/meson.build new file mode 100644 index 000000000..a3cc2c021 --- /dev/null +++ b/src/xz/meson.build @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +if get_option('assume-ram') <= 0 + error('option "assume-ram" accepts only positive integers') +endif + +config_h.set('ASSUME_RAM', get_option('assume-ram')) + +# FIXME -DLOCALEDIR=\"$(localedir)\" +xz_cargs = [ + '-DHAVE_CONFIG_H', +] + +xz_incdir = [ + '../common', + config_dir, +] + +xz_src = [ + 'args.c', + 'coder.c', + 'file_io.c', + 'hardware.c', + 'main.c', + 'message.c', + 'mytime.c', + 'options.c', + 'sandbox.c', + 'signals.c', + 'suffix.c', + 'util.c', + '../common/tuklib_open_stdxxx.c', + '../common/tuklib_progname.c', + '../common/tuklib_exit.c', + '../common/tuklib_mbstr_width.c', + '../common/tuklib_mbstr_fw.c', +] + +if get_option('decoders').length() > 0 + xz_src += [ + 'list.c' + ] +endif + +if sys_windows + xz_rc = win_mod.compile_resources(files('xz_w32res.rc'), + args : xz_cargs, + depend_files : files('../common/common_w32res.rc'), + include_directories : [ '../src/common/', config_dir ] + ) + xz_src += [ xz_rc ] +endif + +executable('xz', xz_src, + c_args: xz_cargs, + dependencies: lzma_dep, + include_directories : xz_incdir, + install: true, +) + +install_man(files('xz.1')) + +xz_links = [ + 'unxz', + 'xzcat', +] + +if get_option('lzma-links') + xz_links += [ + 'lzma', + 'unlzma', + 'lzcat', + ] +endif + + +foreach l : xz_links + install_symlink(l + (sys_windows ? '.exe' : ''), + install_dir: get_option('bindir'), + pointing_to: 'xz' + (sys_windows ? '.exe' : ''), + ) +endforeach diff --git a/src/xzdec/meson.build b/src/xzdec/meson.build new file mode 100644 index 000000000..94c847617 --- /dev/null +++ b/src/xzdec/meson.build @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +xzdec_cargs = [ + '-DHAVE_CONFIG_H', + '-DTUKLIB_GETTEXT=0' +] + +if get_option('decoders').length() > 0 and get_option('xzdec') + xzdec_src = [ + '../common/tuklib_exit.c', + '../common/tuklib_progname.c', + 'xzdec.c' + ] + + xzdec_incdir = [ + '../common', + config_dir, + ] + + if sys_windows + xzdec_rc = win_mod.compile_resources(files('xzdec_w32res.rc'), + args : xzdec_cargs, + depend_files : files('../common/common_w32res.rc'), + include_directories : [ '../src/common/', config_dir ] + ) + xzdec_src += [ xzdec_rc ] + endif + + executable('xzdec', xzdec_src, + c_args: xzdec_cargs, + dependencies: lzma_dep, + include_directories : xzdec_incdir, + install: true, + ) + + install_man(files('xzdec.1')) +endif + +if 'lzma1' in get_option('decoders') and get_option('lzmadec') + lzmadec_src = [ + '../common/tuklib_exit.c', + '../common/tuklib_progname.c', + 'xzdec.c' + ] + + lzmadec_cargs = [ + '-DHAVE_CONFIG_H', + '-DTUKLIB_GETTEXT=0' + ] + + lzmadec_incdir = [ + '../common', + config_dir, + ] + + if sys_windows + lzmadec_rc = win_mod.compile_resources(files('lzmadec_w32res.rc'), + args : [ xzdec_cargs, '-DLZMADEC' ], + depend_files : files('../common/common_w32res.rc'), + include_directories : [ '../src/common/', config_dir ] + ) + lzmadec_src += [ lzmadec_rc ] + endif + + executable('lzmadec', lzmadec_src, + c_args: lzmadec_cargs, + dependencies: lzma_dep, + include_directories : lzmadec_incdir, + install: true, + ) + + if get_option('xzdec') + install_symlink('lzmadec.1', + install_dir: get_option('datadir') / 'man' / 'man1', + pointing_to: 'xzdec.1', + ) + else + fs = import('fs') + fs.copyfile('xzdec.1', 'lzmadec.1') + install_man('lzmadec.1') + endif +endif diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 000000000..0ffe4dceb --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: 0BSD +# Author: Vincent Torri + +xz_test_src = [ + 'create_compress_files', + 'test_check', + 'test_hardware', + 'test_stream_flags', + 'test_filter_flags', + 'test_filter_str', + 'test_block_header', + 'test_index', + 'test_index_hash', + 'test_bcj_exact_size', + 'test_memlimit', + 'test_lzip_decoder', + 'test_vli', +] +if get_option('microlzma') + xz_test_src += [ + 'test_microlzma', + ] +endif + +test_cargs = [ + '-DHAVE_CONFIG_H', +] + +test_incdir = [ + '../src/common', + '../src/liblzma', + '../src/liblzma/api', + config_dir +] + +foreach t : xz_test_src + exe = executable( + t, + files(t + '.c'), + c_args: test_cargs, + dependencies: lzma_dep, + include_directories: test_incdir, + ) + test(t, exe, timeout: 0, workdir: meson.current_source_dir()) +endforeach + +# TODO: script ones