Build-related updates

This commit is contained in:
Eric Biggers 2015-12-03 22:44:19 -06:00
parent 0698e895a1
commit 275d3d2b95
3 changed files with 51 additions and 19 deletions

View File

@ -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

View File

@ -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.

View File

@ -9,7 +9,8 @@
*/
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#undef _ANSI_SOURCE
#define _POSIX_C_SOURCE 199309L
#include <errno.h>
#include <fcntl.h>
@ -19,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
@ -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;