image_compressor_pack 0.1.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.gitignore +15 -0
  4. data/.travis.yml +16 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/Makefile +32 -0
  8. data/README.md +45 -0
  9. data/Rakefile +56 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/certs/ignisf.pem +32 -0
  13. data/ext/image_compressor_pack/extconf.rb +30 -0
  14. data/image_compressor_pack.gemspec +28 -0
  15. data/lib/image_compressor_pack/dynamically_linked_recipes.yml +84 -0
  16. data/lib/image_compressor_pack/recipes.rb +42 -0
  17. data/lib/image_compressor_pack/statically_linked_recipes.yml +93 -0
  18. data/lib/image_compressor_pack/version.rb +3 -0
  19. data/lib/image_compressor_pack.rb +24 -0
  20. data/ports/archives/advancecomp-1.20.tar.gz +0 -0
  21. data/ports/archives/gifsicle-1.88.tar.gz +0 -0
  22. data/ports/archives/jhead-3.00.tar.gz +0 -0
  23. data/ports/archives/jpegoptim-1.4.3.tar.gz +0 -0
  24. data/ports/archives/lcms2-2.7.tar.gz +0 -0
  25. data/ports/archives/libpng-1.6.21.tar.gz +0 -0
  26. data/ports/archives/mozjpeg-3.1-release-source.tar.gz +0 -0
  27. data/ports/archives/nasm-2.12.01.tar.gz +0 -0
  28. data/ports/archives/optipng-0.7.6.tar.gz +0 -0
  29. data/ports/archives/pngcrush-1.8.1.tar.gz +0 -0
  30. data/ports/archives/pngquant-2.7.1-src.tar.gz +0 -0
  31. data/ports/archives/zlib-1.2.8.tar.gz +0 -0
  32. data/ports/patches/jhead/0001-Add-a-configure-shim.patch +21 -0
  33. data/ports/patches/jhead/0002-Specify-a-default-DESTDIR.patch +30 -0
  34. data/ports/patches/jhead/0003-Make-the-configure-script-set-the-DESTDIR.patch +39 -0
  35. data/ports/patches/jhead/0004-Make-the-makefile-install-to-the-proper-location.patch +23 -0
  36. data/ports/patches/jhead/0005-Produce-a-static-binary.patch +25 -0
  37. data/ports/patches/jpegoptim/0001-Link-lm-after-ljpeg.patch +34 -0
  38. data/ports/patches/libpng/0001-Do-not-build-binary-utilities.patch +327 -0
  39. data/ports/patches/mozjpeg/0001-Build-static-binaries.patch +34 -0
  40. data/ports/patches/optipng/0001-Allow-passing-LDFLAGS-as-configure-arg.patch +35 -0
  41. data/ports/patches/pngcrush/0001-Add-an-install-task.patch +33 -0
  42. data/ports/patches/pngcrush/0002-Add-a-configure-script.patch +41 -0
  43. data/ports/patches/pngcrush/0003-Produce-a-static-binary.patch +25 -0
  44. data/ports/patches/pngquant/0001-Work-around-mini-portile-s-configure-invocation.patch +965 -0
  45. data/ports/patches/pngquant/0002-Add-default-LDFLAGS.patch +24 -0
  46. data/ports/patches/pngquant/0003-Disable-libpng-check.patch +77 -0
  47. data/ports/patches/pngquant/0004-Remove-libz-check.patch +37 -0
  48. data/ports/patches/pngquant/0005-Remove-lcms2-check.patch +47 -0
  49. data/ports/patches/pngquant/0006-Do-not-build-static-binary.patch +25 -0
  50. data.tar.gz.sig +0 -0
  51. metadata +168 -0
  52. metadata.gz.sig +0 -0
@@ -0,0 +1,965 @@
1
+ From 2a2d11aa8ebd7942e4ff5e03bcdf77dc1a10462b Mon Sep 17 00:00:00 2001
2
+ From: Petko Bordjukov <bordjukov@gmail.com>
3
+ Date: Thu, 9 Jun 2016 02:51:12 +0300
4
+ Subject: [PATCH 1/6] Work around mini portile's configure invocation
5
+
6
+ ---
7
+ configure | 471 +--------------------------------------------------------
8
+ configure.bash | 469 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
+ 2 files changed, 471 insertions(+), 469 deletions(-)
10
+ create mode 100755 configure.bash
11
+
12
+ diff --git a/configure b/configure
13
+ index 7308b9d..49e92d0 100755
14
+ --- a/configure
15
+ +++ b/configure
16
+ @@ -1,469 +1,2 @@
17
+ -#!/usr/bin/env bash
18
+ -
19
+ -CONFIG="config.mk"
20
+ -PREFIX="/usr/local"
21
+ -VERSION=$(grep LIQ_VERSION_STRING lib/libimagequant.h | grep -Eo "2\.[0-9.]+")
22
+ -
23
+ -DEBUG=
24
+ -SSE=auto
25
+ -OPENMP=
26
+ -LIBPNG_DIR=.
27
+ -if [[ "$OSTYPE" =~ "darwin" ]]; then
28
+ - COCOA_READER=auto
29
+ - LCMS2=0
30
+ -else
31
+ - COCOA_READER=0
32
+ - LCMS2=auto
33
+ -fi
34
+ -EXTRA_CFLAGS=
35
+ -EXTRA_LDFLAGS=
36
+ -
37
+ -# make gcc default compiler unless CC is already set
38
+ -CC=${CC:-gcc}
39
+ -
40
+ -help() {
41
+ - printf "%4s %s\n" "" "$1"
42
+ -}
43
+ -
44
+ -for i in "$@"; do
45
+ - case $i in
46
+ - --help)
47
+ - echo
48
+ - help "--prefix=<dir> installation directory [$PREFIX]"
49
+ - help "--extra-cflags=<flags> append to CFLAGS"
50
+ - help "--extra-ldflags=<flags> append to LDFLAGS"
51
+ - echo
52
+ - help "--enable-debug"
53
+ - help "--enable-sse/--disable-sse enable/disable SSE instructions"
54
+ - echo
55
+ - help "--with-openmp=static compile with multicore support"
56
+ - help "--with-lcms2/--without-lcms2 compile with color profile support"
57
+ -if [[ "$OSTYPE" =~ "darwin" ]]; then
58
+ - help "--with-cocoa/--without-cocoa use Cocoa framework to read images"
59
+ -fi
60
+ - help "--with-libpng=<dir> search for libpng in directory"
61
+ - echo
62
+ - help "CC=<compiler> use given compiler command"
63
+ - help "CFLAGS=<flags> pass options to the compiler"
64
+ - help "LDFLAGS=<flags> pass options to the linker"
65
+ - echo
66
+ - exit 0
67
+ - ;;
68
+ - # Can be set before or after configure. Latter overrides former.
69
+ - CC=*)
70
+ - CC=${i#*=}
71
+ - ;;
72
+ - CFLAGS=*)
73
+ - CFLAGS=${i#*=}
74
+ - ;;
75
+ - LDFLAGS=*)
76
+ - LDFLAGS=${i#*=}
77
+ - ;;
78
+ - --enable-debug)
79
+ - DEBUG=1
80
+ - ;;
81
+ - --enable-sse)
82
+ - SSE=1
83
+ - ;;
84
+ - --disable-sse)
85
+ - SSE=0
86
+ - ;;
87
+ - --with-openmp)
88
+ - OPENMP=1
89
+ - ;;
90
+ - --with-openmp=static)
91
+ - OPENMP=static
92
+ - ;;
93
+ - --with-lcms2)
94
+ - LCMS2=1
95
+ - COCOA_READER=0
96
+ - ;;
97
+ - --without-lcms2)
98
+ - LCMS2=0
99
+ - ;;
100
+ - --with-cocoa)
101
+ - COCOA_READER=1
102
+ - LCMS2=0
103
+ - ;;
104
+ - --without-cocoa)
105
+ - COCOA_READER=0
106
+ - ;;
107
+ - --with-libpng=*)
108
+ - LIBPNG_DIR=${i#*=}
109
+ - ;;
110
+ - --prefix=*)
111
+ - PREFIX=${i#*=}
112
+ - ;;
113
+ - # can be used multiple times or in quotes to set multiple flags
114
+ - --extra-cflags=*)
115
+ - EXTRA_CFLAGS="$EXTRA_CFLAGS ${i#*=}"
116
+ - ;;
117
+ - --extra-ldflags=*)
118
+ - EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
119
+ - ;;
120
+ - *)
121
+ - echo "warning: unknown switch ${i%%=*} (see $0 --help for the list)"
122
+ - ;;
123
+ - esac
124
+ -done
125
+ -
126
+ -# If someone runs sudo make install as very first command, and configure later,
127
+ -# $CONFIG cannot be overwritten, and must be deleted before continuing.
128
+ -if [[ -f "$CONFIG" && ! -w "$CONFIG" ]]; then
129
+ - echo "Cannot overwrite file $CONFIG! Please delete it."
130
+ - exit 1
131
+ -fi
132
+ -
133
+ -cflags() {
134
+ - CFLAGS="$CFLAGS $1"
135
+ -}
136
+ -
137
+ -lflags() {
138
+ - LDFLAGS="$LDFLAGS $1"
139
+ -}
140
+ -
141
+ -status() {
142
+ - printf "%10s: %s\n" "$1" "$2"
143
+ -}
144
+ -
145
+ -# Append to CFLAGS if compiler supports flag, with optional prerequisite.
146
+ -# Fails on errors and warnings.
147
+ -conditional_cflags() {
148
+ - if [ -z "$(echo | "$CC" -xc -S -o /dev/null $2 $1 - 2>&1)" ]; then
149
+ - cflags "$1"
150
+ - fi
151
+ -}
152
+ -
153
+ -# returns first matching file in directory
154
+ -find_f() {
155
+ - echo $(find "$1" -not -type d -name "$2" -print -quit 2> /dev/null)
156
+ -}
157
+ -
158
+ -# returns first matching file in directory (no symlinks)
159
+ -find_h() {
160
+ - echo $(find "$1" -type f -name "$2" -print -quit 2> /dev/null)
161
+ -}
162
+ -
163
+ -find_pkgconfig() {
164
+ - local LIBNAME=$1
165
+ - if pkg-config --exists "$LIBNAME" &> /dev/null; then
166
+ - cflags "$(pkg-config --cflags "$LIBNAME")"
167
+ - lflags "$(pkg-config --libs "$LIBNAME")"
168
+ - status "$LIBNAME" "shared ($(pkg-config --modversion "$LIBNAME"))"
169
+ - return 0
170
+ - fi
171
+ - return 1
172
+ -}
173
+ -
174
+ -find_static() {
175
+ - local LIBNAME=$1
176
+ - local HEADERPATTERN=$2
177
+ - local STATICPATTERN=$3
178
+ -
179
+ - local HPATH=$(find_h . "$HEADERPATTERN")
180
+ - if [ -n "$HPATH" ]; then
181
+ - local APATH=$(find_f . "$STATICPATTERN")
182
+ - if [ -n "$APATH" ]; then
183
+ - cflags "-I${HPATH%/*}"
184
+ - lflags "${APATH}"
185
+ - status "$LIBNAME" "static"
186
+ - return 0
187
+ - fi
188
+ - fi
189
+ - return 1
190
+ -}
191
+ -
192
+ -find_dynamic() {
193
+ - local LIBNAME=$1
194
+ - local HEADERPATTERN=$2
195
+ - local DYNAMICPATTERN=$3
196
+ - local HEADERDIR=$4
197
+ - local LIBDIR=$5
198
+ -
199
+ - local HPATH=$(find_h "$HEADERDIR" "$HEADERPATTERN")
200
+ - if [ -n "$HPATH" ]; then
201
+ - local SOPATH=$(find_f "$LIBDIR" "$DYNAMICPATTERN")
202
+ - if [ -n "$SOPATH" ]; then
203
+ - cflags "-I${HPATH%/*}"
204
+ - lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
205
+ - status "$LIBNAME" "shared ... $SOPATH"
206
+ - return 0
207
+ - fi
208
+ - fi
209
+ - return 1
210
+ -}
211
+ -
212
+ -find_library() {
213
+ - local LIBNAME=$1
214
+ - local DYNAMICLIBNAME=$2
215
+ - local HEADERPATTERN=$3
216
+ - local STATICPATTERN=$4
217
+ - local DYNAMICPATTERN=$5
218
+ -
219
+ - # try static in current directory first
220
+ - if find_static "$LIBNAME" "$HEADERPATTERN" "$STATICPATTERN"; then
221
+ - return 0;
222
+ - fi
223
+ -
224
+ - # try shared
225
+ - if find_pkgconfig "$LIBNAME"; then
226
+ - return 0
227
+ - fi
228
+ -
229
+ - for i in "${DIRS[@]}"; do
230
+ - DIR=($i)
231
+ - if find_dynamic "$LIBNAME" "$HEADERPATTERN" "$DYNAMICPATTERN" "${DIR[0]}" "${DIR[1]}"; then
232
+ - return 0
233
+ - fi
234
+ - done
235
+ - return 1
236
+ -}
237
+ -
238
+ -# returns full png.h version string
239
+ -pngh_string() {
240
+ - echo "$(grep -m1 "define PNG_LIBPNG_VER_STRING" "$1" | \
241
+ - grep -Eo '"[^"]+"' | grep -Eo '[^"]+')"
242
+ -}
243
+ -
244
+ -# returns major minor version numbers from png.h
245
+ -pngh_majmin() {
246
+ - local MAJ=$(grep -m1 "define PNG_LIBPNG_VER_MAJOR" "$1" | grep -Eo "[0-9]+")
247
+ - local MIN=$(grep -m1 "define PNG_LIBPNG_VER_MINOR" "$1" | grep -Eo "[0-9]+")
248
+ - echo "${MAJ}${MIN}"
249
+ -}
250
+ -
251
+ -error() {
252
+ - status "$1" "error ... $2"
253
+ - echo
254
+ - exit 1
255
+ -}
256
+ -
257
+ -echo
258
+ -
259
+ -# basic check
260
+ -if ! echo "int main(){}" | "$CC" -xc -std=c99 -o /dev/null - > /dev/null; then
261
+ - error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
262
+ -fi
263
+ -
264
+ -status "Compiler" "$CC"
265
+ -
266
+ -# init flags
267
+ -CFLAGS=${CFLAGS:--O3 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
268
+ -cflags "-std=c99 -I."
269
+ -
270
+ -# DEBUG
271
+ -if [ -z "$DEBUG" ]; then
272
+ - cflags "-DNDEBUG"
273
+ - status "Debug" "no"
274
+ -else
275
+ - cflags "-g"
276
+ - status "Debug" "yes"
277
+ -fi
278
+ -
279
+ -# SSE
280
+ -if [ "$SSE" = 'auto' ]; then
281
+ - if [[ "$(uname -m)" =~ (amd|x86_)64 ||
282
+ - "$(grep -E -m1 "^flags" /proc/cpuinfo)" =~ "sse" ]]; then
283
+ - SSE=1
284
+ - fi
285
+ -fi
286
+ -
287
+ -if [ "$SSE" -eq 1 ]; then
288
+ - status "SSE" "yes"
289
+ - cflags "-DUSE_SSE=1"
290
+ - cflags "-msse"
291
+ - # Silence a later ICC warning due to -msse working slightly different.
292
+ - conditional_cflags "-wd10121"
293
+ - # Must be set explicitly for GCC on x86_32. Other compilers imply it.
294
+ - conditional_cflags "-mfpmath=sse" "-msse"
295
+ -elif [ "$SSE" -eq 0 ]; then
296
+ - status "SSE" "no"
297
+ - cflags "-DUSE_SSE=0"
298
+ -fi
299
+ -
300
+ -# OpenMP
301
+ -if [ -n "$OPENMP" ]; then
302
+ - if [ "static" = "$OPENMP" ]; then
303
+ - OPENMPFLAGS="-static-libgcc -Bstatic -fopenmp -Bdynamic"
304
+ - else
305
+ - OPENMPFLAGS="-fopenmp"
306
+ - fi
307
+ - if [[ "$("$CC" -xc -E $OPENMPFLAGS <(echo "#ifdef _OPENMP
308
+ - #include <omp.h>
309
+ - #endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
310
+ - cflags "$OPENMPFLAGS"
311
+ - lflags "$OPENMPFLAGS"
312
+ - status "OpenMP" "yes"
313
+ - else
314
+ - error "OpenMP" "not supported by compiler (please install a compiler that supports OpenMP (e.g. gcc) and specify it with the CC= argument)"
315
+ - fi
316
+ -else
317
+ - # silence warnings about omp pragmas
318
+ - cflags "-Wno-unknown-pragmas"
319
+ - conditional_cflags "-wd3180" # ICC
320
+ - status "OpenMP" "no"
321
+ -fi
322
+ -
323
+ -# Cocoa
324
+ -if [[ "$OSTYPE" =~ "darwin" ]]; then
325
+ - cflags "-mmacosx-version-min=10.6"
326
+ - lflags "-mmacosx-version-min=10.6"
327
+ -
328
+ - if [ "$COCOA_READER" != 0 ] && "$CC" 2>/dev/null 1>/dev/null -xc -E <(echo "#import <Cocoa/Cocoa.h>"); then
329
+ - COCOA_READER=1
330
+ - cflags "-DUSE_COCOA=1"
331
+ - lflags "-framework Cocoa"
332
+ - status "Cocoa" "yes"
333
+ - else
334
+ - status "Cocoa" "no"
335
+ - fi
336
+ -fi
337
+ -
338
+ -# pairs of possible *.h and lib*.so locations
339
+ -DIRS=()
340
+ -
341
+ -if command -v >/dev/null libpng-config; then
342
+ - DIRS+=("$(libpng-config --prefix) $(libpng-config --libdir)")
343
+ -fi
344
+ -
345
+ -DIRS+=("/usr/local/include /usr/local/lib"
346
+ - "/usr/include /usr/lib"
347
+ - "/opt/local/include /opt/local/lib" # macports
348
+ - )
349
+ -
350
+ -if [[ "$OSTYPE" =~ "darwin" ]]; then
351
+ - SOLIBSUFFIX=dylib
352
+ -
353
+ - # Search Developer SDK paths, since Apple seems to have dropped the standard Unixy ones
354
+ - XCODE_CMD="xcode-select"
355
+ - XCODE_PATH=$($XCODE_CMD -p)
356
+ - DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib")
357
+ - DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib")
358
+ -else
359
+ - SOLIBSUFFIX=so
360
+ -fi
361
+ -
362
+ -
363
+ -# libpng
364
+ -# try if given flags are enough
365
+ -HAS_LIBPNG=0
366
+ -if echo "#include \"png.h\"
367
+ - int main(){
368
+ - return !png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
369
+ -}" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then
370
+ - status "libpng" "custom flags"
371
+ - HAS_LIBPNG=1
372
+ -fi
373
+ -
374
+ -if [ "$HAS_LIBPNG" -eq 0 ]; then
375
+ - # try static in the given directory
376
+ - PNGH=$(find_h "$LIBPNG_DIR" "png.h")
377
+ - if [ -n "$PNGH" ]; then
378
+ - PNGH_STRING=$(pngh_string "$PNGH")
379
+ - PNGH_MAJMIN=$(pngh_majmin "$PNGH")
380
+ - if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
381
+ - LIBPNGA=$(find_f "$LIBPNG_DIR" "libpng${PNGH_MAJMIN}.a")
382
+ - if [ -n "$LIBPNGA" ]; then
383
+ - cflags "-I${PNGH%/*}"
384
+ - lflags "${LIBPNGA}"
385
+ - status "libpng" "static (${PNGH_STRING})"
386
+ - HAS_LIBPNG=1
387
+ - fi
388
+ - fi
389
+ - fi
390
+ -fi
391
+ -# try shared
392
+ -if [ "$HAS_LIBPNG" -eq 0 ]; then
393
+ - if find_pkgconfig libpng; then
394
+ - HAS_LIBPNG=1
395
+ - else
396
+ - for i in "${DIRS[@]}"; do
397
+ - DIR=($i)
398
+ - PNGH=$(find_h "${DIR[0]}" "png.h")
399
+ - if [ -n "$PNGH" ]; then
400
+ - PNGH_STRING=$(pngh_string "$PNGH")
401
+ - PNGH_MAJMIN=$(pngh_majmin "$PNGH")
402
+ - if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
403
+ - LIBPNGSO=$(find_f "${DIR[1]}" "libpng${PNGH_MAJMIN}.$SOLIBSUFFIX*")
404
+ - if [ -n "$LIBPNGSO" ]; then
405
+ - cflags "-I${PNGH%/*}"
406
+ - lflags "-L${LIBPNGSO%/*} -lpng${PNGH_MAJMIN}"
407
+ - status "libpng" "shared (${PNGH_STRING})"
408
+ - HAS_LIBPNG=1
409
+ - break
410
+ - fi
411
+ - fi
412
+ - fi
413
+ - done
414
+ - fi
415
+ -fi
416
+ -if [ "$HAS_LIBPNG" -eq 0 ]; then
417
+ - if [[ "$OSTYPE" =~ "darwin" ]]; then
418
+ - LIBPNG_CMD='`brew install libpng`'
419
+ - else
420
+ - LIBPNG_CMD='`apt-get install libpng16-dev` or `apt-get install libpng-dev` or `yum install libpng-devel`'
421
+ - fi
422
+ - error "libpng" "not found (try: $LIBPNG_CMD)"
423
+ -fi
424
+ -
425
+ -# zlib
426
+ -if ! find_library "zlib" "z" "zlib.h" "libz.a" "libz.$SOLIBSUFFIX*"; then
427
+ - error "zlib" "not found (please install zlib-devel package)"
428
+ -fi
429
+ -
430
+ -# lcms2
431
+ -if [ "$LCMS2" != 0 ]; then
432
+ - if find_library "lcms2" "lcms2" "lcms2.h" "liblcms2.a" "liblcms2.$SOLIBSUFFIX*"; then
433
+ - cflags "-DUSE_LCMS=1"
434
+ - else
435
+ - if [ "$LCMS2" = 'auto' ]; then
436
+ - status "lcms2" "no"
437
+ - else
438
+ - error "lcms2" "not found (please install libcms2-devel package)"
439
+ - fi
440
+ - fi
441
+ -else
442
+ - status "lcms2" "no"
443
+ -fi
444
+ -
445
+ -echo
446
+ -
447
+ -# As of GCC 4.5, 387 fp math is significantly slower in C99 mode without this.
448
+ -# Note: CPUs without SSE2 use 387 for doubles, even when SSE fp math is set.
449
+ -conditional_cflags "-fexcess-precision=fast"
450
+ -
451
+ -# Intel C++ Compiler
452
+ -
453
+ -# ICC does usually only produce fast(er) code when it can optimize to the full
454
+ -# capabilites of the (Intel) CPU. This is equivalent to -march=native for GCC.
455
+ -conditional_cflags "-xHOST"
456
+ -
457
+ -# Disable unsafe fp optimizations and enforce fp precision as set in the source.
458
+ -conditional_cflags "-fp-model source"
459
+ -
460
+ -# Silence a gold linker warning about string misalignment.
461
+ -conditional_cflags "-falign-stack=maintain-16-byte"
462
+ -
463
+ -lflags "-lm" # Ubuntu requires this library last, issue #38
464
+ -
465
+ -if [ -n "$EXTRA_CFLAGS" ]; then
466
+ - cflags "$EXTRA_CFLAGS"
467
+ -fi
468
+ -
469
+ -if [ -n "$EXTRA_LDFLAGS" ]; then
470
+ - lflags "$EXTRA_LDFLAGS"
471
+ -fi
472
+ -
473
+ -# Overwrite previous configuration.
474
+ -echo "
475
+ -# auto-generated by configure
476
+ -PREFIX = $PREFIX
477
+ -VERSION = $VERSION
478
+ -CC = $CC
479
+ -CFLAGS = $CFLAGS
480
+ -LDFLAGS = $LDFLAGS
481
+ -COCOA_READER = $COCOA_READER
482
+ -" > "$CONFIG"
483
+ -
484
+ -# Configure static library the same way
485
+ -cp "$CONFIG" lib/
486
+ +#!/bin/sh
487
+ +./configure.bash $@
488
+ diff --git a/configure.bash b/configure.bash
489
+ new file mode 100755
490
+ index 0000000..7308b9d
491
+ --- /dev/null
492
+ +++ b/configure.bash
493
+ @@ -0,0 +1,469 @@
494
+ +#!/usr/bin/env bash
495
+ +
496
+ +CONFIG="config.mk"
497
+ +PREFIX="/usr/local"
498
+ +VERSION=$(grep LIQ_VERSION_STRING lib/libimagequant.h | grep -Eo "2\.[0-9.]+")
499
+ +
500
+ +DEBUG=
501
+ +SSE=auto
502
+ +OPENMP=
503
+ +LIBPNG_DIR=.
504
+ +if [[ "$OSTYPE" =~ "darwin" ]]; then
505
+ + COCOA_READER=auto
506
+ + LCMS2=0
507
+ +else
508
+ + COCOA_READER=0
509
+ + LCMS2=auto
510
+ +fi
511
+ +EXTRA_CFLAGS=
512
+ +EXTRA_LDFLAGS=
513
+ +
514
+ +# make gcc default compiler unless CC is already set
515
+ +CC=${CC:-gcc}
516
+ +
517
+ +help() {
518
+ + printf "%4s %s\n" "" "$1"
519
+ +}
520
+ +
521
+ +for i in "$@"; do
522
+ + case $i in
523
+ + --help)
524
+ + echo
525
+ + help "--prefix=<dir> installation directory [$PREFIX]"
526
+ + help "--extra-cflags=<flags> append to CFLAGS"
527
+ + help "--extra-ldflags=<flags> append to LDFLAGS"
528
+ + echo
529
+ + help "--enable-debug"
530
+ + help "--enable-sse/--disable-sse enable/disable SSE instructions"
531
+ + echo
532
+ + help "--with-openmp=static compile with multicore support"
533
+ + help "--with-lcms2/--without-lcms2 compile with color profile support"
534
+ +if [[ "$OSTYPE" =~ "darwin" ]]; then
535
+ + help "--with-cocoa/--without-cocoa use Cocoa framework to read images"
536
+ +fi
537
+ + help "--with-libpng=<dir> search for libpng in directory"
538
+ + echo
539
+ + help "CC=<compiler> use given compiler command"
540
+ + help "CFLAGS=<flags> pass options to the compiler"
541
+ + help "LDFLAGS=<flags> pass options to the linker"
542
+ + echo
543
+ + exit 0
544
+ + ;;
545
+ + # Can be set before or after configure. Latter overrides former.
546
+ + CC=*)
547
+ + CC=${i#*=}
548
+ + ;;
549
+ + CFLAGS=*)
550
+ + CFLAGS=${i#*=}
551
+ + ;;
552
+ + LDFLAGS=*)
553
+ + LDFLAGS=${i#*=}
554
+ + ;;
555
+ + --enable-debug)
556
+ + DEBUG=1
557
+ + ;;
558
+ + --enable-sse)
559
+ + SSE=1
560
+ + ;;
561
+ + --disable-sse)
562
+ + SSE=0
563
+ + ;;
564
+ + --with-openmp)
565
+ + OPENMP=1
566
+ + ;;
567
+ + --with-openmp=static)
568
+ + OPENMP=static
569
+ + ;;
570
+ + --with-lcms2)
571
+ + LCMS2=1
572
+ + COCOA_READER=0
573
+ + ;;
574
+ + --without-lcms2)
575
+ + LCMS2=0
576
+ + ;;
577
+ + --with-cocoa)
578
+ + COCOA_READER=1
579
+ + LCMS2=0
580
+ + ;;
581
+ + --without-cocoa)
582
+ + COCOA_READER=0
583
+ + ;;
584
+ + --with-libpng=*)
585
+ + LIBPNG_DIR=${i#*=}
586
+ + ;;
587
+ + --prefix=*)
588
+ + PREFIX=${i#*=}
589
+ + ;;
590
+ + # can be used multiple times or in quotes to set multiple flags
591
+ + --extra-cflags=*)
592
+ + EXTRA_CFLAGS="$EXTRA_CFLAGS ${i#*=}"
593
+ + ;;
594
+ + --extra-ldflags=*)
595
+ + EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
596
+ + ;;
597
+ + *)
598
+ + echo "warning: unknown switch ${i%%=*} (see $0 --help for the list)"
599
+ + ;;
600
+ + esac
601
+ +done
602
+ +
603
+ +# If someone runs sudo make install as very first command, and configure later,
604
+ +# $CONFIG cannot be overwritten, and must be deleted before continuing.
605
+ +if [[ -f "$CONFIG" && ! -w "$CONFIG" ]]; then
606
+ + echo "Cannot overwrite file $CONFIG! Please delete it."
607
+ + exit 1
608
+ +fi
609
+ +
610
+ +cflags() {
611
+ + CFLAGS="$CFLAGS $1"
612
+ +}
613
+ +
614
+ +lflags() {
615
+ + LDFLAGS="$LDFLAGS $1"
616
+ +}
617
+ +
618
+ +status() {
619
+ + printf "%10s: %s\n" "$1" "$2"
620
+ +}
621
+ +
622
+ +# Append to CFLAGS if compiler supports flag, with optional prerequisite.
623
+ +# Fails on errors and warnings.
624
+ +conditional_cflags() {
625
+ + if [ -z "$(echo | "$CC" -xc -S -o /dev/null $2 $1 - 2>&1)" ]; then
626
+ + cflags "$1"
627
+ + fi
628
+ +}
629
+ +
630
+ +# returns first matching file in directory
631
+ +find_f() {
632
+ + echo $(find "$1" -not -type d -name "$2" -print -quit 2> /dev/null)
633
+ +}
634
+ +
635
+ +# returns first matching file in directory (no symlinks)
636
+ +find_h() {
637
+ + echo $(find "$1" -type f -name "$2" -print -quit 2> /dev/null)
638
+ +}
639
+ +
640
+ +find_pkgconfig() {
641
+ + local LIBNAME=$1
642
+ + if pkg-config --exists "$LIBNAME" &> /dev/null; then
643
+ + cflags "$(pkg-config --cflags "$LIBNAME")"
644
+ + lflags "$(pkg-config --libs "$LIBNAME")"
645
+ + status "$LIBNAME" "shared ($(pkg-config --modversion "$LIBNAME"))"
646
+ + return 0
647
+ + fi
648
+ + return 1
649
+ +}
650
+ +
651
+ +find_static() {
652
+ + local LIBNAME=$1
653
+ + local HEADERPATTERN=$2
654
+ + local STATICPATTERN=$3
655
+ +
656
+ + local HPATH=$(find_h . "$HEADERPATTERN")
657
+ + if [ -n "$HPATH" ]; then
658
+ + local APATH=$(find_f . "$STATICPATTERN")
659
+ + if [ -n "$APATH" ]; then
660
+ + cflags "-I${HPATH%/*}"
661
+ + lflags "${APATH}"
662
+ + status "$LIBNAME" "static"
663
+ + return 0
664
+ + fi
665
+ + fi
666
+ + return 1
667
+ +}
668
+ +
669
+ +find_dynamic() {
670
+ + local LIBNAME=$1
671
+ + local HEADERPATTERN=$2
672
+ + local DYNAMICPATTERN=$3
673
+ + local HEADERDIR=$4
674
+ + local LIBDIR=$5
675
+ +
676
+ + local HPATH=$(find_h "$HEADERDIR" "$HEADERPATTERN")
677
+ + if [ -n "$HPATH" ]; then
678
+ + local SOPATH=$(find_f "$LIBDIR" "$DYNAMICPATTERN")
679
+ + if [ -n "$SOPATH" ]; then
680
+ + cflags "-I${HPATH%/*}"
681
+ + lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
682
+ + status "$LIBNAME" "shared ... $SOPATH"
683
+ + return 0
684
+ + fi
685
+ + fi
686
+ + return 1
687
+ +}
688
+ +
689
+ +find_library() {
690
+ + local LIBNAME=$1
691
+ + local DYNAMICLIBNAME=$2
692
+ + local HEADERPATTERN=$3
693
+ + local STATICPATTERN=$4
694
+ + local DYNAMICPATTERN=$5
695
+ +
696
+ + # try static in current directory first
697
+ + if find_static "$LIBNAME" "$HEADERPATTERN" "$STATICPATTERN"; then
698
+ + return 0;
699
+ + fi
700
+ +
701
+ + # try shared
702
+ + if find_pkgconfig "$LIBNAME"; then
703
+ + return 0
704
+ + fi
705
+ +
706
+ + for i in "${DIRS[@]}"; do
707
+ + DIR=($i)
708
+ + if find_dynamic "$LIBNAME" "$HEADERPATTERN" "$DYNAMICPATTERN" "${DIR[0]}" "${DIR[1]}"; then
709
+ + return 0
710
+ + fi
711
+ + done
712
+ + return 1
713
+ +}
714
+ +
715
+ +# returns full png.h version string
716
+ +pngh_string() {
717
+ + echo "$(grep -m1 "define PNG_LIBPNG_VER_STRING" "$1" | \
718
+ + grep -Eo '"[^"]+"' | grep -Eo '[^"]+')"
719
+ +}
720
+ +
721
+ +# returns major minor version numbers from png.h
722
+ +pngh_majmin() {
723
+ + local MAJ=$(grep -m1 "define PNG_LIBPNG_VER_MAJOR" "$1" | grep -Eo "[0-9]+")
724
+ + local MIN=$(grep -m1 "define PNG_LIBPNG_VER_MINOR" "$1" | grep -Eo "[0-9]+")
725
+ + echo "${MAJ}${MIN}"
726
+ +}
727
+ +
728
+ +error() {
729
+ + status "$1" "error ... $2"
730
+ + echo
731
+ + exit 1
732
+ +}
733
+ +
734
+ +echo
735
+ +
736
+ +# basic check
737
+ +if ! echo "int main(){}" | "$CC" -xc -std=c99 -o /dev/null - > /dev/null; then
738
+ + error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
739
+ +fi
740
+ +
741
+ +status "Compiler" "$CC"
742
+ +
743
+ +# init flags
744
+ +CFLAGS=${CFLAGS:--O3 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
745
+ +cflags "-std=c99 -I."
746
+ +
747
+ +# DEBUG
748
+ +if [ -z "$DEBUG" ]; then
749
+ + cflags "-DNDEBUG"
750
+ + status "Debug" "no"
751
+ +else
752
+ + cflags "-g"
753
+ + status "Debug" "yes"
754
+ +fi
755
+ +
756
+ +# SSE
757
+ +if [ "$SSE" = 'auto' ]; then
758
+ + if [[ "$(uname -m)" =~ (amd|x86_)64 ||
759
+ + "$(grep -E -m1 "^flags" /proc/cpuinfo)" =~ "sse" ]]; then
760
+ + SSE=1
761
+ + fi
762
+ +fi
763
+ +
764
+ +if [ "$SSE" -eq 1 ]; then
765
+ + status "SSE" "yes"
766
+ + cflags "-DUSE_SSE=1"
767
+ + cflags "-msse"
768
+ + # Silence a later ICC warning due to -msse working slightly different.
769
+ + conditional_cflags "-wd10121"
770
+ + # Must be set explicitly for GCC on x86_32. Other compilers imply it.
771
+ + conditional_cflags "-mfpmath=sse" "-msse"
772
+ +elif [ "$SSE" -eq 0 ]; then
773
+ + status "SSE" "no"
774
+ + cflags "-DUSE_SSE=0"
775
+ +fi
776
+ +
777
+ +# OpenMP
778
+ +if [ -n "$OPENMP" ]; then
779
+ + if [ "static" = "$OPENMP" ]; then
780
+ + OPENMPFLAGS="-static-libgcc -Bstatic -fopenmp -Bdynamic"
781
+ + else
782
+ + OPENMPFLAGS="-fopenmp"
783
+ + fi
784
+ + if [[ "$("$CC" -xc -E $OPENMPFLAGS <(echo "#ifdef _OPENMP
785
+ + #include <omp.h>
786
+ + #endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
787
+ + cflags "$OPENMPFLAGS"
788
+ + lflags "$OPENMPFLAGS"
789
+ + status "OpenMP" "yes"
790
+ + else
791
+ + error "OpenMP" "not supported by compiler (please install a compiler that supports OpenMP (e.g. gcc) and specify it with the CC= argument)"
792
+ + fi
793
+ +else
794
+ + # silence warnings about omp pragmas
795
+ + cflags "-Wno-unknown-pragmas"
796
+ + conditional_cflags "-wd3180" # ICC
797
+ + status "OpenMP" "no"
798
+ +fi
799
+ +
800
+ +# Cocoa
801
+ +if [[ "$OSTYPE" =~ "darwin" ]]; then
802
+ + cflags "-mmacosx-version-min=10.6"
803
+ + lflags "-mmacosx-version-min=10.6"
804
+ +
805
+ + if [ "$COCOA_READER" != 0 ] && "$CC" 2>/dev/null 1>/dev/null -xc -E <(echo "#import <Cocoa/Cocoa.h>"); then
806
+ + COCOA_READER=1
807
+ + cflags "-DUSE_COCOA=1"
808
+ + lflags "-framework Cocoa"
809
+ + status "Cocoa" "yes"
810
+ + else
811
+ + status "Cocoa" "no"
812
+ + fi
813
+ +fi
814
+ +
815
+ +# pairs of possible *.h and lib*.so locations
816
+ +DIRS=()
817
+ +
818
+ +if command -v >/dev/null libpng-config; then
819
+ + DIRS+=("$(libpng-config --prefix) $(libpng-config --libdir)")
820
+ +fi
821
+ +
822
+ +DIRS+=("/usr/local/include /usr/local/lib"
823
+ + "/usr/include /usr/lib"
824
+ + "/opt/local/include /opt/local/lib" # macports
825
+ + )
826
+ +
827
+ +if [[ "$OSTYPE" =~ "darwin" ]]; then
828
+ + SOLIBSUFFIX=dylib
829
+ +
830
+ + # Search Developer SDK paths, since Apple seems to have dropped the standard Unixy ones
831
+ + XCODE_CMD="xcode-select"
832
+ + XCODE_PATH=$($XCODE_CMD -p)
833
+ + DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib")
834
+ + DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib")
835
+ +else
836
+ + SOLIBSUFFIX=so
837
+ +fi
838
+ +
839
+ +
840
+ +# libpng
841
+ +# try if given flags are enough
842
+ +HAS_LIBPNG=0
843
+ +if echo "#include \"png.h\"
844
+ + int main(){
845
+ + return !png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
846
+ +}" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then
847
+ + status "libpng" "custom flags"
848
+ + HAS_LIBPNG=1
849
+ +fi
850
+ +
851
+ +if [ "$HAS_LIBPNG" -eq 0 ]; then
852
+ + # try static in the given directory
853
+ + PNGH=$(find_h "$LIBPNG_DIR" "png.h")
854
+ + if [ -n "$PNGH" ]; then
855
+ + PNGH_STRING=$(pngh_string "$PNGH")
856
+ + PNGH_MAJMIN=$(pngh_majmin "$PNGH")
857
+ + if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
858
+ + LIBPNGA=$(find_f "$LIBPNG_DIR" "libpng${PNGH_MAJMIN}.a")
859
+ + if [ -n "$LIBPNGA" ]; then
860
+ + cflags "-I${PNGH%/*}"
861
+ + lflags "${LIBPNGA}"
862
+ + status "libpng" "static (${PNGH_STRING})"
863
+ + HAS_LIBPNG=1
864
+ + fi
865
+ + fi
866
+ + fi
867
+ +fi
868
+ +# try shared
869
+ +if [ "$HAS_LIBPNG" -eq 0 ]; then
870
+ + if find_pkgconfig libpng; then
871
+ + HAS_LIBPNG=1
872
+ + else
873
+ + for i in "${DIRS[@]}"; do
874
+ + DIR=($i)
875
+ + PNGH=$(find_h "${DIR[0]}" "png.h")
876
+ + if [ -n "$PNGH" ]; then
877
+ + PNGH_STRING=$(pngh_string "$PNGH")
878
+ + PNGH_MAJMIN=$(pngh_majmin "$PNGH")
879
+ + if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
880
+ + LIBPNGSO=$(find_f "${DIR[1]}" "libpng${PNGH_MAJMIN}.$SOLIBSUFFIX*")
881
+ + if [ -n "$LIBPNGSO" ]; then
882
+ + cflags "-I${PNGH%/*}"
883
+ + lflags "-L${LIBPNGSO%/*} -lpng${PNGH_MAJMIN}"
884
+ + status "libpng" "shared (${PNGH_STRING})"
885
+ + HAS_LIBPNG=1
886
+ + break
887
+ + fi
888
+ + fi
889
+ + fi
890
+ + done
891
+ + fi
892
+ +fi
893
+ +if [ "$HAS_LIBPNG" -eq 0 ]; then
894
+ + if [[ "$OSTYPE" =~ "darwin" ]]; then
895
+ + LIBPNG_CMD='`brew install libpng`'
896
+ + else
897
+ + LIBPNG_CMD='`apt-get install libpng16-dev` or `apt-get install libpng-dev` or `yum install libpng-devel`'
898
+ + fi
899
+ + error "libpng" "not found (try: $LIBPNG_CMD)"
900
+ +fi
901
+ +
902
+ +# zlib
903
+ +if ! find_library "zlib" "z" "zlib.h" "libz.a" "libz.$SOLIBSUFFIX*"; then
904
+ + error "zlib" "not found (please install zlib-devel package)"
905
+ +fi
906
+ +
907
+ +# lcms2
908
+ +if [ "$LCMS2" != 0 ]; then
909
+ + if find_library "lcms2" "lcms2" "lcms2.h" "liblcms2.a" "liblcms2.$SOLIBSUFFIX*"; then
910
+ + cflags "-DUSE_LCMS=1"
911
+ + else
912
+ + if [ "$LCMS2" = 'auto' ]; then
913
+ + status "lcms2" "no"
914
+ + else
915
+ + error "lcms2" "not found (please install libcms2-devel package)"
916
+ + fi
917
+ + fi
918
+ +else
919
+ + status "lcms2" "no"
920
+ +fi
921
+ +
922
+ +echo
923
+ +
924
+ +# As of GCC 4.5, 387 fp math is significantly slower in C99 mode without this.
925
+ +# Note: CPUs without SSE2 use 387 for doubles, even when SSE fp math is set.
926
+ +conditional_cflags "-fexcess-precision=fast"
927
+ +
928
+ +# Intel C++ Compiler
929
+ +
930
+ +# ICC does usually only produce fast(er) code when it can optimize to the full
931
+ +# capabilites of the (Intel) CPU. This is equivalent to -march=native for GCC.
932
+ +conditional_cflags "-xHOST"
933
+ +
934
+ +# Disable unsafe fp optimizations and enforce fp precision as set in the source.
935
+ +conditional_cflags "-fp-model source"
936
+ +
937
+ +# Silence a gold linker warning about string misalignment.
938
+ +conditional_cflags "-falign-stack=maintain-16-byte"
939
+ +
940
+ +lflags "-lm" # Ubuntu requires this library last, issue #38
941
+ +
942
+ +if [ -n "$EXTRA_CFLAGS" ]; then
943
+ + cflags "$EXTRA_CFLAGS"
944
+ +fi
945
+ +
946
+ +if [ -n "$EXTRA_LDFLAGS" ]; then
947
+ + lflags "$EXTRA_LDFLAGS"
948
+ +fi
949
+ +
950
+ +# Overwrite previous configuration.
951
+ +echo "
952
+ +# auto-generated by configure
953
+ +PREFIX = $PREFIX
954
+ +VERSION = $VERSION
955
+ +CC = $CC
956
+ +CFLAGS = $CFLAGS
957
+ +LDFLAGS = $LDFLAGS
958
+ +COCOA_READER = $COCOA_READER
959
+ +" > "$CONFIG"
960
+ +
961
+ +# Configure static library the same way
962
+ +cp "$CONFIG" lib/
963
+ --
964
+ 2.8.3
965
+