configure 49.9 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
31
  --disable-win32thread    disable win32threads (windows only)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
32
  --disable-interlaced     disable interlaced encoding support
33
  --bit-depth=BIT_DEPTH    set output bit depth (8, 10, all) [all]
34
  --chroma-format=FORMAT   output chroma format (400, 420, 422, 444, all) [all]
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
35
36
37

Advanced options:
  --disable-asm            disable platform-specific assembly optimizations
38
  --enable-lto             enable link-time optimization
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
39
40
41
  --enable-debug           add -g
  --enable-gprof           add -pg
  --enable-strip           add -s
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
42
  --enable-pic             build position-independent code
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
43
44

Cross-compilation:
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
45
46
47
48
  --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
49
External library support:
50
  --disable-avs            disable avisynth support
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
51
52
53
54
  --disable-swscale        disable swscale support
  --disable-lavf           disable libavformat support
  --disable-ffms           disable ffmpegsource support
  --disable-gpac           disable gpac support
55
  --disable-lsmash         disable lsmash support
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
56

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

Diogo Franco's avatar
Diogo Franco committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
77
cc_cflags() {
78
79
    # 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
80
81
82
83
    for arg in $*; do
        [[ "$arg" = -falign-loops* ]] && arg=
        [ "$arg" = -fno-tree-vectorize ] && arg=
        [ "$arg" = -Wshadow ] && arg=
Steven Walters's avatar
Steven Walters committed
84
        [ "$arg" = -Wno-maybe-uninitialized ] && arg=
85
86
87
        [[ "$arg" = -mpreferred-stack-boundary* ]] && arg=
        [[ "$arg" = -l* ]] && arg=
        [[ "$arg" = -L* ]] && arg=
Steven Walters's avatar
Steven Walters committed
88
        if [ $compiler_style = MS ]; then
89
90
            [ "$arg" = -ffast-math ] && arg="-fp:fast"
            [ "$arg" = -Wall ] && arg=
Steven Walters's avatar
Steven Walters committed
91
            [ "$arg" = -Werror ] && arg="-W3 -WX"
Steven Walters's avatar
Steven Walters committed
92
93
94
95
96
            [ "$arg" = -g ] && arg=-Z7
            [ "$arg" = -fomit-frame-pointer ] && arg=
            [ "$arg" = -s ] && arg=
            [ "$arg" = -fPIC ] && arg=
        else
97
98
            [ "$arg" = -ffast-math ] && arg=
            [ "$arg" = -Wall ] && arg=
Steven Walters's avatar
Steven Walters committed
99
            [ "$arg" = -Werror ] && arg="-w3 -Werror"
Steven Walters's avatar
Steven Walters committed
100
        fi
Steven Walters's avatar
Steven Walters committed
101
        [ $compiler = CL -a "$arg" = -O3 ] && arg=-O2
Steven Walters's avatar
Steven Walters committed
102
103
104
105
106

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

Steven Walters's avatar
Steven Walters committed
107
cl_ldflags() {
Steven Walters's avatar
Steven Walters committed
108
109
    for arg in $*; do
        arg=${arg/LIBPATH/libpath}
110
111
112
113
        [ "${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
114
        [ "$arg" = -Wl,-Bsymbolic ] && arg=
Steven Walters's avatar
Steven Walters committed
115
116
117
118
        [ "$arg" = -fno-tree-vectorize ] && arg=
        [ "$arg" = -Werror ] && arg=
        [ "$arg" = -Wshadow ] && arg=
        [ "$arg" = -Wmaybe-uninitialized ] && arg=
119
        [[ "$arg" = -Qdiag-error* ]] && arg=
Steven Walters's avatar
Steven Walters committed
120
121
122
123

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

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

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

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

206
as_check() {
Diogo Franco's avatar
Diogo Franco committed
207
    log_check "whether $AS supports $1"
208
209
210
    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
211
212
213
214
215
216
217
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
218
        log_msg "$as_cmd"
Diogo Franco's avatar
Diogo Franco committed
219
220
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
221
222
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
223
        cat conftest$AS_EXT >> config.log
224
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
225
226
    fi
    return $res
227
228
}

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

Anton Mitrofanov's avatar
Anton Mitrofanov committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
pkg_check() {
    log_check "for packages: $1"
    pkg_cmd="$PKGCONFIG --exists $1"
    if $pkg_cmd >conftest.log 2>&1; then
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
        log_msg "$pkg_cmd"
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
    fi
    return $res
}

Diogo Franco's avatar
Diogo Franco committed
274
define() {
Steven Walters's avatar
Steven Walters committed
275
    echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
Diogo Franco's avatar
Diogo Franco committed
276
277
}

278
die() {
Diogo Franco's avatar
Diogo Franco committed
279
    log_msg "DIED: $@"
280
281
282
283
    echo "$@"
    exit 1
}

284
285
configure_system_override() {
    log_check "system libx264 configuration"
286
287
    x264_config_path="$1/x264_config.h"
    if [ -e "$x264_config_path" ]; then
288
289
        res=$?
        log_ok
290
        arg="$(grep '#define X264_GPL ' $x264_config_path | sed -e 's/#define X264_GPL *//; s/ *$//')"
291
292
293
294
        if [ -n "$arg" ]; then
            [ "$arg" = 0 ] && arg="no" || arg="yes"
            [ "$arg" != "$gpl" ] && die "Incompatible license with system libx264"
        fi
295
        arg="$(grep '#define X264_BIT_DEPTH ' $x264_config_path | sed -e 's/#define X264_BIT_DEPTH *//; s/ *$//')"
296
        if [ -n "$arg" ]; then
297
            [ "$arg" = 0 ] && arg="all"
298
299
            if [ "$arg" != "$bit_depth" ]; then
                echo "Override output bit depth with system libx264 configuration"
300
                bit_depth="$arg"
301
302
            fi
        fi
303
        arg="$(grep '#define X264_CHROMA_FORMAT ' $x264_config_path | sed -e 's/#define X264_CHROMA_FORMAT *//; s/ *$//')"
304
305
306
307
        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"
308
                chroma_format="$arg"
309
310
            fi
        fi
311
        arg="$(grep '#define X264_INTERLACED ' $x264_config_path | sed -e 's/#define X264_INTERLACED *//; s/ *$//')"
312
313
314
315
        if [ -n "$arg" ]; then
            [ "$arg" = 0 ] && arg="no" || arg="yes"
            if [ "$arg" != "$interlaced" ]; then
                echo "Override interlaced encoding support with system libx264 configuration"
316
                interlaced="$arg"
317
318
319
320
321
            fi
        fi
    else
        res=$?
        log_fail
322
        log_msg "Failed search path was: $x264_config_path"
323
324
325
326
    fi
    return $res
}

327
328
rm -f x264_config.h config.h config.mak config.log x264.pc x264.def
rm -rf conftest*
Loren Merritt's avatar
Loren Merritt committed
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# 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."
346
[ -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
347

348
prefix='/usr/local'
Loren Merritt's avatar
Loren Merritt committed
349
350
351
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
libdir='${exec_prefix}/lib'
352
includedir='${prefix}/include'
353
DEVNULL='/dev/null'
354

Nikoli's avatar
Nikoli committed
355
356
357
358
cli="yes"
cli_libx264="internal"
shared="no"
static="no"
Steven Walters's avatar
Steven Walters committed
359
360
361
362
avs="auto"
lavf="auto"
ffms="auto"
gpac="auto"
363
364
lsmash="auto"
mp4="no"
365
gpl="yes"
366
thread="auto"
367
swscale="auto"
368
asm="auto"
369
interlaced="yes"
370
lto="no"
371
debug="no"
372
gprof="no"
Nikoli's avatar
Nikoli committed
373
strip="no"
374
pic="no"
375
bit_depth="all"
376
chroma_format="all"
Steven Walters's avatar
Steven Walters committed
377
compiler="GNU"
Steven Walters's avatar
Steven Walters committed
378
compiler_style="GNU"
Steve Borho's avatar
Steve Borho committed
379
opencl="yes"
380
vsx="auto"
Loren Merritt's avatar
Loren Merritt committed
381

Oka Motofumi's avatar
Oka Motofumi committed
382
CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
383
CFLAGSSO="$CFLAGSSO"
384
CFLAGSCLI="$CFLAGSCLI"
385
LDFLAGS="$LDFLAGS"
386
LDFLAGSCLI="$LDFLAGSCLI"
387
ASFLAGS="$ASFLAGS -I. -I\$(SRCPATH)"
388
RCFLAGS="$RCFLAGS"
389
CHECK_CFLAGS=""
390
HAVE_GETOPT_LONG=1
Anton Mitrofanov's avatar
Anton Mitrofanov committed
391
cross_prefix=""
392

Loren Merritt's avatar
Loren Merritt committed
393
EXE=""
394
395
396
AS_EXT=".S"
NL="
"
Loren Merritt's avatar
Loren Merritt committed
397

398
# list of all preprocessor HAVE values we can define
Anton Mitrofanov's avatar
Anton Mitrofanov committed
399
CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
Kaustubh Raste's avatar
Kaustubh Raste committed
400
             LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
401
             MSA MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10"
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# 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
423
424
425
426
427
428
429
430
431
432
433
434
        --disable-cli)
            cli="no"
            ;;
        --system-libx264)
            cli_libx264="system"
            ;;
        --enable-shared)
            shared="yes"
            ;;
        --enable-static)
            static="yes"
            ;;
435
436
437
        --disable-asm)
            asm="no"
            ;;
438
439
440
        --disable-interlaced)
            interlaced="no"
            ;;
Steven Walters's avatar
Steven Walters committed
441
442
        --disable-avs)
            avs="no"
443
            ;;
Steven Walters's avatar
Steven Walters committed
444
445
        --disable-lavf)
            lavf="no"
446
            ;;
Steven Walters's avatar
Steven Walters committed
447
448
        --disable-ffms)
            ffms="no"
449
            ;;
Steven Walters's avatar
Steven Walters committed
450
451
        --disable-gpac)
            gpac="no"
452
            ;;
453
454
455
        --disable-lsmash)
            lsmash="no"
            ;;
456
457
458
        --disable-gpl)
            gpl="no"
            ;;
459
        --extra-asflags=*)
460
            ASFLAGS="$ASFLAGS $optarg"
461
462
            ;;
        --extra-cflags=*)
463
            CFLAGS="$CFLAGS $optarg"
464
465
            ;;
        --extra-ldflags=*)
466
            LDFLAGS="$LDFLAGS $optarg"
467
            ;;
468
469
470
        --extra-rcflags=*)
            RCFLAGS="$RCFLAGS $optarg"
            ;;
471
472
473
        --disable-thread)
            thread="no"
            ;;
474
475
        --disable-win32thread)
            [ "$thread" != "no" ] && thread="posix"
476
            ;;
477
478
479
        --disable-swscale)
            swscale="no"
            ;;
480
481
482
        --enable-lto)
            lto="auto"
            ;;
483
484
485
486
487
488
489
490
        --enable-debug)
            debug="yes"
            ;;
        --enable-gprof)
            CFLAGS="$CFLAGS -pg"
            LDFLAGS="$LDFLAGS -pg"
            gprof="yes"
            ;;
Nikoli's avatar
Nikoli committed
491
492
493
        --enable-strip)
            strip="yes"
            ;;
494
495
496
497
        --enable-pic)
            pic="yes"
            ;;
        --host=*)
498
            host="$optarg"
499
            ;;
500
501
502
        --disable-vsx)
            vsx="no"
            ;;
Steve Borho's avatar
Steve Borho committed
503
504
505
        --disable-opencl)
            opencl="no"
            ;;
Anton Mitrofanov's avatar
Anton Mitrofanov committed
506
        --cross-prefix=*)
507
            cross_prefix="$optarg"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
508
            ;;
David Conrad's avatar
David Conrad committed
509
        --sysroot=*)
510
511
            CFLAGS="$CFLAGS --sysroot=$optarg"
            LDFLAGS="$LDFLAGS --sysroot=$optarg"
David Conrad's avatar
David Conrad committed
512
            ;;
513
        --bit-depth=*)
514
            bit_depth="$optarg"
515
516
            if [ "$bit_depth" != "8" -a "$bit_depth" != "10" -a "$bit_depth" != "all" ]; then
                echo "Supplied bit depth must be 8, 10 or all."
517
518
519
                exit 1
            fi
            ;;
520
521
        --chroma-format=*)
            chroma_format="$optarg"
522
523
            if [ $chroma_format != "400" -a $chroma_format != "420" -a $chroma_format != "422" -a $chroma_format != "444" -a $chroma_format != "all" ]; then
                echo "Supplied chroma format must be 400, 420, 422, 444 or all."
524
525
526
                exit 1
            fi
            ;;
527
528
529
530
531
532
        *)
            echo "Unknown option $opt, ignored"
            ;;
    esac
done

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

Anton Mitrofanov's avatar
Anton Mitrofanov committed
535
536
CC="${CC-${cross_prefix}gcc}"
STRIP="${STRIP-${cross_prefix}strip}"
537
INSTALL="${INSTALL-install}"
538
PKGCONFIG="${PKGCONFIG-${cross_prefix}pkg-config}"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
539

540
541
542
543
544
545
546
547
548
549
550
551
# ar and ranlib doesn't load the LTO plugin by default, prefer the gcc-prefixed wrappers which does.
if ${cross_prefix}gcc-ar --version >/dev/null 2>&1; then
    AR="${AR-${cross_prefix}gcc-ar}"
else
    AR="${AR-${cross_prefix}ar}"
fi
if ${cross_prefix}gcc-ranlib --version >/dev/null 2>&1; then
    RANLIB="${RANLIB-${cross_prefix}gcc-ranlib}"
else
    RANLIB="${RANLIB-${cross_prefix}ranlib}"
fi

552
if [ "x$host" = x ]; then
Diego Biurrun's avatar
Diego Biurrun committed
553
    host="$(${SRCPATH}/config.guess)"
554
555
fi
# normalize a triplet into a quadruplet
Diego Biurrun's avatar
Diego Biurrun committed
556
host="$(${SRCPATH}/config.sub $host)"
557

558
# split $host
Loren Merritt's avatar
Loren Merritt committed
559
host_cpu="${host%%-*}"
560
host="${host#*-}"
Loren Merritt's avatar
Loren Merritt committed
561
host_vendor="${host%%-*}"
562
host_os="${host#*-}"
563

564
trap 'rm -rf conftest*' EXIT
565

Steven Walters's avatar
Steven Walters committed
566
# test for use of compilers that require specific handling
Diego Biurrun's avatar
Diego Biurrun committed
567
cc_base="$(basename "$CC")"
Steven Walters's avatar
Steven Walters committed
568
QPRE="-"
Steven Walters's avatar
Steven Walters committed
569
if [[ $host_os = mingw* || $host_os = cygwin* ]]; then
570
    if [[ "$cc_base" = icl || "$cc_base" = icl[\ .]* ]]; then
Steven Walters's avatar
Steven Walters committed
571
572
573
        # 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
574
        compiler_style=MS
575
        CFLAGS="$CFLAGS -Qstd=c99 -nologo -Qms0 -DHAVE_STRING_H -I\$(SRCPATH)/extras"
Steven Walters's avatar
Steven Walters committed
576
        QPRE="-Q"
577
578
579
580
581
582
        cpp_check '' '' '_MSC_VER >= 1400' || die "Windows Intel Compiler support requires Visual Studio 2005 or newer"
        if cpp_check '' '' 'defined(_M_AMD64) || defined(_M_X64)' ; then
            host_cpu=x86_64
        elif cpp_check '' '' 'defined(_M_IX86)' ; then
            host_cpu=i486
        fi
583
584
585
586
        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
587
588
589
        # Standard Microsoft Visual Studio
        compiler=CL
        compiler_style=MS
590
        CFLAGS="$CFLAGS -nologo -GS- -DHAVE_STRING_H -I\$(SRCPATH)/extras"
Steven Walters's avatar
Steven Walters committed
591
        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"
592
593
594
595
596
597
598
599
600
        if cpp_check '' '' 'defined(_M_AMD64) || defined(_M_X64)' ; then
            host_cpu=x86_64
        elif cpp_check '' '' 'defined(_M_IX86)' ; then
            host_cpu=i486
        elif cpp_check '' '' 'defined(_M_ARM64)' ; then
            host_cpu=aarch64
        elif cpp_check '' '' 'defined(_M_ARM)' ; then
            host_cpu=arm
        fi
601
602
603
    else
        # MinGW uses broken pre-VS2015 Microsoft printf functions unless it's told to use the POSIX ones.
        CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L"
Steven Walters's avatar
Steven Walters committed
604
605
    fi
else
606
    if [[ "$cc_base" = icc || "$cc_base" = icc[\ .]* ]]; then
Steven Walters's avatar
Steven Walters committed
607
608
609
610
611
        AR="xiar"
        compiler=ICC
    fi
fi

612
if [ $compiler = GNU ]; then
613
614
615
616
617
    if cc_check '' -Werror=unknown-warning-option ; then
        CHECK_CFLAGS="$CHECK_CFLAGS -Werror=unknown-warning-option"
    fi
fi

618
libm=""
619
case $host_os in
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
620
621
622
623
624
625
    beos*)
        SYS="BEOS"
        define HAVE_MALLOC_H
        ;;
    darwin*)
        SYS="MACOSX"
626
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
627
628
629
630
631
632
        if [ "$pic" = "no" ]; then
            cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
        fi
        ;;
    freebsd*)
        SYS="FREEBSD"
633
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
634
635
636
637
        ;;
    kfreebsd*-gnu)
        SYS="FREEBSD"
        define HAVE_MALLOC_H
638
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
639
640
641
        ;;
    netbsd*)
        SYS="NETBSD"
642
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
643
644
645
        ;;
    openbsd*)
        SYS="OPENBSD"
646
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
647
648
649
650
        ;;
    *linux*)
        SYS="LINUX"
        define HAVE_MALLOC_H
651
        libm="-lm"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
652
        ;;
653
654
655
    gnu*)
        SYS="HURD"
        define HAVE_MALLOC_H
656
        libm="-lm"
657
        ;;
658
    cygwin*|mingw*|msys*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
659
        EXE=".exe"
660
        if [[ $host_os = cygwin* ]] && cpp_check "" "" "defined(__CYGWIN__)" ; then
661
            SYS="CYGWIN"
662
            define HAVE_MALLOC_H
663
664
665
        else
            SYS="WINDOWS"
            DEVNULL="NUL"
666
            cc_check '' -lshell32 && LDFLAGSCLI="$LDFLAGSCLI -lshell32"
667
            [ $compiler = GNU ] && RC="${RC-${cross_prefix}windres}" || RC="${RC-rc.exe}"
668
        fi
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
669
670
671
672
        ;;
    sunos*|solaris*)
        SYS="SunOS"
        define HAVE_MALLOC_H
673
        libm="-lm"
674
675
676
677
678
        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
679
680
681
682
683
684
685
686
687
        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
688
689
        HAVE_GETOPT_LONG=0
        ;;
Mike Gorchak's avatar
Mike Gorchak committed
690
691
692
693
694
695
696
    *qnx*)
        SYS="QNX"
        define HAVE_MALLOC_H
        libm="-lm"
        HAVE_GETOPT_LONG=0
        CFLAGS="$CFLAGS -I\$(SRCPATH)/extras"
        ;;
Jerome Duval's avatar
Jerome Duval committed
697
698
699
    *haiku*)
        SYS="HAIKU"
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
700
701
702
    *)
        die "Unknown system $host, edit the configure"
        ;;
703
704
esac

705
706
LDFLAGS="$LDFLAGS $libm"

707
stack_alignment=4
708
case $host_cpu in
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
709
710
    i*86)
        ARCH="X86"
711
        AS="${AS-nasm}"
712
        AS_EXT=".asm"
713
        ASFLAGS="$ASFLAGS -DARCH_X86_64=0 -I\$(SRCPATH)/common/x86/"
Steven Walters's avatar
Steven Walters committed
714
715
716
717
718
        if [ $compiler = GNU ]; then
            if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
                CFLAGS="$CFLAGS -march=i686"
            fi
            if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
719
                CFLAGS="$CFLAGS -mfpmath=sse -msse -msse2"
Steven Walters's avatar
Steven Walters committed
720
            fi
721
722
            CFLAGS="-m32 $CFLAGS"
            LDFLAGS="-m32 $LDFLAGS"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
723
724
        fi
        if [ "$SYS" = MACOSX ]; then
725
            ASFLAGS="$ASFLAGS -f macho32 -DPREFIX"
726
        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
727
728
            ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
            LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
729
            [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
730
            [ $compiler = GNU ] && RCFLAGS="--target=pe-i386 $RCFLAGS"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
731
        else
732
            ASFLAGS="$ASFLAGS -f elf32"
Sean McGovern's avatar
Sean McGovern committed
733
734
        fi
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
735
736
    x86_64)
        ARCH="X86_64"
737
        AS="${AS-nasm}"
738
        AS_EXT=".asm"
739
        ASFLAGS="$ASFLAGS -DARCH_X86_64=1 -I\$(SRCPATH)/common/x86/"
740
        stack_alignment=16
741
        [ $compiler = GNU ] && CFLAGS="-m64 $CFLAGS" && LDFLAGS="-m64 $LDFLAGS"
742
        if [ "$SYS" = MACOSX ]; then
743
            ASFLAGS="$ASFLAGS -f macho64 -DPREFIX"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
744
745
746
747
            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
748
        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
749
            ASFLAGS="$ASFLAGS -f win64"
750
751
752
753
754
755
756
757
758
            if [ $compiler = GNU ]; then
                # only the GNU toolchain is inconsistent in prefixing function names with _
                cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
                cc_check "" "-Wl,--high-entropy-va" && LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"
                LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
                LDFLAGSCLI="$LDFLAGSCLI -Wl,--image-base,0x140000000"
                SOFLAGS="$SOFLAGS -Wl,--image-base,0x180000000"
                RCFLAGS="--target=pe-x86-64 $RCFLAGS"
            fi
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
759
        else
760
            ASFLAGS="$ASFLAGS -f elf64"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
761
762
        fi
        ;;
763
    powerpc*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
764
765
766
        ARCH="PPC"
        if [ $asm = auto ] ; then
            define HAVE_ALTIVEC
767
            AS="${AS-${CC}}"
768
            AS_EXT=".c"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
769
770
771
772
773
774
            if [ $SYS = MACOSX ] ; then
                CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
            else
                CFLAGS="$CFLAGS -maltivec -mabi=altivec"
                define HAVE_ALTIVEC_H
            fi
775
776
777
778
779
780
781
782
            if [ "$vsx" != "no" ] ; then
                vsx="no"
                if cc_check "" "-mvsx" ; then
                    CFLAGS="$CFLAGS -mvsx"
                    define HAVE_VSX
                    vsx="yes"
                fi
            fi
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
783
784
785
786
787
        fi
        ;;
    sparc)
        ARCH="SPARC"
        ;;
Kaustubh Raste's avatar
Kaustubh Raste committed
788
    mips*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
789
        ARCH="MIPS"
Kaustubh Raste's avatar
Kaustubh Raste committed
790
791
        AS="${AS-${CC}}"
        AS_EXT=".c"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
792
793
794
795
        ;;
    arm*)
        ARCH="ARM"
        if [ "$SYS" = MACOSX ] ; then
796
            AS="${AS-${CC}}"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
797
798
799
800
801
802
            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
803
        elif [ "$SYS" = WINDOWS ] && [ "$compiler" = CL ] ; then
804
            AS="${AS-${SRCPATH}/tools/gas-preprocessor.pl -arch arm -as-type armasm -force-thumb -- armasm -nologo -ignore 4509}"
805
806
        elif [ "$SYS" = WINDOWS ] ; then
            AS="${AS-${SRCPATH}/tools/gas-preprocessor.pl -arch arm -as-type clang -force-thumb -- ${CC} -mimplicit-it=always}"
807
808
        else
            AS="${AS-${CC}}"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
809
810
        fi
        ;;
Janne Grunau's avatar
Janne Grunau committed
811
812
    aarch64)
        ARCH="AARCH64"
813
        stack_alignment=16
Janne Grunau's avatar
Janne Grunau committed
814
        if [ "$SYS" = MACOSX ] ; then
815
            AS="${AS-${CC}}"
816
            ASFLAGS="$ASFLAGS -DPREFIX -DPIC"
817
        elif [ "$SYS" = WINDOWS ] && [ "$compiler" = CL ] ; then
818
819
820
            AS="${AS-${SRCPATH}/tools/gas-preprocessor.pl -arch aarch64 -as-type armasm -- armasm64 -nologo}"
        else
            AS="${AS-${CC}}"
Janne Grunau's avatar
Janne Grunau committed
821
822
        fi
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
823
824
825
    s390|s390x)
        ARCH="S390"
        ;;
826
    hppa*|parisc*)
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
827
828
829
830
831
        ARCH="PARISC"
        ;;
    ia64)
        ARCH="IA64"
        ;;
832
833
834
    alpha*)
        ARCH="ALPHA"
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
835
836
837
    *)
        ARCH="$(echo $host_cpu | tr a-z A-Z)"
        ;;
838
839
esac

840
841
[ "$vsx" != "yes" ] && vsx="no"

Henrik Gramner's avatar
Henrik Gramner committed
842
843
844
845
if [ $SYS = WINDOWS ]; then
    if ! rc_check "0 RCDATA {0}" ; then
        RC=""
    fi
Henrik Gramner's avatar
Henrik Gramner committed
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860

    if cpp_check "winapifamily.h" "" "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)" ; then
        [ $compiler = CL ] || die "WinRT requires MSVC"
        define HAVE_WINRT
        CFLAGS="$CFLAGS -MD"
        LDFLAGS="$LDFLAGS -appcontainer"
        if ! cpp_check "" "" "defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603" ; then
            die "_WIN32_WINNT must be defined to at least 0x0603 (Windows 8.1) for WinRT"
        elif cpp_check "" "" "_WIN32_WINNT >= 0x0A00" ; then
            # Universal Windows Platform (Windows 10)
            LDFLAGS="$LDFLAGS -lWindowsApp"
        fi
        cli="no"
        opencl="no"
    fi
Henrik Gramner's avatar
Henrik Gramner committed
861
862
fi

Diogo Franco's avatar
Diogo Franco committed
863
864
865
866
867
868
869
870
871
872
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 ""

873
874
# check requirements

875
876
cc_check || die "No working C compiler found."

Steven Walters's avatar
Steven Walters committed
877
if [ $compiler_style = GNU ]; then
878
    if cc_check '' -std=gnu99 'for( int i = 0; i < 9; i++ );' ; then
879
        CFLAGS="$CFLAGS -std=gnu99 -D_GNU_SOURCE"
880
    elif cc_check '' -std=c99 'for( int i = 0; i < 9; i++ );' ; then
Steven Walters's avatar
Steven Walters committed
881
        CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
882
883
    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
884
    fi
885
886
fi

887
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
888
889
890
    pic="yes"
fi

891
if [ $compiler = GNU -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
Henrik Gramner's avatar
Henrik Gramner committed
892
893
894
    if cc_check '' -mpreferred-stack-boundary=6 ; then
        CFLAGS="$CFLAGS -mpreferred-stack-boundary=6"
        stack_alignment=64
895
896
897
898
899
900
901
902
903
904
905
    elif cc_check '' -mstack-alignment=64 ; then
        CFLAGS="$CFLAGS -mstack-alignment=64"
        stack_alignment=64
    elif [ $stack_alignment -lt 16 ] ; then
        if cc_check '' -mpreferred-stack-boundary=4 ; then
            CFLAGS="$CFLAGS -mpreferred-stack-boundary=4"
            stack_alignment=16
        elif cc_check '' -mstack-alignment=16 ; then
            CFLAGS="$CFLAGS -mstack-alignment=16"
            stack_alignment=16
        fi
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
    fi
elif [ $compiler = ICC -a $ARCH = X86 ]; then
    # icc on linux has various degrees of mod16 stack support
    if [ $SYS = LINUX ]; then
        # >= 12 defaults to a mod16 stack
        if cpp_check "" "" "__INTEL_COMPILER >= 1200" ; then
            stack_alignment=16
        # 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
        elif cpp_check "" "" "__INTEL_COMPILER >= 1100" ; then
            CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
            stack_alignment=16
        fi
        # < 11 is completely incapable of keeping a mod16 stack
    fi
fi

922
if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
923
    if ! as_check "vmovdqa32 [eax]{k1}{z}, zmm0" ; then
924
        VER="$( ($AS --version || echo no assembler) 2>/dev/null | head -n 1 )"
925
        echo "Found $VER"
926
        echo "Minimum version is nasm-2.13"
927
928
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
929
    fi
Steven Walters's avatar
Steven Walters committed
930
    cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' && define HAVE_X86_INLINE_ASM
Diogo Franco's avatar
Diogo Franco committed
931
    define HAVE_MMX
932
fi
933

934
if [ $asm = auto -a $ARCH = ARM ] ; then
935
    # set flags so neon is built by default
936
937
938
939
940
941
942
943
    [ $compiler == CL ] || echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon"

    cc_check '' '' '__asm__("add r0, r1, r2");' && define HAVE_ARM_INLINE_ASM
    if [ $compiler = CL ] && cpp_check '' '' 'defined(_M_ARM) && _M_ARM >= 7' ; then
        define HAVE_ARMV6
        define HAVE_ARMV6T2
        define HAVE_NEON
    elif cc_check '' '' '__asm__("rev ip, ip");' ; then     define HAVE_ARMV6
David Conrad's avatar
David Conrad committed
944
945
        cc_check '' '' '__asm__("movt r0, #0");'         && define HAVE_ARMV6T2
        cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
946
        ASFLAGS="$ASFLAGS -c"
947
    else
948
        echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
949
950
        echo "If you really want to run on such a CPU, configure with --disable-asm."
        exit 1
951
952
953
    fi
fi

Janne Grunau's avatar
Janne Grunau committed
954
if [ $asm = auto -a $ARCH = AARCH64 ] ; then
955
956
957
958
    if [ $compiler = CL ] && cpp_check '' '' 'defined(_M_ARM64)' ; then
        define HAVE_NEON
    elif cc_check '' '' '__asm__("cmeq v0.8h, v0.8h, #0");' ; then
        define HAVE_NEON
Janne Grunau's avatar
Janne Grunau committed
959
960
961
962
963
964
965
966
967
        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
968
969
970
971
    # 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
972
973
974
975
976
977
978
979
980
981
982
983
984
985
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

986
[ $asm = no ] && AS=""
987
[ "x$AS" = x ] && asm="no" || asm="yes"
988

Diogo Franco's avatar
Diogo Franco committed
989
990
define ARCH_$ARCH
define SYS_$SYS
991

992
993
994
define STACK_ALIGNMENT $stack_alignment
ASFLAGS="$ASFLAGS -DSTACK_ALIGNMENT=$stack_alignment"

Steven Walters's avatar
Steven Walters committed
995
# 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
996
CPU_ENDIAN="little-endian"
Steven Walters's avatar
Steven Walters committed
997
998
if [ $compiler = GNU ]; then
    echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
999
    $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
Steven Walters's avatar
Steven Walters committed
1000
1001
    if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
        define WORDS_BIGENDIAN
1002
        CPU_ENDIAN="big-endian"
Steven Walters's avatar
Steven Walters committed
1003
1004
1005
    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
1006
fi
Loren Merritt's avatar
Loren Merritt committed
1007

1008
1009
if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then
    [ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
1010
    if pkg_check x264 ; then
1011
        X264_LIBS="$($PKGCONFIG --libs x264)"
1012
        X264_CFLAGS="$($PKGCONFIG --cflags x264)"
1013
        X264_INCLUDE_DIR="${X264_INCLUDE_DIR-$($PKGCONFIG --variable=includedir x264)}"
1014
        configure_system_override "$X264_INCLUDE_DIR" || die "Detection of system libx264 configuration failed"
1015
1016
1017
1018
1019
    else
        die "Can not find system libx264"
    fi
fi

1020
1021
# autodetect options that weren't forced nor disabled

1022
libpthread=""
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
if [ "$SYS" = "WINDOWS" -a "$thread" = "posix" ] ; then
    if [ "$gpl" = "no" ] ; then
        echo "Warning: pthread-win32 is LGPL and is therefore not supported with --disable-gpl"
        thread="no"
    elif cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
        libpthread="-lpthread"
    elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
        libpthread="-lpthreadGC2"
    elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
        libpthread="-lpthreadGC2 -lwsock32"
        define PTW32_STATIC_LIB
    elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
        libpthread="-lpthreadGC2 -lws2_32"
        define PTW32_STATIC_LIB
    else
        thread="no"
    fi
elif [ "$thread" != "no" ] ; then
1041
    thread="no"
1042
    case $SYS in
1043
        BEOS)
1044
1045
            thread="beos"
            define HAVE_BEOSTHREAD
1046
            ;;
Steven Walters's avatar
Steven Walters committed
1047
        WINDOWS)
1048
1049
            thread="win32"
            define HAVE_WIN32THREAD
1050
            ;;