-
Notifications
You must be signed in to change notification settings - Fork 10
/
configure
executable file
·206 lines (179 loc) · 5.22 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
#!/usr/bin/env bash
CC="${CC:-cc}"
AR="${AR:-ar}"
PREFIX="${PREFIX:-/usr/local}"
CFLAGS="-march=native -mtune=native -std=gnu99 $CFLAGS"
with_fftw=true
with_libjpeg=true
with_libpng=true
with_mjpegtools=true
with_MagicWand=true
use_builtin_signbit=true
verbose=false
testcmd_out=/dev/null
testcmd_err=/dev/null
function usage() {
echo "./configure --opt=arg"
echo ""
echo " --cc \"$CC\""
echo " --ar \"$AR\""
echo " --cflags \"$CFLAGS\""
echo " --prefix \"$PREFIX\""
echo " --binprefix \"$PREFIX/bin\""
echo " --libprefix \"$PREFIX/lib\""
echo " --incprefix \"$PREFIX/include\""
echo " --pcprefix \"$PREFIX/lib/pkgconfig\""
echo ""
echo " --disable-fftw"
echo " --disable-libjpeg"
echo " --disable-libpng"
echo " --disable-mjpegtools"
echo " --disable-MagickWand"
echo " --disable-everything"
echo ""
echo " --default-range [n] (12)"
echo " --coeff-precision [4|8|12] (4)"
echo " --inter-precision [4|8|12] (8)"
echo " --pixel-max (SIZE_MAX)"
echo " --no-builtin-signbit"
echo ""
echo " --verbose"
exit 0
}
for o; do
opt="${o%%=*}"
arg="${o#*=}"
case "$opt" in
--cc) CC="$arg";;
--ar) AR="$arg";;
--cflags) CFLAGS="$arg";;
--prefix) PREFIX="$arg";;
--binprefix) BINPREFIX="$arg";;
--libprefix) LIBPREFIX="$arg";;
--incprefix) INCPREFIX="$arg";;
--disable-fftw ) with_fftw=false;;
--disable-libjpeg ) with_libjpeg=false;;
--disable-libpng ) with_libpng=false;;
--disable-mjpegtools) with_mjpegtools=false;;
--disable-MagickWand) with_MagickWand=false;;
--disable-everything) with_fftw=false; with_libjpeg=false; with_libpng=false; with_mjpegtools=false; with_MagickWand=false;;
--default-range) DEFAULT_RANGE=$arg;;
--coeff-precision) COEFF_PRECISION=$arg;;
--inter-precision) INTER_PRECISION=$arg;;
--pixel-max) PIXEL_MAX=$arg;;
--no-builtin-signbit) use_builtin_signbit=false;;
--verbose) verbose=true; testcmd_out=/dev/stdout; testcmd_err=/dev/stderr;;
--help) usage;;
esac
done
BINPREFIX="${BINPREFIX:-$PREFIX/bin}"
LIBPREFIX="${LIBPREFIX:-$PREFIX/lib}"
INCPREFIX="${INCPREFIX:-$PREFIX/include}"
PCPREFIX="${PCPREFIX:-$PREFIX/lib/pkgconfig}"
function abort() {
echo "${1:-Aborting}"
rm -f config.mak
exit 1
}
function testcmd() {
printf "Testing for %s... " "$1"
$verbose && printf "\n$ %s\n" "${*:2}"
"${@:2}" > "$testcmd_out" 2> "$testcmd_err"
ret=$?
if [ $ret -eq 0 ]; then
printf "ok\n"
else
printf "not found\n"
fi
$verbose && printf "\n"
return $ret
}
function testpc() {
testcmd "$1" pkg-config --exists "$1"
}
function testbin() {
testcmd "$1" command -v "$1"
}
function testcc() {
testcmd "$1" "$CC" $CFLAGS -xc "${@:2}" -o /dev/null -
}
function testinc() {
testcc "$1" -fsyntax-only $(printf -- "-include %s " "$@") <<< ""
}
function testlib() {
testcc "$1" $(printf -- "-l%s " "$@") <<< "int main(void){}"
}
function define() {
echo "$1 is \"$2\""
echo "$1=$2" >> config.mak
}
function expand() {
echo "Generating $2"
while read line; do
eval printf \"%s\\n\" \"$line\"
done < "$1" > "$2"
}
function pcver() {
ver="$(pkg-config --modversion "$1")"
echo ${ver%%.*}
}
testbin "$CC" || abort
testbin "$AR" || abort
if $with_libpng || $with_mjpegtools || $with_MagickWand || $with_fftw; then
testbin pkg-config || abort "configuration depends on pkg-config (http://www.freedesktop.org/wiki/Software/pkg-config/)"
fi
echo
rm -f config.mak
define CC "$(command -v "$CC")"
define AR "$(command -v "$AR")"
define CFLAGS "$CFLAGS"
define PREFIX "$PREFIX"
define BINPREFIX "$BINPREFIX"
define LIBPREFIX "$LIBPREFIX"
define INCPREFIX "$INCPREFIX"
define PCPREFIX "$PCPREFIX"
[ -n "$DEFAULT_RANGE" ] && define DEFAULT_RANGE "$DEFAULT_RANGE"
[ -n "$COEFF_PRECISION" ] && define COEFF_PRECISION "$COEFF_PRECISION"
[ -n "$INTER_PRECISION" ] && define INTER_PRECISION "$INTER_PRECISION"
[ -n "$PIXEL_MAX" ] && define PIXEL_MAX "$PIXEL_MAX"
echo
DEFS=
LIBS=
PCDEPS=
lfftw="fftw3f"
case "$COEFF_PRECISION" in
8) lfftw="fftw3"; DEFS+=" -Dkiss_fft_scalar=double";;
12) lfftw="fftw3l"; DEFS+=" -Dkiss_fft_scalar=double";;
esac
if $with_fftw && testpc $lfftw; then
echo "HAVE_FFTW=$(pcver $lfftw)" >> config.mak
PCDEPS+=" $lfftw"
fi
if $with_libjpeg && testinc stdio.h stddef.h jpeglib.h && testlib jpeg; then
echo "HAVE_LIBJPEG=1" >> config.mak
DEFS+=" -DHAVE_LIBJPEG"
LIBS+=" -ljpeg"
fi
for dep in libpng mjpegtools MagickWand; do
check=with_$dep
if ${!check} && testpc $dep; then
name="$(tr '[a-z]' '[A-Z]' <<< $dep)"
ver="$(pcver $dep)"
echo "HAVE_$name=$ver" >> config.mak
DEFS+=" -DHAVE_$name=$ver"
PCDEPS+=" $dep"
fi
done
testlib m && LIBS+=" -lm"
$use_builtin_signbit && testcc __builtin_signbit -fsyntax-only <<< "void f() { (void)__builtin_signbit(1.0); }" && DEFS+=" -DUSE_BUILTIN_SIGNBIT"
echo
expand lib/resdet.pc.in lib/resdet.pc
if [ -n "$PCDEPS" ]; then
DEFS+=" $(pkg-config --cflags $PCDEPS 2> /dev/null)"
LIBS+=" $(pkg-config --libs $PCDEPS 2> /dev/null)"
fi
echo "DEFS=$DEFS" >> config.mak
echo "LIBS=$LIBS" >> config.mak
if [[ "$DEFS" = *HAVE_MAGICKWAND* && ("$DEFS" = *HAVE_LIBPNG* || "$DEFS" = *HAVE_LIBJPEG*) ]]; then
echo "Note: building both MagickWand and libjpeg/png support. To read JPEGs and PNGs using ImageMagick, configure with --disable-libpng --disable-libjpeg"
fi