forked from ImageOptim/libimagequant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·276 lines (244 loc) · 7.11 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/usr/bin/env bash
CONFIG="config.mk"
PREFIX="/usr/local"
LIBDIR="$PREFIX/lib"
INCLUDEDIR="$PREFIX/include"
PKGCONFIGDIR="$LIBDIR/pkgconfig"
VERSION=$(grep LIQ_VERSION_STRING libimagequant.h | grep -Eo "2\.[0-9.]+")
DEBUG=
QUIET=0
SSE=auto
OPENMP=
EXTRA_CFLAGS=
EXTRA_LDFLAGS=
# make gcc default compiler unless CC is already set
CC=${CC:-gcc}
help() {
printf "%4s %s\n" "" "$1"
}
for i in "$@"; do
case $i in
--help|-h)
echo
help "--prefix=<dir> installation directory [$PREFIX]"
help "--libdir=<dir> installation directory [$LIBDIR]"
help "--includedir=<dir> installation directory [$INCLUDEDIR]"
help "--pkgconfigdir=<dir> installation directory [$PKGCONFIGDIR]"
help "--extra-cflags=<flags> append to CFLAGS"
help "--extra-ldflags=<flags> append to LDFLAGS"
echo
help "--enable-debug"
help "--enable-sse/--disable-sse enable/disable SSE instructions"
echo
help "--with-openmp=static compile with multicore support"
echo
help "CC=<compiler> use given compiler command"
help "CFLAGS=<flags> pass options to the compiler"
help "LDFLAGS=<flags> pass options to the linker"
echo
exit 0
;;
# Can be set before or after configure. Latter overrides former.
CC=*)
CC=${i#*=}
;;
CFLAGS=*)
CFLAGS=${i#*=}
;;
LDFLAGS=*)
LDFLAGS=${i#*=}
;;
--enable-debug)
DEBUG=1
;;
--enable-sse)
SSE=1
;;
--disable-sse)
SSE=0
;;
--quiet)
QUIET=1
;;
'')
# allows a bash quirk
;;
--with-openmp)
OPENMP=1
;;
--with-openmp=static)
OPENMP=static
;;
--prefix=*)
PREFIX=${i#*=}
LIBDIR="$PREFIX/lib"
INCLUDEDIR="$PREFIX/include"
PKGCONFIGDIR="$LIBDIR/pkgconfig"
;;
--libdir=*)
LIBDIR=${i#*=}
PKGCONFIGDIR="$LIBDIR/pkgconfig"
;;
--includedir=*)
INCLUDEDIR=${i#*=}
;;
--pkgconfigdir=*)
PKGCONFIGDIR=${i#*=}
;;
# can be used multiple times or in quotes to set multiple flags
--extra-cflags=*)
EXTRA_CFLAGS="$EXTRA_CFLAGS ${i#*=}"
;;
--extra-ldflags=*)
EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
;;
*)
echo "warning: unknown switch '${i%%=*}' (see $0 --help for the list)"
;;
esac
done
# If someone runs sudo make install as very first command, and configure later,
# $CONFIG cannot be overwritten, and must be deleted before continuing.
if [[ -f "$CONFIG" && ! -w "$CONFIG" ]]; then
echo "Cannot overwrite file $CONFIG! Please delete it."
exit 1
fi
cflags() {
CFLAGS="$CFLAGS $1"
}
lflags() {
LDFLAGS="$LDFLAGS $1"
}
status() {
if [ "$QUIET" -ne 1 ]; then
printf "%10s: %s\n" "$1" "$2"
fi
}
# Append to CFLAGS if compiler supports flag, with optional prerequisite.
# Fails on errors and warnings.
conditional_cflags() {
if [ -z "$(echo | "$CC" -xc -S -o /dev/null $2 $1 - 2>&1)" ]; then
cflags "$1"
fi
}
error() {
status "$1" "error ... $2"
echo
exit 1
}
if [ "$QUIET" -ne 1 ]; then
echo
fi
echo > pngquant-gcccheck.c "int main(){}"
if ! "$CC" -std=c99 -o pngquant-gcccheck pngquant-gcccheck.c; then
rm -f pngquant-gcccheck pngquant-gcccheck.c
error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
fi
rm -f pngquant-gcccheck pngquant-gcccheck.c
status "Compiler" "$CC"
# init flags
CFLAGS=${CFLAGS:--fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
cflags "-std=c99 -I."
# DEBUG
if [ -z "$DEBUG" ]; then
cflags "-O3 -DNDEBUG"
status "Debug" "no"
else
cflags "-O1 -g"
status "Debug" "yes"
fi
# SSE
if [ "$SSE" = 'auto' ]; then
SSE=0
if type uname > /dev/null; then
if [[ "$(uname -m)" =~ "amd64" || "$(uname -m)" =~ "x86_64" ||
"$(grep -E -m1 "^flags" /proc/cpuinfo)" =~ "sse" ]]; then
SSE=1
fi
fi
fi
if [ "$SSE" -eq 1 ]; then
status "SSE" "yes"
cflags "-DUSE_SSE=1"
cflags "-msse"
# Silence a later ICC warning due to -msse working slightly different.
conditional_cflags "-wd10121"
# Must be set explicitly for GCC on x86_32. Other compilers imply it.
conditional_cflags "-mfpmath=sse" "-msse"
elif [ "$SSE" -eq 0 ]; then
status "SSE" "no"
cflags "-DUSE_SSE=0"
fi
# OpenMP
if [ -n "$OPENMP" ]; then
if [ "static" = "$OPENMP" ]; then
OPENMPFLAGS="-static-libgcc -Bstatic -fopenmp -Bdynamic"
else
OPENMPFLAGS="-fopenmp"
fi
if [[ "$("$CC" -xc -E $OPENMPFLAGS <(echo "#ifdef _OPENMP
#include <omp.h>
#endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
cflags "$OPENMPFLAGS"
lflags "$OPENMPFLAGS"
status "OpenMP" "yes"
else
error "OpenMP" "not supported by compiler (please install a compiler that supports OpenMP (e.g. gcc) and specify it with the CC= argument)"
fi
else
# silence warnings about omp pragmas
cflags "-Wno-unknown-pragmas"
conditional_cflags "-wd3180" # ICC
status "OpenMP" "no"
fi
# Cocoa
if [[ "$OSTYPE" =~ "darwin" ]]; then
cflags "-mmacosx-version-min=10.7"
lflags "-mmacosx-version-min=10.7"
fi
if [[ "$OSTYPE" =~ "darwin" ]]; then
SOLIBSUFFIX=dylib
# Search Developer SDK paths, since Apple seems to have dropped the standard Unixy ones
XCODE_CMD="xcode-select"
XCODE_PATH=$($XCODE_CMD -p)
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")
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")
elif [[ "$OSTYPE" =~ "msys" ]]; then
SOLIBSUFFIX=dll
else
SOLIBSUFFIX=so
fi
if [ "$QUIET" -ne 1 ]; then
echo
fi
# As of GCC 4.5, 387 fp math is significantly slower in C99 mode without this.
# Note: CPUs without SSE2 use 387 for doubles, even when SSE fp math is set.
conditional_cflags "-fexcess-precision=fast"
# Intel C++ Compiler
# ICC does usually only produce fast(er) code when it can optimize to the full
# capabilites of the (Intel) CPU. This is equivalent to -march=native for GCC.
conditional_cflags "-xHOST"
# Disable unsafe fp optimizations and enforce fp precision as set in the source.
conditional_cflags "-fp-model source"
# Silence a gold linker warning about string misalignment.
conditional_cflags "-falign-stack=maintain-16-byte"
lflags "-lm" # Ubuntu requires this library last, issue #38
if [ -n "$EXTRA_CFLAGS" ]; then
cflags "$EXTRA_CFLAGS"
fi
if [ -n "$EXTRA_LDFLAGS" ]; then
lflags "$EXTRA_LDFLAGS"
fi
# Overwrite previous configuration.
echo "
# auto-generated by configure
PREFIX = $PREFIX
LIBDIR = $LIBDIR
INCLUDEDIR = $INCLUDEDIR
PKGCONFIGDIR = $PKGCONFIGDIR
VERSION = $VERSION
CC = $CC
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
SOLIBSUFFIX = $SOLIBSUFFIX
" > "$CONFIG"