From 275d3d2b95d07c1a8eb9e3c04733a1e95f489b18 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 3 Dec 2015 22:44:19 -0600 Subject: [PATCH] Build-related updates --- Makefile | 28 +++++++++++++++++++++++----- README.md | 34 +++++++++++++++++++++------------- tools/benchmark.c | 8 +++++++- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 373716c..dd8ea3c 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ BUILD_STATIC_LIBRARY := yes # Build the shared library libdeflate.so? BUILD_SHARED_LIBRARY := no -# Build the benchmark program. Currently Linux only; requires linking to zlib -# for comparison purposes. +# Build the benchmark program? Note that to allow comparisons, the benchmark +# program will be linked with both zlib and libdeflate. BUILD_BENCHMARK_PROGRAM := no # Will compression be supported? @@ -29,12 +29,30 @@ SUPPORT_NEAR_OPTIMAL_PARSING := yes # This is faster but ***insecure***! Default to secure. UNSAFE_DECOMPRESSION := no +# The compiler and archiver +CC := gcc +AR := ar + ############################################################################## -CC = gcc -AR = ar +# Always compile with optimizations enabled! +# But don't change it to -O3 and expect it to be better. +override CFLAGS += -O2 -override CFLAGS += -O2 -I. -std=c99 -fvisibility=hidden +# Use a sane default symbol visibility. +override CFLAGS += -fvisibility=hidden + +# Set the C version. We currently require at least C99. Also, we actually need +# -std=gnu99 instead of -std=c99 for unnamed structs and unions, which are in +# C11 but not C99. But we can't yet use -std=c11 because we want to support +# older versions of gcc. +override CFLAGS += -std=gnu99 + +# Allow including libdeflate.h. +override CFLAGS += -I. + +# Hide non-standard functions from standard headers (e.g. heapsort() on *BSD). +override CFLAGS += -D_ANSI_SOURCE ifeq ($(SUPPORT_NEAR_OPTIMAL_PARSING),yes) override CFLAGS += -DSUPPORT_NEAR_OPTIMAL_PARSING=1 diff --git a/README.md b/README.md index 48b4338..8cf47c9 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,18 @@ on it, and anyone is free to use it for any reason. Building ======== -The build system is currently very simple. Simply run 'make'. There are -various options; see the Makefile for details. The options can be set on the -command line with 'make'. For example, you could run 'make -SUPPORT_COMPRESSION=no' to build a decompression-only library. +Currently, the build system is very bare-bones. On a UNIX-like system, just run +`make`. You need GNU Make and either GCC or Clang. + +There are various options which can be set on the `make` command line; see the +Makefile for details. As an example, you can run `make SUPPORT_COMPRESSION=no` +to build a decompression-only library. + +There is no `make install` yet; just copy the file(s) you want. + +It's possible to build a Windows binary using MinGW, using a command like this: + + $ make CC=x86_64-w64-mingw32-gcc CFLAGS=-static AR=x86_64-w64-mingw32-ar BUILD_BENCHMARK_PROGRAM=yes API === @@ -57,15 +65,15 @@ wrappers for this stream. Both zlib and gzip include checksums, but gzip can include extra information such as the original filename. Generally, you should choose a format as follows: - - If you are compressing whole files with no subdivisions, similar to the - gzip program, you probably should use the gzip format. - - Otherwise, if you don't need the features of the gzip header and footer - but do still want a checksum for corruption detection, you probably should - use the zlib format. - - Otherwise, you probably should use raw DEFLATE. This is ideal if you - don't need checksums, e.g. because they're simply not needed for your use - case or because you already compute your own checksums that are stored - separately from the compressed stream. +- If you are compressing whole files with no subdivisions, similar to the gzip + program, you probably should use the gzip format. +- Otherwise, if you don't need the features of the gzip header and footer but do + still want a checksum for corruption detection, you probably should use the + zlib format. +- Otherwise, you probably should use raw DEFLATE. This is ideal if you don't + need checksums, e.g. because they're simply not needed for your use case or + because you already compute your own checksums that are stored separately from + the compressed stream. Note that gzip and zlib streams can be distinguished from each other based on their starting bytes, but this is not necessarily true of raw DEFLATE streams. diff --git a/tools/benchmark.c b/tools/benchmark.c index 75e252f..955645e 100644 --- a/tools/benchmark.c +++ b/tools/benchmark.c @@ -9,7 +9,8 @@ */ #define _FILE_OFFSET_BITS 64 -#define _GNU_SOURCE +#undef _ANSI_SOURCE +#define _POSIX_C_SOURCE 199309L #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #include #include @@ -278,6 +280,10 @@ do_benchmark(int fd, char *ubuf1, char *ubuf2, uint64_t compress_time_total = 0; uint64_t decompress_time_total = 0; +#ifdef __WIN32__ + _setmode(fd, O_BINARY); +#endif + for (;;) { char *p = ubuf1; ssize_t bytes_read;