mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-08-04 02:06:31 -04:00
Build-related updates
This commit is contained in:
parent
0698e895a1
commit
275d3d2b95
28
Makefile
28
Makefile
@ -6,8 +6,8 @@ BUILD_STATIC_LIBRARY := yes
|
|||||||
# Build the shared library libdeflate.so?
|
# Build the shared library libdeflate.so?
|
||||||
BUILD_SHARED_LIBRARY := no
|
BUILD_SHARED_LIBRARY := no
|
||||||
|
|
||||||
# Build the benchmark program. Currently Linux only; requires linking to zlib
|
# Build the benchmark program? Note that to allow comparisons, the benchmark
|
||||||
# for comparison purposes.
|
# program will be linked with both zlib and libdeflate.
|
||||||
BUILD_BENCHMARK_PROGRAM := no
|
BUILD_BENCHMARK_PROGRAM := no
|
||||||
|
|
||||||
# Will compression be supported?
|
# Will compression be supported?
|
||||||
@ -29,12 +29,30 @@ SUPPORT_NEAR_OPTIMAL_PARSING := yes
|
|||||||
# This is faster but ***insecure***! Default to secure.
|
# This is faster but ***insecure***! Default to secure.
|
||||||
UNSAFE_DECOMPRESSION := no
|
UNSAFE_DECOMPRESSION := no
|
||||||
|
|
||||||
|
# The compiler and archiver
|
||||||
|
CC := gcc
|
||||||
|
AR := ar
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
CC = gcc
|
# Always compile with optimizations enabled!
|
||||||
AR = ar
|
# 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)
|
ifeq ($(SUPPORT_NEAR_OPTIMAL_PARSING),yes)
|
||||||
override CFLAGS += -DSUPPORT_NEAR_OPTIMAL_PARSING=1
|
override CFLAGS += -DSUPPORT_NEAR_OPTIMAL_PARSING=1
|
||||||
|
34
README.md
34
README.md
@ -21,10 +21,18 @@ on it, and anyone is free to use it for any reason.
|
|||||||
Building
|
Building
|
||||||
========
|
========
|
||||||
|
|
||||||
The build system is currently very simple. Simply run 'make'. There are
|
Currently, the build system is very bare-bones. On a UNIX-like system, just run
|
||||||
various options; see the Makefile for details. The options can be set on the
|
`make`. You need GNU Make and either GCC or Clang.
|
||||||
command line with 'make'. For example, you could run 'make
|
|
||||||
SUPPORT_COMPRESSION=no' to build a decompression-only library.
|
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
|
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
|
include extra information such as the original filename. Generally, you should
|
||||||
choose a format as follows:
|
choose a format as follows:
|
||||||
|
|
||||||
- If you are compressing whole files with no subdivisions, similar to the
|
- If you are compressing whole files with no subdivisions, similar to the gzip
|
||||||
gzip program, you probably should use the gzip format.
|
program, you probably should use the gzip format.
|
||||||
- Otherwise, if you don't need the features of the gzip header and footer
|
- Otherwise, if you don't need the features of the gzip header and footer but do
|
||||||
but do still want a checksum for corruption detection, you probably should
|
still want a checksum for corruption detection, you probably should use the
|
||||||
use the zlib format.
|
zlib format.
|
||||||
- Otherwise, you probably should use raw DEFLATE. This is ideal if you
|
- Otherwise, you probably should use raw DEFLATE. This is ideal if you don't
|
||||||
don't need checksums, e.g. because they're simply not needed for your use
|
need checksums, e.g. because they're simply not needed for your use case or
|
||||||
case or because you already compute your own checksums that are stored
|
because you already compute your own checksums that are stored separately from
|
||||||
separately from the compressed stream.
|
the compressed stream.
|
||||||
|
|
||||||
Note that gzip and zlib streams can be distinguished from each other based on
|
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.
|
their starting bytes, but this is not necessarily true of raw DEFLATE streams.
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define _FILE_OFFSET_BITS 64
|
#define _FILE_OFFSET_BITS 64
|
||||||
#define _GNU_SOURCE
|
#undef _ANSI_SOURCE
|
||||||
|
#define _POSIX_C_SOURCE 199309L
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -19,6 +20,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -278,6 +280,10 @@ do_benchmark(int fd, char *ubuf1, char *ubuf2,
|
|||||||
uint64_t compress_time_total = 0;
|
uint64_t compress_time_total = 0;
|
||||||
uint64_t decompress_time_total = 0;
|
uint64_t decompress_time_total = 0;
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
_setmode(fd, O_BINARY);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char *p = ubuf1;
|
char *p = ubuf1;
|
||||||
ssize_t bytes_read;
|
ssize_t bytes_read;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user