libdeflate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/libdeflate/extconf.rb +14 -0
- data/ext/libdeflate/libdeflate/.gitignore +19 -0
- data/ext/libdeflate/libdeflate/COPYING +21 -0
- data/ext/libdeflate/libdeflate/Makefile +231 -0
- data/ext/libdeflate/libdeflate/Makefile.msc +64 -0
- data/ext/libdeflate/libdeflate/NEWS +57 -0
- data/ext/libdeflate/libdeflate/README.md +170 -0
- data/ext/libdeflate/libdeflate/common/common_defs.h +351 -0
- data/ext/libdeflate/libdeflate/common/compiler_gcc.h +134 -0
- data/ext/libdeflate/libdeflate/common/compiler_msc.h +95 -0
- data/ext/libdeflate/libdeflate/lib/adler32.c +213 -0
- data/ext/libdeflate/libdeflate/lib/adler32_impl.h +281 -0
- data/ext/libdeflate/libdeflate/lib/aligned_malloc.c +57 -0
- data/ext/libdeflate/libdeflate/lib/aligned_malloc.h +13 -0
- data/ext/libdeflate/libdeflate/lib/bt_matchfinder.h +357 -0
- data/ext/libdeflate/libdeflate/lib/crc32.c +368 -0
- data/ext/libdeflate/libdeflate/lib/crc32_impl.h +286 -0
- data/ext/libdeflate/libdeflate/lib/crc32_table.h +526 -0
- data/ext/libdeflate/libdeflate/lib/decompress_impl.h +404 -0
- data/ext/libdeflate/libdeflate/lib/deflate_compress.c +2817 -0
- data/ext/libdeflate/libdeflate/lib/deflate_compress.h +14 -0
- data/ext/libdeflate/libdeflate/lib/deflate_constants.h +66 -0
- data/ext/libdeflate/libdeflate/lib/deflate_decompress.c +889 -0
- data/ext/libdeflate/libdeflate/lib/gzip_compress.c +95 -0
- data/ext/libdeflate/libdeflate/lib/gzip_constants.h +45 -0
- data/ext/libdeflate/libdeflate/lib/gzip_decompress.c +130 -0
- data/ext/libdeflate/libdeflate/lib/hc_matchfinder.h +405 -0
- data/ext/libdeflate/libdeflate/lib/lib_common.h +35 -0
- data/ext/libdeflate/libdeflate/lib/matchfinder_avx2.h +53 -0
- data/ext/libdeflate/libdeflate/lib/matchfinder_common.h +205 -0
- data/ext/libdeflate/libdeflate/lib/matchfinder_neon.h +61 -0
- data/ext/libdeflate/libdeflate/lib/matchfinder_sse2.h +53 -0
- data/ext/libdeflate/libdeflate/lib/unaligned.h +202 -0
- data/ext/libdeflate/libdeflate/lib/x86_cpu_features.c +169 -0
- data/ext/libdeflate/libdeflate/lib/x86_cpu_features.h +48 -0
- data/ext/libdeflate/libdeflate/lib/zlib_compress.c +87 -0
- data/ext/libdeflate/libdeflate/lib/zlib_constants.h +21 -0
- data/ext/libdeflate/libdeflate/lib/zlib_decompress.c +91 -0
- data/ext/libdeflate/libdeflate/libdeflate.h +274 -0
- data/ext/libdeflate/libdeflate/programs/benchmark.c +558 -0
- data/ext/libdeflate/libdeflate/programs/checksum.c +197 -0
- data/ext/libdeflate/libdeflate/programs/detect.sh +62 -0
- data/ext/libdeflate/libdeflate/programs/gzip.c +603 -0
- data/ext/libdeflate/libdeflate/programs/prog_util.c +530 -0
- data/ext/libdeflate/libdeflate/programs/prog_util.h +162 -0
- data/ext/libdeflate/libdeflate/programs/test_checksums.c +135 -0
- data/ext/libdeflate/libdeflate/programs/tgetopt.c +118 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/Makefile +12 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_compress/fuzz.c +40 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_compress/inputs/0 +0 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_decompress/fuzz.c +28 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_decompress/inputs/0 +3 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/gzip_decompress/fuzz.c +28 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/gzip_decompress/inputs/0 +0 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/prepare_for_fuzz.sh +14 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/zlib_decompress/fuzz.c +28 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/zlib_decompress/inputs/0 +3 -0
- data/ext/libdeflate/libdeflate/tools/android_build.sh +104 -0
- data/ext/libdeflate/libdeflate/tools/checksum_benchmarks.sh +76 -0
- data/ext/libdeflate/libdeflate/tools/exec_tests.sh +30 -0
- data/ext/libdeflate/libdeflate/tools/gen_crc32_multipliers.c +108 -0
- data/ext/libdeflate/libdeflate/tools/gen_crc32_table.c +100 -0
- data/ext/libdeflate/libdeflate/tools/gzip_tests.sh +412 -0
- data/ext/libdeflate/libdeflate/tools/make-windows-releases +21 -0
- data/ext/libdeflate/libdeflate/tools/mips_build.sh +9 -0
- data/ext/libdeflate/libdeflate/tools/msc_test.bat +3 -0
- data/ext/libdeflate/libdeflate/tools/pgo_build.sh +23 -0
- data/ext/libdeflate/libdeflate/tools/produce_gzip_benchmark_table.sh +37 -0
- data/ext/libdeflate/libdeflate/tools/run_tests.sh +305 -0
- data/ext/libdeflate/libdeflate/tools/windows_build.sh +10 -0
- data/ext/libdeflate/libdeflate_ext.c +389 -0
- data/ext/libdeflate/libdeflate_ext.h +8 -0
- data/lib/libdeflate.rb +2 -0
- data/lib/libdeflate/version.rb +3 -0
- data/libdeflate.gemspec +33 -0
- metadata +230 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 149575c7d11c4b3a79b41b9a877bec0b7d021486
|
4
|
+
data.tar.gz: 99d0996e3f3c91f41d2fd4998dcb388cdd189376
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3da84aba90e0ea51adab9822bdadf2c77b25c40ca7e0dabbd7f833c1796d49e81c39272988874940903d1431b0fed3051309b3342bf4f9421c6d16f3a1872db
|
7
|
+
data.tar.gz: e034b512a2694f1b70b296d6fa55a0e4ad2360ba08922817c34cc635c41a9a030903181bcbbc7340f7b2b5f413d8176512502f225e08a25a7b168e6dfe0ee688
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Satoshi Matsumoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# libdeflate-ruby
|
2
|
+
|
3
|
+
[![Gem](https://img.shields.io/gem/v/libdeflate.svg?style=flat-square)](https://rubygems.org/gems/libdeflate)
|
4
|
+
[![Travis](https://img.shields.io/travis/kaorimatz/libdeflate-ruby.svg?style=flat-square)](https://travis-ci.org/kaorimatz/libdeflate-ruby)
|
5
|
+
[![Coveralls](https://img.shields.io/coveralls/kaorimatz/libdeflate-ruby.svg?style=flat-square)](https://coveralls.io/github/kaorimatz/libdeflate-ruby)
|
6
|
+
[![Gemnasium](https://img.shields.io/gemnasium/kaorimatz/libdeflate-ruby.svg?style=flat-square)](https://gemnasium.com/kaorimatz/libdeflate-ruby)
|
7
|
+
|
8
|
+
Ruby bindings for [libdeflate](https://github.com/ebiggers/libdeflate).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'libdeflate'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install libdeflate
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'libdeflate'
|
30
|
+
|
31
|
+
compressor = Libdeflate::Compressor.new
|
32
|
+
compressed_string = compressor.compress('Hello, World!')
|
33
|
+
|
34
|
+
decompressor = Libdeflate::Decompressor.new
|
35
|
+
decompressed_string = decompressor.decompress(compressed_string)
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kaorimatz/libdeflate.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
+
|
52
|
+
The gem bundles [libdeflate](https://github.com/ebiggers/libdeflate), which is licensed under the terms of the [MIT License](https://github.com/ebiggers/libdeflate/blob/master/COPYING).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
require 'rake/extensiontask'
|
7
|
+
|
8
|
+
task build: :compile
|
9
|
+
|
10
|
+
Rake::ExtensionTask.new('libdeflate_ext') do |ext|
|
11
|
+
ext.ext_dir = 'ext/libdeflate'
|
12
|
+
ext.lib_dir = 'lib/libdeflate'
|
13
|
+
end
|
14
|
+
|
15
|
+
task default: %i[clobber compile spec]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'libdeflate'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('libdeflate')
|
4
|
+
|
5
|
+
if enable_config('bundled-libdeflate', false) || !(find_header('libdeflate.h') && have_library('deflate'))
|
6
|
+
$VPATH << '$(srcdir)/libdeflate/lib'
|
7
|
+
$INCFLAGS << ' -I$(srcdir)/libdeflate -I$(srcdir)/libdeflate/common'
|
8
|
+
|
9
|
+
$srcs = Dir.glob(File.join($srcdir, '*.c'))
|
10
|
+
$srcs += Dir.glob(File.join($srcdir, 'libdeflate', 'lib', '*.c'))
|
11
|
+
$srcs.sort!
|
12
|
+
end
|
13
|
+
|
14
|
+
create_makefile('libdeflate/libdeflate_ext')
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright 2016 Eric Biggers
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation files
|
5
|
+
(the "Software"), to deal in the Software without restriction,
|
6
|
+
including without limitation the rights to use, copy, modify, merge,
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software,
|
8
|
+
and to permit persons to whom the Software is furnished to do so,
|
9
|
+
subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
18
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,231 @@
|
|
1
|
+
#
|
2
|
+
# Use 'make help' to list available targets.
|
3
|
+
#
|
4
|
+
# Define V=1 to enable "verbose" mode, showing all executed commands.
|
5
|
+
#
|
6
|
+
# Define DECOMPRESSION_ONLY to omit all compression code, building a
|
7
|
+
# decompression-only library. If doing this, you must also build a specific
|
8
|
+
# library target such as 'libdeflate.a', as the programs will no longer compile.
|
9
|
+
#
|
10
|
+
# Define DISABLE_GZIP to disable support for the gzip wrapper format.
|
11
|
+
#
|
12
|
+
# Define DISABLE_ZLIB to disable support for the zlib wrapper format.
|
13
|
+
#
|
14
|
+
##############################################################################
|
15
|
+
|
16
|
+
#### Common compiler flags.
|
17
|
+
#### Flags given here are not intended to be overridden, but you can add more
|
18
|
+
#### by defining CFLAGS in the environment or on the 'make' command line.
|
19
|
+
|
20
|
+
cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null \
|
21
|
+
1>&2 2>/dev/null; then echo $(1); fi)
|
22
|
+
|
23
|
+
override CFLAGS := \
|
24
|
+
$(CFLAGS) -O2 -fomit-frame-pointer -std=c99 -I. -Icommon \
|
25
|
+
-Wall -Wundef \
|
26
|
+
$(call cc-option,-Wpedantic) \
|
27
|
+
$(call cc-option,-Wdeclaration-after-statement) \
|
28
|
+
$(call cc-option,-Wmissing-prototypes) \
|
29
|
+
$(call cc-option,-Wstrict-prototypes) \
|
30
|
+
$(call cc-option,-Wvla)
|
31
|
+
|
32
|
+
##############################################################################
|
33
|
+
|
34
|
+
STATIC_LIB_SUFFIX := .a
|
35
|
+
SHARED_LIB_SUFFIX := .so
|
36
|
+
SHARED_LIB_CFLAGS := -fPIC
|
37
|
+
PROG_SUFFIX :=
|
38
|
+
PROG_CFLAGS :=
|
39
|
+
HARD_LINKS := 1
|
40
|
+
|
41
|
+
# Compiling for Windows with MinGW?
|
42
|
+
ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),)
|
43
|
+
ifeq ($(AR),ar)
|
44
|
+
ifneq ($(findstring -mingw,$(CC)),)
|
45
|
+
AR := $(patsubst %-gcc,%-ar,$(CC))
|
46
|
+
endif
|
47
|
+
endif
|
48
|
+
STATIC_LIB_SUFFIX := .lib
|
49
|
+
SHARED_LIB_SUFFIX := .dll
|
50
|
+
SHARED_LIB_CFLAGS :=
|
51
|
+
PROG_SUFFIX := .exe
|
52
|
+
PROG_CFLAGS := -static -municode
|
53
|
+
HARD_LINKS :=
|
54
|
+
override CFLAGS := $(CFLAGS) $(call cc-option,-Wno-pedantic-ms-format)
|
55
|
+
endif
|
56
|
+
|
57
|
+
##############################################################################
|
58
|
+
|
59
|
+
#### Quiet make is enabled by default. Define V=1 to disable.
|
60
|
+
|
61
|
+
ifneq ($(findstring s,$(MAKEFLAGS)),s)
|
62
|
+
ifneq ($(V),1)
|
63
|
+
QUIET_CC = @echo ' CC ' $@;
|
64
|
+
QUIET_CCLD = @echo ' CCLD ' $@;
|
65
|
+
QUIET_AR = @echo ' AR ' $@;
|
66
|
+
QUIET_LN = @echo ' LN ' $@;
|
67
|
+
QUIET_CP = @echo ' CP ' $@;
|
68
|
+
QUIET_GEN = @echo ' GEN ' $@;
|
69
|
+
endif
|
70
|
+
endif
|
71
|
+
|
72
|
+
##############################################################################
|
73
|
+
|
74
|
+
COMMON_HEADERS := $(wildcard common/*.h)
|
75
|
+
DEFAULT_TARGETS :=
|
76
|
+
|
77
|
+
#### Library
|
78
|
+
|
79
|
+
STATIC_LIB := libdeflate$(STATIC_LIB_SUFFIX)
|
80
|
+
SHARED_LIB := libdeflate$(SHARED_LIB_SUFFIX)
|
81
|
+
|
82
|
+
LIB_CFLAGS += $(CFLAGS) -fvisibility=hidden -D_ANSI_SOURCE
|
83
|
+
|
84
|
+
LIB_HEADERS := $(wildcard lib/*.h)
|
85
|
+
|
86
|
+
LIB_SRC := lib/aligned_malloc.c lib/deflate_decompress.c lib/x86_cpu_features.c
|
87
|
+
|
88
|
+
DECOMPRESSION_ONLY :=
|
89
|
+
ifndef DECOMPRESSION_ONLY
|
90
|
+
LIB_SRC += lib/deflate_compress.c
|
91
|
+
endif
|
92
|
+
|
93
|
+
DISABLE_ZLIB :=
|
94
|
+
ifndef DISABLE_ZLIB
|
95
|
+
LIB_SRC += lib/adler32.c lib/zlib_decompress.c
|
96
|
+
ifndef DECOMPRESSION_ONLY
|
97
|
+
LIB_SRC += lib/zlib_compress.c
|
98
|
+
endif
|
99
|
+
endif
|
100
|
+
|
101
|
+
DISABLE_GZIP :=
|
102
|
+
ifndef DISABLE_GZIP
|
103
|
+
LIB_SRC += lib/crc32.c lib/gzip_decompress.c
|
104
|
+
ifndef DECOMPRESSION_ONLY
|
105
|
+
LIB_SRC += lib/gzip_compress.c
|
106
|
+
endif
|
107
|
+
endif
|
108
|
+
|
109
|
+
STATIC_LIB_OBJ := $(LIB_SRC:.c=.o)
|
110
|
+
SHARED_LIB_OBJ := $(LIB_SRC:.c=.shlib.o)
|
111
|
+
|
112
|
+
# Compile static library object files
|
113
|
+
$(STATIC_LIB_OBJ): %.o: %.c $(LIB_HEADERS) $(COMMON_HEADERS) .lib-cflags
|
114
|
+
$(QUIET_CC) $(CC) -o $@ -c $(LIB_CFLAGS) $<
|
115
|
+
|
116
|
+
# Compile shared library object files
|
117
|
+
$(SHARED_LIB_OBJ): %.shlib.o: %.c $(LIB_HEADERS) $(COMMON_HEADERS) .lib-cflags
|
118
|
+
$(QUIET_CC) $(CC) -o $@ -c $(LIB_CFLAGS) $(SHARED_LIB_CFLAGS) -DLIBDEFLATE_DLL $<
|
119
|
+
|
120
|
+
# Create static library
|
121
|
+
$(STATIC_LIB):$(STATIC_LIB_OBJ)
|
122
|
+
$(QUIET_AR) $(AR) cr $@ $+
|
123
|
+
|
124
|
+
DEFAULT_TARGETS += $(STATIC_LIB)
|
125
|
+
|
126
|
+
# Create shared library
|
127
|
+
$(SHARED_LIB):$(SHARED_LIB_OBJ)
|
128
|
+
$(QUIET_CCLD) $(CC) -o $@ $(LDFLAGS) $(LIB_CFLAGS) -shared $+
|
129
|
+
|
130
|
+
DEFAULT_TARGETS += $(SHARED_LIB)
|
131
|
+
|
132
|
+
# Rebuild if CC or LIB_CFLAGS changed
|
133
|
+
.lib-cflags: FORCE
|
134
|
+
@flags='$(CC):$(LIB_CFLAGS)'; \
|
135
|
+
if [ "$$flags" != "`cat $@ 2>/dev/null`" ]; then \
|
136
|
+
[ -e $@ ] && echo "Rebuilding library due to new compiler flags"; \
|
137
|
+
echo "$$flags" > $@; \
|
138
|
+
fi
|
139
|
+
|
140
|
+
##############################################################################
|
141
|
+
|
142
|
+
#### Programs
|
143
|
+
|
144
|
+
PROG_CFLAGS += $(CFLAGS) \
|
145
|
+
-D_DEFAULT_SOURCE \
|
146
|
+
-D_FILE_OFFSET_BITS=64 \
|
147
|
+
-DHAVE_CONFIG_H
|
148
|
+
|
149
|
+
PROG_COMMON_HEADERS := programs/prog_util.h programs/config.h
|
150
|
+
PROG_COMMON_SRC := programs/prog_util.c programs/tgetopt.c
|
151
|
+
NONTEST_PROGRAM_SRC := programs/gzip.c
|
152
|
+
TEST_PROGRAM_SRC := programs/benchmark.c programs/test_checksums.c \
|
153
|
+
programs/checksum.c
|
154
|
+
|
155
|
+
NONTEST_PROGRAMS := $(NONTEST_PROGRAM_SRC:programs/%.c=%$(PROG_SUFFIX))
|
156
|
+
DEFAULT_TARGETS += $(NONTEST_PROGRAMS)
|
157
|
+
TEST_PROGRAMS := $(TEST_PROGRAM_SRC:programs/%.c=%$(PROG_SUFFIX))
|
158
|
+
|
159
|
+
PROG_COMMON_OBJ := $(PROG_COMMON_SRC:%.c=%.o)
|
160
|
+
NONTEST_PROGRAM_OBJ := $(NONTEST_PROGRAM_SRC:%.c=%.o)
|
161
|
+
TEST_PROGRAM_OBJ := $(TEST_PROGRAM_SRC:%.c=%.o)
|
162
|
+
PROG_OBJ := $(PROG_COMMON_OBJ) $(NONTEST_PROGRAM_OBJ) $(TEST_PROGRAM_OBJ)
|
163
|
+
|
164
|
+
# Generate autodetected configuration header
|
165
|
+
programs/config.h:programs/detect.sh .prog-cflags
|
166
|
+
$(QUIET_GEN) CC="$(CC)" CFLAGS="$(PROG_CFLAGS)" $< > $@
|
167
|
+
|
168
|
+
# Compile program object files
|
169
|
+
$(PROG_OBJ): %.o: %.c $(PROG_COMMON_HEADERS) $(COMMON_HEADERS) .prog-cflags
|
170
|
+
$(QUIET_CC) $(CC) -o $@ -c $(PROG_CFLAGS) $<
|
171
|
+
|
172
|
+
# Link the programs.
|
173
|
+
#
|
174
|
+
# Note: the test programs are not compiled by default. One reason is that the
|
175
|
+
# test programs must be linked with zlib for doing comparisons.
|
176
|
+
|
177
|
+
$(NONTEST_PROGRAMS): %$(PROG_SUFFIX): programs/%.o $(PROG_COMMON_OBJ) $(STATIC_LIB)
|
178
|
+
$(QUIET_CCLD) $(CC) -o $@ $(LDFLAGS) $(PROG_CFLAGS) $+
|
179
|
+
|
180
|
+
$(TEST_PROGRAMS): %$(PROG_SUFFIX): programs/%.o $(PROG_COMMON_OBJ) $(STATIC_LIB)
|
181
|
+
$(QUIET_CCLD) $(CC) -o $@ $(LDFLAGS) $(PROG_CFLAGS) $+ -lz
|
182
|
+
|
183
|
+
ifdef HARD_LINKS
|
184
|
+
# Hard link gunzip to gzip
|
185
|
+
gunzip$(PROG_SUFFIX):gzip$(PROG_SUFFIX)
|
186
|
+
$(QUIET_LN) ln -f $< $@
|
187
|
+
else
|
188
|
+
# No hard links; copy gzip to gunzip
|
189
|
+
gunzip$(PROG_SUFFIX):gzip$(PROG_SUFFIX)
|
190
|
+
$(QUIET_CP) cp -f $< $@
|
191
|
+
endif
|
192
|
+
|
193
|
+
DEFAULT_TARGETS += gunzip$(PROG_SUFFIX)
|
194
|
+
|
195
|
+
# Rebuild if CC or PROG_CFLAGS changed
|
196
|
+
.prog-cflags: FORCE
|
197
|
+
@flags='$(CC):$(PROG_CFLAGS)'; \
|
198
|
+
if [ "$$flags" != "`cat $@ 2>/dev/null`" ]; then \
|
199
|
+
[ -e $@ ] && echo "Rebuilding programs due to new compiler flags"; \
|
200
|
+
echo "$$flags" > $@; \
|
201
|
+
fi
|
202
|
+
|
203
|
+
##############################################################################
|
204
|
+
|
205
|
+
all:$(DEFAULT_TARGETS)
|
206
|
+
|
207
|
+
test_programs:$(TEST_PROGRAMS)
|
208
|
+
|
209
|
+
help:
|
210
|
+
@echo "Available targets:"
|
211
|
+
@echo "------------------"
|
212
|
+
@for target in $(DEFAULT_TARGETS) $(TEST_PROGRAMS); do \
|
213
|
+
echo -e "$$target"; \
|
214
|
+
done
|
215
|
+
|
216
|
+
clean:
|
217
|
+
rm -f *.a *.dll *.exe *.exp *.so \
|
218
|
+
lib/*.o lib/*.obj lib/*.dllobj \
|
219
|
+
programs/*.o programs/*.obj \
|
220
|
+
$(DEFAULT_TARGETS) $(TEST_PROGRAMS) programs/config.h \
|
221
|
+
libdeflate.lib libdeflatestatic.lib \
|
222
|
+
.lib-cflags .prog-cflags
|
223
|
+
|
224
|
+
realclean: clean
|
225
|
+
rm -f tags cscope* run_tests.log
|
226
|
+
|
227
|
+
FORCE:
|
228
|
+
|
229
|
+
.PHONY: all test_programs help clean realclean
|
230
|
+
|
231
|
+
.DEFAULT_GOAL = all
|