Hi,
On Mon, 17 Jun 2024 22:12:24 +0900 Kentaro HAYASHI <[email protected]> wrote: > Control: tags -1 patch > > Hi, I've tried a PoC patch to build lz4 with CMake. > > It is not fully achieved yet because > it causes a diff for .symbols, that is not intended. > > In other words, it must tweak build flags further more. > I've revised the previous patch [1] to fix missing/redundant symbol issue. [1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1073192#10 Now patch can be applied like this: $ apt source lz4 $ cd lz4-1.9.4 && quilt pop -a && patch -p1 < 0001-Use-CMake-to-build-lz4.patch && dpkg-buildpackage -us -uc With migrating to CMake, it seems that it can drop existing debian/patches. Regards,
>From 0325fe841956d34e8f153e4da7032d26997d12d7 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi <[email protected]> Date: Mon, 17 Jun 2024 21:58:30 +0900 Subject: [PATCH] Use CMake to build lz4 It can ship missing lz4Config.cmake for CMake. Based on kou's debian/rules. Closes: #1073192 Signed-off-by: Kentaro Hayashi <[email protected]> --- debian/control | 7 +- debian/liblz4-dev.install | 1 + debian/patches/0001-Fix-static-link.patch | 62 ------- .../patches/0002-Change-optimize-to-O2.patch | 157 ------------------ debian/patches/series | 3 +- debian/patches/use-system-xxhash.patch | 78 +++++++++ debian/rules | 16 +- 7 files changed, 95 insertions(+), 229 deletions(-) delete mode 100644 debian/patches/0001-Fix-static-link.patch delete mode 100644 debian/patches/0002-Change-optimize-to-O2.patch create mode 100644 debian/patches/use-system-xxhash.patch diff --git a/debian/control b/debian/control index 106eaea..cf828a2 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,12 @@ Source: lz4 Priority: optional Maintainer: Nobuhiro Iwamatsu <[email protected]> -Build-Depends: debhelper-compat (= 13), python3:any <!nocheck> +Build-Depends: + debhelper-compat (= 13), + python3:any <!nocheck>, + cmake (>= 2.8.12), + libxxhash-dev, + pkgconf Standards-Version: 4.6.1 Section: utils Rules-Requires-Root: no diff --git a/debian/liblz4-dev.install b/debian/liblz4-dev.install index 76f28fa..ef2e1d7 100644 --- a/debian/liblz4-dev.install +++ b/debian/liblz4-dev.install @@ -1,4 +1,5 @@ usr/include/* usr/lib/*/lib*.a usr/lib/*/lib*.so +usr/lib/*/cmake/* usr/lib/*/pkgconfig/* diff --git a/debian/patches/0001-Fix-static-link.patch b/debian/patches/0001-Fix-static-link.patch deleted file mode 100644 index 0b1146f..0000000 --- a/debian/patches/0001-Fix-static-link.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 707fbfb32f82f253a1792347ce76bca98679c8d8 Mon Sep 17 00:00:00 2001 -From: Nobuhiro Iwamatsu <[email protected]> -Date: Sun, 28 Aug 2022 09:06:14 +0900 -Subject: [PATCH 1/2] Fix static link - -Signed-off-by: Nobuhiro Iwamatsu <[email protected]> ---- - programs/Makefile | 6 +++--- - tests/Makefile | 4 +++- - 2 files changed, 6 insertions(+), 4 deletions(-) - -diff --git a/programs/Makefile b/programs/Makefile -index ace0d03..fc4d6f1 100644 ---- a/programs/Makefile -+++ b/programs/Makefile -@@ -91,10 +91,10 @@ lz4-exe.o: lz4-exe.rc - $(WINDRES) -i lz4-exe.rc -o lz4-exe.o - - lz4: $(OBJFILES) lz4-exe.o -- $(CC) $(FLAGS) $^ -o $@$(EXT) -+ $(CC) $(FLAGS) $^ -o $@$(EXT) -L ../lib -llz4 - else - lz4: $(OBJFILES) -- $(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS) -+ $(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS) -L ../lib -llz4 - endif - - .PHONY: lz4-release -@@ -118,7 +118,7 @@ lz4c: lz4 - - lz4c32: CFLAGS += -m32 - lz4c32 : $(SRCFILES) -- $(CC) $(FLAGS) $^ -o $@$(EXT) -+ $(CC) $(FLAGS) $^ -o $@$(EXT) -L ../lib -llz4 - - lz4.1: lz4.1.md $(LIBVER_SRC) - cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | $(SED) -n '/^\.\\\".*/!p' > $@ -diff --git a/tests/Makefile b/tests/Makefile -index 93a5581..b48070a 100644 ---- a/tests/Makefile -+++ b/tests/Makefile -@@ -43,6 +43,8 @@ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) - CPPFLAGS+= -I$(LZ4DIR) -I$(PRGDIR) -DXXH_NAMESPACE=LZ4_ - FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) - -+export LD_LIBRARY_PATH += $(LZ4DIR) -+ - include ../Makefile.inc - - LZ4 := $(PRGDIR)/lz4$(EXT) -@@ -62,7 +64,7 @@ all32: CFLAGS+=-m32 - all32: all - - lz4: -- $(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)" -+ #$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)" - - lib liblz4.pc: - $(MAKE) -C $(LZ4DIR) $@ CFLAGS="$(CFLAGS)" --- -2.36.1 - diff --git a/debian/patches/0002-Change-optimize-to-O2.patch b/debian/patches/0002-Change-optimize-to-O2.patch deleted file mode 100644 index 6ac8f18..0000000 --- a/debian/patches/0002-Change-optimize-to-O2.patch +++ /dev/null @@ -1,157 +0,0 @@ -From 51bdc803b88dc76c79922f8fee2bb82f95934544 Mon Sep 17 00:00:00 2001 -From: Nobuhiro Iwamatsu <[email protected]> -Date: Sun, 28 Aug 2022 09:10:38 +0900 -Subject: [PATCH 2/2] Change optimize to O2 - -Signed-off-by: Nobuhiro Iwamatsu <[email protected]> ---- - Makefile | 14 +++++++------- - contrib/djgpp/Makefile | 2 +- - examples/Makefile | 4 ++-- - lib/Makefile | 2 +- - lib/dll/example/Makefile | 2 +- - programs/Makefile | 2 +- - tests/Makefile | 2 +- - 7 files changed, 14 insertions(+), 14 deletions(-) - -diff --git a/Makefile b/Makefile -index e70c3db..021db67 100644 ---- a/Makefile -+++ b/Makefile -@@ -147,7 +147,7 @@ clangtest: clean - $(MAKE) -C $(TESTDIR) all CC=$(CC) - - .PHONY: clangtest-native --clangtest-native: CFLAGS = -O3 -Werror -Wconversion -Wno-sign-conversion -+clangtest-native: CFLAGS = -O2 -g -Werror -Wconversion -Wno-sign-conversion - clangtest-native: clean - clang -v - $(MAKE) -C $(LZ4DIR) all CC=clang -@@ -156,13 +156,13 @@ clangtest-native: clean - - .PHONY: usan - usan: CC = clang --usan: CFLAGS = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow -+usan: CFLAGS = -O2 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow - usan: LDFLAGS = $(CFLAGS) - usan: clean - CC=$(CC) CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1 - - .PHONY: usan32 --usan32: CFLAGS = -m32 -O3 -g -fsanitize=undefined -+usan32: CFLAGS = -m32 -O2 -g -fsanitize=undefined - usan32: LDFLAGS = $(CFLAGS) - usan32: clean - $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1 -@@ -181,9 +181,9 @@ cppcheck: - platformTest: clean - @echo "\n ---- test lz4 with $(CC) compiler ----" - $(CC) -v -- CFLAGS="-O3 -Werror" $(MAKE) -C $(LZ4DIR) all -- CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all -- CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all -+ CFLAGS="-O2 -g -Werror" $(MAKE) -C $(LZ4DIR) all -+ CFLAGS="-O2 -g -Werror -static" $(MAKE) -C $(PRGDIR) all -+ CFLAGS="-O2 -g -Werror -static" $(MAKE) -C $(TESTDIR) all - $(MAKE) -C $(TESTDIR) test-platform - - .PHONY: versionsTest -@@ -196,7 +196,7 @@ test-freestanding: - - .PHONY: cxxtest cxx32test - cxxtest cxx32test: CC := "$(CXX) -Wno-deprecated" --cxxtest cxx32test: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -+cxxtest cxx32test: CFLAGS = -O2 -g -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror - cxx32test: CFLAGS += -m32 - cxxtest cxx32test: clean - $(CXX) -v -diff --git a/contrib/djgpp/Makefile b/contrib/djgpp/Makefile -index 8cd3580..d49382e 100644 ---- a/contrib/djgpp/Makefile -+++ b/contrib/djgpp/Makefile -@@ -19,7 +19,7 @@ CC = $(CROSS)-gcc - AR = $(CROSS)-ar - LD = $(CROSS)-gcc - --CFLAGS ?= -O3 -std=gnu99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\" -+CFLAGS ?= -O2 -g -std=gnu99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\" - LDFLAGS ?= -s - SRC = programs/bench.c programs/lz4io.c programs/lz4cli.c - OBJ = $(SRC:.c=.o) -diff --git a/examples/Makefile b/examples/Makefile -index 8be5c81..c52b5e5 100644 ---- a/examples/Makefile -+++ b/examples/Makefile -@@ -28,7 +28,7 @@ - # ########################################################################## - - CPPFLAGS += -I../lib --CFLAGS ?= -O3 -+CFLAGS ?= -O2 -g - CFLAGS += -std=gnu99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes - FLAGS := $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS) - -@@ -102,7 +102,7 @@ test : all $(LZ4) - $(LZ4) -vt $(TESTFILE).lz4 - - .PHONY: cxxtest --cxxtest: CFLAGS := -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -+cxxtest: CFLAGS := -O2 -g -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror - cxxtest: clean - CC=$(CXX) $(MAKE) -C . all CFLAGS="$(CFLAGS)" - -diff --git a/lib/Makefile b/lib/Makefile -index 06503cb..0ca1dad 100644 ---- a/lib/Makefile -+++ b/lib/Makefile -@@ -48,7 +48,7 @@ BUILD_STATIC:=yes - - CPPFLAGS+= -DXXH_NAMESPACE=LZ4_ - CPPFLAGS+= $(MOREFLAGS) --CFLAGS ?= -O3 -+CFLAGS ?= -O2 -g - DEBUGFLAGS:= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ - -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ - -Wundef -Wpointer-arith -Wstrict-aliasing=1 -diff --git a/lib/dll/example/Makefile b/lib/dll/example/Makefile -index eb8cc1e..5dbd0ed 100644 ---- a/lib/dll/example/Makefile -+++ b/lib/dll/example/Makefile -@@ -28,7 +28,7 @@ LZ4DIR := ../include - LIBDIR := ../static - DLLDIR := ../dll - --CFLAGS ?= -O3 # can select custom flags. For example : CFLAGS="-O2 -g" make -+CFLAGS ?= -O2 -g # can select custom flags. For example : CFLAGS="-O2 -g" make - CFLAGS += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum \ - -Wdeclaration-after-statement -Wstrict-prototypes \ - -Wpointer-arith -Wstrict-aliasing=1 -diff --git a/programs/Makefile b/programs/Makefile -index fc4d6f1..3cbd71a 100644 ---- a/programs/Makefile -+++ b/programs/Makefile -@@ -47,7 +47,7 @@ SRCFILES = $(sort $(LIBFILES) $(wildcard *.c)) - OBJFILES = $(SRCFILES:.c=.o) - - CPPFLAGS += -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ --CFLAGS ?= -O3 -+CFLAGS ?= -O2 -g - DEBUGFLAGS= -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \ - -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ - -Wpointer-arith -Wstrict-aliasing=1 -diff --git a/tests/Makefile b/tests/Makefile -index b48070a..ca398f5 100644 ---- a/tests/Makefile -+++ b/tests/Makefile -@@ -35,7 +35,7 @@ PYTHON ?= python3 - - DEBUGLEVEL?= 1 - DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL) --CFLAGS ?= -O3 # can select custom optimization flags. Example : CFLAGS=-O2 make -+CFLAGS ?= -O2 -g # can select custom optimization flags. Example : CFLAGS=-O2 make - CFLAGS += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \ - -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ - -Wpointer-arith -Wstrict-aliasing=1 --- -2.36.1 - diff --git a/debian/patches/series b/debian/patches/series index 5a400cd..d763c26 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,2 +1 @@ -0001-Fix-static-link.patch -0002-Change-optimize-to-O2.patch +use-system-xxhash.patch diff --git a/debian/patches/use-system-xxhash.patch b/debian/patches/use-system-xxhash.patch new file mode 100644 index 0000000..3c44392 --- /dev/null +++ b/debian/patches/use-system-xxhash.patch @@ -0,0 +1,78 @@ +From: Sutou Kouhei <[email protected]> +Date: Mon, 17 Jun 2024 22:00:07 +0900 +Subject: Use xxHash in system library + +Description: Do not use bundled xxHash library. +Origin: Sutou Kouhei <[email protected]> +Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1073192 +Forwarded: not-needed +Author: Kentaro Hayashi <[email protected]> + + +Signed-off-by: Kentaro Hayashi <[email protected]> +--- + build/cmake/CMakeLists.txt | 14 +++++++++++--- + 1 file changed, 11 insertions(+), 3 deletions(-) + +diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt +index eb7007b..37b8e03 100644 +--- a/build/cmake/CMakeLists.txt ++++ b/build/cmake/CMakeLists.txt +@@ -87,7 +87,8 @@ set(LZ4_SOURCES + "${LZ4_LIB_SOURCE_DIR}/lz4hc.h" + "${LZ4_LIB_SOURCE_DIR}/lz4frame.c" + "${LZ4_LIB_SOURCE_DIR}/lz4frame.h" +- "${LZ4_LIB_SOURCE_DIR}/xxhash.c") ++ "${LZ4_LIB_SOURCE_DIR}/lz4file.h" ++ "${LZ4_LIB_SOURCE_DIR}/lz4file.c") + set(LZ4_CLI_SOURCES + "${LZ4_PROG_SOURCE_DIR}/bench.c" + "${LZ4_PROG_SOURCE_DIR}/lz4cli.c" +@@ -99,6 +100,9 @@ set(LZ4_CLI_SOURCES + # used. + option(LZ4_POSITION_INDEPENDENT_LIB "Use position independent code for static library (if applicable)" ON) + ++find_package(PkgConfig REQUIRED) ++pkg_check_modules(XXHASH REQUIRED libxxhash) ++ + # liblz4 + set(LZ4_LIBRARIES_BUILT) + if(BUILD_SHARED_LIBS) +@@ -115,6 +119,7 @@ if(BUILD_SHARED_LIBS) + LZ4_DLL_EXPORT=1) + endif() + list(APPEND LZ4_LIBRARIES_BUILT lz4_shared) ++ target_link_libraries(lz4_shared ${XXHASH_LIBRARIES}) + endif() + if(BUILD_STATIC_LIBS) + set(STATIC_LIB_NAME lz4) +@@ -129,6 +134,7 @@ if(BUILD_STATIC_LIBS) + OUTPUT_NAME ${STATIC_LIB_NAME} + POSITION_INDEPENDENT_CODE ${LZ4_POSITION_INDEPENDENT_LIB}) + list(APPEND LZ4_LIBRARIES_BUILT lz4_static) ++ target_link_libraries(lz4_static ${XXHASH_STATIC_LIBRARIES}) + endif() + + if(BUILD_STATIC_LIBS) +@@ -142,8 +148,9 @@ if (LZ4_BUILD_CLI) + set(LZ4_PROGRAMS_BUILT lz4cli) + add_executable(lz4cli ${LZ4_CLI_SOURCES}) + set_target_properties(lz4cli PROPERTIES OUTPUT_NAME lz4) ++ target_link_libraries(lz4cli ${XXHASH_LIBRARIES}) + if (BUILD_STATIC_LIBS) +- target_link_libraries(lz4cli ${LZ4_LINK_LIBRARY}) ++ target_link_libraries(lz4cli ${LZ4_LINK_LIBRARY} ${XXHASH_STATIC_LIBRARIES}) + endif() + endif() + +@@ -152,8 +159,9 @@ if (LZ4_BUILD_LEGACY_LZ4C) + list(APPEND LZ4_PROGRAMS_BUILT lz4c) + add_executable(lz4c ${LZ4_CLI_SOURCES}) + set_target_properties(lz4c PROPERTIES COMPILE_DEFINITIONS "ENABLE_LZ4C_LEGACY_OPTIONS") ++ target_link_libraries(lz4c ${XXHASH_LIBRARIES}) + if (BUILD_STATIC_LIBS) +- target_link_libraries(lz4c ${LZ4_LINK_LIBRARY}) ++ target_link_libraries(lz4c ${LZ4_LINK_LIBRARY} ${XXHASH_STATIC_LIBRARIES}) + endif() + endif() + diff --git a/debian/rules b/debian/rules index e164ea7..6a6e7a8 100755 --- a/debian/rules +++ b/debian/rules @@ -2,7 +2,7 @@ # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 -CPPFLAGS:= $(shell dpkg-buildflags --get CPPFLAGS) -DLZ4F_PUBLISH_STATIC_FUNCTIONS +CPPFLAGS:= $(shell dpkg-buildflags --get CPPFLAGS) -fvisibility=hidden -DLZ4F_PUBLISH_STATIC_FUNCTIONS CFLAGS:= $(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS) CXXFLAGS:= $(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS) LDFLAGS:= $(shell dpkg-buildflags --get LDFLAGS) @@ -27,16 +27,18 @@ endif %: dh $@ +override_dh_auto_configure: + dh_auto_configure --buildsystem=cmake --sourcedirectory=build/cmake -- \ + -DBUILD_STATIC_LIBS=ON \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo + override_dh_auto_build: - dh_auto_build -- CC=$(CC) V=1 + dh_auto_build --buildsystem=cmake override_dh_auto_install: - dh_auto_install -- \ - CC=$(CC) \ - DESTDIR=$$(pwd)/debian/tmp \ - LIBDIR=$(DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH) + dh_auto_install --buildsystem=cmake override_dh_auto_test: ifeq "$(disable_test)" "0" - make test + dh_auto_test --buildsystem=cmake endif -- 2.45.2

