summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2024-04-03 18:52:57 +0200
committerFelix Fietkau <nbd@nbd.name>2024-04-03 18:56:58 +0200
commit1f3e0177d99ef68a5a837489413e9ed8753d2a69 (patch)
tree598fb8e00b349fbae52c18945ed36887e307bdd8 /tools
parent7a78b22dc8f3159f2a0dda498cd12ac27a026ea8 (diff)
downloadopenwrt-1f3e0177d99ef68a5a837489413e9ed8753d2a69.tar.gz
openwrt-1f3e0177d99ef68a5a837489413e9ed8753d2a69.tar.bz2
openwrt-1f3e0177d99ef68a5a837489413e9ed8753d2a69.zip
tools/bzip2: switch to cmake
Fixes portability issues on macOS. CMakeLists.txt is a stripped-down backport from bzip2 upstream Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'tools')
-rw-r--r--tools/bzip2/Makefile24
-rw-r--r--tools/bzip2/patches/021-merge-and-improve-makefiles.patch401
-rw-r--r--tools/bzip2/patches/100-cmake.patch382
3 files changed, 384 insertions, 423 deletions
diff --git a/tools/bzip2/Makefile b/tools/bzip2/Makefile
index 0c5a92849a..86df143826 100644
--- a/tools/bzip2/Makefile
+++ b/tools/bzip2/Makefile
@@ -22,31 +22,11 @@ PKG_CPE_ID:=cpe:/a:bzip:bzip2
HOST_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/host-build.mk
+include $(INCLUDE_DIR)/cmake.mk
HOSTCC := $(HOSTCC_NOCACHE)
HOST_CFLAGS += $(HOST_FPIC)
-HOST_MAKE_FLAGS+= \
- CFLAGS="$(HOST_CFLAGS)" \
- LDFLAGS="$(HOST_LDFLAGS)" \
- ENABLE_BIN_SHARED=1 \
- ENABLE_BIN_STATIC=0 \
- ENABLE_LIB_SHARED=1 \
- ENABLE_LIB_STATIC=1 \
- ENABLE_DEV=1 \
- ENABLE_DOCS=1 \
- ENABLE_TESTS=0 \
- PREFIX="$(HOST_BUILD_PREFIX)"
-
-define Host/Configure
-endef
-
-define Host/Uninstall
- $(call Host/Compile/Default,uninstall)
- $(call Host/Compile/Default,clean)
-endef
-
-define Host/Clean
-endef
+CMAKE_HOST_OPTIONS += -DENABLE_EXAMPLES=off
$(eval $(call HostBuild))
diff --git a/tools/bzip2/patches/021-merge-and-improve-makefiles.patch b/tools/bzip2/patches/021-merge-and-improve-makefiles.patch
deleted file mode 100644
index 9d98c34bdb..0000000000
--- a/tools/bzip2/patches/021-merge-and-improve-makefiles.patch
+++ /dev/null
@@ -1,401 +0,0 @@
---- a/bzip2.c
-+++ b/bzip2.c
-@@ -54,7 +54,7 @@
- #include <math.h>
- #include <errno.h>
- #include <ctype.h>
--#include "bzlib.h"
-+#include <bzlib.h>
-
- #define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); }
- #define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); }
---- a/bzlib_private.h
-+++ b/bzlib_private.h
-@@ -30,7 +30,7 @@
- #include <string.h>
- #endif
-
--#include "bzlib.h"
-+#include <bzlib.h>
-
-
-
---- a/Makefile
-+++ b/Makefile
-@@ -21,11 +21,38 @@
- LDFLAGS=
-
- BIGFILES=-D_FILE_OFFSET_BITS=64
--CFLAGS=-Wall -Winline -O2 -g $(BIGFILES)
-+CFLAGS_COMMON=-Wall -Winline -O2 -g $(BIGFILES) -I.
-+CFLAGS_NOPIC=$(filter-out -O%,$(CFLAGS)) $(CFLAGS_COMMON)
-+CFLAGS_PIC=$(filter-out -O%,$(CFLAGS)) -fpic -fPIC $(CFLAGS_COMMON)
-
- # Where you want it installed when you do 'make install'
--PREFIX=/usr/local
--
-+PREFIX?=/usr/local
-+ENABLE_BIN_STATIC?=1
-+ENABLE_BIN_SHARED?=1
-+ENABLE_LIB_STATIC?=1
-+ENABLE_LIB_SHARED?=1
-+ENABLE_DEV?=1
-+ENABLE_DOCS?=1
-+ENABLE_TESTS?=1
-+
-+ifeq ($(ENABLE_BIN_STATIC),1)
-+ ENABLE_BIN=1
-+ ifneq ($(ENABLE_LIB_STATIC),1)
-+ ENABLE_LIB_STATIC=1
-+ endif
-+endif
-+ifeq ($(ENABLE_BIN_SHARED),1)
-+ ENABLE_BIN=1
-+ ifneq ($(ENABLE_LIB_SHARED),1)
-+ ENABLE_LIB_STATIC=1
-+ endif
-+endif
-+ifeq ($(ENABLE_LIB_STATIC),1)
-+ ENABLE_LIB=1
-+endif
-+ifeq ($(ENABLE_LIB_SHARED),1)
-+ ENABLE_LIB=1
-+endif
-
- OBJS= blocksort.o \
- huffman.o \
-@@ -35,15 +62,38 @@
- decompress.o \
- bzlib.o
-
--all: libbz2.a bzip2 bzip2recover test
--
--bzip2: libbz2.a bzip2.o
-- $(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
-+TGTS_all:=
-+TGTS_bzip2:=bzip2.o
-+TGTS_check:=
-+TGTS_install:=
-+ifeq ($(ENABLE_LIB),1)
-+ TGTS_all+=libbz2
-+ TGTS_bzip2+=libbz2
-+endif
-+ifeq ($(ENABLE_BIN),1)
-+ TGTS_all+=bzip2 bzip2recover
-+ TGTS_install+=bzip2 bzip2recover
-+endif
-+ifeq ($(ENABLE_TESTS),1)
-+ TGTS_all+=test
-+ TGTS_check+=test
-+endif
-+
-+all: $(TGTS_all)
-+
-+bzip2: $(TGTS_bzip2)
-+ifeq ($(ENABLE_BIN_STATIC),1)
-+ $(CC) $(CFLAGS_NOPIC) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
-+endif
-+ifeq ($(ENABLE_BIN_SHARED),1)
-+ $(CC) $(CFLAGS_PIC) -o bzip2-shared bzip2.o libbz2.so.1.0
-+endif
-
- bzip2recover: bzip2recover.o
-- $(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
-+ $(CC) $(CFLAGS_NOPIC) $(LDFLAGS) -o bzip2recover bzip2recover.o
-
--libbz2.a: $(OBJS)
-+libbz2: $(OBJS)
-+ifeq ($(ENABLE_LIB_STATIC),1)
- rm -f libbz2.a
- $(AR) cq libbz2.a $(OBJS)
- @if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \
-@@ -51,8 +101,18 @@
- echo $(RANLIB) libbz2.a ; \
- $(RANLIB) libbz2.a ; \
- fi
-+endif
-+ifeq ($(ENABLE_LIB_SHARED),1)
-+ $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 $(LDFLAGS) -o libbz2.so.1.0.8 $(OBJS)
-+ rm -f libbz2.so.1.0
-+ rm -f libbz2.so.1
-+ rm -f libbz2.so
-+ ln -s libbz2.so.1.0.8 libbz2.so.1.0
-+ ln -s libbz2.so.1.0 libbz2.so.1
-+ ln -s libbz2.so.1 libbz2.so
-+endif
-
--check: test
-+check: $(TGTS_check)
- test: bzip2
- @cat words1
- ./bzip2 -1 < sample1.ref > sample1.rb2
-@@ -69,69 +129,153 @@
- cmp sample3.tst sample3.ref
- @cat words3
-
--install: bzip2 bzip2recover
-+install: $(TGTS_install)
-+ifeq ($(ENABLE_BIN),1)
- if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
-+endif
-+ifeq ($(ENABLE_LIB),1)
- if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
-+endif
-+ifeq ($(ENABLE_DEV),1)
-+ if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
-+endif
-+ifeq ($(ENABLE_DOCS),1)
- if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi
- if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi
-- if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
-+endif
-+ifeq ($(ENABLE_BIN),1)
-+ ifeq ($(ENABLE_BIN_STATIC),1)
- cp -f bzip2 $(PREFIX)/bin/bzip2
-- cp -f bzip2 $(PREFIX)/bin/bunzip2
-- cp -f bzip2 $(PREFIX)/bin/bzcat
-+ chmod a+rx $(PREFIX)/bin/bzip2
-+ endif
-+ ifeq ($(ENABLE_BIN_SHARED),1)
-+ ifeq ($(ENABLE_BIN_STATIC),1)
-+ cp -f bzip2-shared $(PREFIX)/bin/bzip2-shared
-+ chmod a+rx $(PREFIX)/bin/bzip2-shared
-+ else
-+ cp -f bzip2-shared $(PREFIX)/bin/bzip2
-+ endif
-+ endif
-+ rm -f $(PREFIX)/bin/bunzip2
-+ rm -f $(PREFIX)/bin/bzcat
-+ ( cd $(PREFIX)/bin && ln -s bzip2 bunzip2 )
-+ ( cd $(PREFIX)/bin && ln -s bzip2 bzcat )
-+ rm -f $(PREFIX)/bin/bunzip2-shared
-+ rm -f $(PREFIX)/bin/bzcat-shared
-+ ifeq ($(ENABLE_BIN_SHARED),1)
-+ ifeq ($(ENABLE_BIN_STATIC),1)
-+ ( cd $(PREFIX)/bin && ln -s bzip2-shared bunzip2-shared )
-+ ( cd $(PREFIX)/bin && ln -s bzip2-shared bzcat-shared )
-+ endif
-+ endif
- cp -f bzip2recover $(PREFIX)/bin/bzip2recover
-- chmod a+x $(PREFIX)/bin/bzip2
-- chmod a+x $(PREFIX)/bin/bunzip2
-- chmod a+x $(PREFIX)/bin/bzcat
-- chmod a+x $(PREFIX)/bin/bzip2recover
-- cp -f bzip2.1 $(PREFIX)/man/man1
-- chmod a+r $(PREFIX)/man/man1/bzip2.1
-- cp -f bzlib.h $(PREFIX)/include
-- chmod a+r $(PREFIX)/include/bzlib.h
-- cp -f libbz2.a $(PREFIX)/lib
-- chmod a+r $(PREFIX)/lib/libbz2.a
-+ chmod a+rx $(PREFIX)/bin/bzip2recover
- cp -f bzgrep $(PREFIX)/bin/bzgrep
-- ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep
-- ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep
-- chmod a+x $(PREFIX)/bin/bzgrep
-+ chmod a+rx $(PREFIX)/bin/bzgrep
-+ rm -f $(PREFIX)/bin/bzegrep
-+ rm -f $(PREFIX)/bin/bzfgrep
-+ ( cd $(PREFIX)/bin && ln -s bzgrep bzegrep )
-+ ( cd $(PREFIX)/bin && ln -s bzgrep bzfgrep )
- cp -f bzmore $(PREFIX)/bin/bzmore
-- ln -s -f $(PREFIX)/bin/bzmore $(PREFIX)/bin/bzless
-- chmod a+x $(PREFIX)/bin/bzmore
-+ chmod a+rx $(PREFIX)/bin/bzmore
-+ rm -f $(PREFIX)/bin/bzless
-+ ( cd $(PREFIX)/bin && ln -s bzmore bzless )
-+ rm -f $(PREFIX)/bin/bzcmp
- cp -f bzdiff $(PREFIX)/bin/bzdiff
-- ln -s -f $(PREFIX)/bin/bzdiff $(PREFIX)/bin/bzcmp
-- chmod a+x $(PREFIX)/bin/bzdiff
-- cp -f bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/man/man1
-- chmod a+r $(PREFIX)/man/man1/bzgrep.1
-- chmod a+r $(PREFIX)/man/man1/bzmore.1
-- chmod a+r $(PREFIX)/man/man1/bzdiff.1
-+ chmod a+rx $(PREFIX)/bin/bzdiff
-+ ( cd $(PREFIX)/bin && ln -s bzdiff bzcmp )
-+endif
-+ifeq ($(ENABLE_DEV),1)
-+ cp -f bzlib.h $(PREFIX)/include
-+ chmod a+r $(PREFIX)/include/bzlib.h
-+endif
-+ifeq ($(ENABLE_DOCS),1)
-+ cp -f bzip2.1 bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/man/man1
- echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1
- echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzfgrep.1
- echo ".so man1/bzmore.1" > $(PREFIX)/man/man1/bzless.1
- echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
-+ chmod a+r $(PREFIX)/man/man1/bzip2.1
-+ chmod a+r $(PREFIX)/man/man1/bzgrep.1
-+ chmod a+r $(PREFIX)/man/man1/bzmore.1
-+ chmod a+r $(PREFIX)/man/man1/bzdiff.1
-+ chmod a+r $(PREFIX)/man/man1/bzegrep.1
-+ chmod a+r $(PREFIX)/man/man1/bzfgrep.1
-+ chmod a+r $(PREFIX)/man/man1/bzless.1
-+ chmod a+r $(PREFIX)/man/man1/bzcmp.1
-+endif
-+ifeq ($(ENABLE_LIB_SHARED),1)
-+ cp -f libbz2.so.1.0.8 $(PREFIX)/lib
-+ chmod a+r $(PREFIX)/lib/libbz2.so.1.0.8
-+ rm -f $(PREFIX)/lib/libbz2.so.1.0
-+ rm -f $(PREFIX)/lib/libbz2.so.1
-+ rm -f $(PREFIX)/lib/libbz2.so
-+ ( cd $(PREFIX)/lib && ln -s libbz2.so.1.0.8 libbz2.so.1.0 )
-+ ( cd $(PREFIX)/lib && ln -s libbz2.so.1.0 libbz2.so.1 )
-+ ( cd $(PREFIX)/lib && ln -s libbz2.so.1 libbz2.so )
-+endif
-+ifeq ($(ENABLE_LIB_STATIC),1)
-+ cp -f libbz2.a $(PREFIX)/lib
-+ chmod a+r $(PREFIX)/lib/libbz2.a
-+endif
-+
-+uninstall:
-+ rm -f $(PREFIX)/bin/bzip2
-+ rm -f $(PREFIX)/bin/bzip2-shared
-+ rm -f $(PREFIX)/bin/bunzip2
-+ rm -f $(PREFIX)/bin/bzcat
-+ rm -f $(PREFIX)/bin/bunzip2-shared
-+ rm -f $(PREFIX)/bin/bzcat-shared
-+ rm -f $(PREFIX)/bin/bzip2recover
-+ rm -f $(PREFIX)/bin/bzgrep
-+ rm -f $(PREFIX)/bin/bzegrep
-+ rm -f $(PREFIX)/bin/bzfgrep
-+ rm -f $(PREFIX)/bin/bzmore
-+ rm -f $(PREFIX)/bin/bzless
-+ rm -f $(PREFIX)/bin/bzdiff
-+ rm -f $(PREFIX)/bin/bzcmp
-+ rm -f $(PREFIX)/include/bzlib.h
-+ rm -f $(PREFIX)/lib/libbz2.so.1.0.8
-+ rm -f $(PREFIX)/lib/libbz2.so.1.0
-+ rm -f $(PREFIX)/lib/libbz2.so.1
-+ rm -f $(PREFIX)/lib/libbz2.so
-+ rm -f $(PREFIX)/lib/libbz2.a
-+ rm -f $(PREFIX)/man/man1/bzip2.1
-+ rm -f $(PREFIX)/man/man1/bzgrep.1
-+ rm -f $(PREFIX)/man/man1/bzmore.1
-+ rm -f $(PREFIX)/man/man1/bzdiff.1
-+ rm -f $(PREFIX)/man/man1/bzegrep.1
-+ rm -f $(PREFIX)/man/man1/bzfgrep.1
-+ rm -f $(PREFIX)/man/man1/bzless.1
-+ rm -f $(PREFIX)/man/man1/bzcmp.1
-+ (rmdir $(PREFIX)/bin $(PREFIX)/include $(PREFIX)/lib $(PREFIX)/man/man1 $(PREFIX)/man || true ) 2> /dev/null
-
- clean:
-- rm -f *.o libbz2.a bzip2 bzip2recover \
-+ rm -f $(OBJS) bzip2.o \
-+ libbz2.so.1.0.8 libbz2.so.1.0 libbz2.so.1 libbz2.so \
-+ libbz2.a bzip2 bzip2-shared bzip2recover \
- sample1.rb2 sample2.rb2 sample3.rb2 \
- sample1.tst sample2.tst sample3.tst
-
- blocksort.o: blocksort.c
- @cat words0
-- $(CC) $(CFLAGS) -c blocksort.c
-+ $(CC) $(CFLAGS_NOPIC) -c blocksort.c
- huffman.o: huffman.c
-- $(CC) $(CFLAGS) -c huffman.c
-+ $(CC) $(CFLAGS_NOPIC) -c huffman.c
- crctable.o: crctable.c
-- $(CC) $(CFLAGS) -c crctable.c
-+ $(CC) $(CFLAGS_NOPIC) -c crctable.c
- randtable.o: randtable.c
-- $(CC) $(CFLAGS) -c randtable.c
-+ $(CC) $(CFLAGS_NOPIC) -c randtable.c
- compress.o: compress.c
-- $(CC) $(CFLAGS) -c compress.c
-+ $(CC) $(CFLAGS_NOPIC) -c compress.c
- decompress.o: decompress.c
-- $(CC) $(CFLAGS) -c decompress.c
-+ $(CC) $(CFLAGS_NOPIC) -c decompress.c
- bzlib.o: bzlib.c
-- $(CC) $(CFLAGS) -c bzlib.c
-+ $(CC) $(CFLAGS_NOPIC) -c bzlib.c
- bzip2.o: bzip2.c
-- $(CC) $(CFLAGS) -c bzip2.c
-+ $(CC) $(CFLAGS_NOPIC) -c bzip2.c
- bzip2recover.o: bzip2recover.c
-- $(CC) $(CFLAGS) -c bzip2recover.c
-+ $(CC) $(CFLAGS_NOPIC) -c bzip2recover.c
-
-
- distclean: clean
-@@ -189,7 +333,6 @@
- $(DISTNAME)/bzmore.1 \
- $(DISTNAME)/bzgrep \
- $(DISTNAME)/bzgrep.1 \
-- $(DISTNAME)/Makefile-libbz2_so \
- $(DISTNAME)/bz-common.xsl \
- $(DISTNAME)/bz-fo.xsl \
- $(DISTNAME)/bz-html.xsl \
---- a/Makefile-libbz2_so
-+++ b/Makefile-libbz2_so
-@@ -1,59 +0,0 @@
--
--# This Makefile builds a shared version of the library,
--# libbz2.so.1.0.8, with soname libbz2.so.1.0,
--# at least on x86-Linux (RedHat 7.2),
--# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).
--# Please see the README file for some important info
--# about building the library like this.
--
--# ------------------------------------------------------------------
--# This file is part of bzip2/libbzip2, a program and library for
--# lossless, block-sorting data compression.
--#
--# bzip2/libbzip2 version 1.0.8 of 13 July 2019
--# Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
--#
--# Please read the WARNING, DISCLAIMER and PATENTS sections in the
--# README file.
--#
--# This program is released under the terms of the license contained
--# in the file LICENSE.
--# ------------------------------------------------------------------
--
--
--SHELL=/bin/sh
--CC=gcc
--BIGFILES=-D_FILE_OFFSET_BITS=64
--CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES)
--
--OBJS= blocksort.o \
-- huffman.o \
-- crctable.o \
-- randtable.o \
-- compress.o \
-- decompress.o \
-- bzlib.o
--
--all: $(OBJS)
-- $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.8 $(OBJS)
-- $(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.8
-- rm -f libbz2.so.1.0
-- ln -s libbz2.so.1.0.8 libbz2.so.1.0
--
--clean:
-- rm -f $(OBJS) bzip2.o libbz2.so.1.0.8 libbz2.so.1.0 bzip2-shared
--
--blocksort.o: blocksort.c
-- $(CC) $(CFLAGS) -c blocksort.c
--huffman.o: huffman.c
-- $(CC) $(CFLAGS) -c huffman.c
--crctable.o: crctable.c
-- $(CC) $(CFLAGS) -c crctable.c
--randtable.o: randtable.c
-- $(CC) $(CFLAGS) -c randtable.c
--compress.o: compress.c
-- $(CC) $(CFLAGS) -c compress.c
--decompress.o: decompress.c
-- $(CC) $(CFLAGS) -c decompress.c
--bzlib.o: bzlib.c
-- $(CC) $(CFLAGS) -c bzlib.c
---- a/unzcrash.c
-+++ b/unzcrash.c
-@@ -30,7 +30,7 @@
-
- #include <stdio.h>
- #include <assert.h>
--#include "bzlib.h"
-+#include <bzlib.h>
-
- #define M_BLOCK 1000000
-
diff --git a/tools/bzip2/patches/100-cmake.patch b/tools/bzip2/patches/100-cmake.patch
new file mode 100644
index 0000000000..0ed37b2e44
--- /dev/null
+++ b/tools/bzip2/patches/100-cmake.patch
@@ -0,0 +1,382 @@
+--- /dev/null
++++ b/CMakeLists.txt
+@@ -0,0 +1,354 @@
++cmake_minimum_required(VERSION 3.12)
++
++project(bzip2
++ VERSION 1.0.8
++ DESCRIPTION "This Bzip2/libbz2 a program and library for lossless block-sorting data compression."
++ LANGUAGES C)
++
++# See versioning rule:
++# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
++#
++# KEEP THESE IN SYNC WITH meson.build OR STUFF WILL BREAK!
++set(LT_CURRENT 1)
++set(LT_REVISION 8)
++set(LT_AGE 0)
++
++set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
++
++include_directories(${PROJECT_BINARY_DIR})
++
++math(EXPR LT_SOVERSION "${LT_CURRENT} - ${LT_AGE}")
++set(LT_VERSION "${LT_SOVERSION}.${LT_AGE}.${LT_REVISION}")
++set(PACKAGE_VERSION ${PROJECT_VERSION})
++
++set(ENABLE_APP_DEFAULT ON)
++set(ENABLE_EXAMPLES_DEFAULT OFF)
++set(ENABLE_DOCS_DEFAULT OFF)
++include(CMakeOptions.txt)
++
++if(ENABLE_LIB_ONLY AND (ENABLE_APP OR ENABLE_EXAMPLES))
++ # Remember when disabled options are disabled for later diagnostics.
++ set(ENABLE_LIB_ONLY_DISABLED_OTHERS 1)
++else()
++ set(ENABLE_LIB_ONLY_DISABLED_OTHERS 0)
++endif()
++if(ENABLE_LIB_ONLY)
++ set(ENABLE_APP OFF)
++ set(ENABLE_EXAMPLES OFF)
++endif()
++
++# Do not disable assertions based on CMAKE_BUILD_TYPE.
++foreach(_build_type Release MinSizeRel RelWithDebInfo)
++ foreach(_lang C)
++ string(TOUPPER CMAKE_${_lang}_FLAGS_${_build_type} _var)
++ string(REGEX REPLACE "(^|)[/-]D *NDEBUG($|)" " " ${_var} "${${_var}}")
++ endforeach()
++endforeach()
++
++# Support the latest c++ standard available.
++include(CheckCCompilerFlag)
++include(CheckCXXCompilerFlag)
++
++function(extract_valid_c_flags varname)
++ set(valid_flags)
++ foreach(flag IN LISTS ARGN)
++ string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
++ set(flag_var "C_FLAG_${flag_var}")
++ check_c_compiler_flag("${flag}" "${flag_var}")
++ if(${flag_var})
++ set(valid_flags "${valid_flags} ${flag}")
++ endif()
++ endforeach()
++ set(${varname} "${valid_flags}" PARENT_SCOPE)
++endfunction()
++if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
++ set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build type" FORCE)
++
++ # Include "None" as option to disable any additional (optimization) flags,
++ # relying on just CMAKE_C_FLAGS and CMAKE_CXX_FLAGS (which are empty by
++ # default). These strings are presented in cmake-gui.
++ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
++ None Debug Release MinSizeRel RelWithDebInfo)
++endif()
++
++# Install a symlink of script to the "bin" directory.
++# Not intended for use on Windows.
++function(install_script_symlink original symlink)
++ add_custom_command(OUTPUT ${symlink}
++ COMMAND ${CMAKE_COMMAND} -E create_symlink ${original} ${symlink}
++ DEPENDS ${original}
++ COMMENT "Generating symbolic link ${symlink} of ${original}")
++ add_custom_target(${symlink}_tgt ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${symlink})
++ install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${symlink} DESTINATION ${CMAKE_INSTALL_BINDIR})
++endfunction()
++
++# Install a symlink of binary target to the "bin" directory.
++# On Windows, it will be a copy instead of a symlink.
++function(install_target_symlink original symlink)
++ if(WIN32)
++ set(op copy)
++ set(symlink "${symlink}.exe")
++ else()
++ set(op create_symlink)
++ endif()
++ add_custom_command(TARGET ${original} POST_BUILD
++ COMMAND ${CMAKE_COMMAND} -E ${op} $<TARGET_FILE_NAME:${original}> ${symlink}
++ WORKING_DIRECTORY $<TARGET_FILE_DIR:${original}>
++ COMMENT "Generating symbolic link (or copy) ${symlink} of ${original}")
++ install(PROGRAMS $<TARGET_FILE_DIR:${original}>/${symlink} DESTINATION ${CMAKE_INSTALL_BINDIR})
++endfunction()
++
++include(GNUInstallDirs)
++
++# Checks for header files.
++include(CheckIncludeFile)
++check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
++check_include_file(fcntl.h HAVE_FCNTL_H)
++check_include_file(inttypes.h HAVE_INTTYPES_H)
++check_include_file(limits.h HAVE_LIMITS_H)
++check_include_file(netdb.h HAVE_NETDB_H)
++check_include_file(netinet/in.h HAVE_NETINET_IN_H)
++check_include_file(pwd.h HAVE_PWD_H)
++check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
++check_include_file(sys/time.h HAVE_SYS_TIME_H)
++check_include_file(syslog.h HAVE_SYSLOG_H)
++check_include_file(time.h HAVE_TIME_H)
++check_include_file(unistd.h HAVE_UNISTD_H)
++
++include(CheckTypeSize)
++# Checks for typedefs, structures, and compiler characteristics.
++# AC_TYPE_SIZE_T
++check_type_size("ssize_t" SIZEOF_SSIZE_T)
++if(NOT SIZEOF_SSIZE_T)
++ # ssize_t is a signed type in POSIX storing at least -1.
++ # Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools).
++ set(ssize_t int)
++endif()
++
++include(CheckStructHasMember)
++check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF)
++
++include(CheckSymbolExists)
++# XXX does this correctly detect initgroups (un)availability on cygwin?
++check_symbol_exists(initgroups grp.h HAVE_DECL_INITGROUPS)
++if(NOT HAVE_DECL_INITGROUPS AND HAVE_UNISTD_H)
++ # FreeBSD declares initgroups() in unistd.h
++ check_symbol_exists(initgroups unistd.h HAVE_DECL_INITGROUPS2)
++ if(HAVE_DECL_INITGROUPS2)
++ set(HAVE_DECL_INITGROUPS 1)
++ endif()
++endif()
++
++set(WARNCFLAGS)
++if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
++ if(ENABLE_WERROR)
++ set(WARNCFLAGS /WX)
++ endif()
++else()
++ if(ENABLE_WERROR)
++ extract_valid_c_flags(WARNCFLAGS -Werror)
++ endif()
++
++ # For C compiler
++ # Please keep this list in sync with meson.build
++ extract_valid_c_flags(WARNCFLAGS
++ -Wall
++ -Wextra
++ -Wmissing-prototypes
++ -Wstrict-prototypes
++ -Wmissing-declarations
++ -Wpointer-arith
++ -Wdeclaration-after-statement
++ -Wformat-security
++ -Wwrite-strings
++ -Wshadow
++ -Winline
++ -Wnested-externs
++ -Wfloat-equal
++ -Wundef
++ -Wendif-labels
++ -Wempty-body
++ -Wcast-align
++ -Wclobbered
++ -Wvla
++ -Wpragmas
++ -Wunreachable-code
++ -Waddress
++ -Wattributes
++ -Wdiv-by-zero
++ -Wshorten-64-to-32
++ -Wconversion
++ -Wextended-offsetof
++ -Wformat-nonliteral
++ -Wlanguage-extension-token
++ -Wmissing-field-initializers
++ -Wmissing-noreturn
++ -Wmissing-variable-declarations
++ # -Wpadded # Not used because we cannot change public structs
++ -Wsign-conversion
++ # -Wswitch-enum # Not used because this basically disallows default case
++ -Wunreachable-code-break
++ -Wunused-macros
++ -Wunused-parameter
++ -Wredundant-decls
++ -Wheader-guard
++ -Wno-format-nonliteral # This is required because we pass format string as "const char*.
++ )
++endif()
++
++if(ENABLE_DEBUG)
++ set(DEBUGBUILD 1)
++endif()
++
++#add_definitions(-DHAVE_CONFIG_H)
++#configure_file(cmakeconfig.h.in config.h)
++
++# autotools-compatible names
++# Sphinx expects relative paths in the .rst files. Use the fact that the files
++# below are all one directory level deep.
++file(RELATIVE_PATH top_srcdir ${CMAKE_CURRENT_BINARY_DIR}/dir ${CMAKE_CURRENT_SOURCE_DIR})
++file(RELATIVE_PATH top_builddir ${CMAKE_CURRENT_BINARY_DIR}/dir ${CMAKE_CURRENT_BINARY_DIR})
++set(abs_top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
++set(abs_top_builddir ${CMAKE_CURRENT_BINARY_DIR})
++# bzip2.pc (pkg-config file)
++set(prefix ${CMAKE_INSTALL_PREFIX})
++set(exec_prefix ${CMAKE_INSTALL_PREFIX})
++set(bindir ${CMAKE_INSTALL_FULL_BINDIR})
++set(sbindir ${CMAKE_INSTALL_FULL_SBINDIR})
++set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
++set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
++set(VERSION ${PACKAGE_VERSION})
++
++#
++# The build targets.
++# In a larger project, the following would be in subdirectories and
++# These targets would be included with `add_subdirectory()`
++#
++set(BZ2_SOURCES
++ blocksort.c
++ huffman.c
++ crctable.c
++ randtable.c
++ compress.c
++ decompress.c
++ bzlib.c)
++
++# The bz2 OBJECT-library, required for bzip2, bzip2recover.
++add_library(bz2_ObjLib OBJECT)
++target_sources(bz2_ObjLib
++ PRIVATE ${BZ2_SOURCES}
++ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bzlib_private.h
++ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/bzlib.h)
++
++if(ENABLE_SHARED_LIB)
++ # The libbz2 shared library.
++ add_library(bz2 SHARED ${BZ2_RES})
++ target_sources(bz2
++ PRIVATE ${BZ2_SOURCES}
++ ${CMAKE_CURRENT_SOURCE_DIR}/libbz2.def
++ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bzlib_private.h
++ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/bzlib.h)
++ # Always use '-fPIC'/'-fPIE' option for shared libraries.
++ set_property(TARGET bz2 PROPERTY POSITION_INDEPENDENT_CODE ON)
++ set_target_properties(bz2 PROPERTIES
++ COMPILE_FLAGS "${WARNCFLAGS}"
++ VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION})
++ install(TARGETS bz2 DESTINATION ${CMAKE_INSTALL_LIBDIR})
++ install(FILES bzlib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
++
++ if(USE_OLD_SONAME)
++ # Hack to support the old libbz2.so.1.0 version by including an extra copy.
++ # Technically the old SONAME is not libtool compatible.
++ # This hack is to support binary compatibility with libbz2 in some distro packages.
++ if(UNIX AND NOT APPLE)
++ add_library(bz2_old_soname SHARED ${BZ2_RES})
++ target_sources(bz2_old_soname
++ PRIVATE ${BZ2_SOURCES}
++ ${CMAKE_CURRENT_SOURCE_DIR}/libbz2.def
++ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bzlib_private.h
++ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/bzlib.h
++ )
++ set_target_properties(bz2_old_soname PROPERTIES
++ COMPILE_FLAGS "${WARNCFLAGS}"
++ VERSION ${LT_SOVERSION}.${LT_AGE} SOVERSION ${LT_SOVERSION}.${LT_AGE}
++ OUTPUT_NAME bz2
++ )
++ install(TARGETS bz2_old_soname DESTINATION ${CMAKE_INSTALL_LIBDIR})
++ endif()
++ endif()
++endif()
++
++if(ENABLE_STATIC_LIB)
++ # The libbz2 static library.
++ add_library(bz2_static STATIC)
++ target_sources(bz2_static
++ PRIVATE ${BZ2_SOURCES}
++ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bzlib_private.h
++ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/bzlib.h)
++ set_target_properties(bz2_static PROPERTIES
++ COMPILE_FLAGS "${WARNCFLAGS}"
++ VERSION ${LT_VERSION}
++ SOVERSION ${LT_SOVERSION}
++ ARCHIVE_OUTPUT_NAME bz2_static)
++ target_compile_definitions(bz2_static PUBLIC BZ2_STATICLIB)
++ install(TARGETS bz2_static DESTINATION ${CMAKE_INSTALL_LIBDIR})
++ install(FILES bzlib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
++endif()
++
++if(ENABLE_APP)
++ # The bzip2 executable.
++ add_executable(bzip2)
++ target_sources(bzip2
++ PRIVATE bzip2.c)
++ target_link_libraries(bzip2
++ PRIVATE bz2_ObjLib)
++ if(WIN32)
++ target_compile_definitions(bzip2 PUBLIC BZ_LCCWIN32 BZ_UNIX=0)
++ else()
++ target_compile_definitions(bzip2 PUBLIC BZ_LCCWIN32=0 BZ_UNIX)
++ endif()
++ install(TARGETS bzip2 DESTINATION ${CMAKE_INSTALL_BINDIR})
++
++ # Create bzip2 copies bzcat and bunzip.
++ # The default behavior is altered in bzip2.c code by checking the program name.
++ install_target_symlink(bzip2 bzcat)
++ install_target_symlink(bzip2 bunzip)
++
++ # The bzip2recover executable.
++ add_executable(bzip2recover)
++ target_sources(bzip2recover
++ PRIVATE bzip2recover.c)
++ target_link_libraries(bzip2recover
++ PRIVATE bz2_ObjLib)
++ if(WIN32)
++ target_compile_definitions(bzip2recover PUBLIC BZ_LCCWIN32 BZ_UNIX=0)
++ else()
++ target_compile_definitions(bzip2recover PUBLIC BZ_LCCWIN32=0 BZ_UNIX)
++ endif()
++ install(TARGETS bzip2recover DESTINATION ${CMAKE_INSTALL_BINDIR})
++
++ if(ENABLE_EXAMPLES)
++ if(ENABLE_SHARED_LIB)
++ # The dlltest executable.
++ add_executable(dlltest)
++ target_sources(dlltest
++ PRIVATE dlltest.c)
++ target_link_libraries(dlltest bz2)
++ install(TARGETS dlltest DESTINATION ${CMAKE_INSTALL_BINDIR})
++ endif()
++ endif()
++
++ if(NOT WIN32)
++ # Install shell scripts, and renamed copies.
++ install(PROGRAMS bzdiff bzgrep bzmore
++ DESTINATION ${CMAKE_INSTALL_BINDIR})
++
++ install_script_symlink(bzdiff bzcmp)
++
++ install_script_symlink(bzgrep bzegrep)
++ install_script_symlink(bzgrep bzfgrep)
++
++ install_script_symlink(bzmore bzless)
++ endif()
++
++endif()
+--- /dev/null
++++ b/CMakeOptions.txt
+@@ -0,0 +1,22 @@
++# Features that can be enabled for cmake (see CMakeLists.txt)
++
++option(ENABLE_WERROR "Turn on compile time warnings")
++
++option(ENABLE_DEBUG "Turn on debug output")
++
++option(ENABLE_APP "Build applications (bzip2, and bzip2recover)"
++ ${ENABLE_APP_DEFAULT})
++
++option(ENABLE_DOCS "Generate documentation"
++ ${ENABLE_DOCS_DEFAULT})
++
++option(ENABLE_EXAMPLES "Build examples"
++ ${ENABLE_EXAMPLES_DEFAULT})
++
++option(ENABLE_LIB_ONLY "Build libbz2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0")
++
++option(ENABLE_STATIC_LIB "Build libbz2 in static mode also")
++
++option(ENABLE_SHARED_LIB "Build libbz2 as a shared library" ON)
++
++option(USE_OLD_SONAME "Use libbz2.so.1.0 for compatibility with old Makefiles" OFF)