-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
250 lines (215 loc) · 6.75 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
#!/bin/bash
#----------------------------------------------------------------------------------------------
# configure script
#----------------------------------------------------------------------------------------------
# -- help -------------------------------------------------------------------------------------
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
cat << EOF
Usage: [PKG_CONFIG_PATH=/foo/bar/lib/pkgconfig] ./configure [options]
options:
-h, --help print help (this)
--prefix=PREFIX set dir for headers and lids [NONE]
--libdir=DIR set dir for libs [NONE]
--includedir=DIR set dir for headers [NONE]
--extra-cflags=XCFLAGS add XCFLAGS to CFLAGS
--extra-ldflags=XLDFLAGS add XLDFLAGS to LDFLAGS
--extra-libs=XLIBS add XLIBS to LIBS
--cross-prefix=PREFIX use PREFIX for compilation tools
--sysroot=SYSROOT root of cross-build tree
EOF
exit 1
fi
#-- func --------------------------------------------------------------------------------------
error_exit()
{
echo error: $1
exit 1
}
log_echo()
{
echo $1
echo >> config.log
echo --------------------------------- >> config.log
echo $1 >> config.log
}
cc_check()
{
rm -f conftest.c
if [ -n "$3" ]; then
echo "#include <$3>" >> config.log
echo "#include <$3>" > conftest.c
fi
echo "int main(void){$4 return 0;}" >> config.log
echo "int main(void){$4 return 0;}" >> conftest.c
echo $CC conftest.c -o conftest $1 $2 >> config.log
$CC conftest.c -o conftest $1 $2 2>> config.log
ret=$?
echo $ret >> config.log
rm -f conftest*
return $ret
}
#----------------------------------------------------------------------------------------------
rm -f config.* .depend
SRCDIR="$(cd $(dirname $0); pwd)"
test "$SRCDIR" = "$(pwd)" && SRCDIR=.
test -n "$(echo $SRCDIR | grep ' ')" && \
error_exit "out-of-tree builds are impossible with whitespace in source path"
# -- init -------------------------------------------------------------------------------------
CC="gcc"
LD="gcc"
RC="windres"
STRIP="strip"
prefix=""
includedir=""
libdir=""
CFLAGS="-Wall -std=c99 -I. -I$SRCDIR"
LDFLAGS="-L."
DEPLIBS="liblsmash opus"
EXT=""
SRC_MP4OPUSENC="mp4opusenc.c"
SRC_MP4OPUSDEC="mp4opusdec.c"
# -- options ----------------------------------------------------------------------------------
echo all command lines: > config.log
echo "$*" >> config.log
for opt; do
optarg="${opt#*=}"
case "$opt" in
--prefix=*)
prefix="$optarg"
;;
--libdir=*)
libdir="$optarg"
;;
--includedir=*)
includedir="$optarg"
;;
--extra-cflags=*)
XCFLAGS="$optarg"
;;
--extra-ldflags=*)
XLDFLAGS="$optarg"
;;
--extra-libs=*)
XLIBS="$optarg"
;;
--cross-prefix=*)
CROSS="$optarg"
;;
--sysroot=*)
CFLAGS="$CFLAGS --sysroot=$optarg"
LDFLAGS="$LDFLAGS --sysroot=$optarg"
;;
*)
error_exit "unknown option $opt"
;;
esac
done
# -- add extra --------------------------------------------------------------------------------
if test -n "$prefix"; then
CFLAGS="$CFLAGS -I$prefix/include"
LDFLAGS="$LDFLAGS -L$prefix/lib"
fi
test -n "$includedir" && CFLAGS="$CFLAGS -I$includedir"
test -n "$libdir" && LDFLAGS="$LDFLAGS -L$libdir"
CFLAGS="$CFLAGS $XCFLAGS"
LDFLAGS="$LDFLAGS $XLDFLAGS"
# -- check_exe --------------------------------------------------------------------------------
CC="${CROSS}${CC}"
LD="${CROSS}${LD}"
RC="${CROSS}${RC}"
STRIP="${CROSS}${STRIP}"
for f in "$CC" "$LD" "$RC" "$STRIP"; do
test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
done
if test -n "$TARGET_OS"; then
TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
else
TARGET_OS=$($CC -dumpmachine | tr '[A-Z]' '[a-z]')
fi
case "$TARGET_OS" in
*mingw*)
EXT=".exe"
;;
*cygwin*)
EXT=".exe"
;;
*)
;;
esac
# -- check & set cflags and ldflags ----------------------------------------------------------
log_echo "CFLAGS/LDFLAGS checking..."
if ! cc_check "$CFLAGS" "$LDFLAGS"; then
error_exit "invalid CFLAGS/LDFLAGS"
fi
if cc_check "-Os -ffast-math $CFLAGS" "$LDFLAGS"; then
CFLAGS="-Os -ffast-math $CFLAGS"
fi
if cc_check "$CFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
CFLAGS="$CFLAGS -fexcess-precision=fast"
fi
# -- check pkg-config ----------------------------------------------------------------
PKGCONFIGEXE="pkg-config"
test -n "$(which ${CROSS}${PKGCONFIGEXE} 2> /dev/null)" && \
PKGCONFIGEXE=${CROSS}${PKGCONFIGEXE}
if $PKGCONFIGEXE --exists $DEPLIBS 2> /dev/null; then
LIBS="$($PKGCONFIGEXE --libs $DEPLIBS)"
CFLAGS="$CFLAGS $($PKGCONFIGEXE --cflags $DEPLIBS)"
else
for lib in $DEPLIBS; do
LIBS="$LIBS -l${lib#lib}"
done
log_echo "warning: pkg-config or pc files not found, lib detection may be inaccurate."
fi
# -- check liblsmash -----------------------------------------------------------------------------
log_echo "checking for liblsmash..."
if ! cc_check "$CFLAGS" "$LDFLAGS $LIBS $XLIBS" "lsmash.h" "lsmash_create_root();" ; then
log_echo "error: liblsmash checking failed"
error_exit "lsmash.h might not be installed or some libs missing."
fi
# -- check libopus -----------------------------------------------------------------------------
log_echo "checking for libopus..."
if ! cc_check "$CFLAGS" "$LDFLAGS $LIBS $XLIBS" "opus/opus_multistream.h" "opus_multistream_decoder_init((void*)1,0,0,0,0,(void*)1);" ; then
log_echo "error: libopus checking failed"
error_exit "opus_multistream.h might not be installed or some libs missing."
fi
LIBS="$LIBS $XLIBS"
# -- output config.mak ------------------------------------------------------------------------
rm -f config.mak
cat >> config.mak << EOF
CC = $CC
LD = $LD
RC = $RC
STRIP = $STRIP
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
LIBS = $LIBS
SRCDIR = $SRCDIR
SRC_MP4OPUSENC = $SRC_MP4OPUSENC
SRC_MP4OPUSDEC = $SRC_MP4OPUSDEC
MP4OPUSENC = mp4opusenc$EXT
MP4OPUSDEC = mp4opusdec$EXT
EOF
cat >> config.log << EOF
---------------------------------
setting
---------------------------------
EOF
cat config.mak >> config.log
cat << EOF
settings...
CC = $CC
LD = $LD
RC = $RC
STRIP = $STRIP
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
LIBS = $LIBS
EOF
test "$SRCDIR" = "." || cp -f $SRCDIR/GNUmakefile .
# ---------------------------------------------------------------------------------------------
cat << EOF
configure finished.
type 'make' : compile all tools
type 'make mp4opusenc' : compile mp4opusenc
type 'make mp4opusdec' : compile mp4opusdec
EOF