lz4c legacy commands are now enabled at runtime based on link/binary name "lz4c"

instead of selected at compilation time depending on a macro.
This design makes it possible to have a single binary which supports both modes.

An advantageous side effect is that when doing `make; make install`
no additional binary is created during `make install`
(it used to create `lz4c`, because `make` would only build `lz4`)
This commit is contained in:
Yann Collet 2017-08-14 16:56:05 -07:00
parent 731cff1208
commit 01cdbfb5fe
3 changed files with 39 additions and 38 deletions

View File

@ -62,7 +62,9 @@ lib lib-release:
@$(MAKE) -C $(LZ4DIR) $@ @$(MAKE) -C $(LZ4DIR) $@
.PHONY: lz4 lz4-release .PHONY: lz4 lz4-release
lz4 lz4-release: lib lz4 : lib
lz4-release : lib-release
lz4 lz4-release :
@$(MAKE) -C $(PRGDIR) $@ @$(MAKE) -C $(PRGDIR) $@
@cp $(PRGDIR)/lz4$(EXT) . @cp $(PRGDIR)/lz4$(EXT) .
@ -91,6 +93,7 @@ clean:
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
HOST_OS = POSIX HOST_OS = POSIX
.PHONY: install uninstall
install uninstall: install uninstall:
@$(MAKE) -C $(LZ4DIR) $@ @$(MAKE) -C $(LZ4DIR) $@
@$(MAKE) -C $(PRGDIR) $@ @$(MAKE) -C $(PRGDIR) $@

View File

@ -82,10 +82,12 @@ lz4-release: DEBUGFLAGS=
lz4-release: lz4 lz4-release: lz4
lz4c32: CFLAGS += -m32 lz4c32: CFLAGS += -m32
lz4c: CPPFLAGS += -DENABLE_LZ4C_LEGACY_OPTIONS lz4c32 : $(SRCFILES)
lz4c lz4c32 : $(SRCFILES)
$(CC) $(FLAGS) $^ -o $@$(EXT) $(CC) $(FLAGS) $^ -o $@$(EXT)
lz4c: lz4
ln -s lz4 lz4c
lz4.1: lz4.1.md lz4.1: lz4.1.md
cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@

View File

@ -30,14 +30,6 @@
The license of this compression CLI program is GPLv2. The license of this compression CLI program is GPLv2.
*/ */
/**************************************
* Tuning parameters
***************************************/
/* ENABLE_LZ4C_LEGACY_OPTIONS :
Control the availability of -c0, -c1 and -hc legacy arguments
Default : Legacy options are disabled */
/* #define ENABLE_LZ4C_LEGACY_OPTIONS */
/**************************** /****************************
* Includes * Includes
@ -62,6 +54,8 @@
#define LZ4_EXTENSION ".lz4" #define LZ4_EXTENSION ".lz4"
#define LZ4CAT "lz4cat" #define LZ4CAT "lz4cat"
#define UNLZ4 "unlz4" #define UNLZ4 "unlz4"
#define LZ4_LEGACY "lz4c"
static int g_lz4c_legacy_commands = 0;
#define KB *(1U<<10) #define KB *(1U<<10)
#define MB *(1U<<20) #define MB *(1U<<20)
@ -154,13 +148,13 @@ static int usage_advanced(const char* exeName)
DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s) \n"); DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s) \n");
DISPLAY( " -B# : cut file into independent blocks of size # bytes [32+] \n"); DISPLAY( " -B# : cut file into independent blocks of size # bytes [32+] \n");
DISPLAY( " or predefined block size [4-7] (default: 7) \n"); DISPLAY( " or predefined block size [4-7] (default: 7) \n");
#if defined(ENABLE_LZ4C_LEGACY_OPTIONS) if (g_lz4c_legacy_commands) {
DISPLAY( "Legacy arguments : \n"); DISPLAY( "Legacy arguments : \n");
DISPLAY( " -c0 : fast compression \n"); DISPLAY( " -c0 : fast compression \n");
DISPLAY( " -c1 : high compression \n"); DISPLAY( " -c1 : high compression \n");
DISPLAY( " -hc : high compression \n"); DISPLAY( " -hc : high compression \n");
DISPLAY( " -y : overwrite output without prompting \n"); DISPLAY( " -y : overwrite output without prompting \n");
#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */ }
EXTENDED_HELP; EXTENDED_HELP;
return 0; return 0;
} }
@ -212,7 +206,7 @@ static int usage_longhelp(const char* exeName)
DISPLAY( "-------------------------------------\n"); DISPLAY( "-------------------------------------\n");
DISPLAY( "3 : compress data stream from 'generator', send result to 'consumer'\n"); DISPLAY( "3 : compress data stream from 'generator', send result to 'consumer'\n");
DISPLAY( " generator | %s | consumer \n", exeName); DISPLAY( " generator | %s | consumer \n", exeName);
#if defined(ENABLE_LZ4C_LEGACY_OPTIONS) if (g_lz4c_legacy_commands) {
DISPLAY( "\n"); DISPLAY( "\n");
DISPLAY( "***** Warning *****\n"); DISPLAY( "***** Warning *****\n");
DISPLAY( "Legacy arguments take precedence. Therefore : \n"); DISPLAY( "Legacy arguments take precedence. Therefore : \n");
@ -222,7 +216,7 @@ static int usage_longhelp(const char* exeName)
DISPLAY( "It is not equivalent to :\n"); DISPLAY( "It is not equivalent to :\n");
DISPLAY( " %s -h -c filename\n", exeName); DISPLAY( " %s -h -c filename\n", exeName);
DISPLAY( "which would display help text and exit\n"); DISPLAY( "which would display help text and exit\n");
#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */ }
return 0; return 0;
} }
@ -314,7 +308,7 @@ int main(int argc, const char** argv)
inFileNames[0] = stdinmark; inFileNames[0] = stdinmark;
LZ4IO_setOverwrite(0); LZ4IO_setOverwrite(0);
/* lz4cat predefined behavior */ /* predefined behaviors, based on binary/link name */
if (exeNameMatch(exeName, LZ4CAT)) { if (exeNameMatch(exeName, LZ4CAT)) {
mode = om_decompress; mode = om_decompress;
LZ4IO_setOverwrite(1); LZ4IO_setOverwrite(1);
@ -325,6 +319,7 @@ int main(int argc, const char** argv)
multiple_inputs=1; multiple_inputs=1;
} }
if (exeNameMatch(exeName, UNLZ4)) { mode = om_decompress; } if (exeNameMatch(exeName, UNLZ4)) { mode = om_decompress; }
if (exeNameMatch(exeName, LZ4_LEGACY)) { g_lz4c_legacy_commands=1; }
/* command switches */ /* command switches */
for(i=1; i<argc; i++) { for(i=1; i<argc; i++) {
@ -370,13 +365,13 @@ int main(int argc, const char** argv)
while (argument[1]!=0) { while (argument[1]!=0) {
argument ++; argument ++;
#if defined(ENABLE_LZ4C_LEGACY_OPTIONS) if (g_lz4c_legacy_commands) {
/* Legacy arguments (-c0, -c1, -hc, -y, -s) */ /* Legacy commands (-c0, -c1, -hc, -y) */
if ((argument[0]=='c') && (argument[1]=='0')) { cLevel=0; argument++; continue; } /* -c0 (fast compression) */ if ((argument[0]=='c') && (argument[1]=='0')) { cLevel=0; argument++; continue; } /* -c0 (fast compression) */
if ((argument[0]=='c') && (argument[1]=='1')) { cLevel=9; argument++; continue; } /* -c1 (high compression) */ if ((argument[0]=='c') && (argument[1]=='1')) { cLevel=9; argument++; continue; } /* -c1 (high compression) */
if ((argument[0]=='h') && (argument[1]=='c')) { cLevel=9; argument++; continue; } /* -hc (high compression) */ if ((argument[0]=='h') && (argument[1]=='c')) { cLevel=9; argument++; continue; } /* -hc (high compression) */
if (*argument=='y') { LZ4IO_setOverwrite(1); continue; } /* -y (answer 'yes' to overwrite permission) */ if (argument[0]=='y') { LZ4IO_setOverwrite(1); continue; } /* -y (answer 'yes' to overwrite permission) */
#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */ }
if ((*argument>='0') && (*argument<='9')) { if ((*argument>='0') && (*argument<='9')) {
cLevel = readU32FromChar(&argument); cLevel = readU32FromChar(&argument);
@ -530,7 +525,8 @@ int main(int argc, const char** argv)
#ifdef _FILE_OFFSET_BITS #ifdef _FILE_OFFSET_BITS
DISPLAYLEVEL(4, "_FILE_OFFSET_BITS defined: %ldL\n", (long) _FILE_OFFSET_BITS); DISPLAYLEVEL(4, "_FILE_OFFSET_BITS defined: %ldL\n", (long) _FILE_OFFSET_BITS);
#endif #endif
if ((mode == om_compress) || (mode == om_bench)) DISPLAYLEVEL(4, "Blocks size : %u KB\n", (U32)(blockSize>>10)); if ((mode == om_compress) || (mode == om_bench))
DISPLAYLEVEL(4, "Blocks size : %u KB\n", (U32)(blockSize>>10));
if (multiple_inputs) { if (multiple_inputs) {
input_filename = inFileNames[0]; input_filename = inFileNames[0];