From d68fc6394fd76b19177534fac293d4ce21ea89cf Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Tue, 1 Feb 2022 17:27:37 -0500 Subject: [mod_deflate] --with-libdeflate to use libdeflate configure --with-libdeflate option to use libdeflate (must also configure --enable-mmap for mod_deflate to use libdeflate on input files larger than 64kB; libdeflate not used on files <= 64kB) --- SConstruct | 10 ++++++++++ configure.ac | 30 ++++++++++++++++++++++++++++++ meson_options.txt | 5 +++++ src/CMakeLists.txt | 14 +++++++++++++- src/Makefile.am | 4 ++-- src/SConscript | 2 +- src/config.h.cmake | 3 +++ src/meson.build | 12 +++++++++++- 8 files changed, 75 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index c837de1e..c6ab650b 100644 --- a/SConstruct +++ b/SConstruct @@ -244,6 +244,7 @@ vars.AddVariables( BoolVariable('with_brotli', 'enable brotli compression', 'no'), PackageVariable('with_dbi', 'enable dbi support', 'no'), BoolVariable('with_fam', 'enable FAM/gamin support', 'no'), + BoolVariable('with_libdeflate', 'enable libdeflate compression', 'no'), BoolVariable('with_maxminddb', 'enable MaxMind GeoIP2 support', 'no'), BoolVariable('with_krb5', 'enable krb5 auth support', 'no'), BoolVariable('with_ldap', 'enable ldap auth support', 'no'), @@ -332,6 +333,7 @@ if 1: LIBCRYPT = '', LIBCRYPTO = '', LIBDBI = '', + LIBDEFLATE = '', LIBDL = '', LIBGNUTLS = '', LIBGSSAPI_KRB5 = '', @@ -531,6 +533,14 @@ if 1: ) autoconf.haveFunc('FAMNoExists') + if env['with_libdeflate']: + if not autoconf.CheckLibWithHeader('deflate', 'libdeflate.h', 'C'): + fail("Couldn't find libdeflate") + autoconf.env.Append( + CPPFLAGS = [ '-DHAVE_LIBDEFLATE' ], + LIBDEFLATE = 'libdeflate', + ) + if env['with_maxminddb']: if not autoconf.CheckLibWithHeader('maxminddb', 'maxminddb.h', 'C'): fail("Couldn't find maxminddb") diff --git a/configure.ac b/configure.ac index 414227d5..dfa924a8 100644 --- a/configure.ac +++ b/configure.ac @@ -1085,6 +1085,36 @@ if test "$WITH_BROTLI" != no; then AC_SUBST([BROTLI_LIBS]) fi +dnl libdeflate +AC_MSG_NOTICE([----------------------------------------]) +AC_MSG_CHECKING([for libdeflate support]) +AC_ARG_WITH([libdeflate], + [AS_HELP_STRING([--with-libdeflate], + [Enable libdeflate support for mod_deflate] + )], + [WITH_LIBDEFLATE=$withval], + [WITH_LIBDEFLATE=no] +) +AC_MSG_RESULT([$WITH_LIBDEFLATE]) + +if test "$WITH_LIBDEFLATE" != no; then + if test "$WITH_LIBDEFLATE" != yes; then + DEFLATE_LIBS="-L$WITH_LIBDEFLATE -ldeflate" + CPPFLAGS="$CPPFLAGS -I$WITH_LIBDEFLATE" + else + AC_CHECK_HEADERS([libdeflate.h], [], + [AC_MSG_ERROR([libdeflate header not found, install them or build without --with-libdeflate])] + ) + AC_CHECK_LIB([deflate], [libdeflate_alloc_compressor], + [DEFLATE_LIBS=-ldeflate], + [AC_MSG_ERROR([libdeflate library not found, install it or build without --with-libdeflate])] + ) + fi + + AC_DEFINE([HAVE_LIBDEFLATE], [1], [libdeflate]) + AC_SUBST([DEFLATE_LIBS]) +fi + dnl Check for fam/gamin AC_MSG_NOTICE([----------------------------------------]) AC_MSG_CHECKING([for FAM]) diff --git a/meson_options.txt b/meson_options.txt index 320a6df9..bced4efe 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -13,6 +13,11 @@ option('with_dbi', value: false, description: 'with dbi-support for mod_auth mod_vhostdb_dbi [default: off]', ) +option('with_libdeflate', + type: 'boolean', + value: false, + description: 'with libdeflate-support for mod_deflate [default: off]', +) option('with_fam', type: 'boolean', value: false, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9480261f..c9e874b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ option(WITH_PAM "with PAM-support for mod_auth [default: off]") option(WITH_LUA "with lua 5.1 for mod_magnet [default: off]") # option(WITH_VALGRIND "with internal support for valgrind [default: off]") option(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]") +option(WITH_LIBDEFLATE "with libdeflate-support for mod_deflate [default: off]") option(WITH_LIBEV "libev support for fdevent handlers [default: off]") option(WITH_LIBUNWIND "with libunwind to print backtraces in asserts [default: off]") option(WITH_MAXMINDDB "with MaxMind GeoIP2-support mod_maxminddb [default: off]") @@ -774,6 +775,14 @@ else() unset(HAVE_LIBLBER) endif() +if(WITH_LIBDEFLATE) + check_include_files(libdeflate.h HAVE_LIBDEFLATE_H) + check_library_exists(deflate libdeflate_alloc_compressor "" HAVE_LIBDEFLATE) +else() + unset(HAVE_LIBDEFLATE_H) + unset(HAVE_LIBDEFLATE) +endif() + if(WITH_PAM) check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H) check_library_exists(pam pam_start "" HAVE_PAM) @@ -1085,7 +1094,7 @@ if(WITH_SASL) target_link_libraries(mod_authn_sasl ${L_MOD_AUTHN_SASL}) endif() -if(HAVE_ZLIB_H OR HAVE_ZSTD_H OR HAVE_BZLIB_H OR HAVE_BROTLI) +if(HAVE_ZLIB_H OR HAVE_ZSTD_H OR HAVE_BZLIB_H OR HAVE_BROTLI OR HAVE_LIBDEFLATE) if(HAVE_ZLIB_H) set(L_MOD_DEFLATE ${L_MOD_DEFLATE} ${ZLIB_LIBRARY}) endif() @@ -1098,6 +1107,9 @@ if(HAVE_ZLIB_H OR HAVE_ZSTD_H OR HAVE_BZLIB_H OR HAVE_BROTLI) if(HAVE_BROTLI) set(L_MOD_DEFLATE ${L_MOD_DEFLATE} brotlienc) endif() + if(HAVE_LIBDEFLATE) + set(L_MOD_DEFLATE ${L_MOD_DEFLATE} deflate) + endif() target_link_libraries(mod_deflate ${L_MOD_DEFLATE}) endif() diff --git a/src/Makefile.am b/src/Makefile.am index 487c1b9f..dfced5b4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -277,7 +277,7 @@ mod_access_la_LIBADD = $(common_libadd) lib_LTLIBRARIES += mod_deflate.la mod_deflate_la_SOURCES = mod_deflate.c mod_deflate_la_LDFLAGS = $(BROTLI_CFLAGS) $(common_module_ldflags) -mod_deflate_la_LIBADD = $(Z_LIB) $(ZSTD_LIB) $(BZ_LIB) $(BROTLI_LIBS) $(common_libadd) +mod_deflate_la_LIBADD = $(Z_LIB) $(ZSTD_LIB) $(BZ_LIB) $(BROTLI_LIBS) $(DEFLATE_LIBS) $(common_libadd) lib_LTLIBRARIES += mod_auth.la mod_auth_la_SOURCES = mod_auth.c @@ -477,7 +477,7 @@ lighttpd_LDADD = \ $(common_libadd) \ $(CRYPT_LIB) $(CRYPTO_LIB) $(XXHASH_LIBS) \ $(XML_LIBS) $(SQLITE_LIBS) $(UUID_LIBS) $(ELFTC_LIB) \ - $(PCRE_LIB) $(Z_LIB) $(ZSTD_LIB) $(BZ_LIB) $(BROTLI_LIBS) \ + $(PCRE_LIB) $(Z_LIB) $(ZSTD_LIB) $(BZ_LIB) $(BROTLI_LIBS) $(DEFLATE_LIBS) \ $(DL_LIB) $(SENDFILE_LIB) $(ATTR_LIB) \ $(FAM_LIBS) $(LIBEV_LIBS) $(LIBUNWIND_LIBS) lighttpd_LDFLAGS = -export-dynamic diff --git a/src/SConscript b/src/SConscript index 5480bb25..9f3a8fc7 100644 --- a/src/SConscript +++ b/src/SConscript @@ -101,7 +101,7 @@ modules = { 'mod_auth' : { 'src' : [ 'mod_auth.c', 'mod_auth_api.c' ], 'lib' : [ env['LIBCRYPTO'] ] }, 'mod_authn_file' : { 'src' : [ 'mod_authn_file.c' ], 'lib' : [ env['LIBCRYPT'], env['LIBCRYPTO'] ] }, 'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] }, - 'mod_deflate' : { 'src' : [ 'mod_deflate.c' ], 'lib' : [ env['LIBZ'], env['LIBZSTD'], env['LIBBZ2'], env['LIBBROTLI'], 'm' ] }, + 'mod_deflate' : { 'src' : [ 'mod_deflate.c' ], 'lib' : [ env['LIBZ'], env['LIBZSTD'], env['LIBBZ2'], env['LIBBROTLI'], env['LIBDEFLATE'], 'm' ] }, 'mod_dirlisting' : { 'src' : [ 'mod_dirlisting.c' ] }, 'mod_evasive' : { 'src' : [ 'mod_evasive.c' ] }, 'mod_evhost' : { 'src' : [ 'mod_evhost.c' ] }, diff --git a/src/config.h.cmake b/src/config.h.cmake index fe0a7ce9..a7c81ef7 100644 --- a/src/config.h.cmake +++ b/src/config.h.cmake @@ -100,6 +100,9 @@ #cmakedefine HAVE_ZSTD #cmakedefine HAVE_ZSTD_H +/* libdeflate */ +#cmakedefine HAVE_LIBDEFLATE + /* FAM */ #cmakedefine HAVE_FAM_H #cmakedefine HAVE_FAMNOEXISTS diff --git a/src/meson.build b/src/meson.build index b192e6f2..f5817cae 100644 --- a/src/meson.build +++ b/src/meson.build @@ -307,6 +307,16 @@ if get_option('with_fam') and not(conf_data.get('HAVE_SYS_INOTIFY_H')) conf_data.set('HAVE_FAM_H', true) endif +libdeflate = [] +if get_option('with_libdeflate') + libdeflate = [ compiler.find_library('deflate') ] + if compiler.has_function('libdeflate_alloc_compressor', args: defs, dependencies: libdeflate, prefix: '#include ') + conf_data.set('HAVE_LIBDEFLATE', true) + else + error('Couldn\'t find libdeflate header / library') + endif +endif + libmaxminddb = [] if get_option('with_maxminddb') libmaxminddb = [ compiler.find_library('maxminddb') ] @@ -970,7 +980,7 @@ modules = [ [ 'mod_alias', [ 'mod_alias.c' ] ], [ 'mod_auth', [ 'mod_auth.c', 'mod_auth_api.c' ], [ libcrypto ] ], [ 'mod_authn_file', [ 'mod_authn_file.c' ], [ libcrypt, libcrypto ] ], - [ 'mod_deflate', [ 'mod_deflate.c' ], libbz2 + libz + libzstd + libbrotli ], + [ 'mod_deflate', [ 'mod_deflate.c' ], libbz2 + libz + libzstd + libbrotli + libdeflate ], [ 'mod_dirlisting', [ 'mod_dirlisting.c' ] ], [ 'mod_evasive', [ 'mod_evasive.c' ] ], [ 'mod_evhost', [ 'mod_evhost.c' ] ], -- cgit v1.2.1