configure 45.7 KB
Newer Older
1
#!/bin/bash
2

Loren Merritt's avatar
Loren Merritt committed
3
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
4
5
cat <<EOF
Usage: ./configure [options]
Loren Merritt's avatar
Loren Merritt committed
6

Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
7
8
Help:
  -h, --help               print this message
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
9

Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
10
11
12
13
14
15
16
17
18
19
20
Standard options:
  --prefix=PREFIX          install architecture-independent files in PREFIX
                           [/usr/local]
  --exec-prefix=EPREFIX    install architecture-dependent files in EPREFIX
                           [PREFIX]
  --bindir=DIR             install binaries in DIR [EPREFIX/bin]
  --libdir=DIR             install libs in DIR [EPREFIX/lib]
  --includedir=DIR         install includes in DIR [PREFIX/include]
  --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS
21
  --extra-rcflags=ERCFLAGS add ERCFLAGS to RCFLAGS
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
22
23
24

Configuration options:
  --disable-cli            disable cli
Nikoli's avatar
Nikoli committed
25
26
27
  --system-libx264         use system libx264 instead of internal
  --enable-shared          build shared library
  --enable-static          build static library
Steve Borho's avatar
Steve Borho committed
28
  --disable-opencl         disable OpenCL features
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
29
30
  --disable-gpl            disable GPL-only features
  --disable-thread         disable multithreaded encoding
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
31
  --enable-win32thread     use win32threads (windows only)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
32
33
  --disable-interlaced     disable interlaced encoding support
  --bit-depth=BIT_DEPTH    set output bit depth (8-10) [8]
34
  --chroma-format=FORMAT   output chroma format (420, 422, 444, all) [all]
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
35
36
37
38
39
40

Advanced options:
  --disable-asm            disable platform-specific assembly optimizations
  --enable-debug           add -g
  --enable-gprof           add -pg
  --enable-strip           add -s
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
41
  --enable-pic             build position-independent code
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
42
43

Cross-compilation:
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
44
45
46
47
  --host=HOST              build programs to run on HOST
  --cross-prefix=PREFIX    use PREFIX for compilation tools
  --sysroot=SYSROOT        root of cross-build tree

Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
48
External library support:
49
  --disable-avs            disable avisynth support
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
50
51
52
53
  --disable-swscale        disable swscale support
  --disable-lavf           disable libavformat support
  --disable-ffms           disable ffmpegsource support
  --disable-gpac           disable gpac support
54
  --disable-lsmash         disable lsmash support
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
55

Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
56
EOF
Loren Merritt's avatar
Loren Merritt committed
57
58
59
exit 1
fi

Diogo Franco's avatar
Diogo Franco committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
log_check() {
    echo -n "checking $1... " >> config.log
}

log_ok() {
    echo "yes" >> config.log
}

log_fail() {
    echo "no" >> config.log
}

log_msg() {
    echo "$1" >> config.log
}

Steven Walters's avatar
Steven Walters committed
76
cc_cflags() {
77
78
    # several non gcc compilers issue an incredibly large number of warnings on high warning levels,
    # suppress them by reducing the warning level rather than having to use #pragmas
Steven Walters's avatar
Steven Walters committed
79
80
81
82
    for arg in $*; do
        [[ "$arg" = -falign-loops* ]] && arg=
        [ "$arg" = -fno-tree-vectorize ] && arg=
        [ "$arg" = -Wshadow ] && arg=
Steven Walters's avatar
Steven Walters committed
83
        [ "$arg" = -Wno-maybe-uninitialized ] && arg=
84
85
86
        [[ "$arg" = -mpreferred-stack-boundary* ]] && arg=
        [[ "$arg" = -l* ]] && arg=
        [[ "$arg" = -L* ]] && arg=
Steven Walters's avatar
Steven Walters committed
87
        if [ $compiler_style = MS ]; then
88
89
            [ "$arg" = -ffast-math ] && arg="-fp:fast"
            [ "$arg" = -Wall ] && arg=
Steven Walters's avatar
Steven Walters committed
90
            [ "$arg" = -Werror ] && arg="-W3 -WX"
Steven Walters's avatar
Steven Walters committed
91
92
93
94
95
            [ "$arg" = -g ] && arg=-Z7
            [ "$arg" = -fomit-frame-pointer ] && arg=
            [ "$arg" = -s ] && arg=
            [ "$arg" = -fPIC ] && arg=
        else
96
97
            [ "$arg" = -ffast-math ] && arg=
            [ "$arg" = -Wall ] && arg=
Steven Walters's avatar
Steven Walters committed
98
            [ "$arg" = -Werror ] && arg="-w3 -Werror"
Steven Walters's avatar
Steven Walters committed
99
        fi
Steven Walters's avatar
Steven Walters committed
100
        [ $compiler = CL -a "$arg" = -O3 ] && arg=-O2
Steven Walters's avatar
Steven Walters committed
101
102
103
104
105

        [ -n "$arg" ] && echo -n "$arg "
    done
}

Steven Walters's avatar
Steven Walters committed
106
cl_ldflags() {
Steven Walters's avatar
Steven Walters committed
107
108
    for arg in $*; do
        arg=${arg/LIBPATH/libpath}
109
110
111
112
        [ "${arg#-libpath:}" == "$arg" -a "${arg#-l}" != "$arg" ] && arg=${arg#-l}.lib
        [ "${arg#-L}" != "$arg" ] && arg=-libpath:${arg#-L}
        [ "$arg" = -Wl,--large-address-aware ] && arg=-largeaddressaware
        [ "$arg" = -s ] && arg=
Steven Walters's avatar
Steven Walters committed
113
        [ "$arg" = -Wl,-Bsymbolic ] && arg=
Steven Walters's avatar
Steven Walters committed
114
115
116
117
        [ "$arg" = -fno-tree-vectorize ] && arg=
        [ "$arg" = -Werror ] && arg=
        [ "$arg" = -Wshadow ] && arg=
        [ "$arg" = -Wmaybe-uninitialized ] && arg=
118
        [[ "$arg" = -Qdiag-error* ]] && arg=
Steven Walters's avatar
Steven Walters committed
119
120
121
122

        arg=${arg/pthreadGC/pthreadVC}
        [ "$arg" = avifil32.lib ] && arg=vfw32.lib
        [ "$arg" = gpac_static.lib ] && arg=libgpac_static.lib
123
        [ "$arg" = x264.lib ] && arg=libx264.lib
Steven Walters's avatar
Steven Walters committed
124
125
126
127
128

        [ -n "$arg" ] && echo -n "$arg "
    done
}

129
cc_check() {
Diogo Franco's avatar
Diogo Franco committed
130
    if [ -z "$3" ]; then
131
        if [ -z "$1$2" ]; then
Diogo Franco's avatar
Diogo Franco committed
132
            log_check "whether $CC works"
133
134
        elif [ -z "$1" ]; then
            log_check "for $2"
Diogo Franco's avatar
Diogo Franco committed
135
136
137
138
        else
            log_check "for $1"
        fi
    elif [ -z "$1" ]; then
139
140
141
142
143
        if [ -z "$2" ]; then
            log_check "whether $CC supports $3"
        else
            log_check "whether $CC supports $3 with $2"
        fi
Diogo Franco's avatar
Diogo Franco committed
144
    else
145
        log_check "for $3 in $1";
Diogo Franco's avatar
Diogo Franco committed
146
    fi
147
    rm -f conftest.c
148
149
150
    for arg in $1; do
        echo "#include <$arg>" >> conftest.c
    done
Steven Walters's avatar
Steven Walters committed
151
152
    echo "int main (void) { $3 return 0; }" >> conftest.c
    if [ $compiler_style = MS ]; then
153
        cc_cmd="$CC conftest.c $(cc_cflags $CFLAGS $CHECK_CFLAGS $2) -link $(cl_ldflags $2 $LDFLAGSCLI $LDFLAGS)"
Steven Walters's avatar
Steven Walters committed
154
    else
155
        cc_cmd="$CC conftest.c $CFLAGS $CHECK_CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest"
Steven Walters's avatar
Steven Walters committed
156
157
    fi
    if $cc_cmd >conftest.log 2>&1; then
Diogo Franco's avatar
Diogo Franco committed
158
159
160
161
162
163
164
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
Steven Walters's avatar
Steven Walters committed
165
        log_msg "$cc_cmd"
166
167
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
168
169
170
171
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
        cat conftest.c >> config.log
        log_msg "--------------------------------------------------"
172
173
174
175
176
177
178
    fi
    return $res
}

cpp_check() {
    log_check "whether $3 is true"
    rm -f conftest.c
179
180
181
    for arg in $1; do
        echo "#include <$arg>" >> conftest.c
    done
182
    echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c
Steven Walters's avatar
Steven Walters committed
183
184
185
186
187
188
    if [ $compiler_style = MS ]; then
        cpp_cmd="$CC conftest.c $(cc_cflags $CFLAGS $2) -P"
    else
        cpp_cmd="$CC conftest.c $CFLAGS $2 -E -o conftest"
    fi
    if $cpp_cmd >conftest.log 2>&1; then
189
190
191
192
193
194
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
195
196
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
197
198
199
200
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
        cat conftest.c >> config.log
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
201
202
    fi
    return $res
203
204
}

205
as_check() {
Diogo Franco's avatar
Diogo Franco committed
206
    log_check "whether $AS supports $1"
207
208
209
    echo "$1" > conftest$AS_EXT
    as_cmd="$AS conftest$AS_EXT $ASFLAGS $2 -o conftest.o"
    if $as_cmd >conftest.log 2>&1; then
Diogo Franco's avatar
Diogo Franco committed
210
211
212
213
214
215
216
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
217
        log_msg "$as_cmd"
Diogo Franco's avatar
Diogo Franco committed
218
219
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
220
221
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
222
        cat conftest$AS_EXT >> config.log
223
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
224
225
    fi
    return $res
226
227
}

Henrik Gramner's avatar
Henrik Gramner committed
228
229
230
rc_check() {
    log_check "whether $RC works"
    echo "$1" > conftest.rc
Steven Walters's avatar
Steven Walters committed
231
    if [ $compiler = GNU ]; then
232
        rc_cmd="$RC $RCFLAGS -o conftest.o conftest.rc"
Steven Walters's avatar
Steven Walters committed
233
234
    else
        rc_cmd="$RC $RCFLAGS -foconftest.o conftest.rc"
235
236
    fi
    if $rc_cmd >conftest.log 2>&1; then
Henrik Gramner's avatar
Henrik Gramner committed
237
238
239
240
241
242
243
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
244
        log_msg "$rc_cmd"
Henrik Gramner's avatar
Henrik Gramner committed
245
246
247
248
249
250
251
252
253
254
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
        cat conftest.rc >> config.log
        log_msg "--------------------------------------------------"
    fi
    return $res
}

Diogo Franco's avatar
Diogo Franco committed
255
define() {
Steven Walters's avatar
Steven Walters committed
256
    echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
Diogo Franco's avatar
Diogo Franco committed
257
258
}

259
die() {
Diogo Franco's avatar
Diogo Franco committed
260
    log_msg "DIED: $@"
261
262
263
264
    echo "$@"
    exit 1
}

265
266
configure_system_override() {
    log_check "system libx264 configuration"
267
268
    x264_config_path="$1/x264_config.h"
    if [ -e "$x264_config_path" ]; then
269
270
        res=$?
        log_ok
271
        arg="$(grep '#define X264_GPL ' $x264_config_path | sed -e 's/#define X264_GPL *//; s/ *$//')"
272
273
274
275
        if [ -n "$arg" ]; then
            [ "$arg" = 0 ] && arg="no" || arg="yes"
            [ "$arg" != "$gpl" ] && die "Incompatible license with system libx264"
        fi
276
        arg="$(grep '#define X264_BIT_DEPTH ' $x264_config_path | sed -e 's/#define X264_BIT_DEPTH *//; s/ *$//')"
277
278
279
        if [ -n "$arg" ]; then
            if [ "$arg" != "$bit_depth" ]; then
                echo "Override output bit depth with system libx264 configuration"
280
                bit_depth="$arg"
281
282
            fi
        fi
283
        arg="$(grep '#define X264_CHROMA_FORMAT ' $x264_config_path | sed -e 's/#define X264_CHROMA_FORMAT *//; s/ *$//')"
284
285
286
287
        if [ -n "$arg" ]; then
            [ "$arg" = 0 ] && arg="all" || arg="${arg#X264_CSP_I}"
            if [ "$arg" != "$chroma_format" ]; then
                echo "Override output chroma format with system libx264 configuration"
288
                chroma_format="$arg"
289
290
            fi
        fi
291
        arg="$(grep '#define X264_INTERLACED ' $x264_config_path | sed -e 's/#define X264_INTERLACED *//; s/ *$//')"
292
293
294
295
        if [ -n "$arg" ]; then
            [ "$arg" = 0 ] && arg="no" || arg="yes"
            if [ "$arg" != "$interlaced" ]; then
                echo "Override interlaced encoding support with system libx264 configuration"
296
                interlaced="$arg"
297
298
299
300
301
            fi
        fi
    else
        res=$?
        log_fail
302
        log_msg "Failed search path was: $x264_config_path"
303
304
305
306
    fi
    return $res
}

Steven Walters's avatar
Steven Walters committed
307
rm -f x264_config.h config.h config.mak config.log x264.pc x264.def conftest*
Loren Merritt's avatar
Loren Merritt committed
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# Construct a path to the specified directory relative to the working directory
relative_path() {
    local base="${PWD%/}"
    local path="$(cd "$1" >/dev/null; printf '%s/.' "${PWD%/}")"
    local up=''

    while [[ $path != "$base/"* ]]; do
        base="${base%/*}"
        up="../$up"
    done

    dirname "$up${path#"$base/"}"
}

SRCPATH="$(relative_path "$(dirname "$0")")"
echo "$SRCPATH" | grep -q ' ' && die "Out of tree builds are impossible with whitespace in source path."
325
[ -e "$SRCPATH/config.h" -o -e "$SRCPATH/x264_config.h" ] && die "Out of tree builds are impossible with config.h/x264_config.h in source dir."
Oka Motofumi's avatar
Oka Motofumi committed
326

327
prefix='/usr/local'
Loren Merritt's avatar
Loren Merritt committed
328
329
330
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
libdir='${exec_prefix}/lib'
331
includedir='${prefix}/include'
332
DEVNULL='/dev/null'
333

Nikoli's avatar
Nikoli committed
334
335
336
337
cli="yes"
cli_libx264="internal"
shared="no"
static="no"
Steven Walters's avatar
Steven Walters committed
338
339
340
341
avs="auto"
lavf="auto"
ffms="auto"
gpac="auto"
342
343
lsmash="auto"
mp4="no"
344
gpl="yes"
345
thread="auto"
346
swscale="auto"
347
asm="auto"
348
interlaced="yes"
349
debug="no"
350
gprof="no"
Nikoli's avatar
Nikoli committed
351
strip="no"
352
pic="no"
353
bit_depth="8"
354
chroma_format="all"
Steven Walters's avatar
Steven Walters committed
355
compiler="GNU"
Steven Walters's avatar
Steven Walters committed
356
compiler_style="GNU"
Steve Borho's avatar
Steve Borho committed
357
opencl="yes"
Loren Merritt's avatar
Loren Merritt committed
358

Oka Motofumi's avatar
Oka Motofumi committed
359
CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
360
LDFLAGS="$LDFLAGS"
361
LDFLAGSCLI="$LDFLAGSCLI"
362
ASFLAGS="$ASFLAGS -I. -I\$(SRCPATH)"
363
RCFLAGS="$RCFLAGS"
364
CHECK_CFLAGS=""
365
HAVE_GETOPT_LONG=1
Anton Mitrofanov's avatar
Anton Mitrofanov committed
366
cross_prefix=""
367

Loren Merritt's avatar
Loren Merritt committed
368
EXE=""
369
370
371
AS_EXT=".S"
NL="
"
Loren Merritt's avatar
Loren Merritt committed
372

373
# list of all preprocessor HAVE values we can define
Anton Mitrofanov's avatar
Anton Mitrofanov committed
374
CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
Kaustubh Raste's avatar
Kaustubh Raste committed
375
376
             LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
             MSA"
377

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# parse options

for opt do
    optarg="${opt#*=}"
    case "$opt" in
        --prefix=*)
            prefix="$optarg"
            ;;
        --exec-prefix=*)
            exec_prefix="$optarg"
            ;;
        --bindir=*)
            bindir="$optarg"
            ;;
        --libdir=*)
            libdir="$optarg"
            ;;
        --includedir=*)
            includedir="$optarg"
            ;;
Nikoli's avatar
Nikoli committed
398
399
400
401
402
403
404
405
406
407
408
409
        --disable-cli)
            cli="no"
            ;;
        --system-libx264)
            cli_libx264="system"
            ;;
        --enable-shared)
            shared="yes"
            ;;
        --enable-static)
            static="yes"
            ;;
410
411
412
        --disable-asm)
            asm="no"
            ;;
413
414
415
        --disable-interlaced)
            interlaced="no"
            ;;
Steven Walters's avatar
Steven Walters committed
416
417
        --disable-avs)
            avs="no"
418
            ;;
Steven Walters's avatar
Steven Walters committed
419
420
        --disable-lavf)
            lavf="no"
421
            ;;
Steven Walters's avatar
Steven Walters committed
422
423
        --disable-ffms)
            ffms="no"
424
            ;;
Steven Walters's avatar
Steven Walters committed
425
426
        --disable-gpac)
            gpac="no"
427
            ;;
428
429
430
        --disable-lsmash)
            lsmash="no"
            ;;
431
432
433
        --disable-gpl)
            gpl="no"
            ;;
434
        --extra-asflags=*)
435
            ASFLAGS="$ASFLAGS $optarg"
436
437
            ;;
        --extra-cflags=*)
438
            CFLAGS="$CFLAGS $optarg"
439
440
            ;;
        --extra-ldflags=*)
441
            LDFLAGS="$LDFLAGS $optarg"
442
            ;;
443
444
445
        --extra-rcflags=*)
            RCFLAGS="$RCFLAGS $optarg"
            ;;
446
447
448
449
450
        --disable-thread)
            thread="no"
            ;;
        --enable-win32thread)
            thread="win32"
451
            ;;
452
453
454
        --disable-swscale)
            swscale="no"
            ;;
455
456
457
458
459
460
461
462
        --enable-debug)
            debug="yes"
            ;;
        --enable-gprof)
            CFLAGS="$CFLAGS -pg"
            LDFLAGS="$LDFLAGS -pg"
            gprof="yes"
            ;;
Nikoli's avatar
Nikoli committed
463
464
465
        --enable-strip)
            strip="yes"
            ;;
466
467
468
469
        --enable-pic)
            pic="yes"
            ;;
        --host=*)
470
            host="$optarg"
471
            ;;
Steve Borho's avatar
Steve Borho committed
472
473
474
        --disable-opencl)
            opencl="no"
            ;;
Anton Mitrofanov's avatar
Anton Mitrofanov committed
475
        --cross-prefix=*)
476
            cross_prefix="$optarg"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
477
            ;;
David Conrad's avatar
David Conrad committed
478
        --sysroot=*)
479
480
            CFLAGS="$CFLAGS --sysroot=$optarg"
            LDFLAGS="$LDFLAGS --sysroot=$optarg"
David Conrad's avatar
David Conrad committed
481
            ;;
482
        --bit-depth=*)
483
            bit_depth="$optarg"
484
485
486
487
488
489
            if [ "$bit_depth" -lt "8" -o "$bit_depth" -gt "10" ]; then
                echo "Supplied bit depth must be in range [8,10]."
                exit 1
            fi
            bit_depth=`expr $bit_depth + 0`
            ;;
490
491
492
493
494
495
496
        --chroma-format=*)
            chroma_format="$optarg"
            if [ $chroma_format != "420" -a $chroma_format != "422" -a $chroma_format != "444" -a $chroma_format != "all" ]; then
                echo "Supplied chroma format must be 420, 422, 444 or all."
                exit 1
            fi
            ;;
497
498
499
500
501
502
        *)
            echo "Unknown option $opt, ignored"
            ;;
    esac
done

Nikoli's avatar
Nikoli committed
503
504
[ "$cli" = "no" -a "$shared" = "no" -a "$static" = "no" ] && die "Nothing to build. Enable cli, shared or static."

Anton Mitrofanov's avatar
Anton Mitrofanov committed
505
506
507
508
CC="${CC-${cross_prefix}gcc}"
AR="${AR-${cross_prefix}ar}"
RANLIB="${RANLIB-${cross_prefix}ranlib}"
STRIP="${STRIP-${cross_prefix}strip}"
509
INSTALL="${INSTALL-install}"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
510

511
if [ "x$host" = x ]; then
Oka Motofumi's avatar
Oka Motofumi committed
512
    host=`${SRCPATH}/config.guess`
513
514
fi
# normalize a triplet into a quadruplet
Oka Motofumi's avatar
Oka Motofumi committed
515
host=`${SRCPATH}/config.sub $host`
516

517
# split $host
Loren Merritt's avatar
Loren Merritt committed
518
host_cpu="${host%%-*}"
519
host="${host#*-}"
Loren Merritt's avatar
Loren Merritt committed
520
host_vendor="${host%%-*}"
521
host_os="${host#*-}"
522

523
524
trap 'rm -f conftest*' EXIT

Steven Walters's avatar
Steven Walters committed
525
526
527
# test for use of compilers that require specific handling
cc_base=`basename "$CC"`
QPRE="-"
Steven Walters's avatar
Steven Walters committed
528
if [[ $host_os = mingw* || $host_os = cygwin* ]]; then
529
    if [[ "$cc_base" = icl || "$cc_base" = icl[\ .]* ]]; then
Steven Walters's avatar
Steven Walters committed
530
531
532
        # Windows Intel Compiler creates dependency generation with absolute Windows paths, Cygwin's make does not support Windows paths.
        [[ $host_os = cygwin* ]] && die "Windows Intel Compiler support requires MSYS"
        compiler=ICL
Steven Walters's avatar
Steven Walters committed
533
        compiler_style=MS
534
        CFLAGS="$CFLAGS -Qstd=c99 -nologo -Qms0 -DHAVE_STRING_H -I\$(SRCPATH)/extras"
Steven Walters's avatar
Steven Walters committed
535
536
537
538
        QPRE="-Q"
        `$CC 2>&1 | grep -q IA-32` && host_cpu=i486
        `$CC 2>&1 | grep -q "Intel(R) 64"` && host_cpu=x86_64
        cpp_check "" "" "_MSC_VER >= 1400" || die "Windows Intel Compiler support requires Visual Studio 2005 or newer"
539
540
541
542
        if cc_check '' -Qdiag-error:10006,10157 ; then
            CHECK_CFLAGS="$CHECK_CFLAGS -Qdiag-error:10006,10157"
        fi
    elif [[ "$cc_base" = cl || "$cc_base" = cl[\ .]* ]]; then
Steven Walters's avatar
Steven Walters committed
543
544
545
        # Standard Microsoft Visual Studio
        compiler=CL
        compiler_style=MS
546
        CFLAGS="$CFLAGS -nologo -GS- -DHAVE_STRING_H -I\$(SRCPATH)/extras"
547
548
        `$CC 2>&1 | grep -q 'x86'` && host_cpu=i486
        `$CC 2>&1 | grep -q 'x64'` && host_cpu=x86_64
Steven Walters's avatar
Steven Walters committed
549
        cpp_check '' '' '_MSC_VER > 1800 || (_MSC_VER == 1800 && _MSC_FULL_VER >= 180030324)' || die "Microsoft Visual Studio support requires Visual Studio 2013 Update 2 or newer"
Steven Walters's avatar
Steven Walters committed
550
551
    fi
else
552
    if [[ "$cc_base" = icc || "$cc_base" = icc[\ .]* ]]; then
Steven Walters's avatar
Steven Walters committed
553
554
555
556
557
        AR="xiar"
        compiler=ICC
    fi
fi

558
559
560
561
562
563
if [[ "$cc_base" = clang || "$cc_base" = clang[\ .]* ]]; then
    if cc_check '' -Werror=unknown-warning-option ; then
        CHECK_CFLAGS="$CHECK_CFLAGS -Werror=unknown-warning-option"
    fi
fi

564
libm=""
565
case $host_os in
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
566
567
568
569
570
571
    beos*)
        SYS="BEOS"
        define HAVE_MALLOC_H
        ;;
    darwin*)
        SYS="MACOSX"
572
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
573
574
575
576
577
578
        if [ "$pic" = "no" ]; then
            cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
        fi
        ;;
    freebsd*)
        SYS="FREEBSD"
579
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
580
581
582
583
        ;;
    kfreebsd*-gnu)
        SYS="FREEBSD"
        define HAVE_MALLOC_H
584
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
585
586
587
        ;;
    netbsd*)
        SYS="NETBSD"
588
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
589
590
591
        ;;
    openbsd*)
        SYS="OPENBSD"
592
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
593
594
595
596
        ;;
    *linux*)
        SYS="LINUX"
        define HAVE_MALLOC_H
597
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
598
        ;;
599
600
601
    gnu*)
        SYS="HURD"
        define HAVE_MALLOC_H
602
        libm="-lm"
603
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
604
605
    cygwin*)
        EXE=".exe"
Henrik Gramner's avatar
Henrik Gramner committed
606
        if [ $compiler_style = GNU ] && cc_check "" -mno-cygwin; then
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
607
608
609
            CFLAGS="$CFLAGS -mno-cygwin"
            LDFLAGS="$LDFLAGS -mno-cygwin"
        fi
Diogo Franco's avatar
Diogo Franco committed
610
        if cpp_check "" "" "defined(__CYGWIN__)" ; then
611
612
613
614
615
            define HAVE_MALLOC_H
            SYS="CYGWIN"
        else
            SYS="WINDOWS"
            DEVNULL="NUL"
Henrik Gramner's avatar
Henrik Gramner committed
616
            LDFLAGSCLI="$LDFLAGSCLI -lshell32"
617
            RC="${RC-${cross_prefix}windres}"
618
        fi
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
619
620
        ;;
    mingw*)
Steven Walters's avatar
Steven Walters committed
621
        SYS="WINDOWS"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
622
623
        EXE=".exe"
        DEVNULL="NUL"
Henrik Gramner's avatar
Henrik Gramner committed
624
        LDFLAGSCLI="$LDFLAGSCLI -lshell32"
Steven Walters's avatar
Steven Walters committed
625
        [ $compiler = GNU ] && RC="${RC-${cross_prefix}windres}" || RC="${RC-rc}"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
626
627
628
629
        ;;
    sunos*|solaris*)
        SYS="SunOS"
        define HAVE_MALLOC_H
630
        libm="-lm"
631
632
633
634
635
        if cc_check "" /usr/lib/64/values-xpg6.o; then
            LDFLAGS="$LDFLAGS /usr/lib/64/values-xpg6.o"
        else
            LDFLAGS="$LDFLAGS /usr/lib/values-xpg6.o"
        fi
636
637
638
639
640
641
642
643
644
        if test -x /usr/ucb/install ; then
            INSTALL=/usr/ucb/install
        elif test -x /usr/bin/ginstall ; then
            # OpenSolaris
            INSTALL=/usr/bin/ginstall
        elif test -x /usr/gnu/bin/install ; then
            # OpenSolaris
            INSTALL=/usr/gnu/bin/install
        fi
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
645
646
        HAVE_GETOPT_LONG=0
        ;;
Mike Gorchak's avatar
Mike Gorchak committed
647
648
649
650
651
652
653
    *qnx*)
        SYS="QNX"
        define HAVE_MALLOC_H
        libm="-lm"
        HAVE_GETOPT_LONG=0
        CFLAGS="$CFLAGS -I\$(SRCPATH)/extras"
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
654
655
656
    *)
        die "Unknown system $host, edit the configure"
        ;;
657
658
esac

659
660
LDFLAGS="$LDFLAGS $libm"

661
stack_alignment=16
662
case $host_cpu in
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
663
664
    i*86)
        ARCH="X86"
665
        AS="${AS-yasm}"
666
        AS_EXT=".asm"
667
        ASFLAGS="$ASFLAGS -DARCH_X86_64=0 -I\$(SRCPATH)/common/x86/"
Steven Walters's avatar
Steven Walters committed
668
669
670
671
672
673
674
        if [ $compiler = GNU ]; then
            if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
                CFLAGS="$CFLAGS -march=i686"
            fi
            if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
                CFLAGS="$CFLAGS -mfpmath=sse -msse"
            fi
675
676
            CFLAGS="-m32 $CFLAGS"
            LDFLAGS="-m32 $LDFLAGS"
Steven Walters's avatar
Steven Walters committed
677
        elif [ $compiler = ICC ]; then
Steven Walters's avatar
Steven Walters committed
678
679
680
681
            # icc on linux has various degrees of mod16 stack support
            if [ $SYS = LINUX ]; then
                # < 11 is completely incapable of keeping a mod16 stack
                if cpp_check "" "" "__INTEL_COMPILER < 1100" ; then
682
                    stack_alignment=4
Steven Walters's avatar
Steven Walters committed
683
684
685
686
687
688
                # 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
                elif cpp_check "" "" "__INTEL_COMPILER < 1200" ; then
                    CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
                fi
                # >= 12 defaults to a mod16 stack
            fi
Steven Walters's avatar
Steven Walters committed
689
690
691
        else # ICL/CL
            # always a mod4 stack
            stack_alignment=4
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
692
693
        fi
        if [ "$SYS" = MACOSX ]; then
694
            ASFLAGS="$ASFLAGS -f macho32 -DPREFIX"
695
        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
696
697
            ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
            LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
698
            [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
699
            [ $compiler = GNU ] && RCFLAGS="--target=pe-i386 $RCFLAGS"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
700
        else
701
            ASFLAGS="$ASFLAGS -f elf32"
Sean McGovern's avatar
Sean McGovern committed
702
703
        fi
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
704
705
    x86_64)
        ARCH="X86_64"
706
        AS="${AS-yasm}"
707
        AS_EXT=".asm"
708
        ASFLAGS="$ASFLAGS -DARCH_X86_64=1 -I\$(SRCPATH)/common/x86/"
709
        [ $compiler = GNU ] && CFLAGS="-m64 $CFLAGS" && LDFLAGS="-m64 $LDFLAGS"
710
        if [ "$SYS" = MACOSX ]; then
711
            ASFLAGS="$ASFLAGS -f macho64 -DPIC -DPREFIX"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
712
713
714
715
            if cc_check '' "-arch x86_64"; then
                CFLAGS="$CFLAGS -arch x86_64"
                LDFLAGS="$LDFLAGS -arch x86_64"
            fi
Diogo Franco's avatar
Diogo Franco committed
716
        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
717
            ASFLAGS="$ASFLAGS -f win64"
Steven Walters's avatar
Steven Walters committed
718
719
            # only the GNU toolchain is inconsistent in prefixing function names with _
            [ $compiler = GNU ] && cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
720
            [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
721
            [ $compiler = GNU ] && RCFLAGS="--target=pe-x86-64 $RCFLAGS"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
722
        else
723
            ASFLAGS="$ASFLAGS -f elf64"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
724
725
        fi
        ;;
726
    powerpc*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
727
728
729
        ARCH="PPC"
        if [ $asm = auto ] ; then
            define HAVE_ALTIVEC
730
            AS="${AS-${CC}}"
731
            AS_EXT=".c"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
732
733
734
735
736
737
738
739
740
741
742
            if [ $SYS = MACOSX ] ; then
                CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
            else
                CFLAGS="$CFLAGS -maltivec -mabi=altivec"
                define HAVE_ALTIVEC_H
            fi
        fi
        ;;
    sparc)
        ARCH="SPARC"
        ;;
Kaustubh Raste's avatar
Kaustubh Raste committed
743
    mips*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
744
        ARCH="MIPS"
Kaustubh Raste's avatar
Kaustubh Raste committed
745
746
        AS="${AS-${CC}}"
        AS_EXT=".c"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
747
748
749
750
        ;;
    arm*)
        ARCH="ARM"
        if [ "$SYS" = MACOSX ] ; then
751
            AS="${AS-${SRCPATH}/tools/gas-preprocessor.pl -arch arm -- ${CC}}"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
752
753
754
755
756
757
758
            ASFLAGS="$ASFLAGS -DPREFIX -DPIC"  # apple's ld doesn't support movw/movt relocations at all
            # build for armv7 by default
            if ! echo $CFLAGS | grep -Eq '\-arch' ; then
                CFLAGS="$CFLAGS -arch armv7"
                LDFLAGS="$LDFLAGS -arch armv7"
            fi
        else
759
            AS="${AS-${CC}}"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
760
761
        fi
        ;;
Janne Grunau's avatar
Janne Grunau committed
762
763
764
    aarch64)
        ARCH="AARCH64"
        if [ "$SYS" = MACOSX ] ; then
765
            AS="${AS-${SRCPATH}/tools/gas-preprocessor.pl -arch aarch64 -- ${CC}}"
Janne Grunau's avatar
Janne Grunau committed
766
767
768
769
770
            ASFLAGS="$ASFLAGS -DPREFIX"
        else
            AS="${AS-${CC}}"
        fi
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
771
772
773
    s390|s390x)
        ARCH="S390"
        ;;
774
    hppa*|parisc*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
775
776
777
778
779
        ARCH="PARISC"
        ;;
    ia64)
        ARCH="IA64"
        ;;
780
781
782
    alpha*)
        ARCH="ALPHA"
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
783
784
785
    *)
        ARCH="$(echo $host_cpu | tr a-z A-Z)"
        ;;
786
787
esac

Henrik Gramner's avatar
Henrik Gramner committed
788
789
790
791
792
793
if [ $SYS = WINDOWS ]; then
    if ! rc_check "0 RCDATA {0}" ; then
        RC=""
    fi
fi

Diogo Franco's avatar
Diogo Franco committed
794
795
796
797
798
799
800
801
802
803
log_msg "x264 configure script"
if [ -n "$*" ]; then
    msg="Command line options:"
    for i in $@; do
        msg="$msg \"$i\""
    done
    log_msg "$msg"
fi
log_msg ""

804
805
# check requirements

806
807
cc_check || die "No working C compiler found."

Steven Walters's avatar
Steven Walters committed
808
if [ $compiler_style = GNU ]; then
809
    if cc_check '' -std=gnu99 'for( int i = 0; i < 9; i++ );' ; then
Steven Walters's avatar
Steven Walters committed
810
        CFLAGS="$CFLAGS -std=gnu99"
811
    elif cc_check '' -std=c99 'for( int i = 0; i < 9; i++ );' ; then
Steven Walters's avatar
Steven Walters committed
812
        CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
813
814
    elif ! cc_check '' '' 'for( int i = 0; i < 9; i++ );' ; then
        die "C99 compiler is needed for compilation."
Steven Walters's avatar
Steven Walters committed
815
    fi
816
817
fi

818
if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" -o $ARCH = "PARISC" -o $ARCH = "MIPS" -o $ARCH = "AARCH64" \) ] ; then
819
820
821
    pic="yes"
fi

822
if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
823
    if ! as_check "vpmovzxwd ymm0, xmm0" ; then
824
        VER=`($AS --version || echo no assembler) 2>/dev/null | head -n 1`
825
        echo "Found $VER"
826
        echo "Minimum version is yasm-1.2.0"
827
828
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
829
    fi
Steven Walters's avatar
Steven Walters committed
830
    cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' && define HAVE_X86_INLINE_ASM
831
    ASFLAGS="$ASFLAGS -Worphan-labels"
Diogo Franco's avatar
Diogo Franco committed
832
    define HAVE_MMX
833
    if [ $compiler = GNU ] && cc_check '' -mpreferred-stack-boundary=5 ; then
834
        CFLAGS="$CFLAGS -mpreferred-stack-boundary=5"
835
        stack_alignment=32
836
    fi
837
fi
838

839
if [ $asm = auto -a $ARCH = ARM ] ; then
840
    # set flags so neon is built by default
841
    echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon"
842

David Conrad's avatar
David Conrad committed
843
844
845
    if  cc_check '' '' '__asm__("rev ip, ip");' ; then      define HAVE_ARMV6
        cc_check '' '' '__asm__("movt r0, #0");'         && define HAVE_ARMV6T2
        cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
846
        ASFLAGS="$ASFLAGS -c"
847
    else
848
        echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
849
850
        echo "If you really want to run on such a CPU, configure with --disable-asm."
        exit 1
851
852
853
    fi
fi

Janne Grunau's avatar
Janne Grunau committed
854
855
856
857
858
859
860
861
862
863
864
if [ $asm = auto -a $ARCH = AARCH64 ] ; then
    if  cc_check '' '' '__asm__("cmeq v0.8h, v0.8h, #0");' ; then define HAVE_NEON
        ASFLAGS="$ASFLAGS -c"
    else
        echo "no NEON support, try adding -mfpu=neon to CFLAGS"
        echo "If you really want to run on such a CPU, configure with --disable-asm."
        exit 1
    fi
fi

if [ $asm = auto -a \( $ARCH = ARM -o $ARCH = AARCH64 \) ] ; then
865
866
867
868
    # check if the assembler supports '.func' (clang 3.5 does not)
    as_check ".func test${NL}.endfunc" && define HAVE_AS_FUNC 1
fi

Kaustubh Raste's avatar
Kaustubh Raste committed
869
870
871
872
873
874
875
876
877
878
879
880
881
882
if [ $asm = auto -a $ARCH = MIPS ] ; then
    if ! echo $CFLAGS | grep -Eq '(-march|-mmsa|-mno-msa)' ; then
        cc_check '' '-mmsa -mfp64 -mhard-float' && CFLAGS="-mmsa -mfp64 -mhard-float $CFLAGS"
    fi

    if cc_check '' '' '__asm__("addvi.b $w0, $w1, 1");' ; then
        define HAVE_MSA
    else
        echo "You specified a pre-MSA CPU in your CFLAGS."
        echo "If you really want to run on such a CPU, configure with --disable-asm."
        exit 1
    fi
fi

883
[ $asm = no ] && AS=""
884
[ "x$AS" = x ] && asm="no" || asm="yes"
885

Diogo Franco's avatar
Diogo Franco committed
886
887
define ARCH_$ARCH
define SYS_$SYS
888

889
890
891
define STACK_ALIGNMENT $stack_alignment
ASFLAGS="$ASFLAGS -DSTACK_ALIGNMENT=$stack_alignment"

Steven Walters's avatar
Steven Walters committed
892
# skip endianness check for Intel Compiler and MSVS, as all supported platforms are little. each have flags that will cause the check to fail as well
893
CPU_ENDIAN="little-endian"
Steven Walters's avatar
Steven Walters committed
894
895
if [ $compiler = GNU ]; then
    echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
896
    $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
Steven Walters's avatar
Steven Walters committed
897
898
    if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
        define WORDS_BIGENDIAN
899
        CPU_ENDIAN="big-endian"
Steven Walters's avatar
Steven Walters committed
900
901
902
    elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then
        die "endian test failed"
    fi
Kieran Kunhya's avatar
Kieran Kunhya committed
903
fi
Loren Merritt's avatar
Loren Merritt committed
904

905
906
907
if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then
    [ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static"
    if ${cross_prefix}pkg-config --exists x264 2>/dev/null; then
908
909
910
        X264_LIBS="$(${cross_prefix}pkg-config --libs x264)"
        X264_INCLUDE_DIR="${X264_INCLUDE_DIR-$(${cross_prefix}pkg-config --variable=includedir x264)}"
        configure_system_override "$X264_INCLUDE_DIR" || die "Detection of system libx264 configuration failed"
911
912
913
914
915
    else
        die "Can not find system libx264"
    fi
fi

916
917
# autodetect options that weren't forced nor disabled

918
# pthread-win32 is lgpl, prevent its use if --disable-gpl is specified and targeting windows
Steven Walters's avatar
Steven Walters committed
919
[ "$SYS" = "WINDOWS" -a "$gpl" = "no" -a "$thread" = "auto" ] && thread="win32"
920

921
libpthread=""
922
923
if [ "$thread" = "auto" ]; then
    thread="no"
924
    case $SYS in
925
        BEOS)
926
927
            thread="beos"
            define HAVE_BEOSTHREAD
928
            ;;
Steven Walters's avatar
Steven Walters committed
929
        WINDOWS)
930
            if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
931
                thread="posix"
932
933
                libpthread="-lpthread"
            elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
934
                thread="posix"
935
936
                libpthread="-lpthreadGC2"
            elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
937
                thread="posix"
Loren Merritt's avatar
Loren Merritt committed
938
                libpthread="-lpthreadGC2 -lwsock32"
Diogo Franco's avatar
Diogo Franco committed
939
                define PTW32_STATIC_LIB
Anton Mitrofanov's avatar
Anton Mitrofanov committed
940
            elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
941
                thread="posix"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
942
                libpthread="-lpthreadGC2 -lws2_32"
Diogo Franco's avatar
Diogo Franco committed
943
                define PTW32_STATIC_LIB
944
945
946
            else
                # default to native threading if pthread-win32 is unavailable
                thread="win32"
947
948
            fi
            ;;
Mike Gorchak's avatar
Mike Gorchak committed
949
        QNX)
Xiaolei Yu's avatar
Xiaolei Yu committed
950
            cc_check pthread.h -lc "pthread_create(0,0,0,0);" && thread="posix" && libpthread="-lc"
Mike Gorchak's avatar
Mike Gorchak committed
951
            ;;
952
        *)
Xiaolei Yu's avatar
Xiaolei Yu committed
953
954
955
956
957
958
            if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
               thread="posix"
               libpthread="-lpthread"
            else
                cc_check pthread.h "" "pthread_create(0,0,0,0);" && thread="posix" && libpthread=""
            fi
959
960
961
            ;;
    esac
fi
962
if [ "$thread" = "posix" ]; then
963
    LDFLAGS="$LDFLAGS $libpthread"
964
    define HAVE_POSIXTHREAD
965
966
967
    if [ "$SYS" = "LINUX" ] && cc_check sched.h "-D_GNU_SOURCE -Werror" "cpu_set_t p_aff; return CPU_COUNT(&p_aff);" ; then
        define HAVE_CPU_COUNT
    fi
968
969
fi
if [ "$thread" = "win32" ]; then
970
    # cygwin does not support win32 threads
Steven Walters's avatar
Steven Walters committed
971
    if [ "$SYS" = "WINDOWS" ]; then
972
973
974
975
        define HAVE_WIN32THREAD
    else
        thread="no"
    fi
976
fi
977
[ "$thread" != "no" ] && define HAVE_THREAD
978

979
if cc_check "math.h" "-Werror" "return log2f(2);"