// Then from the command line
parse_real(args, argc, argv);
+ // If encoder or decoder support was omitted at build time,
+ // show an error now so that the rest of the code can rely on
+ // that whatever is in opt_mode is also supported.
+#ifndef HAVE_ENCODERS
+ if (opt_mode == MODE_COMPRESS)
+ message_fatal(_("Compression support was disabled "
+ "at build time"));
+#endif
+#ifndef HAVE_DECODERS
+ // Even MODE_LIST cannot work without decoder support so MODE_COMPRESS
+ // is the only valid choice.
+ if (opt_mode != MODE_COMPRESS)
+ message_fatal(_("Decompression support was disabled "
+ "at build time"));
+#endif
+
// Never remove the source file when the destination is not on disk.
// In test mode the data is written nowhere, but setting opt_stdout
// will make the rest of the code behave well.
/// This becomes false if the --check=CHECK option is used.
static bool check_default = true;
-#ifdef MYTHREAD_ENABLED
+#if defined(HAVE_ENCODERS) && defined(MYTHREAD_ENABLED)
static lzma_mt mt_options = {
.flags = 0,
.timeout = 300,
// Get the memory usage. Note that if --format=raw was used,
// we can be decompressing.
const uint64_t memory_limit = hardware_memlimit_get(opt_mode);
- uint64_t memory_usage;
+ uint64_t memory_usage = UINT64_MAX;
if (opt_mode == MODE_COMPRESS) {
-#ifdef MYTHREAD_ENABLED
+#ifdef HAVE_ENCODERS
+# ifdef MYTHREAD_ENABLED
if (opt_format == FORMAT_XZ && hardware_threads_get() > 1) {
mt_options.threads = hardware_threads_get();
mt_options.block_size = opt_block_size;
" threads."),
mt_options.threads);
} else
-#endif
+# endif
{
memory_usage = lzma_raw_encoder_memusage(filters);
}
+#endif
} else {
+#ifdef HAVE_DECODERS
memory_usage = lzma_raw_decoder_memusage(filters);
+#endif
}
if (memory_usage == UINT64_MAX)
// Print memory usage info before possible dictionary
// size auto-adjusting.
+ //
+ // NOTE: If only encoder support was built, we cannot show the
+ // what the decoder memory usage will be.
message_mem_needed(V_DEBUG, memory_usage);
+#ifdef HAVE_DECODERS
if (opt_mode == MODE_COMPRESS) {
const uint64_t decmem = lzma_raw_decoder_memusage(filters);
if (decmem != UINT64_MAX)
"%s MiB of memory."), uint64_to_str(
round_up_to_mib(decmem), 0));
}
+#endif
if (memory_usage <= memory_limit)
return;
assert(opt_mode == MODE_COMPRESS);
-#ifdef MYTHREAD_ENABLED
+#ifdef HAVE_ENCODERS
+# ifdef MYTHREAD_ENABLED
if (opt_format == FORMAT_XZ && mt_options.threads > 1) {
// Try to reduce the number of threads before
// adjusting the compression settings down.
uint64_to_str(round_up_to_mib(
memory_limit), 2));
}
-#endif
+# endif
if (memory_usage <= memory_limit)
return;
uint64_to_str(orig_dict_size >> 20, 0),
uint64_to_str(opt->dict_size >> 20, 1),
uint64_to_str(round_up_to_mib(memory_limit), 2));
+#endif
return;
}
+#ifdef HAVE_DECODERS
/// Return true if the data in in_buf seems to be in the .xz format.
static bool
is_format_xz(void)
return true;
}
+#endif
/// Detect the input file type (for now, this done only when decompressing),
lzma_ret ret = LZMA_PROG_ERROR;
if (opt_mode == MODE_COMPRESS) {
+#ifdef HAVE_ENCODERS
switch (opt_format) {
case FORMAT_AUTO:
// args.c ensures this.
break;
case FORMAT_XZ:
-#ifdef MYTHREAD_ENABLED
+# ifdef MYTHREAD_ENABLED
if (hardware_threads_get() > 1)
ret = lzma_stream_encoder_mt(
&strm, &mt_options);
else
-#endif
+# endif
ret = lzma_stream_encoder(
&strm, filters, check);
break;
ret = lzma_raw_encoder(&strm, filters);
break;
}
+#endif
} else {
+#ifdef HAVE_DECODERS
uint32_t flags = 0;
// It seems silly to warn about unsupported check if the
strm.avail_out = 0;
ret = lzma_code(&strm, LZMA_RUN);
}
+#endif
}
if (ret != LZMA_OK) {
// coder_run() handles compression, decompression, and testing.
// list_file() is for --list.
- void (*run)(const char *filename) = opt_mode == MODE_LIST
- ? &list_file : &coder_run;
+ void (*run)(const char *filename) = &coder_run;
+#ifdef HAVE_DECODERS
+ if (opt_mode == MODE_LIST)
+ run = &list_file;
+#endif
// Process the files given on the command line. Note that if no names
// were given, args_parse() gave us a fake "-" filename.
(void)fclose(args.files_file);
}
+#ifdef HAVE_DECODERS
// All files have now been handled. If in --list mode, display
// the totals before exiting. We don't have signal handlers
// enabled in --list mode, so we don't need to check user_abort.
assert(!user_abort);
list_totals();
}
+#endif
#ifndef NDEBUG
coder_free();