diff --git a/lib/archive/version.lock b/lib/archive/version.lock index b8756480..96c6a22a 100644 --- a/lib/archive/version.lock +++ b/lib/archive/version.lock @@ -1,4 +1,4 @@ brotli 1.0.9 -liblzma: https://tukaani.org/xz/ 5.4.2 +liblzma: https://tukaani.org/xz/ 5.4.3 zstd: https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz#lib zlib: https://github.com/chromium/chromium/tree/71774699ed1905a70f5f98375613b012781c880c/third_party/zlib \ No newline at end of file diff --git a/lib/archive/xz/CMakeLists.txt b/lib/archive/xz/CMakeLists.txt index 878a9b89..4c8f23e3 100644 --- a/lib/archive/xz/CMakeLists.txt +++ b/lib/archive/xz/CMakeLists.txt @@ -14,90 +14,83 @@ include(cmake/tuklib_mbstr.cmake) # Definitions common to all targets: add_compile_definitions( # Package info: - PACKAGE_NAME="XZ Utils" + PACKAGE_NAME="${PACKAGE_NAME}" PACKAGE_BUGREPORT="xz@tukaani.org" PACKAGE_URL="https://tukaani.org/xz/" - # Features: - HAVE_CHECK_CRC32 - HAVE_CHECK_CRC64 - HAVE_CHECK_SHA256 - HAVE_DECODERS - HAVE_DECODER_ARM - HAVE_DECODER_ARMTHUMB - HAVE_DECODER_ARM64 - HAVE_DECODER_DELTA - HAVE_DECODER_IA64 - HAVE_DECODER_LZMA1 - HAVE_DECODER_LZMA2 - HAVE_DECODER_POWERPC - HAVE_DECODER_SPARC - HAVE_DECODER_X86 - HAVE_ENCODERS - HAVE_ENCODER_ARM - HAVE_ENCODER_ARMTHUMB - HAVE_ENCODER_ARM64 - HAVE_ENCODER_DELTA - HAVE_ENCODER_IA64 - HAVE_ENCODER_LZMA1 - HAVE_ENCODER_LZMA2 - HAVE_ENCODER_POWERPC - HAVE_ENCODER_SPARC - HAVE_ENCODER_X86 - HAVE_MF_BT2 - HAVE_MF_BT3 - HAVE_MF_BT4 - HAVE_MF_HC3 - HAVE_MF_HC4 - HAVE_LZIP_DECODER - # Standard headers and types are available: HAVE_STDBOOL_H HAVE__BOOL HAVE_STDINT_H HAVE_INTTYPES_H + # Always enable CRC32 since liblzma should never build without it. + HAVE_CHECK_CRC32 + # Disable assert() checks when no build type has been specified. Non-empty # build types like "Release" and "Debug" handle this by default. $<$:NDEBUG> ) + +###################### +# System definitions # +###################### + +# _GNU_SOURCE and such definitions. This specific macro is special since +# it also adds the definitions to CMAKE_REQUIRED_DEFINITIONS. +tuklib_use_system_extensions(ALL) + +# This is needed by liblzma and xz. tuklib_integer(ALL) -# Threading support: -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads REQUIRED) -if(CMAKE_USE_WIN32_THREADS_INIT) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - # Define to 1 when using Windows 95 (and thus XP) compatible threads. This - # avoids use of features that were added in Windows Vista. - # This is used for 32-bit x86 builds for compatibility reasons since it - # makes no measurable difference in performance compared to Vista threads. - add_compile_definitions(MYTHREAD_WIN95) - else() - # Define to 1 when using Windows Vista compatible threads. This uses features - # that are not available on Windows XP. - add_compile_definitions(MYTHREAD_VISTA) +# Check for clock_gettime(). Do this before checking for threading so +# that we know there if CLOCK_MONOTONIC is available. +if(NOT WIN32 AND NOT DEFINED HAVE_CLOCK_GETTIME) + check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME) + if(NOT HAVE_CLOCK_GETTIME) + # With glibc <= 2.17 or Solaris 10 this needs librt. + unset(HAVE_CLOCK_GETTIME CACHE) + + list(INSERT CMAKE_REQUIRED_LIBRARIES 0 rt) + check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME) + + # If it was found now, add it to all targets and keep it + # in CMAKE_REQUIRED_LIBRARIES for further tests too. + if(HAVE_CLOCK_GETTIME) + link_libraries(rt) + else() + list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0) + endif() endif() -else() - add_compile_definitions(MYTHREAD_POSIX) - - # Check if pthread_condattr_setclock() exists to use CLOCK_MONOTONIC. - if(HAVE_DECL_CLOCK_MONOTONIC) - list(INSERT CMAKE_REQUIRED_LIBRARIES 0 "${CMAKE_THREAD_LIBS_INIT}") - check_symbol_exists(pthread_condattr_setclock pthread.h - HAVE_PTHREAD_CONDATTR_SETCLOCK) - tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK) + if(HAVE_CLOCK_GETTIME) + # Check if CLOCK_MONOTONIC is available for clock_gettime(). + check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC) + + add_compile_definitions( + HAVE_CLOCK_GETTIME + HAVE_CLOCK_MONOTONIC + ) endif() endif() +# Options for new enough GCC or Clang on any arch or operating system: +if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang) + # configure.ac has a long list but it won't be copied here: + add_compile_options(-Wall -Wextra) +endif() + +############################################################################# +# liblzma +############################################################################# + +option(BUILD_SHARED_LIBS "Build liblzma as a shared library instead of static") + add_library(liblzma src/common/mythread.h src/common/sysdefs.h src/common/tuklib_common.h src/common/tuklib_config.h - src/common/tuklib_cpucores.c - src/common/tuklib_cpucores.h src/common/tuklib_integer.h src/common/tuklib_physmem.c src/common/tuklib_physmem.h @@ -118,128 +111,22 @@ add_library(liblzma src/liblzma/api/lzma/vli.h src/liblzma/check/check.c src/liblzma/check/check.h - src/liblzma/check/crc32_fast.c - src/liblzma/check/crc32_table.c - src/liblzma/check/crc32_table_be.h - src/liblzma/check/crc32_table_le.h - src/liblzma/check/crc64_fast.c - src/liblzma/check/crc64_table.c - src/liblzma/check/crc64_table_be.h - src/liblzma/check/crc64_table_le.h src/liblzma/check/crc_macros.h - src/liblzma/check/sha256.c - src/liblzma/common/alone_decoder.c - src/liblzma/common/alone_decoder.h - src/liblzma/common/alone_encoder.c - src/liblzma/common/auto_decoder.c - src/liblzma/common/block_buffer_decoder.c - src/liblzma/common/block_buffer_encoder.c - src/liblzma/common/block_buffer_encoder.h - src/liblzma/common/block_decoder.c - src/liblzma/common/block_decoder.h - src/liblzma/common/block_encoder.c - src/liblzma/common/block_encoder.h - src/liblzma/common/block_header_decoder.c - src/liblzma/common/block_header_encoder.c src/liblzma/common/block_util.c src/liblzma/common/common.c src/liblzma/common/common.h - src/liblzma/common/easy_buffer_encoder.c - src/liblzma/common/easy_decoder_memusage.c - src/liblzma/common/easy_encoder.c - src/liblzma/common/easy_encoder_memusage.c src/liblzma/common/easy_preset.c src/liblzma/common/easy_preset.h - src/liblzma/common/file_info.c - src/liblzma/common/filter_buffer_decoder.c - src/liblzma/common/filter_buffer_encoder.c src/liblzma/common/filter_common.c src/liblzma/common/filter_common.h - src/liblzma/common/filter_decoder.c - src/liblzma/common/filter_decoder.h - src/liblzma/common/filter_encoder.c - src/liblzma/common/filter_encoder.h - src/liblzma/common/filter_flags_decoder.c - src/liblzma/common/filter_flags_encoder.c - src/liblzma/common/hardware_cputhreads.c src/liblzma/common/hardware_physmem.c src/liblzma/common/index.c src/liblzma/common/index.h - src/liblzma/common/index_decoder.c - src/liblzma/common/index_decoder.h - src/liblzma/common/index_encoder.c - src/liblzma/common/index_encoder.h - src/liblzma/common/index_hash.c - src/liblzma/common/lzip_decoder.c - src/liblzma/common/lzip_decoder.h src/liblzma/common/memcmplen.h - src/liblzma/common/microlzma_decoder.c - src/liblzma/common/microlzma_encoder.c - src/liblzma/common/outqueue.c - src/liblzma/common/outqueue.h - src/liblzma/common/stream_buffer_decoder.c - src/liblzma/common/stream_buffer_encoder.c - src/liblzma/common/stream_decoder.c - src/liblzma/common/stream_decoder_mt.c - src/liblzma/common/stream_decoder.h - src/liblzma/common/stream_encoder.c - src/liblzma/common/stream_encoder_mt.c src/liblzma/common/stream_flags_common.c src/liblzma/common/stream_flags_common.h - src/liblzma/common/stream_flags_decoder.c - src/liblzma/common/stream_flags_encoder.c src/liblzma/common/string_conversion.c - src/liblzma/common/vli_decoder.c - src/liblzma/common/vli_encoder.c src/liblzma/common/vli_size.c - src/liblzma/delta/delta_common.c - src/liblzma/delta/delta_common.h - src/liblzma/delta/delta_decoder.c - src/liblzma/delta/delta_decoder.h - src/liblzma/delta/delta_encoder.c - src/liblzma/delta/delta_encoder.h - src/liblzma/delta/delta_private.h - src/liblzma/lz/lz_decoder.c - src/liblzma/lz/lz_decoder.h - src/liblzma/lz/lz_encoder.c - src/liblzma/lz/lz_encoder.h - src/liblzma/lz/lz_encoder_hash.h - src/liblzma/lz/lz_encoder_hash_table.h - src/liblzma/lz/lz_encoder_mf.c - src/liblzma/lzma/fastpos.h - src/liblzma/lzma/fastpos_table.c - src/liblzma/lzma/lzma2_decoder.c - src/liblzma/lzma/lzma2_decoder.h - src/liblzma/lzma/lzma2_encoder.c - src/liblzma/lzma/lzma2_encoder.h - src/liblzma/lzma/lzma_common.h - src/liblzma/lzma/lzma_decoder.c - src/liblzma/lzma/lzma_decoder.h - src/liblzma/lzma/lzma_encoder.c - src/liblzma/lzma/lzma_encoder.h - src/liblzma/lzma/lzma_encoder_optimum_fast.c - src/liblzma/lzma/lzma_encoder_optimum_normal.c - src/liblzma/lzma/lzma_encoder_presets.c - src/liblzma/lzma/lzma_encoder_private.h - src/liblzma/rangecoder/price.h - src/liblzma/rangecoder/price_table.c - src/liblzma/rangecoder/range_common.h - src/liblzma/rangecoder/range_decoder.h - src/liblzma/rangecoder/range_encoder.h - src/liblzma/simple/arm.c - src/liblzma/simple/armthumb.c - src/liblzma/simple/arm64.c - src/liblzma/simple/ia64.c - src/liblzma/simple/powerpc.c - src/liblzma/simple/simple_coder.c - src/liblzma/simple/simple_coder.h - src/liblzma/simple/simple_decoder.c - src/liblzma/simple/simple_decoder.h - src/liblzma/simple/simple_encoder.c - src/liblzma/simple/simple_encoder.h - src/liblzma/simple/simple_private.h - src/liblzma/simple/sparc.c - src/liblzma/simple/x86.c ) target_include_directories(liblzma PRIVATE @@ -254,11 +141,488 @@ target_include_directories(liblzma PRIVATE src/common ) -target_link_libraries(liblzma Threads::Threads) + +###################### +# Size optimizations # +###################### + +option(ENABLE_SMALL "Reduce code size at expense of speed. \ +This may be useful together with CMAKE_BUILD_TYPE=MinSizeRel.") + +if(ENABLE_SMALL) + add_compile_definitions(HAVE_SMALL) +endif() + + +########## +# Checks # +########## + +set(ADDITIONAL_SUPPORTED_CHECKS crc64 sha256) + +set(ADDITIONAL_CHECK_TYPES "${ADDITIONAL_SUPPORTED_CHECKS}" CACHE STRING + "Additional check types to support (crc32 is always built)") + +foreach(CHECK IN LISTS ADDITIONAL_CHECK_TYPES) + if(NOT CHECK IN_LIST ADDITIONAL_SUPPORTED_CHECKS) + message(SEND_ERROR "'${CHECK}' is not a supported check type") + endif() +endforeach() + +if(ENABLE_SMALL) + target_sources(liblzma PRIVATE src/liblzma/check/crc32_small.c) +else() + target_sources(liblzma PRIVATE + src/liblzma/check/crc32_fast.c + src/liblzma/check/crc32_table.c + src/liblzma/check/crc32_table_be.h + src/liblzma/check/crc32_table_le.h + ) +endif() + +if("crc64" IN_LIST ADDITIONAL_CHECK_TYPES) + add_compile_definitions("HAVE_CHECK_CRC64") + + if(ENABLE_SMALL) + target_sources(liblzma PRIVATE src/liblzma/check/crc64_small.c) + else() + target_sources(liblzma PRIVATE + src/liblzma/check/crc64_fast.c + src/liblzma/check/crc64_table.c + src/liblzma/check/crc64_table_be.h + src/liblzma/check/crc64_table_le.h + ) + endif() +endif() + +if("sha256" IN_LIST ADDITIONAL_CHECK_TYPES) + add_compile_definitions("HAVE_CHECK_SHA256") + target_sources(liblzma PRIVATE src/liblzma/check/sha256.c) +endif() + + +################# +# Match finders # +################# + +set(SUPPORTED_MATCH_FINDERS hc3 hc4 bt2 bt3 bt4) + +set(MATCH_FINDERS "${SUPPORTED_MATCH_FINDERS}" CACHE STRING + "Match finders to support (at least one is required for LZMA1 or LZMA2)") + +foreach(MF IN LISTS MATCH_FINDERS) + if(MF IN_LIST SUPPORTED_MATCH_FINDERS) + string(TOUPPER "${MF}" MF_UPPER) + add_compile_definitions("HAVE_MF_${MF_UPPER}") + else() + message(SEND_ERROR "'${MF}' is not a supported match finder") + endif() +endforeach() + + +############# +# Threading # +############# + +# Supported thread methods: +# ON - autodetect the best threading method. The autodetection will +# prefer Windows threading (win95 or vista) over posix if both are +# available. vista threads will be used over win95 unless it is a +# 32-bit build. +# OFF - Disable threading. +# posix - Use posix threading, or throw an error if not available. +# win95 - Use Windows win95 threading, or throw an error if not available. +# vista - Use Windows vista threading, or throw an error if not available. +set(SUPPORTED_THREAD_METHODS ON OFF posix win95 vista) + +set(ENABLE_THREADS ON CACHE STRING + "Threading method type to support. Set to 'OFF' to disable threading") + +# Create dropdown in CMake GUI since only 1 threading method is possible +# to select in a build. +set_property(CACHE ENABLE_THREADS + PROPERTY STRINGS "${SUPPORTED_THREAD_METHODS}") + +if(NOT ENABLE_THREADS IN_LIST SUPPORTED_THREAD_METHODS) + message(SEND_ERROR "'${ENABLE_THREADS}' is not a supported thread type") +endif() + +if(ENABLE_THREADS) + # Also set THREADS_PREFER_PTHREAD_FLAG since the flag has no effect + # for Windows threading. + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package(Threads REQUIRED) + + # If both Windows and posix threading are available, prefer Windows. + if(CMAKE_USE_WIN32_THREADS_INIT AND NOT ENABLE_THREADS STREQUAL "posix") + if(ENABLE_THREADS STREQUAL "win95" + OR (ENABLE_THREADS STREQUAL "ON" + AND CMAKE_SIZEOF_VOID_P EQUAL 4)) + # Use Windows 95 (and thus XP) compatible threads. + # This avoids use of features that were added in + # Windows Vista. This is used for 32-bit x86 builds for + # compatibility reasons since it makes no measurable difference + # in performance compared to Vista threads. + # + # The Win95 threading lacks thread-safe one-time initialization + # function. + if (ENABLE_SMALL) + message(SEND_ERROR "Threading method win95 and ENABLE_SMALL " + "cannot be used at the same time") + endif() + + add_compile_definitions(MYTHREAD_WIN95) + else() + add_compile_definitions(MYTHREAD_VISTA) + endif() + elseif(CMAKE_USE_PTHREADS_INIT) + if(ENABLE_THREADS STREQUAL "posix" OR ENABLE_THREADS STREQUAL "ON") + # Overwrite ENABLE_THREADS in case it was set to "ON". + # The threading library only needs to be explicitly linked + # for posix threads, so this is needed for creating + # liblzma-config.cmake later. + set(ENABLE_THREADS "posix") + + target_link_libraries(liblzma Threads::Threads) + add_compile_definitions(MYTHREAD_POSIX) + + # Check if pthread_condattr_setclock() exists to use CLOCK_MONOTONIC. + if(HAVE_CLOCK_MONOTONIC) + list(INSERT CMAKE_REQUIRED_LIBRARIES 0 "${CMAKE_THREAD_LIBS_INIT}") + check_symbol_exists(pthread_condattr_setclock pthread.h + HAVE_PTHREAD_CONDATTR_SETCLOCK) + tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK) + endif() + else() + message(SEND_ERROR + "Windows thread method requested, but a compatible " + "library could not be found") + endif() + else() + message(SEND_ERROR "No supported threading library found") + endif() + + target_sources(liblzma PRIVATE + src/common/tuklib_cpucores.c + src/common/tuklib_cpucores.h + src/liblzma/common/hardware_cputhreads.c + src/liblzma/common/outqueue.c + src/liblzma/common/outqueue.h + ) +endif() + + +############ +# Encoders # +############ + +set(SIMPLE_FILTERS + x86 + arm + armthumb + arm64 + powerpc + ia64 + sparc +) + +# The SUPPORTED_FILTERS are shared between Encoders and Decoders +# since only lzip does not appear in both lists. lzip is a special +# case anyway, so it is handled separately in the Decoders section. +set(SUPPORTED_FILTERS + lzma1 + lzma2 + delta + "${SIMPLE_FILTERS}" +) + +set(ENCODERS "${SUPPORTED_FILTERS}" CACHE STRING "Encoders to support") + +# If LZMA2 is enabled, then LZMA1 must also be enabled. +if(NOT "lzma1" IN_LIST ENCODERS AND "lzma2" IN_LIST ENCODERS) + message(SEND_ERROR "LZMA2 encoder requires that LZMA1 is also enabled") +endif() + +# If LZMA1 is enabled, then at least one match finder must be enabled. +if(MATCH_FINDERS STREQUAL "" AND "lzma1" IN_LIST ENCODERS) + message(SEND_ERROR "At least 1 match finder is required for an " + "LZ-based encoder") +endif() + +set(HAVE_DELTA_CODER OFF) +set(SIMPLE_ENCODERS OFF) +set(HAVE_ENCODERS OFF) + +foreach(ENCODER IN LISTS ENCODERS) + if(ENCODER IN_LIST SUPPORTED_FILTERS) + set(HAVE_ENCODERS ON) + + if(NOT SIMPLE_ENCODERS AND ENCODER IN_LIST SIMPLE_FILTERS) + set(SIMPLE_ENCODERS ON) + endif() + + string(TOUPPER "${ENCODER}" ENCODER_UPPER) + add_compile_definitions("HAVE_ENCODER_${ENCODER_UPPER}") + else() + message(SEND_ERROR "'${ENCODER}' is not a supported encoder") + endif() +endforeach() + +if(HAVE_ENCODERS) + add_compile_definitions(HAVE_ENCODERS) + + target_sources(liblzma PRIVATE + src/liblzma/common/alone_encoder.c + src/liblzma/common/block_buffer_encoder.c + src/liblzma/common/block_buffer_encoder.h + src/liblzma/common/block_encoder.c + src/liblzma/common/block_encoder.h + src/liblzma/common/block_header_encoder.c + src/liblzma/common/easy_buffer_encoder.c + src/liblzma/common/easy_encoder.c + src/liblzma/common/easy_encoder_memusage.c + src/liblzma/common/filter_buffer_encoder.c + src/liblzma/common/filter_encoder.c + src/liblzma/common/filter_encoder.h + src/liblzma/common/filter_flags_encoder.c + src/liblzma/common/index_encoder.c + src/liblzma/common/index_encoder.h + src/liblzma/common/stream_buffer_encoder.c + src/liblzma/common/stream_encoder.c + src/liblzma/common/stream_flags_encoder.c + src/liblzma/common/vli_encoder.c + ) + + if(ENABLE_THREADS) + target_sources(liblzma PRIVATE + src/liblzma/common/stream_encoder_mt.c + ) + endif() + + if(SIMPLE_ENCODERS) + target_sources(liblzma PRIVATE + src/liblzma/simple/simple_encoder.c + src/liblzma/simple/simple_encoder.h + ) + endif() + + if("lzma1" IN_LIST ENCODERS) + target_sources(liblzma PRIVATE + src/liblzma/lzma/lzma_encoder.c + src/liblzma/lzma/lzma_encoder.h + src/liblzma/lzma/lzma_encoder_optimum_fast.c + src/liblzma/lzma/lzma_encoder_optimum_normal.c + src/liblzma/lzma/lzma_encoder_private.h + src/liblzma/lzma/fastpos.h + src/liblzma/lz/lz_encoder.c + src/liblzma/lz/lz_encoder.h + src/liblzma/lz/lz_encoder_hash.h + src/liblzma/lz/lz_encoder_hash_table.h + src/liblzma/lz/lz_encoder_mf.c + src/liblzma/rangecoder/price.h + src/liblzma/rangecoder/price_table.c + src/liblzma/rangecoder/range_encoder.h + ) + + if(NOT ENABLE_SMALL) + target_sources(liblzma PRIVATE src/liblzma/lzma/fastpos_table.c) + endif() + endif() + + if("lzma2" IN_LIST ENCODERS) + target_sources(liblzma PRIVATE + src/liblzma/lzma/lzma2_encoder.c + src/liblzma/lzma/lzma2_encoder.h + ) + endif() + + if("delta" IN_LIST ENCODERS) + set(HAVE_DELTA_CODER ON) + target_sources(liblzma PRIVATE + src/liblzma/delta/delta_encoder.c + src/liblzma/delta/delta_encoder.h + ) + endif() +endif() + + +############ +# Decoders # +############ + +set(DECODERS "${SUPPORTED_FILTERS}" CACHE STRING "Decoders to support") + +set(SIMPLE_DECODERS OFF) +set(HAVE_DECODERS OFF) + +foreach(DECODER IN LISTS DECODERS) + if(DECODER IN_LIST SUPPORTED_FILTERS) + set(HAVE_DECODERS ON) + + if(NOT SIMPLE_DECODERS AND DECODER IN_LIST SIMPLE_FILTERS) + set(SIMPLE_DECODERS ON) + endif() + + string(TOUPPER "${DECODER}" DECODER_UPPER) + add_compile_definitions("HAVE_DECODER_${DECODER_UPPER}") + else() + message(SEND_ERROR "'${DECODER}' is not a supported decoder") + endif() +endforeach() + +if(HAVE_DECODERS) + add_compile_definitions(HAVE_DECODERS) + + target_sources(liblzma PRIVATE + src/liblzma/common/alone_decoder.c + src/liblzma/common/alone_decoder.h + src/liblzma/common/auto_decoder.c + src/liblzma/common/block_buffer_decoder.c + src/liblzma/common/block_decoder.c + src/liblzma/common/block_decoder.h + src/liblzma/common/block_header_decoder.c + src/liblzma/common/easy_decoder_memusage.c + src/liblzma/common/file_info.c + src/liblzma/common/filter_buffer_decoder.c + src/liblzma/common/filter_decoder.c + src/liblzma/common/filter_decoder.h + src/liblzma/common/filter_flags_decoder.c + src/liblzma/common/index_decoder.c + src/liblzma/common/index_decoder.h + src/liblzma/common/index_hash.c + src/liblzma/common/stream_buffer_decoder.c + src/liblzma/common/stream_decoder.c + src/liblzma/common/stream_flags_decoder.c + src/liblzma/common/stream_decoder.h + src/liblzma/common/vli_decoder.c + ) + + if(ENABLE_THREADS) + target_sources(liblzma PRIVATE + src/liblzma/common/stream_decoder_mt.c + ) + endif() + + if(SIMPLE_DECODERS) + target_sources(liblzma PRIVATE + src/liblzma/simple/simple_decoder.c + src/liblzma/simple/simple_decoder.h + ) + endif() + + if("lzma1" IN_LIST DECODERS) + target_sources(liblzma PRIVATE + src/liblzma/lzma/lzma_decoder.c + src/liblzma/lzma/lzma_decoder.h + src/liblzma/rangecoder/range_decoder.h + src/liblzma/lz/lz_decoder.c + src/liblzma/lz/lz_decoder.h + ) + endif() + + if("lzma2" IN_LIST DECODERS) + target_sources(liblzma PRIVATE + src/liblzma/lzma/lzma2_decoder.c + src/liblzma/lzma/lzma2_decoder.h + ) + endif() + + if("delta" IN_LIST DECODERS) + set(HAVE_DELTA_CODER ON) + target_sources(liblzma PRIVATE + src/liblzma/delta/delta_decoder.c + src/liblzma/delta/delta_decoder.h + ) + endif() +endif() + +# Some sources must appear if the filter is configured as either +# an encoder or decoder. +if("lzma1" IN_LIST ENCODERS OR "lzma1" IN_LIST DECODERS) + target_sources(liblzma PRIVATE + src/liblzma/rangecoder/range_common.h + src/liblzma/lzma/lzma_encoder_presets.c + src/liblzma/lzma/lzma_common.h + ) +endif() + +if(HAVE_DELTA_CODER) + target_sources(liblzma PRIVATE + src/liblzma/delta/delta_common.c + src/liblzma/delta/delta_common.h + src/liblzma/delta/delta_private.h + ) +endif() + +if(SIMPLE_ENCODERS OR SIMPLE_DECODERS) + target_sources(liblzma PRIVATE + src/liblzma/simple/simple_coder.c + src/liblzma/simple/simple_coder.h + src/liblzma/simple/simple_private.h + ) +endif() + +foreach(SIMPLE_CODER IN LISTS SIMPLE_FILTERS) + if(SIMPLE_CODER IN_LIST ENCODERS OR SIMPLE_CODER IN_LIST DECODERS) + target_sources(liblzma PRIVATE "src/liblzma/simple/${SIMPLE_CODER}.c") + endif() +endforeach() + + +############# +# MicroLZMA # +############# + +option(MICROLZMA_ENCODER + "MicroLZMA encoder (needed by specific applications only)" ON) + +option(MICROLZMA_DECODER + "MicroLZMA decoder (needed by specific applications only)" ON) + +if(MICROLZMA_ENCODER) + if(NOT "lzma1" IN_LIST ENCODERS) + message(SEND_ERROR "The LZMA1 encoder is required to support the " + "MicroLZMA encoder") + endif() + + target_sources(liblzma PRIVATE src/liblzma/common/microlzma_encoder.c) +endif() + +if(MICROLZMA_DECODER) + if(NOT "lzma1" IN_LIST DECODERS) + message(SEND_ERROR "The LZMA1 decoder is required to support the " + "MicroLZMA decoder") + endif() + + target_sources(liblzma PRIVATE src/liblzma/common/microlzma_decoder.c) +endif() + + +############################# +# lzip (.lz) format support # +############################# + +option(LZIP_DECODER "Support lzip decoder" ON) + +if(LZIP_DECODER) + # If lzip decoder support is requested, make sure LZMA1 decoder is enabled. + if(NOT "lzma1" IN_LIST DECODERS) + message(SEND_ERROR "The LZMA1 decoder is required to support the " + "lzip decoder") + endif() + + add_compile_definitions(HAVE_LZIP_DECODER) + + target_sources(liblzma PRIVATE + src/liblzma/common/lzip_decoder.c + src/liblzma/common/lzip_decoder.h + ) +endif() + +### # Put the tuklib functions under the lzma_ namespace. target_compile_definitions(liblzma PRIVATE TUKLIB_SYMBOL_PREFIX=lzma_) - tuklib_cpucores(liblzma) tuklib_physmem(liblzma) diff --git a/lib/archive/xz/src/common/tuklib_integer.h b/lib/archive/xz/src/common/tuklib_integer.h index b58ef68d..24d9efb1 100644 --- a/lib/archive/xz/src/common/tuklib_integer.h +++ b/lib/archive/xz/src/common/tuklib_integer.h @@ -52,6 +52,12 @@ // and such functions. #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1500) # include +// Only include when it is needed. GCC and Clang can both +// use __builtin's, so we only need Windows instrincs when using MSVC. +// GCC and Clang can set _MSC_VER on Windows, so we need to exclude these +// cases explicitly. +#elif defined(_MSC_VER) && !TUKLIB_GNUC_REQ(3, 4) && !defined(__clang__) +# include #endif @@ -630,7 +636,7 @@ bsr32(uint32_t n) #if defined(__INTEL_COMPILER) return _bit_scan_reverse(n); -#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX +#elif (TUKLIB_GNUC_REQ(3, 4) || defined(__clang__)) && UINT_MAX == UINT32_MAX // GCC >= 3.4 has __builtin_clz(), which gives good results on // multiple architectures. On x86, __builtin_clz() ^ 31U becomes // either plain BSR (so the XOR gets optimized away) or LZCNT and @@ -684,7 +690,7 @@ clz32(uint32_t n) #if defined(__INTEL_COMPILER) return _bit_scan_reverse(n) ^ 31U; -#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX +#elif (TUKLIB_GNUC_REQ(3, 4) || defined(__clang__)) && UINT_MAX == UINT32_MAX return (uint32_t)__builtin_clz(n); #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) @@ -736,7 +742,7 @@ ctz32(uint32_t n) #if defined(__INTEL_COMPILER) return _bit_scan_forward(n); -#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX >= UINT32_MAX +#elif (TUKLIB_GNUC_REQ(3, 4) || defined(__clang__)) && UINT_MAX >= UINT32_MAX return (uint32_t)__builtin_ctz(n); #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) diff --git a/lib/archive/xz/src/liblzma/Makefile.am b/lib/archive/xz/src/liblzma/Makefile.am index 89fd59fc..8b3a678b 100644 --- a/lib/archive/xz/src/liblzma/Makefile.am +++ b/lib/archive/xz/src/liblzma/Makefile.am @@ -24,7 +24,7 @@ liblzma_la_CPPFLAGS = \ -I$(top_srcdir)/src/liblzma/simple \ -I$(top_srcdir)/src/common \ -DTUKLIB_SYMBOL_PREFIX=lzma_ -liblzma_la_LDFLAGS = -no-undefined -version-info 9:2:4 +liblzma_la_LDFLAGS = -no-undefined -version-info 9:3:4 EXTRA_DIST += liblzma_generic.map liblzma_linux.map validate_map.sh if COND_SYMVERS_GENERIC diff --git a/lib/archive/xz/src/liblzma/Makefile.in b/lib/archive/xz/src/liblzma/Makefile.in index 1e2117e9..193e2f94 100644 --- a/lib/archive/xz/src/liblzma/Makefile.in +++ b/lib/archive/xz/src/liblzma/Makefile.in @@ -191,8 +191,10 @@ host_triplet = @host@ @COND_FILTER_LZMA1_TRUE@am__append_23 = lzma/fastpos_tablegen.c \ @COND_FILTER_LZMA1_TRUE@ rangecoder/price_tablegen.c -@COND_FILTER_LZMA1_TRUE@am__append_24 = lzma/lzma_common.h \ +@COND_FILTER_LZMA1_TRUE@am__append_24 = \ +@COND_FILTER_LZMA1_TRUE@ lzma/lzma_common.h \ @COND_FILTER_LZMA1_TRUE@ lzma/lzma_encoder_presets.c + @COND_ENCODER_LZMA1_TRUE@@COND_FILTER_LZMA1_TRUE@am__append_25 = \ @COND_ENCODER_LZMA1_TRUE@@COND_FILTER_LZMA1_TRUE@ lzma/fastpos.h \ @COND_ENCODER_LZMA1_TRUE@@COND_FILTER_LZMA1_TRUE@ lzma/lzma_encoder.h \ @@ -877,7 +879,7 @@ liblzma_la_CPPFLAGS = \ -I$(top_srcdir)/src/common \ -DTUKLIB_SYMBOL_PREFIX=lzma_ -liblzma_la_LDFLAGS = -no-undefined -version-info 9:2:4 $(am__append_1) \ +liblzma_la_LDFLAGS = -no-undefined -version-info 9:3:4 $(am__append_1) \ $(am__append_2) $(am__append_48) pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = liblzma.pc diff --git a/lib/archive/xz/src/liblzma/api/lzma.h b/lib/archive/xz/src/liblzma/api/lzma.h index 4d8e3994..f38513d3 100644 --- a/lib/archive/xz/src/liblzma/api/lzma.h +++ b/lib/archive/xz/src/liblzma/api/lzma.h @@ -10,7 +10,7 @@ * * liblzma is part of XZ Utils . XZ Utils includes * a gzip-like command line tool named xz and some other tools. XZ Utils - * is developed and maintained by Lasse Collin. + * is developed and maintained by Lasse Collin and Jia Tan. * * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK * . diff --git a/lib/archive/xz/src/liblzma/api/lzma/version.h b/lib/archive/xz/src/liblzma/api/lzma/version.h index 3a0f710a..7f910523 100644 --- a/lib/archive/xz/src/liblzma/api/lzma/version.h +++ b/lib/archive/xz/src/liblzma/api/lzma/version.h @@ -23,7 +23,7 @@ #define LZMA_VERSION_MINOR 4 /** \brief Patch version number of the liblzma release. */ -#define LZMA_VERSION_PATCH 2 +#define LZMA_VERSION_PATCH 3 /** * \brief Version stability marker diff --git a/lib/archive/xz/src/liblzma/common/alone_encoder.c b/lib/archive/xz/src/liblzma/common/alone_encoder.c index c9392f37..7d3812fa 100644 --- a/lib/archive/xz/src/liblzma/common/alone_encoder.c +++ b/lib/archive/xz/src/liblzma/common/alone_encoder.c @@ -75,7 +75,6 @@ alone_encoder_end(void *coder_ptr, const lzma_allocator *allocator) } -// At least for now, this is not used by any internal function. static lzma_ret alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_options_lzma *options) @@ -141,16 +140,6 @@ alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, } -/* -extern lzma_ret -lzma_alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, - const lzma_options_alone *options) -{ - lzma_next_coder_init(&alone_encoder_init, next, allocator, options); -} -*/ - - extern LZMA_API(lzma_ret) lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options) { diff --git a/lib/archive/xz/src/liblzma/common/memcmplen.h b/lib/archive/xz/src/liblzma/common/memcmplen.h index 5a481a02..db3fff60 100644 --- a/lib/archive/xz/src/liblzma/common/memcmplen.h +++ b/lib/archive/xz/src/liblzma/common/memcmplen.h @@ -19,6 +19,16 @@ # include #endif +// Only include if it is needed. The header is only needed +// on Windows when using an MSVC compatible compiler. The Intel compiler +// can use the intrinsics without the header file. +#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \ + && (defined(_MSC_VER) \ + && defined(_M_X64) \ + && !defined(__INTEL_COMPILER)) +# include +#endif + /// Find out how many equal bytes the two buffers have. /// @@ -89,7 +99,8 @@ lzma_memcmplen(const uint8_t *buf1, const uint8_t *buf2, // version isn't used on x86-64. # define LZMA_MEMCMPLEN_EXTRA 16 while (len < limit) { - const uint32_t x = 0xFFFF ^ _mm_movemask_epi8(_mm_cmpeq_epi8( + const uint32_t x = 0xFFFF ^ (uint32_t)_mm_movemask_epi8( + _mm_cmpeq_epi8( _mm_loadu_si128((const __m128i *)(buf1 + len)), _mm_loadu_si128((const __m128i *)(buf2 + len)))); diff --git a/lib/archive/xz/src/liblzma/lzma/Makefile.inc b/lib/archive/xz/src/liblzma/lzma/Makefile.inc index 506b328c..25440d85 100644 --- a/lib/archive/xz/src/liblzma/lzma/Makefile.inc +++ b/lib/archive/xz/src/liblzma/lzma/Makefile.inc @@ -7,12 +7,9 @@ EXTRA_DIST += lzma/fastpos_tablegen.c -liblzma_la_SOURCES += lzma/lzma_common.h - -if COND_FILTER_LZMA1 liblzma_la_SOURCES += \ + lzma/lzma_common.h \ lzma/lzma_encoder_presets.c -endif if COND_ENCODER_LZMA1 liblzma_la_SOURCES += \