Mercurial > molko
changeset 303:48a09c9d3d00
core: make zstd optional
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 24 Jun 2021 20:30:41 +0200 |
parents | f09c166fd4d4 |
children | 3ccf841ca1fe |
files | GNUmakefile config.h.in libmlk-core/core/zfile.c |
diffstat | 3 files changed, 33 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile Thu Jun 24 20:22:47 2021 +0200 +++ b/GNUmakefile Thu Jun 24 20:30:41 2021 +0200 @@ -30,6 +30,7 @@ # Compile time options. NLS= 1 COMPRESS= 1 +ZSTD= 1 LIBMLK_SQLITE= extern/libsqlite/libmlk-sqlite.a LIBMLK_SQLITE_SRCS= extern/libsqlite/sqlite3.c @@ -207,8 +208,10 @@ JANSSON_INCS:= $(shell pkg-config --cflags jansson) JANSSON_LIBS:= $(shell pkg-config --libs jansson) +ifeq (${ZSTD},1) ZSTD_INCS:= $(shell pkg-config --cflags libzstd) ZSTD_LIBS:= $(shell pkg-config --libs libzstd) +endif INCS= -I. \ -Iextern/libsqlite \ @@ -231,6 +234,13 @@ SED.nls= /@define WITH_NLS@/d endif +ifeq (${ZSTD},1) +LIBS+= -lintl +SED.zstd= s/@define WITH_ZSTD@/\#define MOLKO_WITH_ZSTD/ +else +SED.zstd= /@define WITH_ZSTD@/d +endif + # Can't use standard input otherwise frame content size isn't available. ifeq (${COMPRESS},1) TILESET.cmd= ${MLK_TILESET} < $< > $@.tmp && zstd -17 $@.tmp --rm -fqo $@ @@ -247,7 +257,8 @@ config.h: config.h.in @echo "SED $<" - @sed -e "${SED.nls}" < $< > $@ + @sed -e "${SED.nls}" \ + -e "${SED.zstd}" < $< > $@ .c.o: @echo "CC $<"
--- a/config.h.in Thu Jun 24 20:22:47 2021 +0200 +++ b/config.h.in Thu Jun 24 20:30:41 2021 +0200 @@ -1,1 +1,2 @@ @define WITH_NLS@ +@define WITH_ZSTD@
--- a/libmlk-core/core/zfile.c Thu Jun 24 20:22:47 2021 +0200 +++ b/libmlk-core/core/zfile.c Thu Jun 24 20:30:41 2021 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" + #include <sys/stat.h> #include <assert.h> #include <errno.h> @@ -25,7 +27,15 @@ #include <string.h> #include <unistd.h> -#include <zstd.h> +/* + * If not enabled, we still need to check if a file is in zstandard so we use + * the magic number defined in the zstd.h file or copy it if zstd is disabled. + */ +#if defined(MOLKO_WITH_ZSTD) +# include <zstd.h> +#else +# define ZSTD_MAGICNUMBER 0xFD2FB528 +#endif #include "zfile.h" @@ -47,6 +57,7 @@ static int decompress(int fd, struct zfile *zf) { +#if defined(MOLKO_WITH_ZSTD) char *in = NULL; unsigned long long datasz; struct stat st; @@ -89,6 +100,14 @@ free(in); return -1; +#else + (void)fd; + (void)zf; + + errno = ENOTSUP; + + return -1; +#endif } static int