From f57393c0e89183420c3b926d21d3888eb67c91e4 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 24 Oct 2022 11:30:24 +0200 Subject: [PATCH] all: simplify include path handling; update src/Makefile --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 3 +-- src/Makefile | 40 +++++++++++++++++++++++----------------- src/compress_lzma.cpp | 30 +++++++++++++++--------------- src/compress_zlib.cpp | 4 +++- src/conf.h | 9 +++------ src/p_vmlinz.cpp | 2 +- src/util/dt_impl.cpp | 2 +- 8 files changed, 48 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b4f50a4..93fee630 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -238,7 +238,7 @@ jobs: set s=%H%\upx\src cat .GITREV.txt set /p GITREV=<.GITREV.txt - cl -MT -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\upx\vendor\doctest -I%H%\upx\vendor\lzma-sdk -I%H%\upx\vendor\ucl\include -I%H%\upx\vendor\zlib -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj + cl -MT -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\upx\vendor -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj - name: 'Make artifact' shell: bash run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 729b9d16..22db99aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,8 +136,7 @@ else() endif() set(t upx) -target_include_directories(${t} PRIVATE vendor/doctest vendor/ucl/include vendor/zlib) -set_source_files_properties(src/compress_lzma.cpp PROPERTIES COMPILE_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR}/vendor/lzma-sdk") +target_include_directories(${t} PRIVATE vendor) target_compile_definitions(${t} PRIVATE $<$:DEBUG=1>) if(GITREV_SHORT) target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}") diff --git a/src/Makefile b/src/Makefile index 385c9fcd..5d0536e8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,8 @@ # UPX Makefile - needs GNU make # -# NOTE: this Makefile is deprecated, please use the CMake build instead ! +# IMPORTANT NOTE: this Makefile is deprecated and won't work +# any longer - please use the CMake build instead! MAKEFLAGS += -r .SUFFIXES: @@ -11,7 +12,7 @@ export SHELL = /bin/sh # build configuration options for this Makefile BUILD_TYPE_DEBUG ?= 0 BUILD_TYPE_SANITIZE ?= 0 -BUILD_USE_DEPEND ?= 1 +BUILD_USE_DEPEND ?= 0 ifndef srcdir srcdir := $(dir $(lastword $(MAKEFILE_LIST))) @@ -26,6 +27,18 @@ ifneq ($(srcdir),.) vpath %.h .:$(srcdir) endif +# redirect to CMake build +ifeq ($(BUILD_TYPE_DEBUG),1) +default: $(top_srcdir)/build/debug/upx +else +default: $(top_srcdir)/build/release/upx +endif +.PHONY: default +$(top_srcdir)/build/debug/upx: + $(MAKE) -C $(top_srcdir) build/debug +$(top_srcdir)/build/release/upx: + $(MAKE) -C $(top_srcdir) build/release + # check git submodules ifeq ($(wildcard $(top_srcdir)/vendor/doctest/doctest/.),) $(error ERROR: missing git submodule; run 'git submodule update --init') @@ -66,16 +79,8 @@ ifneq ($(GITREV_SHORT),) endif endif -INCLUDES += -I$(top_srcdir)/vendor/doctest - # we need UCL and zlib - you can set envvar UPX_UCLDIR -ifneq ($(wildcard $(UPX_UCLDIR)/include/ucl/ucl.h),) - INCLUDES += -I$(UPX_UCLDIR)/include - LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext)))) -else - # please use the CMake build - ##INCLUDES += -I$(top_srcdir)/vendor/ucl/include -endif -LIBS += -lucl -lz +INCLUDES += -I$(top_srcdir)/vendor +LIBS += -lupx_vendor_ucl -lupx_vendor_zlib # default flags that you can change or override ifeq ($(BUILD_TYPE_DEBUG),1) @@ -136,7 +141,6 @@ upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES) $(strip $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -o $@ -E $<) # object overrides -compress_lzma$(objext) : INCLUDES += -I$(top_srcdir)/vendor/lzma-sdk # these are the only 2 objects that are actually speed-sensitive compress_lzma$(objext) : override CXXFLAGS_SANITIZE = filteri$(objext) : override CXXFLAGS_SANITIZE = @@ -146,7 +150,6 @@ ifeq ($(BUILD_USE_DEPEND),1) @rm -f $@ @echo "Updating $@" @$(strip $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -MM) $(filter %.cpp,$^) > $@ -./.depend : INCLUDES += -I$(top_srcdir)/vendor/lzma-sdk else ./.depend: .PHONY: ./.depend @@ -185,7 +188,9 @@ endif # you also can override upx_testsuite_SRCDIR ifndef upx_testsuite_SRCDIR # search standard locations below $(top_srcdir) -ifneq ($(wildcard $(top_srcdir)/../upx-testsuite.git/files/packed/.),) +ifneq ($(wildcard $(top_srcdir)/../upx--upx-testsuite.git/files/packed/.),) +upx_testsuite_SRCDIR := $(top_srcdir)/../upx--upx-testsuite.git +else ifneq ($(wildcard $(top_srcdir)/../upx-testsuite.git/files/packed/.),) upx_testsuite_SRCDIR := $(top_srcdir)/../upx-testsuite.git else ifneq ($(wildcard $(top_srcdir)/../upx-testsuite/files/packed/.),) upx_testsuite_SRCDIR := $(top_srcdir)/../upx-testsuite @@ -196,10 +201,11 @@ endif # The actual (new) checksums are in tmp-testsuite/testsuite_1/.sha256sums.recreate ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),) ifneq ($(wildcard $(top_srcdir)/.github/travis_testsuite_1.sh),) -run-testsuite: export upx_exe := ./upx$(exeext) +run-testsuite: export upx_exe := $(top_srcdir)/build/release/upx run-testsuite: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR) run-testsuite: export upx_testsuite_BUILDDIR := ./tmp-testsuite -run-testsuite: upx$(exeext) +run-testsuite: export UPX_DEBUG_DOCTEST_VERBOSE := 0 +run-testsuite: $(top_srcdir)/build/release/upx time -p bash $(top_srcdir)/.github/travis_testsuite_1.sh .PHONY: run-testsuite endif diff --git a/src/compress_lzma.cpp b/src/compress_lzma.cpp index 62d51f96..cf6e982d 100644 --- a/src/compress_lzma.cpp +++ b/src/compress_lzma.cpp @@ -232,9 +232,9 @@ error: #undef _NO_EXCEPTIONS #undef NULL #define NULL nullptr -#include "C/Common/MyInitGuid.h" -//#include "C/7zip/Compress/LZMA/LZMADecoder.h" -#include "C/7zip/Compress/LZMA/LZMAEncoder.h" +#include +//#include +#include namespace MyLzma { @@ -302,16 +302,16 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS } // namespace -#include "C/Common/Alloc.cpp" -#include "C/Common/CRC.cpp" -//#include "C/7zip/Common/InBuffer.cpp" -#include "C/7zip/Common/OutBuffer.cpp" -#include "C/7zip/Common/StreamUtils.cpp" -#include "C/7zip/Compress/LZ/LZInWindow.cpp" -//#include "C/7zip/Compress/LZ/LZOutWindow.cpp" -//#include "C/7zip/Compress/LZMA/LZMADecoder.cpp" -#include "C/7zip/Compress/LZMA/LZMAEncoder.cpp" -#include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp" +#include +#include +//#include +#include +#include +#include +//#include +//#include +#include +#include #undef RC_NORMALIZE @@ -422,8 +422,8 @@ error: #undef _LZMA_OUT_READ #undef _LZMA_PROB32 #undef _LZMA_LOC_OPT -#include "C/7zip/Compress/LZMA_C/LzmaDecode.h" -#include "C/7zip/Compress/LZMA_C/LzmaDecode.c" +#include +#include int upx_lzma_decompress ( const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned* dst_len, diff --git a/src/compress_zlib.cpp b/src/compress_zlib.cpp index 3ea05d33..d27067f5 100644 --- a/src/compress_zlib.cpp +++ b/src/compress_zlib.cpp @@ -29,7 +29,8 @@ #include "conf.h" #include "compress.h" #include "util/membuffer.h" -#include +#include +#include void zlib_compress_config_t::reset() @@ -102,6 +103,7 @@ int upx_zlib_compress ( const upx_bytep src, unsigned src_len, mem_level, strategy); if (zr != Z_OK) goto error; + assert(s.state->level == level); zr = deflate(&s, Z_FINISH); if (zr != Z_STREAM_END) goto error; diff --git a/src/conf.h b/src/conf.h index 8cef9f54..e2b3c559 100644 --- a/src/conf.h +++ b/src/conf.h @@ -161,11 +161,8 @@ typedef unsigned char upx_byte; #define WITH_ZLIB 1 #if (WITH_UCL) # define ucl_compress_config_t REAL_ucl_compress_config_t -# include -# include -# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010300L) -# error "please upgrade your UCL installation" -# endif +# include +# include # undef ucl_compress_config_t # undef ucl_compress_config_p #endif @@ -740,7 +737,7 @@ unsigned membuffer_get_size(MemBuffer &mb); #include "util/xspan.h" //#define DOCTEST_CONFIG_DISABLE 1 -#include +#include // util/dt_check.cpp void upx_compiler_sanity_check(); diff --git a/src/p_vmlinz.cpp b/src/p_vmlinz.cpp index e93aedd0..d5efdb01 100644 --- a/src/p_vmlinz.cpp +++ b/src/p_vmlinz.cpp @@ -34,7 +34,7 @@ #include "packer.h" #include "p_vmlinz.h" #include "linker.h" -#include +#include static const #include "stub/i386-linux.kernel.vmlinuz.h" diff --git a/src/util/dt_impl.cpp b/src/util/dt_impl.cpp index a2611cc9..de40644f 100644 --- a/src/util/dt_impl.cpp +++ b/src/util/dt_impl.cpp @@ -38,7 +38,7 @@ #endif #define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS #if !defined(DOCTEST_CONFIG_DISABLE) -#include +#include #endif /* vim:set ts=4 sw=4 et: */