diff options
-rw-r--r-- | configure.ac | 173 | ||||
-rw-r--r-- | include/compress.h | 2 | ||||
-rw-r--r-- | lib/comp/compressor.c | 19 | ||||
-rw-r--r-- | mkfs/options.c | 5 |
4 files changed, 110 insertions, 89 deletions
diff --git a/configure.ac b/configure.ac index 4971e11..84a94f4 100644 --- a/configure.ac +++ b/configure.ac @@ -42,118 +42,117 @@ AC_SUBST([WARN_CFLAGS]) ##### config options ##### AC_ARG_WITH([gzip], - [AS_HELP_STRING([--without-gzip], - [Build without gzip compression support])], - [case "${withval}" in - yes) AM_CONDITIONAL([WITH_GZIP], [true]) ;; - no) AM_CONDITIONAL([WITH_GZIP], [false]) ;; - *) AC_MSG_ERROR([bad value ${withval} for --without-gzip]) ;; - esac], - [AM_CONDITIONAL([WITH_GZIP], [true])]) + [AS_HELP_STRING([--with-gzip], [Build with gzip compression support])], + [want_gzip="${withval}"], [want_gzip="maybe"]) AC_ARG_WITH([xz], - [AS_HELP_STRING([--without-xz], - [Build without xz compression support])], - [case "${withval}" in - yes) AM_CONDITIONAL([WITH_XZ], [true]) ;; - no) AM_CONDITIONAL([WITH_XZ], [false]) ;; - *) AC_MSG_ERROR([bad value ${withval} for --without-xz]) ;; - esac], - [AM_CONDITIONAL([WITH_XZ], [true])]) + [AS_HELP_STRING([--with-xz], [Build with xz compression support])], + [want_xz="${withval}"], [want_xz="maybe"]) AC_ARG_WITH([lzo], - [AS_HELP_STRING([--without-lzo], - [Build without lzo compression support])], - [case "${withval}" in - yes) AM_CONDITIONAL([WITH_LZO], [true]) ;; - no) AM_CONDITIONAL([WITH_LZO], [false]) ;; - *) AC_MSG_ERROR([bad value ${withval} for --without-lzo]) ;; - esac], - [AM_CONDITIONAL([WITH_LZO], [true])]) + [AS_HELP_STRING([--with-lzo], [Build with lzo compression support])], + [want_lzo="${withval}"], [want_lzo="maybe"]) AC_ARG_WITH([lz4], - [AS_HELP_STRING([--without-lz4], - [Build without lz4 compression support])], - [case "${withval}" in - yes) AM_CONDITIONAL([WITH_LZ4], [true]) ;; - no) AM_CONDITIONAL([WITH_LZ4], [false]) ;; - *) AC_MSG_ERROR([bad value ${withval} for --without-lz4]) ;; - esac], - [AM_CONDITIONAL([WITH_LZ4], [true])]) + [AS_HELP_STRING([--without-lz4], [Build with lz4 compression support])], + [want_lz4="${withval}"], [want_lz4="maybe"]) AC_ARG_WITH([zstd], - [AS_HELP_STRING([--without-zstd], - [Build without zstd compression support])], - [case "${withval}" in - yes) AM_CONDITIONAL([WITH_ZSTD], [true]) ;; - no) AM_CONDITIONAL([WITH_ZSTD], [false]) ;; - *) AC_MSG_ERROR([bad value ${withval} for --without-zstd]) ;; - esac], - [AM_CONDITIONAL([WITH_ZSTD], [true])]) + [AS_HELP_STRING([--with-zstd], [Build with zstd compression support])], + [want_zstd="${withval}"], [want_zstd="maybe"]) AC_ARG_WITH([selinux], - [AS_HELP_STRING([--without-selinux], - [Build without SELinux label file support])], - [case "${withval}" in - yes) AM_CONDITIONAL([WITH_SELINUX], [true]) ;; - no) AM_CONDITIONAL([WITH_SELINUX], [false]) ;; - *) AC_MSG_ERROR([bad value ${withval} for --without-selinux]) ;; - esac], - [AM_CONDITIONAL([WITH_SELINUX], [true])]) + [AS_HELP_STRING([--with-selinux], + [Build with SELinux label file support])], + [want_selinux="${withval}"], [want_selinux="maybe"]) ##### search for dependencies ##### -need_zlib="no" -need_xz="no" -need_lzo="no" -need_lz4="no" -need_zstd="no" -need_selinux="no" - -AM_COND_IF([WITH_GZIP], [need_zlib="yes"]) -AM_COND_IF([WITH_XZ], [need_xz="yes"]) -AM_COND_IF([WITH_LZO], [need_lzo="yes"]) -AM_COND_IF([WITH_LZ4], [need_lz4="yes"]) -AM_COND_IF([WITH_ZSTD], [need_zstd="yes"]) -AM_COND_IF([WITH_SELINUX], [need_selinux="yes"]) - -if test "x$need_zlib" = "xyes"; then - PKG_CHECK_MODULES(ZLIB, [zlib], [], [AC_MSG_ERROR([cannot find zlib])]) -fi +PKG_CHECK_MODULES(ZLIB, [zlib], + [AM_CONDITIONAL([WITH_GZIP], [true])], + [AM_CONDITIONAL([WITH_GZIP], [false])]) -if test "x$need_xz" = "xyes"; then - PKG_CHECK_MODULES(XZ, [liblzma >= 5.0.0], [], - [AC_MSG_ERROR([cannot find xz sdk])]) -fi +PKG_CHECK_MODULES(XZ, [liblzma >= 5.0.0], + [AM_CONDITIONAL([WITH_XZ], [true])], + [AM_CONDITIONAL([WITH_XZ], [false])]) + +PKG_CHECK_MODULES(LZ4, [liblz4], + [AM_CONDITIONAL([WITH_LZ4], [true])], + [AM_CONDITIONAL([WITH_LZ4], [false])]) -if test "x$need_lzo" = "xyes"; then +PKG_CHECK_MODULES(ZSTD, [libzstd], + [AM_CONDITIONAL([WITH_ZSTD], [true])], + [AM_CONDITIONAL([WITH_ZSTD], [false])]) + +AM_CONDITIONAL([WITH_LZO], [false]) + +if test "x$want_lzo" != "xno"; then AC_ARG_VAR([LZO_CFLAGS], [C compiler flags for lzo]) AC_ARG_VAR([LZO_LIBS], [linker flags for lzo]) + AM_CONDITIONAL([WITH_LZO], [true]) + AC_CHECK_LIB([lzo2], [lzo1x_1_15_compress], [LZO_LIBS="-llzo2"], - [AC_CHECK_LIB([lzo],[lzo1x_1_15_compress],[LZO_LIBS="-llzo"], - [AC_MSG_ERROR([cannot find lzo library])] - )] - ) + [AC_CHECK_LIB([lzo],[lzo1x_1_15_compress], + [ZO_LIBS="-llzo"], + [AM_CONDITIONAL([WITH_LZO], [false])] + )] + ) fi -if test "x$need_lz4" = "xyes"; then - PKG_CHECK_MODULES(LZ4, [liblz4], [], - [AC_MSG_ERROR([cannot lz4 library])]) -fi +AM_CONDITIONAL([WITH_SELINUX], [false]) -if test "x$need_zstd" = "xyes"; then - PKG_CHECK_MODULES(ZSTD, [libzstd], [], - [AC_MSG_ERROR([cannot zstd library])]) -fi +if test "x$want_selinux" != "xno"; then + AM_CONDITIONAL([WITH_SELINUX], [true]) -if test "x$need_selinux" = "xyes"; then PKG_CHECK_MODULES(LIBSELINUX, [libselinux], [], - [AC_MSG_ERROR([cannot find libselinux])]) - + [AM_CONDITIONAL([WITH_SELINUX], [false])]) AC_CHECK_HEADERS([selinux/selinux.h], [], - [AC_MSG_ERROR([cannot find SELinux system headers])]) + [AM_CONDITIONAL([WITH_SELINUX], [false])]) AC_CHECK_HEADERS([selinux/label.h], [], - [AC_MSG_ERROR([cannot find SELinux system headers])]) + [AM_CONDITIONAL([WITH_SELINUX], [false])]) +fi + +case "$want_gzip" in +yes) AM_COND_IF([WITH_GZIP], [], [AC_MSG_ERROR([cannot find zlib])]) ;; +no) AM_CONDITIONAL([WITH_GZIP], [false]) ;; +esac + +case "$want_xz" in +yes) AM_COND_IF([WITH_XZ], [], [AC_MSG_ERROR([cannot find xz sdk])]) ;; +no) AM_CONDITIONAL([WITH_XZ], [false]) ;; +esac + +case "$want_lzo" in +yes) AM_COND_IF([WITH_LZO], [], [AC_MSG_ERROR([cannot find lzo library])]) ;; +no) AM_CONDITIONAL([WITH_LZO], [false]) ;; +esac + +case "$want_lz4" in +yes) AM_COND_IF([WITH_LZ4], [], [AC_MSG_ERROR([cannot find lz4 library])]) ;; +no) AM_CONDITIONAL([WITH_LZ4], [false]) ;; +esac + +case "$want_zstd" in +yes) AM_COND_IF([WITH_ZSTD], [], [AC_MSG_ERROR([cannot find zstd library])]) ;; +no) AM_CONDITIONAL([WITH_ZSTD], [false]) ;; +esac + +case "$want_selinux" in +yes) AM_COND_IF([WITH_SELINUX], [], [AC_MSG_ERROR([cannot find selinux])]) ;; +no) AM_CONDITIONAL([WITH_SELINUX], [false]) ;; +esac + +##### sanity check ##### + +have_compressor="no" +AM_COND_IF([WITH_GZIP], [have_compressor="yes"]) +AM_COND_IF([WITH_XZ], [have_compressor="yes"]) +AM_COND_IF([WITH_LZO], [have_compressor="yes"]) +AM_COND_IF([WITH_LZ4], [have_compressor="yes"]) +AM_COND_IF([WITH_ZSTD], [have_compressor="yes"]) + +if test "x$have_compressor" != "xyes"; then + AC_MSG_ERROR([no compressor available. At lest one is required]) fi ##### generate output ##### diff --git a/include/compress.h b/include/compress.h index 5f13bc6..c9a4e08 100644 --- a/include/compress.h +++ b/include/compress.h @@ -49,4 +49,6 @@ compressor_t *compressor_create(E_SQFS_COMPRESSOR id, bool compress, void compressor_print_help(E_SQFS_COMPRESSOR id); +E_SQFS_COMPRESSOR compressor_get_default(void); + #endif /* COMPRESS_H */ diff --git a/lib/comp/compressor.c b/lib/comp/compressor.c index 44b3643..6dff416 100644 --- a/lib/comp/compressor.c +++ b/lib/comp/compressor.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ #include <string.h> +#include <stdlib.h> #include <stdio.h> #include "internal.h" @@ -127,3 +128,21 @@ void compressor_print_help(E_SQFS_COMPRESSOR id) helpfuns[id](); } + +E_SQFS_COMPRESSOR compressor_get_default(void) +{ +#if defined(WITH_XZ) + return SQFS_COMP_XZ; +#elif defined(WITH_ZSTD) + return SQFS_COMP_ZSTD; +#elif defined(WITH_GZIP) + return SQFS_COMP_GZIP; +#elif defined(WITH_LZO) + return SQFS_COMP_LZO; +#elif defined(WITH_LZ4) + return SQFS_COMP_LZ4; +#else + fputs("No compressor implementation available!\n", stderr); + exit(EXIT_FAILURE); +#endif +} diff --git a/mkfs/options.c b/mkfs/options.c index e1223ad..69e66f4 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -61,7 +61,7 @@ static const char *help_string = "\n" " --compressor, -c <name> Select the compressor to use.\n" " A list of available compressors is below.\n" -" Defaults to 'xz'.\n" +" Defaults to '%s'.\n" " --comp-extra, -X <options> A comma seperated list of extra options for\n" " the selected compressor. Specify 'help' to\n" " get a list of available options.\n" @@ -240,7 +240,7 @@ void process_command_line(options_t *opt, int argc, char **argv) opt->def_mode = 0755; opt->def_mtime = 0; opt->outmode = O_WRONLY | O_CREAT | O_EXCL; - opt->compressor = SQFS_COMP_XZ; + opt->compressor = compressor_get_default(); opt->blksz = SQFS_DEFAULT_BLOCK_SIZE; opt->devblksz = SQFS_DEVBLK_SIZE; opt->quiet = false; @@ -308,6 +308,7 @@ void process_command_line(options_t *opt, int argc, char **argv) #endif case 'h': printf(help_string, __progname, + compressors[compressor_get_default()], SQFS_DEFAULT_BLOCK_SIZE, SQFS_DEVBLK_SIZE); fputs("Available compressors:\n", stdout); |