make: fix lz4 mt compilation on linux/posix

now lz4 build defaults to single-thread mode
This commit is contained in:
Yann Collet 2023-12-28 16:25:38 -08:00
parent d3ae8e0e85
commit cbe7211b9c
5 changed files with 37 additions and 9 deletions

View File

@ -62,6 +62,7 @@ lz4-release : lib-release
lz4 lz4-release :
$(MAKE) -C $(PRGDIR) $@
$(LN_SF) $(PRGDIR)/lz4$(EXT) .
echo lz4 build completed
.PHONY: examples
examples: liblz4.a

1
programs/.gitignore vendored
View File

@ -4,6 +4,7 @@ unlz4
lz4cat
lz4c
lz4c32
lz4-nomt
lz4-wlib
datagen
frametest

View File

@ -60,13 +60,25 @@ ifeq ($(TARGET_OS)$(shell $(OS_VERSION)),SunOS5.10)
LDFLAGS += -lrt
endif
FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
ALLFLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
# thread detection
NUM_SYMBOL := \#
NO_THREAD_MSG:= ==> no pthread support: building for single-thread mode only
HAVE_PTHREAD := $(shell printf '$(NUM_SYMBOL)include <pthread.h>\nint main(void) { return 0; }' > have_pthread.c && $(CC) $(ALLFLAGS) -o have_pthread$(EXT) have_pthread.c -pthread 2> $(VOID) && rm have_pthread$(EXT) && echo 1 || echo 0; rm have_pthread.c)
HAVE_THREAD := $(shell [ "$(HAVE_PTHREAD)" -eq "1" -o -n "$(filter Windows%,$(OS))" ] && echo 1 || echo 0)
ifeq ($(HAVE_PTHREAD), 1)
THREAD_MSG := ==> building with multithreading support
THREAD_CPP := -DLZ4IO_MULTITHREAD
THREAD_LD := -pthread
else
THREAD_MSG := $(NO_THREAD_MSG)
endif
LZ4_VERSION=$(LIBVER)
MD2ROFF = ronn
MD2ROFF = ronn
MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)"
.PHONY:default
default: lz4-release
@ -74,7 +86,7 @@ default: lz4-release
$(V)$(VERBOSE).SILENT:
.PHONY:all
all: lz4 lz4c unlz4 lz4cat
all: lz4 lz4-nomt lz4c unlz4 lz4cat
.PHONY:all32
all32: CFLAGS+=-m32
@ -94,10 +106,13 @@ 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) $(ALLFLAGS) $^ -o $@$(EXT)
else
lz4: CPPFLAGS += $(THREAD_CPP)
lz4: LDFLAGS += $(THREAD_LD)
lz4: $(OBJFILES)
$(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS)
echo "$(THREAD_MSG)"
$(CC) $(ALLFLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS)
endif
CLEAN += lz4
@ -105,6 +120,10 @@ CLEAN += lz4
lz4-release: DEBUGFLAGS=
lz4-release: lz4
CLEAN += lz4-nomt
lz4-nomt: $(SRCFILES)
$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
CLEAN += lz4-wlib
lz4-wlib: LIBFILES =
lz4-wlib: SRCFILES+= $(LIBDIR)/xxhash.c # benchmark unit needs XXH64()
@ -112,7 +131,7 @@ lz4-wlib: LDFLAGS += -L $(LIBDIR)
lz4-wlib: LDLIBS = -llz4
lz4-wlib: liblz4 $(OBJFILES)
@echo WARNING: $@ must link to an extended variant of the dynamic library which also exposes unstable symbols
$(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS)
$(CC) $(ALLFLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS)
.PHONY:liblz4
liblz4:
@ -125,7 +144,7 @@ lz4c: lz4
CLEAN += lz4c32
lz4c32: CFLAGS += -m32
lz4c32 : $(SRCFILES)
$(CC) $(FLAGS) $^ -o $@$(EXT)
$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
CLEAN += unlz4
unlz4: lz4

View File

@ -1396,6 +1396,7 @@ LZ4IO_compressFilename_extRess(cRess_t ress,
int compressionLevel,
const LZ4IO_prefs_t* const io_prefs)
{
#if defined(LZ4IO_MULTITHREAD)
/* do NOT employ multi-threading in the following scenarios: */
if ( (io_prefs->contentSizeFlag) /* content size present in frame header*/
|| (io_prefs->blockIndependence == LZ4F_blockLinked) /* blocks are not independent */
@ -1403,6 +1404,12 @@ LZ4IO_compressFilename_extRess(cRess_t ress,
return LZ4IO_compressFilename_extRess_ST(ress, srcFileName, dstFileName, compressionLevel, io_prefs);
return LZ4IO_compressFilename_extRess_MT(ress, srcFileName, dstFileName, compressionLevel, io_prefs);
#else
/* Only single-thread available */
return LZ4IO_compressFilename_extRess_ST(ress, srcFileName, dstFileName, compressionLevel, io_prefs);
#endif
}
int LZ4IO_compressFilename(const char* srcFileName, const char* dstFileName, int compressionLevel, const LZ4IO_prefs_t* prefs)

View File

@ -33,7 +33,7 @@
#endif
#ifdef LZ4IO_NO_MT
#if !defined(LZ4IO_MULTITHREAD)
/* ===================================================== */
/* Backup implementation with no multi-threading support */