K-means weightp
[x264-7mod.git] / configure
blobae4baf942911f4d77b926fb0f1326308f368a695
1 #!/bin/bash
3 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
4 cat <<EOF
5 Usage: ./configure [options]
7 Help:
8 -h, --help print this message
10 Standard options:
11 --prefix=PREFIX install architecture-independent files in PREFIX
12 [/usr/local]
13 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
14 [PREFIX]
15 --bindir=DIR install binaries in DIR [EPREFIX/bin]
16 --libdir=DIR install libs in DIR [EPREFIX/lib]
17 --includedir=DIR install includes in DIR [PREFIX/include]
18 --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS
19 --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS
20 --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS
21 --extra-rcflags=ERCFLAGS add ERCFLAGS to RCFLAGS
23 Configuration options:
24 --disable-cli disable cli
25 --system-libx264 use system libx264 instead of internal
26 --enable-shared build shared library
27 --enable-static build static library
28 --disable-opencl disable OpenCL features
29 --disable-gpl disable GPL-only features
30 --disable-thread disable multithreaded encoding
31 --disable-win32thread disable win32threads (windows only)
32 --disable-interlaced disable interlaced encoding support
33 --bit-depth=BIT_DEPTH set output bit depth (8-10) [8]
34 --chroma-format=FORMAT output chroma format (420, 422, 444, all) [all]
36 Advanced options:
37 --disable-asm disable platform-specific assembly optimizations
38 --enable-lto enable link-time optimization
39 --enable-debug add -g
40 --enable-gprof add -pg
41 --enable-strip add -s
42 --enable-pic build position-independent code
44 Cross-compilation:
45 --host=HOST build programs to run on HOST
46 --cross-prefix=PREFIX use PREFIX for compilation tools
47 --sysroot=SYSROOT root of cross-build tree
49 External library support:
50 --disable-avs disable avisynth support
51 --disable-swscale disable swscale support
52 --disable-lavf disable libavformat support
53 --disable-ffms disable ffmpegsource support
54 --disable-gpac disable gpac support
55 --disable-lsmash disable lsmash support
56 --disable-avi-output disables avi output (using libavformat)
58 EOF
59 exit 1
62 log_check() {
63 echo -n "checking $1... " >> config.log
66 log_ok() {
67 echo "yes" >> config.log
70 log_fail() {
71 echo "no" >> config.log
74 log_msg() {
75 echo "$1" >> config.log
78 cc_cflags() {
79 # several non gcc compilers issue an incredibly large number of warnings on high warning levels,
80 # suppress them by reducing the warning level rather than having to use #pragmas
81 for arg in $*; do
82 [[ "$arg" = -falign-loops* ]] && arg=
83 [ "$arg" = -fno-tree-vectorize ] && arg=
84 [ "$arg" = -Wshadow ] && arg=
85 [ "$arg" = -Wno-maybe-uninitialized ] && arg=
86 [[ "$arg" = -mpreferred-stack-boundary* ]] && arg=
87 [[ "$arg" = -l* ]] && arg=
88 [[ "$arg" = -L* ]] && arg=
89 if [ $compiler_style = MS ]; then
90 [ "$arg" = -ffast-math ] && arg="-fp:fast"
91 [ "$arg" = -Wall ] && arg=
92 [ "$arg" = -Werror ] && arg="-W3 -WX"
93 [ "$arg" = -g ] && arg=-Z7
94 [ "$arg" = -fomit-frame-pointer ] && arg=
95 [ "$arg" = -s ] && arg=
96 [ "$arg" = -fPIC ] && arg=
97 else
98 [ "$arg" = -ffast-math ] && arg=
99 [ "$arg" = -Wall ] && arg=
100 [ "$arg" = -Werror ] && arg="-w3 -Werror"
102 [ $compiler = CL -a "$arg" = -O3 ] && arg=-O2
104 [ -n "$arg" ] && echo -n "$arg "
105 done
108 cl_ldflags() {
109 for arg in $*; do
110 arg=${arg/LIBPATH/libpath}
111 [ "${arg#-libpath:}" == "$arg" -a "${arg#-l}" != "$arg" ] && arg=${arg#-l}.lib
112 [ "${arg#-L}" != "$arg" ] && arg=-libpath:${arg#-L}
113 [ "$arg" = -Wl,--large-address-aware ] && arg=-largeaddressaware
114 [ "$arg" = -s ] && arg=
115 [ "$arg" = -Wl,-Bsymbolic ] && arg=
116 [ "$arg" = -fno-tree-vectorize ] && arg=
117 [ "$arg" = -Werror ] && arg=
118 [ "$arg" = -Wshadow ] && arg=
119 [ "$arg" = -Wmaybe-uninitialized ] && arg=
120 [[ "$arg" = -Qdiag-error* ]] && arg=
122 arg=${arg/pthreadGC/pthreadVC}
123 [ "$arg" = avifil32.lib ] && arg=vfw32.lib
124 [ "$arg" = gpac_static.lib ] && arg=libgpac_static.lib
125 [ "$arg" = x264.lib ] && arg=libx264.lib
127 [ -n "$arg" ] && echo -n "$arg "
128 done
131 cc_check() {
132 if [ -z "$3" ]; then
133 if [ -z "$1$2" ]; then
134 log_check "whether $CC works"
135 elif [ -z "$1" ]; then
136 log_check "for $2"
137 else
138 log_check "for $1"
140 elif [ -z "$1" ]; then
141 if [ -z "$2" ]; then
142 log_check "whether $CC supports $3"
143 else
144 log_check "whether $CC supports $3 with $2"
146 else
147 log_check "for $3 in $1";
149 rm -f conftest.c
150 for arg in $1; do
151 echo "#include <$arg>" >> conftest.c
152 done
153 echo "int main (void) { $3 return 0; }" >> conftest.c
154 if [ $compiler_style = MS ]; then
155 cc_cmd="$CC conftest.c $(cc_cflags $CFLAGS $CHECK_CFLAGS $2) -link $(cl_ldflags $2 $LDFLAGSCLI $LDFLAGS)"
156 else
157 cc_cmd="$CC conftest.c $CFLAGS $CHECK_CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest"
159 if $cc_cmd >conftest.log 2>&1; then
160 res=$?
161 log_ok
162 else
163 res=$?
164 log_fail
165 log_msg "Failed commandline was:"
166 log_msg "--------------------------------------------------"
167 log_msg "$cc_cmd"
168 cat conftest.log >> config.log
169 log_msg "--------------------------------------------------"
170 log_msg "Failed program was:"
171 log_msg "--------------------------------------------------"
172 cat conftest.c >> config.log
173 log_msg "--------------------------------------------------"
175 return $res
178 cpp_check() {
179 log_check "whether $3 is true"
180 rm -f conftest.c
181 for arg in $1; do
182 echo "#include <$arg>" >> conftest.c
183 done
184 echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c
185 if [ $compiler_style = MS ]; then
186 cpp_cmd="$CC conftest.c $(cc_cflags $CFLAGS $2) -P"
187 else
188 cpp_cmd="$CC conftest.c $CFLAGS $2 -E -o conftest"
190 if $cpp_cmd >conftest.log 2>&1; then
191 res=$?
192 log_ok
193 else
194 res=$?
195 log_fail
196 log_msg "--------------------------------------------------"
197 cat conftest.log >> config.log
198 log_msg "--------------------------------------------------"
199 log_msg "Failed program was:"
200 log_msg "--------------------------------------------------"
201 cat conftest.c >> config.log
202 log_msg "--------------------------------------------------"
204 return $res
207 as_check() {
208 log_check "whether $AS supports $1"
209 echo "$1" > conftest$AS_EXT
210 as_cmd="$AS conftest$AS_EXT $ASFLAGS $2 -o conftest.o"
211 if $as_cmd >conftest.log 2>&1; then
212 res=$?
213 log_ok
214 else
215 res=$?
216 log_fail
217 log_msg "Failed commandline was:"
218 log_msg "--------------------------------------------------"
219 log_msg "$as_cmd"
220 cat conftest.log >> config.log
221 log_msg "--------------------------------------------------"
222 log_msg "Failed program was:"
223 log_msg "--------------------------------------------------"
224 cat conftest$AS_EXT >> config.log
225 log_msg "--------------------------------------------------"
227 return $res
230 rc_check() {
231 log_check "whether $RC works"
232 echo "$1" > conftest.rc
233 if [ $compiler = GNU ]; then
234 rc_cmd="$RC $RCFLAGS -o conftest.o conftest.rc"
235 else
236 rc_cmd="$RC $RCFLAGS -foconftest.o conftest.rc"
238 if $rc_cmd >conftest.log 2>&1; then
239 res=$?
240 log_ok
241 else
242 res=$?
243 log_fail
244 log_msg "Failed commandline was:"
245 log_msg "--------------------------------------------------"
246 log_msg "$rc_cmd"
247 cat conftest.log >> config.log
248 log_msg "--------------------------------------------------"
249 log_msg "Failed program was:"
250 log_msg "--------------------------------------------------"
251 cat conftest.rc >> config.log
252 log_msg "--------------------------------------------------"
254 return $res
257 define() {
258 echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
261 die() {
262 log_msg "DIED: $@"
263 echo "$@"
264 exit 1
267 configure_system_override() {
268 log_check "system libx264 configuration"
269 x264_config_path="$1/x264_config.h"
270 if [ -e "$x264_config_path" ]; then
271 res=$?
272 log_ok
273 arg="$(grep '#define X264_GPL ' $x264_config_path | sed -e 's/#define X264_GPL *//; s/ *$//')"
274 if [ -n "$arg" ]; then
275 [ "$arg" = 0 ] && arg="no" || arg="yes"
276 [ "$arg" != "$gpl" ] && die "Incompatible license with system libx264"
278 arg="$(grep '#define X264_BIT_DEPTH ' $x264_config_path | sed -e 's/#define X264_BIT_DEPTH *//; s/ *$//')"
279 if [ -n "$arg" ]; then
280 if [ "$arg" != "$bit_depth" ]; then
281 echo "Override output bit depth with system libx264 configuration"
282 bit_depth="$arg"
285 arg="$(grep '#define X264_CHROMA_FORMAT ' $x264_config_path | sed -e 's/#define X264_CHROMA_FORMAT *//; s/ *$//')"
286 if [ -n "$arg" ]; then
287 [ "$arg" = 0 ] && arg="all" || arg="${arg#X264_CSP_I}"
288 if [ "$arg" != "$chroma_format" ]; then
289 echo "Override output chroma format with system libx264 configuration"
290 chroma_format="$arg"
293 arg="$(grep '#define X264_INTERLACED ' $x264_config_path | sed -e 's/#define X264_INTERLACED *//; s/ *$//')"
294 if [ -n "$arg" ]; then
295 [ "$arg" = 0 ] && arg="no" || arg="yes"
296 if [ "$arg" != "$interlaced" ]; then
297 echo "Override interlaced encoding support with system libx264 configuration"
298 interlaced="$arg"
301 else
302 res=$?
303 log_fail
304 log_msg "Failed search path was: $x264_config_path"
306 return $res
309 rm -f x264_config.h config.h config.mak config.log x264.pc x264.def
310 rm -rf conftest*
312 # Construct a path to the specified directory relative to the working directory
313 relative_path() {
314 local base="${PWD%/}"
315 local path="$(cd "$1" >/dev/null; printf '%s/.' "${PWD%/}")"
316 local up=''
318 while [[ $path != "$base/"* ]]; do
319 base="${base%/*}"
320 up="../$up"
321 done
323 dirname "$up${path#"$base/"}"
326 SRCPATH="$(relative_path "$(dirname "$0")")"
327 echo "$SRCPATH" | grep -q ' ' && die "Out of tree builds are impossible with whitespace in source path."
328 [ -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."
330 prefix='/usr/local'
331 exec_prefix='${prefix}'
332 bindir='${exec_prefix}/bin'
333 libdir='${exec_prefix}/lib'
334 includedir='${prefix}/include'
335 DEVNULL='/dev/null'
337 cli="yes"
338 cli_libx264="internal"
339 shared="no"
340 static="no"
341 avs="auto"
342 lavf="auto"
343 ffms="auto"
344 gpac="auto"
345 lsmash="auto"
346 mp4="no"
347 avi_output="auto"
348 gpl="yes"
349 thread="auto"
350 swscale="auto"
351 asm="auto"
352 interlaced="yes"
353 lto="no"
354 debug="no"
355 gprof="no"
356 strip="no"
357 pic="no"
358 bit_depth="8"
359 chroma_format="all"
360 compiler="GNU"
361 compiler_style="GNU"
362 opencl="yes"
363 vsx="auto"
365 CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
366 LDFLAGS="$LDFLAGS"
367 LDFLAGSCLI="$LDFLAGSCLI"
368 ASFLAGS="$ASFLAGS -I. -I\$(SRCPATH)"
369 RCFLAGS="$RCFLAGS"
370 CHECK_CFLAGS=""
371 HAVE_GETOPT_LONG=1
372 cross_prefix=""
374 EXE=""
375 AS_EXT=".S"
376 NL="
379 # list of all preprocessor HAVE values we can define
380 CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
381 LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
382 MSA MMAP WINRT VSX ARM_INLINE_ASM AVI_OUTPUT"
384 # parse options
386 for opt do
387 optarg="${opt#*=}"
388 case "$opt" in
389 --prefix=*)
390 prefix="$optarg"
392 --exec-prefix=*)
393 exec_prefix="$optarg"
395 --bindir=*)
396 bindir="$optarg"
398 --libdir=*)
399 libdir="$optarg"
401 --includedir=*)
402 includedir="$optarg"
404 --disable-cli)
405 cli="no"
407 --system-libx264)
408 cli_libx264="system"
410 --enable-shared)
411 shared="yes"
413 --enable-static)
414 static="yes"
416 --disable-asm)
417 asm="no"
419 --disable-interlaced)
420 interlaced="no"
422 --disable-avs)
423 avs="no"
425 --disable-lavf)
426 lavf="no"
428 --disable-ffms)
429 ffms="no"
431 --disable-gpac)
432 gpac="no"
434 --disable-lsmash)
435 lsmash="no"
437 --disable-avi-output)
438 avi_output="no"
440 --disable-gpl)
441 gpl="no"
443 --extra-asflags=*)
444 ASFLAGS="$ASFLAGS $optarg"
446 --extra-cflags=*)
447 CFLAGS="$CFLAGS $optarg"
449 --extra-ldflags=*)
450 LDFLAGS="$LDFLAGS $optarg"
452 --extra-rcflags=*)
453 RCFLAGS="$RCFLAGS $optarg"
455 --disable-thread)
456 thread="no"
458 --disable-win32thread)
459 [ "$thread" != "no" ] && thread="posix"
461 --disable-swscale)
462 swscale="no"
464 --enable-lto)
465 lto="auto"
467 --enable-debug)
468 debug="yes"
470 --enable-gprof)
471 CFLAGS="$CFLAGS -pg"
472 LDFLAGS="$LDFLAGS -pg"
473 gprof="yes"
475 --enable-strip)
476 strip="yes"
478 --enable-pic)
479 pic="yes"
481 --host=*)
482 host="$optarg"
484 --disable-vsx)
485 vsx="no"
487 --disable-opencl)
488 opencl="no"
490 --cross-prefix=*)
491 cross_prefix="$optarg"
493 --sysroot=*)
494 CFLAGS="$CFLAGS --sysroot=$optarg"
495 LDFLAGS="$LDFLAGS --sysroot=$optarg"
497 --bit-depth=*)
498 bit_depth="$optarg"
499 if [ "$bit_depth" -lt "8" -o "$bit_depth" -gt "10" ]; then
500 echo "Supplied bit depth must be in range [8,10]."
501 exit 1
503 bit_depth=`expr $bit_depth + 0`
505 --chroma-format=*)
506 chroma_format="$optarg"
507 if [ $chroma_format != "420" -a $chroma_format != "422" -a $chroma_format != "444" -a $chroma_format != "all" ]; then
508 echo "Supplied chroma format must be 420, 422, 444 or all."
509 exit 1
513 echo "Unknown option $opt, ignored"
515 esac
516 done
518 [ "$cli" = "no" -a "$shared" = "no" -a "$static" = "no" ] && die "Nothing to build. Enable cli, shared or static."
520 CC="${CC-${cross_prefix}gcc}"
521 STRIP="${STRIP-${cross_prefix}strip}"
522 INSTALL="${INSTALL-install}"
523 PKGCONFIG="${PKGCONFIG-${cross_prefix}pkg-config}"
525 # ar and ranlib doesn't load the LTO plugin by default, prefer the gcc-prefixed wrappers which does.
526 if ${cross_prefix}gcc-ar --version >/dev/null 2>&1; then
527 AR="${AR-${cross_prefix}gcc-ar}"
528 else
529 AR="${AR-${cross_prefix}ar}"
531 if ${cross_prefix}gcc-ranlib --version >/dev/null 2>&1; then
532 RANLIB="${RANLIB-${cross_prefix}gcc-ranlib}"
533 else
534 RANLIB="${RANLIB-${cross_prefix}ranlib}"
537 if [ "x$host" = x ]; then
538 host=`${SRCPATH}/config.guess`
540 # normalize a triplet into a quadruplet
541 host=`${SRCPATH}/config.sub $host`
543 # split $host
544 host_cpu="${host%%-*}"
545 host="${host#*-}"
546 host_vendor="${host%%-*}"
547 host_os="${host#*-}"
549 trap 'rm -rf conftest*' EXIT
551 # test for use of compilers that require specific handling
552 cc_base=`basename "$CC"`
553 QPRE="-"
554 if [[ $host_os = mingw* || $host_os = cygwin* ]]; then
555 if [[ "$cc_base" = icl || "$cc_base" = icl[\ .]* ]]; then
556 # Windows Intel Compiler creates dependency generation with absolute Windows paths, Cygwin's make does not support Windows paths.
557 [[ $host_os = cygwin* ]] && die "Windows Intel Compiler support requires MSYS"
558 compiler=ICL
559 compiler_style=MS
560 CFLAGS="$CFLAGS -Qstd=c99 -nologo -Qms0 -DHAVE_STRING_H -I\$(SRCPATH)/extras"
561 QPRE="-Q"
562 cpp_check '' '' '_MSC_VER >= 1400' || die "Windows Intel Compiler support requires Visual Studio 2005 or newer"
563 if cpp_check '' '' 'defined(_M_AMD64) || defined(_M_X64)' ; then
564 host_cpu=x86_64
565 elif cpp_check '' '' 'defined(_M_IX86)' ; then
566 host_cpu=i486
568 if cc_check '' -Qdiag-error:10006,10157 ; then
569 CHECK_CFLAGS="$CHECK_CFLAGS -Qdiag-error:10006,10157"
571 elif [[ "$cc_base" = cl || "$cc_base" = cl[\ .]* ]]; then
572 # Standard Microsoft Visual Studio
573 compiler=CL
574 compiler_style=MS
575 CFLAGS="$CFLAGS -nologo -GS- -DHAVE_STRING_H -I\$(SRCPATH)/extras"
576 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"
577 if cpp_check '' '' 'defined(_M_AMD64) || defined(_M_X64)' ; then
578 host_cpu=x86_64
579 elif cpp_check '' '' 'defined(_M_IX86)' ; then
580 host_cpu=i486
581 elif cpp_check '' '' 'defined(_M_ARM64)' ; then
582 host_cpu=aarch64
583 elif cpp_check '' '' 'defined(_M_ARM)' ; then
584 host_cpu=arm
586 else
587 # MinGW uses broken pre-VS2015 Microsoft printf functions unless it's told to use the POSIX ones.
588 CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L"
590 else
591 if [[ "$cc_base" = icc || "$cc_base" = icc[\ .]* ]]; then
592 AR="xiar"
593 compiler=ICC
597 if [ $compiler = GNU ]; then
598 if cc_check '' -Werror=unknown-warning-option ; then
599 CHECK_CFLAGS="$CHECK_CFLAGS -Werror=unknown-warning-option"
603 libm=""
604 case $host_os in
605 beos*)
606 SYS="BEOS"
607 define HAVE_MALLOC_H
609 darwin*)
610 SYS="MACOSX"
611 libm="-lm"
612 if [ "$pic" = "no" ]; then
613 cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
616 freebsd*)
617 SYS="FREEBSD"
618 libm="-lm"
620 kfreebsd*-gnu)
621 SYS="FREEBSD"
622 define HAVE_MALLOC_H
623 libm="-lm"
625 netbsd*)
626 SYS="NETBSD"
627 libm="-lm"
629 openbsd*)
630 SYS="OPENBSD"
631 libm="-lm"
633 *linux*)
634 SYS="LINUX"
635 define HAVE_MALLOC_H
636 libm="-lm"
638 gnu*)
639 SYS="HURD"
640 define HAVE_MALLOC_H
641 libm="-lm"
643 cygwin*|mingw*|msys*)
644 EXE=".exe"
645 if [[ $host_os = cygwin* ]] && cpp_check "" "" "defined(__CYGWIN__)" ; then
646 SYS="CYGWIN"
647 define HAVE_MALLOC_H
648 else
649 SYS="WINDOWS"
650 DEVNULL="NUL"
651 cc_check '' -lshell32 && LDFLAGSCLI="$LDFLAGSCLI -lshell32"
652 [ $compiler = GNU ] && RC="${RC-${cross_prefix}windres}" || RC="${RC-rc.exe}"
655 sunos*|solaris*)
656 SYS="SunOS"
657 define HAVE_MALLOC_H
658 libm="-lm"
659 if cc_check "" /usr/lib/64/values-xpg6.o; then
660 LDFLAGS="$LDFLAGS /usr/lib/64/values-xpg6.o"
661 else
662 LDFLAGS="$LDFLAGS /usr/lib/values-xpg6.o"
664 if test -x /usr/ucb/install ; then
665 INSTALL=/usr/ucb/install
666 elif test -x /usr/bin/ginstall ; then
667 # OpenSolaris
668 INSTALL=/usr/bin/ginstall
669 elif test -x /usr/gnu/bin/install ; then
670 # OpenSolaris
671 INSTALL=/usr/gnu/bin/install
673 HAVE_GETOPT_LONG=0
675 *qnx*)
676 SYS="QNX"
677 define HAVE_MALLOC_H
678 libm="-lm"
679 HAVE_GETOPT_LONG=0
680 CFLAGS="$CFLAGS -I\$(SRCPATH)/extras"
682 *haiku*)
683 SYS="HAIKU"
686 die "Unknown system $host, edit the configure"
688 esac
690 LDFLAGS="$LDFLAGS $libm"
692 stack_alignment=4
693 case $host_cpu in
694 i*86)
695 ARCH="X86"
696 AS="${AS-nasm}"
697 AS_EXT=".asm"
698 ASFLAGS="$ASFLAGS -DARCH_X86_64=0 -I\$(SRCPATH)/common/x86/"
699 if [ $compiler = GNU ]; then
700 if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
701 CFLAGS="$CFLAGS -march=i686"
703 if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
704 CFLAGS="$CFLAGS -mfpmath=sse -msse -msse2"
706 CFLAGS="-m32 $CFLAGS"
707 LDFLAGS="-m32 $LDFLAGS"
709 if [ "$SYS" = MACOSX ]; then
710 ASFLAGS="$ASFLAGS -f macho32 -DPREFIX"
711 elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
712 ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
713 LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
714 [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
715 [ $compiler = GNU ] && RCFLAGS="--target=pe-i386 $RCFLAGS"
716 else
717 ASFLAGS="$ASFLAGS -f elf32"
720 x86_64)
721 ARCH="X86_64"
722 AS="${AS-nasm}"
723 AS_EXT=".asm"
724 ASFLAGS="$ASFLAGS -DARCH_X86_64=1 -I\$(SRCPATH)/common/x86/"
725 stack_alignment=16
726 [ $compiler = GNU ] && CFLAGS="-m64 $CFLAGS" && LDFLAGS="-m64 $LDFLAGS"
727 if [ "$SYS" = MACOSX ]; then
728 ASFLAGS="$ASFLAGS -f macho64 -DPIC -DPREFIX"
729 if cc_check '' "-arch x86_64"; then
730 CFLAGS="$CFLAGS -arch x86_64"
731 LDFLAGS="$LDFLAGS -arch x86_64"
733 elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
734 ASFLAGS="$ASFLAGS -f win64"
735 if [ $compiler = GNU ]; then
736 # only the GNU toolchain is inconsistent in prefixing function names with _
737 cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
738 cc_check "" "-Wl,--high-entropy-va" && LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"
739 LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
740 LDFLAGSCLI="$LDFLAGSCLI -Wl,--image-base,0x140000000"
741 SOFLAGS="$SOFLAGS -Wl,--image-base,0x180000000"
742 RCFLAGS="--target=pe-x86-64 $RCFLAGS"
744 else
745 ASFLAGS="$ASFLAGS -f elf64"
748 powerpc*)
749 ARCH="PPC"
750 if [ $asm = auto ] ; then
751 define HAVE_ALTIVEC
752 AS="${AS-${CC}}"
753 AS_EXT=".c"
754 if [ $SYS = MACOSX ] ; then
755 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
756 else
757 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
758 define HAVE_ALTIVEC_H
760 if [ "$vsx" != "no" ] ; then
761 vsx="no"
762 if cc_check "" "-mvsx" ; then
763 CFLAGS="$CFLAGS -mvsx"
764 define HAVE_VSX
765 vsx="yes"
770 sparc)
771 ARCH="SPARC"
773 mips*)
774 ARCH="MIPS"
775 AS="${AS-${CC}}"
776 AS_EXT=".c"
778 arm*)
779 ARCH="ARM"
780 if [ "$SYS" = MACOSX ] ; then
781 AS="${AS-${CC}}"
782 ASFLAGS="$ASFLAGS -DPREFIX -DPIC" # apple's ld doesn't support movw/movt relocations at all
783 # build for armv7 by default
784 if ! echo $CFLAGS | grep -Eq '\-arch' ; then
785 CFLAGS="$CFLAGS -arch armv7"
786 LDFLAGS="$LDFLAGS -arch armv7"
788 elif [ "$SYS" = WINDOWS ] ; then
789 AS="${AS-${SRCPATH}/tools/gas-preprocessor.pl -arch arm -as-type armasm -force-thumb -- armasm -nologo -ignore 4509}"
790 else
791 AS="${AS-${CC}}"
794 aarch64)
795 ARCH="AARCH64"
796 stack_alignment=16
797 AS="${AS-${CC}}"
798 if [ "$SYS" = MACOSX ] ; then
799 ASFLAGS="$ASFLAGS -DPREFIX -DPIC"
802 s390|s390x)
803 ARCH="S390"
805 hppa*|parisc*)
806 ARCH="PARISC"
808 ia64)
809 ARCH="IA64"
811 alpha*)
812 ARCH="ALPHA"
815 ARCH="$(echo $host_cpu | tr a-z A-Z)"
817 esac
819 [ "$vsx" != "yes" ] && vsx="no"
821 if [ $SYS = WINDOWS ]; then
822 if ! rc_check "0 RCDATA {0}" ; then
823 RC=""
826 if cpp_check "winapifamily.h" "" "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)" ; then
827 [ $compiler = CL ] || die "WinRT requires MSVC"
828 define HAVE_WINRT
829 CFLAGS="$CFLAGS -MD"
830 LDFLAGS="$LDFLAGS -appcontainer"
831 if ! cpp_check "" "" "defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603" ; then
832 die "_WIN32_WINNT must be defined to at least 0x0603 (Windows 8.1) for WinRT"
833 elif cpp_check "" "" "_WIN32_WINNT >= 0x0A00" ; then
834 # Universal Windows Platform (Windows 10)
835 LDFLAGS="$LDFLAGS -lWindowsApp"
837 cli="no"
838 opencl="no"
842 log_msg "x264 configure script"
843 if [ -n "$*" ]; then
844 msg="Command line options:"
845 for i in $@; do
846 msg="$msg \"$i\""
847 done
848 log_msg "$msg"
850 log_msg ""
852 # check requirements
854 cc_check || die "No working C compiler found."
856 if [ $compiler_style = GNU ]; then
857 if cc_check '' -std=gnu99 'for( int i = 0; i < 9; i++ );' ; then
858 CFLAGS="$CFLAGS -std=gnu99 -D_GNU_SOURCE"
859 elif cc_check '' -std=c99 'for( int i = 0; i < 9; i++ );' ; then
860 CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
861 elif ! cc_check '' '' 'for( int i = 0; i < 9; i++ );' ; then
862 die "C99 compiler is needed for compilation."
866 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
867 pic="yes"
870 if [ $compiler = GNU -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
871 if cc_check '' -mpreferred-stack-boundary=6 ; then
872 CFLAGS="$CFLAGS -mpreferred-stack-boundary=6"
873 stack_alignment=64
874 elif cc_check '' -mpreferred-stack-boundary=5 ; then
875 CFLAGS="$CFLAGS -mpreferred-stack-boundary=5"
876 stack_alignment=32
877 elif [ $stack_alignment -lt 16 ] && cc_check '' -mpreferred-stack-boundary=4 ; then
878 CFLAGS="$CFLAGS -mpreferred-stack-boundary=4"
879 stack_alignment=16
881 elif [ $compiler = ICC -a $ARCH = X86 ]; then
882 # icc on linux has various degrees of mod16 stack support
883 if [ $SYS = LINUX ]; then
884 # >= 12 defaults to a mod16 stack
885 if cpp_check "" "" "__INTEL_COMPILER >= 1200" ; then
886 stack_alignment=16
887 # 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
888 elif cpp_check "" "" "__INTEL_COMPILER >= 1100" ; then
889 CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
890 stack_alignment=16
892 # < 11 is completely incapable of keeping a mod16 stack
896 if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
897 if ! as_check "vmovdqa32 [eax]{k1}{z}, zmm0" ; then
898 VER=`($AS --version || echo no assembler) 2>/dev/null | head -n 1`
899 echo "Found $VER"
900 echo "Minimum version is nasm-2.13"
901 echo "If you really want to compile without asm, configure with --disable-asm."
902 exit 1
904 cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' && define HAVE_X86_INLINE_ASM
905 define HAVE_MMX
908 if [ $asm = auto -a $ARCH = ARM ] ; then
909 # set flags so neon is built by default
910 [ $compiler == CL ] || echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon"
912 cc_check '' '' '__asm__("add r0, r1, r2");' && define HAVE_ARM_INLINE_ASM
913 if [ $compiler = CL ] && cpp_check '' '' 'defined(_M_ARM) && _M_ARM >= 7' ; then
914 define HAVE_ARMV6
915 define HAVE_ARMV6T2
916 define HAVE_NEON
917 elif cc_check '' '' '__asm__("rev ip, ip");' ; then define HAVE_ARMV6
918 cc_check '' '' '__asm__("movt r0, #0");' && define HAVE_ARMV6T2
919 cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
920 ASFLAGS="$ASFLAGS -c"
921 else
922 echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
923 echo "If you really want to run on such a CPU, configure with --disable-asm."
924 exit 1
928 if [ $asm = auto -a $ARCH = AARCH64 ] ; then
929 if cc_check '' '' '__asm__("cmeq v0.8h, v0.8h, #0");' ; then define HAVE_NEON
930 ASFLAGS="$ASFLAGS -c"
931 else
932 echo "no NEON support, try adding -mfpu=neon to CFLAGS"
933 echo "If you really want to run on such a CPU, configure with --disable-asm."
934 exit 1
938 if [ $asm = auto -a \( $ARCH = ARM -o $ARCH = AARCH64 \) ] ; then
939 # check if the assembler supports '.func' (clang 3.5 does not)
940 as_check ".func test${NL}.endfunc" && define HAVE_AS_FUNC 1
943 if [ $asm = auto -a $ARCH = MIPS ] ; then
944 if ! echo $CFLAGS | grep -Eq '(-march|-mmsa|-mno-msa)' ; then
945 cc_check '' '-mmsa -mfp64 -mhard-float' && CFLAGS="-mmsa -mfp64 -mhard-float $CFLAGS"
948 if cc_check '' '' '__asm__("addvi.b $w0, $w1, 1");' ; then
949 define HAVE_MSA
950 else
951 echo "You specified a pre-MSA CPU in your CFLAGS."
952 echo "If you really want to run on such a CPU, configure with --disable-asm."
953 exit 1
957 [ $asm = no ] && AS=""
958 [ "x$AS" = x ] && asm="no" || asm="yes"
960 define ARCH_$ARCH
961 define SYS_$SYS
963 define STACK_ALIGNMENT $stack_alignment
964 ASFLAGS="$ASFLAGS -DSTACK_ALIGNMENT=$stack_alignment"
966 # 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
967 CPU_ENDIAN="little-endian"
968 if [ $compiler = GNU ]; then
969 echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
970 $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
971 if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
972 define WORDS_BIGENDIAN
973 CPU_ENDIAN="big-endian"
974 elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then
975 die "endian test failed"
979 if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then
980 [ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static"
981 if $PKGCONFIG --exists x264 2>/dev/null; then
982 X264_LIBS="$($PKGCONFIG --libs x264)"
983 X264_INCLUDE_DIR="${X264_INCLUDE_DIR-$($PKGCONFIG --variable=includedir x264)}"
984 configure_system_override "$X264_INCLUDE_DIR" || die "Detection of system libx264 configuration failed"
985 else
986 die "Can not find system libx264"
990 # autodetect options that weren't forced nor disabled
992 libpthread=""
993 if [ "$SYS" = "WINDOWS" -a "$thread" = "posix" ] ; then
994 if [ "$gpl" = "no" ] ; then
995 echo "Warning: pthread-win32 is LGPL and is therefore not supported with --disable-gpl"
996 thread="no"
997 elif cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
998 libpthread="-lpthread"
999 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
1000 libpthread="-lpthreadGC2"
1001 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
1002 libpthread="-lpthreadGC2 -lwsock32"
1003 define PTW32_STATIC_LIB
1004 elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
1005 libpthread="-lpthreadGC2 -lws2_32"
1006 define PTW32_STATIC_LIB
1007 else
1008 thread="no"
1010 elif [ "$thread" != "no" ] ; then
1011 thread="no"
1012 case $SYS in
1013 BEOS)
1014 thread="beos"
1015 define HAVE_BEOSTHREAD
1017 WINDOWS)
1018 thread="win32"
1019 define HAVE_WIN32THREAD
1021 QNX)
1022 cc_check pthread.h -lc "pthread_create(0,0,0,0);" && thread="posix" && libpthread="-lc"
1025 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
1026 thread="posix"
1027 libpthread="-lpthread"
1028 else
1029 cc_check pthread.h "" "pthread_create(0,0,0,0);" && thread="posix" && libpthread=""
1032 esac
1034 if [ "$thread" = "posix" ]; then
1035 LDFLAGS="$LDFLAGS $libpthread"
1036 define HAVE_POSIXTHREAD
1037 if [ "$SYS" = "LINUX" ] && cc_check sched.h "-D_GNU_SOURCE -Werror" "cpu_set_t p_aff; return CPU_COUNT(&p_aff);" ; then
1038 define HAVE_CPU_COUNT
1041 [ "$thread" != "no" ] && define HAVE_THREAD
1043 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
1044 define HAVE_LOG2F
1047 if [ "$SYS" != "WINDOWS" ] && cpp_check "sys/mman.h unistd.h" "" "defined(MAP_PRIVATE)"; then
1048 define HAVE_MMAP
1051 if [ "$SYS" = "LINUX" -a \( "$ARCH" = "X86" -o "$ARCH" = "X86_64" \) ] && cc_check "sys/mman.h" "" "MADV_HUGEPAGE;" ; then
1052 define HAVE_THP
1055 if [ "$cli" = "no" ] ; then
1056 avs="no"
1057 lavf="no"
1058 ffms="no"
1059 gpac="no"
1060 lsmash="no"
1061 mp4="no"
1062 swscale="no"
1065 if [ "$swscale" = "auto" ] ; then
1066 swscale="no"
1067 if $PKGCONFIG --exists libswscale 2>/dev/null; then
1068 SWSCALE_LIBS="$SWSCALE_LIBS $($PKGCONFIG --libs libswscale libavutil)"
1069 SWSCALE_CFLAGS="$SWSCALE_CFLAGS $($PKGCONFIG --cflags libswscale libavutil)"
1071 [ -z "$SWSCALE_LIBS" ] && SWSCALE_LIBS="-lswscale -lavutil"
1073 if cc_check "libswscale/swscale.h" "$SWSCALE_CFLAGS $SWSCALE_LIBS" "sws_init_context(0,0,0);" ; then
1074 if cpp_check "libavutil/pixdesc.h" "$SWSCALE_CFLAGS $SWSCALE_LIBS" "defined(AV_PIX_FMT_FLAG_RGB)" ; then
1075 swscale="yes"
1076 else
1077 echo "Warning: AV_PIX_FMT_FLAG_RGB is missing from libavutil, update for swscale support"
1082 if [ "$lavf" = "auto" ] ; then
1083 lavf="no"
1084 if $PKGCONFIG --exists libavformat libavcodec libswscale 2>/dev/null; then
1085 LAVF_LIBS="$LAVF_LIBS $($PKGCONFIG --libs libavformat libavcodec libavutil libswscale)"
1086 LAVF_CFLAGS="$LAVF_CFLAGS $($PKGCONFIG --cflags libavformat libavcodec libavutil libswscale)"
1088 if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
1089 LAVF_LIBS="-lavformat"
1090 for lib in -lpostproc -lavcodec -lswscale -lavutil -lm -lz -lbz2 $libpthread -lavifil32 -lws2_32; do
1091 cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
1092 done
1094 LAVF_LIBS="-L. $LAVF_LIBS"
1095 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "av_frame_free(0);" ; then
1096 if [ "$swscale" = "yes" ]; then
1097 lavf="yes"
1098 else
1099 echo "Warning: libavformat is not supported without swscale support"
1104 if [ "$ffms" = "auto" ] ; then
1105 ffms_major="2"; ffms_minor="21"; ffms_micro="0"; ffms_bump="0"
1106 ffms="no"
1108 if $PKGCONFIG --exists ffms2 2>/dev/null; then
1109 FFMS2_LIBS="$FFMS2_LIBS $($PKGCONFIG --libs ffms2)"
1110 FFMS2_CFLAGS="$FFMS2_CFLAGS $($PKGCONFIG --cflags ffms2)"
1112 [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
1114 if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
1115 ffms="yes"
1116 elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
1117 ffms="yes"
1118 FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
1121 error="ffms must be at least version $ffms_major.$ffms_minor.$ffms_micro.$ffms_bump"
1122 if [ $ffms = "yes" ] && ! cpp_check "ffms.h" "$FFMS2_CFLAGS" "FFMS_VERSION >= (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)" "$error"; then
1123 ffms="no"
1124 echo "Warning: $error"
1126 if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
1127 echo "Warning: ffms is not supported without swscale support"
1128 ffms="no"
1132 if [ "$swscale" = "yes" ]; then
1133 LDFLAGSCLI="$SWSCALE_LIBS $LDFLAGSCLI"
1134 CFLAGS="$CFLAGS $SWSCALE_CFLAGS"
1135 define HAVE_SWSCALE
1136 if [ "$lavf" = "yes" ]; then
1137 LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
1138 CFLAGS="$CFLAGS $LAVF_CFLAGS"
1139 define HAVE_LAVF
1141 if [ "$ffms" = "yes" ]; then
1142 LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
1143 CFLAGS="$CFLAGS $FFMS2_CFLAGS"
1144 define HAVE_FFMS
1148 if [ "$lsmash" = "auto" ] ; then
1149 lsmash="no"
1150 if $PKGCONFIG --exists liblsmash 2>/dev/null; then
1151 LSMASH_LIBS="$LSMASH_LIBS $($PKGCONFIG --libs liblsmash)"
1152 LSMASH_CFLAGS="$LSMASH_CFLAGS $($PKGCONFIG --cflags liblsmash)"
1154 [ -z "$LSMASH_LIBS" ] && LSMASH_LIBS="-llsmash"
1156 if cc_check lsmash.h "$LSMASH_CFLAGS $LSMASH_LIBS" ; then
1157 if cpp_check lsmash.h "$LSMASH_CFLAGS" "LSMASH_VERSION_MAJOR > 1 || (LSMASH_VERSION_MAJOR == 1 && LSMASH_VERSION_MINOR >= 5)" ; then
1158 lsmash="yes"
1159 else
1160 echo "Warning: lsmash is too old, update to rev.895 or later"
1165 if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then
1166 gpac="no"
1167 GPAC_LIBS="-lgpac_static"
1168 cc_check "" -lz && GPAC_LIBS="$GPAC_LIBS -lz"
1169 if [ "$SYS" = "WINDOWS" ] ; then
1170 cc_check "" -lws2_32 && GPAC_LIBS="$GPAC_LIBS -lws2_32"
1171 cc_check "" -lwinmm && GPAC_LIBS="$GPAC_LIBS -lwinmm"
1173 if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
1174 if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
1175 gpac="yes"
1176 else
1177 echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
1182 if [ "$lsmash" = "yes" ] ; then
1183 mp4="lsmash"
1184 LDFLAGSCLI="$LSMASH_LIBS $LDFLAGSCLI"
1185 CFLAGS="$CFLAGS $LSMASH_CFLAGS"
1186 define HAVE_LSMASH
1187 elif [ "$gpac" = "yes" ] ; then
1188 mp4="gpac"
1189 define HAVE_GPAC
1190 LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
1193 if [ "$avi_output" = "auto" ] ; then
1194 avi_output="no"
1195 if ${cross_prefix}pkg-config --exists libavformat 2>$DEVNULL; then
1196 AVI_LIBS="$AVI_LIBS $(${cross_prefix}pkg-config --libs libavformat)"
1197 AVI_CFLAGS="$AVI_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat)"
1199 if [ -z "$AVI_LIBS" -a -z "$AVI_CFLAGS" ]; then
1200 AVI_LIBS="-lavformat"
1201 for lib in -lavcodec -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
1202 cc_check "" $lib && AVI_LIBS="$AVI_LIBS $lib"
1203 done
1205 AVI_LIBS="-L. $AVI_LIBS"
1206 if cc_check libavformat/avformat.h "$AVI_CFLAGS $AVI_LIBS" ; then
1207 if cc_check libavformat/avformat.h "$AVI_CFLAGS $AVI_LIBS" 'av_register_all(); av_guess_format( "avi", NULL, NULL );' ; then
1208 avi_output="yes"
1213 if [ "$avi_output" = "yes" ]; then
1214 LDFLAGSCLI="$AVI_LIBS $LDFLAGSCLI"
1215 [ -n "$AVI_CFLAGS" ] && CFLAGS="$CFLAGS $AVI_CFLAGS"
1216 define HAVE_AVI_OUTPUT
1219 if [ "$avs" = "auto" ] ; then
1220 avs="no"
1221 # cygwin can use avisynth if it can use LoadLibrary
1222 if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibraryW(0);") ; then
1223 avs="avisynth"
1224 define HAVE_AVS
1225 define USE_AVXSYNTH 0
1226 elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
1227 # AvxSynth currently only supports Linux and OSX
1228 avs="avxsynth"
1229 define HAVE_AVS
1230 define USE_AVXSYNTH 1
1231 AVS_LIBS="-ldl"
1232 LDFLAGSCLI="$AVS_LIBS $LDFLAGSCLI"
1236 cc_check "stdint.h" "" "uint32_t test_vec __attribute__ ((vector_size (16))) = {0,1,2,3};" && define HAVE_VECTOREXT
1238 if [ "$pic" = "yes" ] ; then
1239 [ "$SYS" != WINDOWS -a "$SYS" != CYGWIN ] && CFLAGS="$CFLAGS -fPIC"
1240 ASFLAGS="$ASFLAGS -DPIC"
1241 # resolve textrels in the x86 asm
1242 cc_check stdio.h "-shared -Wl,-Bsymbolic" && SOFLAGS="$SOFLAGS -Wl,-Bsymbolic"
1243 [ $SYS = SunOS -a "$ARCH" = "X86" ] && SOFLAGS="$SOFLAGS -mimpure-text"
1246 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
1247 CFLAGS="$CFLAGS -fomit-frame-pointer"
1250 if [ "$strip" = "yes" ]; then
1251 LDFLAGS="$LDFLAGS -s"
1254 if [ "$debug" = "yes" ]; then
1255 CFLAGS="-O1 -g $CFLAGS"
1256 RCFLAGS="$RCFLAGS -DDEBUG"
1257 else
1258 CFLAGS="-O3 -ffast-math $CFLAGS"
1259 if [ "$lto" = "auto" ] && [ $compiler = GNU ] && cc_check "" "-flto" ; then
1260 lto="yes"
1261 CFLAGS="$CFLAGS -flto"
1262 LDFLAGS="$LDFLAGS -O3 -flto"
1265 [ "$lto" = "auto" ] && lto="no"
1267 if cc_check '' -fno-tree-vectorize ; then
1268 CFLAGS="$CFLAGS -fno-tree-vectorize"
1271 if [ $SYS = WINDOWS -a $ARCH = X86 -a $compiler = GNU ] ; then
1272 # workaround gcc/ld bug with alignment of static variables/arrays that are initialized to zero
1273 cc_check '' -fno-zero-initialized-in-bss && CFLAGS="$CFLAGS -fno-zero-initialized-in-bss"
1276 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
1277 define fseek fseeko
1278 define ftell ftello
1279 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
1280 define fseek fseeko64
1281 define ftell ftello64
1282 elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then
1283 define fseek _fseeki64
1284 define ftell _ftelli64
1287 if cc_check '' -Wshadow ; then
1288 CFLAGS="-Wshadow $CFLAGS"
1291 if cc_check '' -Wmaybe-uninitialized ; then
1292 CFLAGS="-Wno-maybe-uninitialized $CFLAGS"
1295 if [ $compiler = ICC -o $compiler = ICL ] ; then
1296 if cc_check 'extras/intel_dispatcher.h' '' 'x264_intel_dispatcher_override();' ; then
1297 define HAVE_INTEL_DISPATCHER
1301 if [ "$bit_depth" -gt "8" ]; then
1302 define HIGH_BIT_DEPTH
1303 ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH=1"
1304 opencl="no"
1305 else
1306 ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH=0"
1309 if [ "$chroma_format" != "all" ]; then
1310 define CHROMA_FORMAT CHROMA_$chroma_format
1313 ASFLAGS="$ASFLAGS -DBIT_DEPTH=$bit_depth"
1315 [ $gpl = yes ] && define HAVE_GPL && x264_gpl=1 || x264_gpl=0
1317 [ $interlaced = yes ] && define HAVE_INTERLACED && x264_interlaced=1 || x264_interlaced=0
1319 libdl=""
1320 if [ "$opencl" = "yes" ]; then
1321 opencl="no"
1322 # cygwin can use opencl if it can use LoadLibrary
1323 if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibraryW(0);") ; then
1324 opencl="yes"
1325 define HAVE_OPENCL
1326 elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
1327 opencl="yes"
1328 define HAVE_OPENCL
1329 libdl="-ldl"
1331 LDFLAGS="$LDFLAGS $libdl"
1334 #define undefined vars as 0
1335 for var in $CONFIG_HAVE; do
1336 grep -q "HAVE_$var 1" config.h || define HAVE_$var 0
1337 done
1339 # generate exported config file
1341 config_chroma_format="X264_CSP_I$chroma_format"
1342 [ "$config_chroma_format" == "X264_CSP_Iall" ] && config_chroma_format="0"
1343 cat > x264_config.h << EOF
1344 #define X264_BIT_DEPTH $bit_depth
1345 #define X264_GPL $x264_gpl
1346 #define X264_INTERLACED $x264_interlaced
1347 #define X264_CHROMA_FORMAT $config_chroma_format
1350 if [ "$cli_libx264" = "system" ] ; then
1351 if [ "$shared" = "yes" ]; then
1352 CLI_LIBX264='$(SONAME)'
1353 else
1354 CLI_LIBX264=
1355 LDFLAGSCLI="$X264_LIBS $LDFLAGSCLI"
1356 cc_check 'stdint.h x264.h' '' 'x264_encoder_open(0);' || die "System libx264 can't be used for compilation of this version"
1358 else
1359 CLI_LIBX264='$(LIBX264)'
1362 DEPMM="${QPRE}MM"
1363 DEPMT="${QPRE}MT"
1364 if [ $compiler_style = MS ]; then
1365 AR="lib.exe -nologo -out:"
1366 LD="link.exe -out:"
1367 if [ $compiler = ICL ]; then
1368 AR="xi$AR"
1369 LD="xi$LD"
1370 else
1371 mslink="$(dirname "$(command -v cl.exe 2>/dev/null)")/link.exe"
1372 [ -x "$mslink" ] && LD="\"$mslink\" -out:"
1374 HAVE_GETOPT_LONG=0
1375 LDFLAGS="-nologo -incremental:no $(cl_ldflags $LDFLAGS)"
1376 LDFLAGSCLI="$(cl_ldflags $LDFLAGSCLI)"
1377 LIBX264=libx264.lib
1378 RANLIB=
1379 [ -n "$RC" ] && RCFLAGS="$RCFLAGS -nologo -I. -I\$(SRCPATH)/extras -fo"
1380 STRIP=
1381 if [ $debug = yes ]; then
1382 LDFLAGS="-debug $LDFLAGS"
1383 CFLAGS="-D_DEBUG $CFLAGS"
1384 else
1385 CFLAGS="-DNDEBUG $CFLAGS"
1387 else # gcc/icc
1388 DEPMM="$DEPMM -g0"
1389 AR="$AR rc "
1390 LD="$CC -o "
1391 LIBX264=libx264.a
1392 [ -n "$RC" ] && RCFLAGS="$RCFLAGS -I. -o "
1394 [ $compiler != GNU ] && CFLAGS="$(cc_cflags $CFLAGS)"
1395 if [ $compiler = ICC -o $compiler = ICL ]; then
1396 # icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP
1397 [ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
1398 PROF_GEN_CC="${QPRE}prof-gen ${QPRE}prof-dir."
1399 PROF_GEN_LD=
1400 PROF_USE_CC="${QPRE}prof-use ${QPRE}prof-dir."
1401 PROF_USE_LD=
1402 elif [ $compiler = CL ]; then
1403 # Visual Studio
1404 # _M_IX86_FP is only defined on x86
1405 [ $ARCH = X86 ] && cpp_check '' '' '_M_IX86_FP >= 1' && define __SSE__
1406 [ $ARCH = X86_64 ] && define __SSE__
1407 # As long as the cli application can't link against the dll, the dll can not be pgo'd.
1408 # pgds are link flag specific and the -dll flag for creating the dll makes it unshareable with the cli
1409 PROF_GEN_CC="-GL"
1410 PROF_GEN_LD="-LTCG:PGINSTRUMENT"
1411 PROF_USE_CC="-GL"
1412 PROF_USE_LD="-LTCG:PGOPTIMIZE"
1413 else
1414 PROF_GEN_CC="-fprofile-generate"
1415 PROF_GEN_LD="-fprofile-generate"
1416 PROF_USE_CC="-fprofile-use"
1417 PROF_USE_LD="-fprofile-use"
1420 # generate config files
1422 cat > config.mak << EOF
1423 SRCPATH=$SRCPATH
1424 prefix=$prefix
1425 exec_prefix=$exec_prefix
1426 bindir=$bindir
1427 libdir=$libdir
1428 includedir=$includedir
1429 SYS_ARCH=$ARCH
1430 SYS=$SYS
1431 CC=$CC
1432 CFLAGS=$CFLAGS
1433 COMPILER=$compiler
1434 COMPILER_STYLE=$compiler_style
1435 DEPMM=$DEPMM
1436 DEPMT=$DEPMT
1437 LD=$LD
1438 LDFLAGS=$LDFLAGS
1439 LIBX264=$LIBX264
1440 AR=$AR
1441 RANLIB=$RANLIB
1442 STRIP=$STRIP
1443 INSTALL=$INSTALL
1444 AS=$AS
1445 ASFLAGS=$ASFLAGS
1446 RC=$RC
1447 RCFLAGS=$RCFLAGS
1448 EXE=$EXE
1449 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
1450 DEVNULL=$DEVNULL
1451 PROF_GEN_CC=$PROF_GEN_CC
1452 PROF_GEN_LD=$PROF_GEN_LD
1453 PROF_USE_CC=$PROF_USE_CC
1454 PROF_USE_LD=$PROF_USE_LD
1455 HAVE_OPENCL=$opencl
1458 if [ $compiler_style = MS ]; then
1459 echo '%.o: %.c' >> config.mak
1460 echo ' $(CC) $(CFLAGS) -c -Fo$@ $<' >> config.mak
1463 if [ "$cli" = "yes" ]; then
1464 echo 'default: cli' >> config.mak
1465 echo 'install: install-cli' >> config.mak
1468 if [ "$shared" = "yes" ]; then
1469 API=$(grep '#define X264_BUILD' < ${SRCPATH}/x264.h | cut -f 3 -d ' ')
1470 if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
1471 echo "SONAME=libx264-$API.dll" >> config.mak
1472 if [ $compiler_style = MS ]; then
1473 echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak
1474 # GNU ld on windows defaults to exporting all global functions if there are no explicit __declspec(dllexport) declarations
1475 # MSVC link does not act similarly, so it is required to make an export definition out of x264.h and use it at link time
1476 echo "SOFLAGS=-dll -def:x264.def -implib:\$(IMPLIBNAME) $SOFLAGS" >> config.mak
1477 echo "EXPORTS" > x264.def
1478 # export API functions
1479 grep "^\(int\|void\|x264_t\).*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264.*\)(.*/\1/;s/open/open_$API/g" >> x264.def
1480 # export API variables/data. must be flagged with the DATA keyword
1481 grep "extern.*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264\w*\)\W.*/\1 DATA/;" >> x264.def
1482 else
1483 echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
1484 echo "SOFLAGS=-shared -Wl,--out-implib,\$(IMPLIBNAME) $SOFLAGS" >> config.mak
1486 elif [ "$SYS" = "MACOSX" ]; then
1487 echo "SOSUFFIX=dylib" >> config.mak
1488 echo "SONAME=libx264.$API.dylib" >> config.mak
1489 echo "SOFLAGS=-shared -dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name \$(DESTDIR)\$(libdir)/\$(SONAME) $SOFLAGS" >> config.mak
1490 elif [ "$SYS" = "SunOS" ]; then
1491 echo "SOSUFFIX=so" >> config.mak
1492 echo "SONAME=libx264.so.$API" >> config.mak
1493 echo "SOFLAGS=-shared -Wl,-h,\$(SONAME) $SOFLAGS" >> config.mak
1494 else
1495 echo "SOSUFFIX=so" >> config.mak
1496 echo "SONAME=libx264.so.$API" >> config.mak
1497 echo "SOFLAGS=-shared -Wl,-soname,\$(SONAME) $SOFLAGS" >> config.mak
1499 echo 'default: lib-shared' >> config.mak
1500 echo 'install: install-lib-shared' >> config.mak
1503 if [ "$static" = "yes" ]; then
1504 echo 'default: lib-static' >> config.mak
1505 echo 'install: install-lib-static' >> config.mak
1508 echo "LDFLAGSCLI = $LDFLAGSCLI" >> config.mak
1509 echo "CLI_LIBX264 = $CLI_LIBX264" >> config.mak
1511 ${SRCPATH}/version.sh >> x264_config.h
1513 cat > x264.pc << EOF
1514 prefix=$prefix
1515 exec_prefix=$exec_prefix
1516 libdir=$libdir
1517 includedir=$includedir
1519 Name: x264
1520 Description: H.264 (MPEG4 AVC) encoder library
1521 Version: $(grep POINTVER < x264_config.h | sed -e 's/.* "//; s/".*//')
1522 Libs: -L$libdir -lx264 $([ "$shared" = "yes" ] || echo $libpthread $libm $libdl)
1523 Libs.private: $([ "$shared" = "yes" ] && echo $libpthread $libm $libdl)
1524 Cflags: -I$includedir
1527 filters="crop select_every hqdn3d pad vflip"
1528 gpl_filters="yadif"
1529 [ $swscale = yes ] && filters="resize $filters"
1530 [ $gpl = yes ] && filters="$filters $gpl_filters"
1531 [ $SYS = WINDOWS ] && filters="$filters subtitles"
1533 cat > conftest.log <<EOF
1534 platform: $ARCH
1535 byte order: $CPU_ENDIAN
1536 system: $SYS
1537 cli: $cli
1538 libx264: $cli_libx264
1539 shared: $shared
1540 static: $static
1541 asm: $asm
1542 interlaced: $interlaced
1543 avs: $avs
1544 lavf: $lavf
1545 ffms: $ffms
1546 mp4: $mp4
1547 avi output: $avi_output
1548 gpl: $gpl
1549 thread: $thread
1550 opencl: $opencl
1551 filters: $filters
1552 lto: $lto
1553 debug: $debug
1554 gprof: $gprof
1555 strip: $strip
1556 PIC: $pic
1557 bit depth: $bit_depth
1558 chroma format: $chroma_format
1561 echo >> config.log
1562 cat conftest.log >> config.log
1563 cat conftest.log
1565 [ "$SRCPATH" != "." ] && ln -sf ${SRCPATH}/Makefile ./Makefile
1566 mkdir -p common/{aarch64,arm,mips,ppc,x86} encoder extras filters/video input output tools
1568 echo
1569 echo "You can run 'make' or 'make fprofiled' now."