]> git.sesse.net Git - x264/blob - configure
Add SSE support to rectangle.h for 16-byte stores
[x264] / configure
1 #!/bin/bash
2
3 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
4 cat <<EOF
5 Usage: ./configure [options]
6
7 available options:
8
9   --help                   print this message
10   --disable-avs            disables avisynth support (windows only)
11   --disable-lavf           disables libavformat support
12   --disable-ffms           disables ffmpegsource support
13   --disable-gpac           disables gpac support
14   --disable-gpl            disables GPL-only features
15   --disable-thread         disables multithreaded encoding
16   --enable-win32thread     use win32threads (windows only)
17   --disable-swscale        disables swscale support
18   --disable-asm            disables platform-specific assembly optimizations
19   --enable-debug           adds -g, doesn't strip
20   --enable-gprof           adds -pg, doesn't strip
21   --enable-visualize       enables visualization (X11 only)
22   --enable-pic             build position-independent code
23   --enable-shared          build shared library
24   --bit-depth=BIT_DEPTH    sets output bit depth (8-10), default 8
25   --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS
26   --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS
27   --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS
28   --host=HOST              build programs to run on HOST
29   --cross-prefix=PREFIX    use PREFIX for compilation tools
30   --sysroot=SYSROOT        root of cross-build tree
31
32 EOF
33 exit 1
34 fi
35
36 log_check() {
37     echo -n "checking $1... " >> config.log
38 }
39
40 log_ok() {
41     echo "yes" >> config.log
42 }
43
44 log_fail() {
45     echo "no" >> config.log
46 }
47
48 log_msg() {
49     echo "$1" >> config.log
50 }
51
52 intel_cflags() {
53     # Intel Compiler issues an incredibly large number of warnings on any warning level,
54     # suppress them by disabling all warnings rather than having to use #pragmas to disable most of them
55     for arg in $*; do
56         [ $arg = -ffast-math ] && arg=
57         [[ "$arg" = -falign-loops* ]] && arg=
58         [ "$arg" = -fno-tree-vectorize ] && arg=
59         [ "$arg" = -Wshadow ] && arg=
60         if [ $compiler = ICL ]; then
61             [ "$arg" = -Wall ] && arg=-W0
62             [ "$arg" = -g ] && arg=-Z7
63             [ "$arg" = -fomit-frame-pointer ] && arg=
64             [ "$arg" = -s ] && arg=
65             [ "$arg" = -fPIC ] && arg=
66         else
67             [ "$arg" = -Wall ] && arg=-w0
68         fi
69
70         [ -n "$arg" ] && echo -n "$arg "
71     done
72 }
73
74 icl_ldflags() {
75     for arg in $*; do
76         arg=${arg/LIBPATH/libpath}
77         [ ${arg#-libpath:} == $arg -a ${arg#-l} != $arg ] && arg=${arg#-l}.lib
78         [ ${arg#-L} != $arg ] && arg=-libpath:${arg#-L}
79         [ $arg = -Wl,--large-address-aware ] && arg=-largeaddressaware
80         [ $arg = -s ] && arg=
81         [ "$arg" = -Wl,-Bsymbolic ] && arg=
82
83         arg=${arg/pthreadGC/pthreadVC}
84         [ "$arg" = avifil32.lib ] && arg=vfw32.lib
85         [ "$arg" = gpac_static.lib ] && arg=libgpac_static.lib
86
87         [ -n "$arg" ] && echo -n "$arg "
88     done
89 }
90
91 cc_check() {
92     if [ -z "$3" ]; then
93         if [ -z "$1$2" ]; then
94             log_check "whether $CC works"
95         elif [ -z "$1" ]; then
96             log_check "for $2"
97         else
98             log_check "for $1"
99         fi
100     elif [ -z "$1" ]; then
101         if [ -z "$2" ]; then
102             log_check "whether $CC supports $3"
103         else
104             log_check "whether $CC supports $3 with $2"
105         fi
106     else
107         log_check "for $3 in $1";
108     fi
109     rm -f conftest.c
110     [ -n "$1" ] && echo "#include <$1>" > conftest.c
111     echo "int main () { $3 return 0; }" >> conftest.c
112     if [ $compiler = ICL ]; then
113         cc_cmd="$CC conftest.c $CFLAGS $2 -link $(icl_ldflags $2 $LDFLAGSCLI $LDFLAGS)"
114     else
115         cc_cmd="$CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest"
116     fi
117     if $cc_cmd >conftest.log 2>&1; then
118         res=$?
119         log_ok
120     else
121         res=$?
122         log_fail
123         log_msg "Failed commandline was:"
124         log_msg "--------------------------------------------------"
125         log_msg "$cc_cmd"
126         cat conftest.log >> config.log
127         log_msg "--------------------------------------------------"
128         log_msg "Failed program was:"
129         log_msg "--------------------------------------------------"
130         cat conftest.c >> config.log
131         log_msg "--------------------------------------------------"
132     fi
133     return $res
134 }
135
136 cpp_check() {
137     log_check "whether $3 is true"
138     rm -f conftest.c
139     [ -n "$1" ] && echo "#include <$1>" > conftest.c
140     echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c
141
142     if $CC conftest.c $CFLAGS $2 -E -o conftest >conftest.log 2>&1; then
143         res=$?
144         log_ok
145     else
146         res=$?
147         log_fail
148         log_msg "--------------------------------------------------"
149         cat conftest.log >> config.log
150         log_msg "--------------------------------------------------"
151         log_msg "Failed program was:"
152         log_msg "--------------------------------------------------"
153         cat conftest.c >> config.log
154         log_msg "--------------------------------------------------"
155     fi
156     return $res
157 }
158
159 as_check() {
160     log_check "whether $AS supports $1"
161     echo "$1" > conftest.asm
162     if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
163         res=$?
164         log_ok
165     else
166         res=$?
167         log_fail
168         log_msg "Failed commandline was:"
169         log_msg "--------------------------------------------------"
170         log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
171         cat conftest.log >> config.log
172         log_msg "--------------------------------------------------"
173         log_msg "Failed program was:"
174         log_msg "--------------------------------------------------"
175         cat conftest.asm >> config.log
176         log_msg "--------------------------------------------------"
177     fi
178     return $res
179 }
180
181 define() {
182     echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
183 }
184
185 die() {
186     log_msg "DIED: $@"
187     echo "$@"
188     exit 1
189 }
190
191 rm -f x264_config.h config.h config.mak config.log x264.pc x264.def conftest*
192
193 prefix='/usr/local'
194 exec_prefix='${prefix}'
195 bindir='${exec_prefix}/bin'
196 libdir='${exec_prefix}/lib'
197 includedir='${prefix}/include'
198 DEVNULL='/dev/null'
199
200 avs="auto"
201 lavf="auto"
202 ffms="auto"
203 gpac="auto"
204 gpl="yes"
205 thread="auto"
206 swscale="auto"
207 asm="auto"
208 debug="no"
209 gprof="no"
210 pic="no"
211 vis="no"
212 shared="no"
213 bit_depth="8"
214 compiler="GNU"
215
216 CFLAGS="$CFLAGS -Wall -I."
217 LDFLAGS="$LDFLAGS"
218 LDFLAGSCLI="$LDFLAGSCLI"
219 ASFLAGS="$ASFLAGS"
220 HAVE_GETOPT_LONG=1
221 cross_prefix=""
222
223 EXE=""
224
225 # list of all preprocessor HAVE values we can define
226 CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F VISUALIZE SWSCALE LAVF FFMS GPAC GF_MALLOC AVS GPL VECTOREXT"
227
228 # parse options
229
230 for opt do
231     optarg="${opt#*=}"
232     case "$opt" in
233         --prefix=*)
234             prefix="$optarg"
235             ;;
236         --exec-prefix=*)
237             exec_prefix="$optarg"
238             ;;
239         --bindir=*)
240             bindir="$optarg"
241             ;;
242         --libdir=*)
243             libdir="$optarg"
244             ;;
245         --includedir=*)
246             includedir="$optarg"
247             ;;
248         --disable-asm)
249             asm="no"
250             ;;
251         --disable-avs)
252             avs="no"
253             ;;
254         --disable-lavf)
255             lavf="no"
256             ;;
257         --disable-ffms)
258             ffms="no"
259             ;;
260         --disable-gpac)
261             gpac="no"
262             ;;
263         --disable-gpl)
264             gpl="no"
265             ;;
266         --extra-asflags=*)
267             ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
268             ;;
269         --extra-cflags=*)
270             CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
271             ;;
272         --extra-ldflags=*)
273             LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
274             ;;
275         --disable-thread)
276             thread="no"
277             ;;
278         --enable-win32thread)
279             thread="win32"
280             ;;
281         --disable-swscale)
282             swscale="no"
283             ;;
284         --enable-debug)
285             debug="yes"
286             ;;
287         --enable-gprof)
288             CFLAGS="$CFLAGS -pg"
289             LDFLAGS="$LDFLAGS -pg"
290             gprof="yes"
291             ;;
292         --enable-pic)
293             pic="yes"
294             ;;
295         --enable-shared)
296             shared="yes"
297             ;;
298         --enable-visualize)
299             vis="yes"
300             ;;
301         --host=*)
302             host="${opt#--host=}"
303             ;;
304         --cross-prefix=*)
305             cross_prefix="${opt#--cross-prefix=}"
306             ;;
307         --sysroot=*)
308             CFLAGS="$CFLAGS --sysroot=${opt#--sysroot=}"
309             LDFLAGS="$LDFLAGS --sysroot=${opt#--sysroot=}"
310             ;;
311         --bit-depth=*)
312             bit_depth="${opt#--bit-depth=}"
313             if [ "$bit_depth" -lt "8" -o "$bit_depth" -gt "10" ]; then
314                 echo "Supplied bit depth must be in range [8,10]."
315                 exit 1
316             fi
317             bit_depth=`expr $bit_depth + 0`
318             ;;
319         *)
320             echo "Unknown option $opt, ignored"
321             ;;
322     esac
323 done
324
325 CC="${CC-${cross_prefix}gcc}"
326 AR="${AR-${cross_prefix}ar}"
327 RANLIB="${RANLIB-${cross_prefix}ranlib}"
328 STRIP="${STRIP-${cross_prefix}strip}"
329
330 if [ "x$host" = x ]; then
331     host=`./config.guess`
332 fi
333 # normalize a triplet into a quadruplet
334 host=`./config.sub $host`
335
336 # split $host
337 host_cpu="${host%%-*}"
338 host="${host#*-}"
339 host_vendor="${host%%-*}"
340 host_os="${host#*-}"
341
342 # test for use of Intel Compiler
343 if [[ $host_os = mingw* || $host_os = cygwin* ]]; then
344     if [[ `basename "$CC"` = icl* ]]; then
345         # Windows Intel Compiler creates dependency generation with absolute Windows paths, Cygwin's make does not support Windows paths.
346         [[ $host_os = cygwin* ]] && die "Windows Intel Compiler support requires MSYS"
347         compiler=ICL
348         CFLAGS="$CFLAGS -Qstd=c99 -nologo -Qms0 -DHAVE_STRING_H -Iextras"
349         QPRE="-Q"
350         `$CC 2>&1 | grep -q IA-32` && host_cpu=i486
351         `$CC 2>&1 | grep -q "Intel(R) 64"` && host_cpu=x86_64
352         cpp_check "" "" "_MSC_VER >= 1400" || die "Windows Intel Compiler support requires Visual Studio 2005 or newer"
353     fi
354 else
355     if [[ `basename "$CC"` = icc* ]]; then
356         AR="xiar"
357         compiler=ICC
358         QPRE="-"
359     fi
360 fi
361
362 case $host_os in
363     beos*)
364         SYS="BEOS"
365         define HAVE_MALLOC_H
366         ;;
367     darwin*)
368         SYS="MACOSX"
369         CFLAGS="$CFLAGS -falign-loops=16"
370         LDFLAGS="$LDFLAGS -lm"
371         if [ "$pic" = "no" ]; then
372             cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
373         fi
374         ;;
375     freebsd*)
376         SYS="FREEBSD"
377         LDFLAGS="$LDFLAGS -lm"
378         ;;
379     kfreebsd*-gnu)
380         SYS="FREEBSD"
381         define HAVE_MALLOC_H
382         LDFLAGS="$LDFLAGS -lm"
383         ;;
384     netbsd*)
385         SYS="NETBSD"
386         LDFLAGS="$LDFLAGS -lm"
387         ;;
388     openbsd*)
389         SYS="OPENBSD"
390         LDFLAGS="$LDFLAGS -lm"
391         ;;
392     *linux*)
393         SYS="LINUX"
394         define HAVE_MALLOC_H
395         LDFLAGS="$LDFLAGS -lm"
396         ;;
397     cygwin*)
398         EXE=".exe"
399         if cc_check "" -mno-cygwin; then
400             CFLAGS="$CFLAGS -mno-cygwin"
401             LDFLAGS="$LDFLAGS -mno-cygwin"
402         fi
403         if cpp_check "" "" "defined(__CYGWIN32__)" ; then
404             define HAVE_MALLOC_H
405             SYS="CYGWIN"
406         else
407             SYS="WINDOWS"
408             DEVNULL="NUL"
409         fi
410         ;;
411     mingw*)
412         SYS="WINDOWS"
413         EXE=".exe"
414         DEVNULL="NUL"
415         ;;
416     sunos*|solaris*)
417         SYS="SunOS"
418         define HAVE_MALLOC_H
419         LDFLAGS="$LDFLAGS -lm"
420         HAVE_GETOPT_LONG=0
421         ;;
422     *)
423         die "Unknown system $host, edit the configure"
424         ;;
425 esac
426
427 case $host_cpu in
428     i*86)
429         ARCH="X86"
430         AS="yasm"
431         ASFLAGS="$ASFLAGS -O2"
432         if [ $compiler = GNU ]; then
433             if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
434                 CFLAGS="$CFLAGS -march=i686"
435             fi
436             if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
437                 CFLAGS="$CFLAGS -mfpmath=sse -msse"
438             fi
439         else
440             # icc on linux has various degrees of mod16 stack support
441             if [ $SYS = LINUX ]; then
442                 # < 11 is completely incapable of keeping a mod16 stack
443                 if cpp_check "" "" "__INTEL_COMPILER < 1100" ; then
444                     define BROKEN_STACK_ALIGNMENT
445                 # 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
446                 elif cpp_check "" "" "__INTEL_COMPILER < 1200" ; then
447                     CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
448                 fi
449                 # >= 12 defaults to a mod16 stack
450             fi
451             # icl on windows has no mod16 stack support
452             [ $SYS = WINDOWS ] && define BROKEN_STACK_ALIGNMENT
453         fi
454         if [ "$SYS" = MACOSX ]; then
455             ASFLAGS="$ASFLAGS -f macho -DPREFIX"
456         elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
457             ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
458             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
459         else
460             ASFLAGS="$ASFLAGS -f elf"
461         fi
462         ;;
463     x86_64)
464         ARCH="X86_64"
465         AS="yasm"
466         if [ "$SYS" = MACOSX ]; then
467             ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
468             if cc_check '' "-arch x86_64"; then
469                 CFLAGS="$CFLAGS -arch x86_64"
470                 LDFLAGS="$LDFLAGS -arch x86_64"
471             fi
472         elif [ "$SYS" = WINDOWS ]; then
473             ASFLAGS="$ASFLAGS -f win32 -m amd64"
474             # only the GNU toolchain is inconsistent in prefixing function names with _
475             [ $compiler = GNU ] && cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
476         else
477             ASFLAGS="$ASFLAGS -f elf -m amd64"
478         fi
479         ;;
480     powerpc|powerpc64)
481         ARCH="PPC"
482         if [ $asm = auto ] ; then
483             define HAVE_ALTIVEC
484             AS="${AS-${cross_prefix}gcc}"
485             if [ $SYS = MACOSX ] ; then
486                 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
487             else
488                 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
489                 define HAVE_ALTIVEC_H
490             fi
491         fi
492         ;;
493     sparc)
494         ARCH="SPARC"
495         case $(uname -m) in
496             sun4u|sun4v)
497                 if [ $asm = auto ]; then
498                     ARCH="UltraSPARC"
499                     if ! echo $CFLAGS | grep -Eq '\-mcpu' ; then
500                         CFLAGS="$CFLAGS -mcpu=ultrasparc"
501                         LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
502                     fi
503                     AS="${AS-${cross_prefix}as}"
504                     ASFLAGS="$ASFLAGS -xarch=v8plusa"
505                 fi
506                 ;;
507         esac
508         ;;
509     mips|mipsel|mips64|mips64el)
510         ARCH="MIPS"
511         ;;
512     arm*)
513         ARCH="ARM"
514         if [ "$SYS" = MACOSX ] ; then
515             AS="${AS-extras/gas-preprocessor.pl $CC}"
516             ASFLAGS="$ASFLAGS -DPREFIX -DPIC"  # apple's ld doesn't support movw/movt relocations at all
517             # build for armv7 by default
518             if ! echo $CFLAGS | grep -Eq '\-arch' ; then
519                 CFLAGS="$CFLAGS -arch armv7"
520                 LDFLAGS="$LDFLAGS -arch armv7"
521             fi
522         else
523             AS="${AS-${cross_prefix}gcc}"
524         fi
525         ;;
526     s390|s390x)
527         ARCH="S390"
528         ;;
529     parisc|parisc64)
530         ARCH="PARISC"
531         ;;
532     ia64)
533         ARCH="IA64"
534         ;;
535     *)
536         ARCH="$(echo $host_cpu | tr a-z A-Z)"
537         ;;
538 esac
539
540 log_msg "x264 configure script"
541 if [ -n "$*" ]; then
542     msg="Command line options:"
543     for i in $@; do
544         msg="$msg \"$i\""
545     done
546     log_msg "$msg"
547 fi
548 log_msg ""
549
550 # check requirements
551
552 cc_check || die "No working C compiler found."
553
554 if [ $compiler != ICL ]; then
555     if cc_check '' -std=gnu99 'for( int i = 0; i < 9; i++ );' ; then
556         CFLAGS="$CFLAGS -std=gnu99"
557     elif cc_check '' -std=c99 'for( int i = 0; i < 9; i++ );' ; then
558         CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
559     elif ! cc_check '' '' 'for( int i = 0; i < 9; i++ );' ; then
560         die "C99 compiler is needed for compilation."
561     fi
562 fi
563
564 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then
565     pic="yes"
566 fi
567
568 if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
569     if ! as_check "vpaddw xmm0, xmm0, xmm0" ; then
570         VER=`($AS --version || echo no assembler) 2>/dev/null | head -n 1`
571         echo "Found $VER"
572         echo "Minimum version is yasm-0.7.0"
573         echo "If you really want to compile without asm, configure with --disable-asm."
574         exit 1
575     fi
576     if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
577         VER=`(${cross_prefix}as --version || echo no gnu as) 2>/dev/null | head -n 1`
578         echo "Found $VER"
579         echo "Minimum version is binutils-2.17"
580         echo "Your compiler can't handle inline SSSE3 asm."
581         echo "If you really want to compile without asm, configure with --disable-asm."
582         exit 1
583     fi
584     define HAVE_MMX
585 fi
586
587 if [ $asm = auto -a $ARCH = ARM ] ; then
588     # set flags so neon is built by default
589     echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
590
591     if  cc_check '' '' '__asm__("rev ip, ip");' ; then      define HAVE_ARMV6
592         cc_check '' '' '__asm__("movt r0, #0");'         && define HAVE_ARMV6T2
593         cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
594         ASFLAGS="$ASFLAGS $CFLAGS -c"
595     else
596         echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
597         echo "If you really want to run on such a CPU, configure with --disable-asm."
598         exit 1
599     fi
600 fi
601
602 [ $asm = no ] && AS=""
603 [ "x$AS" = x ] && asm="no" || asm="yes"
604
605 define ARCH_$ARCH
606 define SYS_$SYS
607
608 # skip endianness check for Intel Compiler, as all supported platforms are little. the -ipo flag will also cause the check to fail
609 if [ $compiler = GNU ]; then
610     echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
611     $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
612     if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
613         define WORDS_BIGENDIAN
614     elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then
615         die "endian test failed"
616     fi
617 fi
618
619 # autodetect options that weren't forced nor disabled
620
621 # pthread-win32 is lgpl, prevent its use if --disable-gpl is specified and targeting windows
622 [ "$SYS" = "WINDOWS" -a "$gpl" = "no" -a "$thread" = "auto" ] && thread="win32"
623
624 libpthread=""
625 if [ "$thread" = "auto" ]; then
626     thread="no"
627     case $SYS in
628         BEOS)
629             thread="beos"
630             define HAVE_BEOSTHREAD
631             ;;
632         WINDOWS)
633             if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
634                 thread="posix"
635                 libpthread="-lpthread"
636             elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
637                 thread="posix"
638                 libpthread="-lpthreadGC2"
639             elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
640                 thread="posix"
641                 libpthread="-lpthreadGC2 -lwsock32"
642                 define PTW32_STATIC_LIB
643             elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
644                 thread="posix"
645                 libpthread="-lpthreadGC2 -lws2_32"
646                 define PTW32_STATIC_LIB
647             else
648                 # default to native threading if pthread-win32 is unavailable
649                 thread="win32"
650             fi
651             ;;
652         OPENBSD)
653             cc_check pthread.h -pthread && thread="posix" && libpthread="-pthread"
654             ;;
655         *)
656             cc_check pthread.h -lpthread && thread="posix" && libpthread="-lpthread"
657             ;;
658     esac
659 fi
660 if [ "$thread" = "posix" ]; then
661     LDFLAGS="$LDFLAGS $libpthread"
662     define HAVE_POSIXTHREAD
663 fi
664 if [ "$thread" = "win32" ]; then
665     # cygwin does not support win32 threads
666     if [ "$SYS" = "WINDOWS" ]; then
667         define HAVE_WIN32THREAD
668     else
669         thread="no"
670     fi
671 fi
672 [ "$thread" != "no" ] && define HAVE_THREAD
673
674 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
675     define HAVE_LOG2F
676 fi
677
678 if [ "$vis" = "yes" ] ; then
679     save_CFLAGS="$CFLAGS"
680     CFLAGS="$CFLAGS -I/usr/X11R6/include"
681     if cc_check "X11/Xlib.h" "-L/usr/X11R6/lib -lX11" "XOpenDisplay(0);" ; then
682         LDFLAGS="-L/usr/X11R6/lib -lX11 $LDFLAGS"
683         define HAVE_VISUALIZE
684     else
685         vis="no"
686         CFLAGS="$save_CFLAGS"
687    fi
688 fi
689
690 if [ "$swscale" = "auto" ] ; then
691     swscale="no"
692     if ${cross_prefix}pkg-config --exists libswscale 2>/dev/null; then
693         SWSCALE_LIBS="$SWSCALE_LIBS $(${cross_prefix}pkg-config --libs libswscale)"
694         SWSCALE_CFLAGS="$SWSCALE_CFLAGS $(${cross_prefix}pkg-config --cflags libswscale)"
695     fi
696     [ -z "$SWSCALE_LIBS" ] && SWSCALE_LIBS="-lswscale -lavutil"
697
698     error="swscale must be at least version 0.9.0"
699     if cc_check "libswscale/swscale.h" "$SWSCALE_CFLAGS $SWSCALE_LIBS" "sws_getContext(0,0,0,0,0,0,0,0,0,0);" ; then
700         if cpp_check "libswscale/swscale.h" "$SWSCALE_CFLAGS" "LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(0,9,0)" "$error"; then
701             # we use colorspaces that were defined in libavutil r19775
702             if cc_check "libavutil/pixfmt.h" "$SWSCALE_CFLAGS" "enum PixelFormat pixfmt = PIX_FMT_YUV422P16LE;" ; then
703                 swscale="yes"
704             else
705                 echo "Warning: libavutil is too old, update to ffmpeg r19775+"
706             fi
707         else
708             echo "Warning: ${error}"
709         fi
710     fi
711 fi
712
713 if [ "$lavf" = "auto" ] ; then
714     lavf="no"
715     if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>/dev/null; then
716         LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libavutil libswscale)"
717         LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libavutil libswscale)"
718     fi
719     if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
720         LAVF_LIBS="-lavformat"
721         for lib in -lpostproc -lavcodec -lavcore -lswscale -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
722             cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
723         done
724     fi
725     LAVF_LIBS="-L. $LAVF_LIBS"
726     if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2(0,0,0,0);" ; then
727         # libvautil/pixdesc.h included the private header intreadwrite.h until r21854
728         if cc_check libavutil/pixdesc.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
729             if [ "$swscale" = "yes" ]; then
730                 lavf="yes"
731             else
732                 echo "Warning: libavformat is not supported without swscale support"
733             fi
734         else
735             echo "Warning: libavutil is too old, update to ffmpeg r21854+"
736         fi
737     fi
738 fi
739
740 if [ "$ffms" = "auto" ] ; then
741     ffms_major="2"; ffms_minor="14"; ffms_micro="0"; ffms_bump="0"
742     ffms="no"
743
744     if ${cross_prefix}pkg-config --exists ffms2 2>/dev/null; then
745         FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
746         FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
747     fi
748     [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
749
750     if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
751         ffms="yes"
752     elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
753         ffms="yes"
754         FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
755     fi
756
757     error="ffms must be at least version $ffms_major.$ffms_minor.$ffms_micro.$ffms_bump"
758     if [ $ffms = "yes" ] && ! cpp_check "ffms.h" "$FFMS2_CFLAGS" "FFMS_VERSION >= (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)" "$error"; then
759        ffms="no"
760        echo "Warning: $error"
761     fi
762     if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
763         echo "Warning: ffms is not supported without swscale support"
764         ffms="no"
765     fi
766 fi
767
768 if [ "$swscale" = "yes" ]; then
769     LDFLAGSCLI="$SWSCALE_LIBS $LDFLAGSCLI"
770     CFLAGS="$CFLAGS $SWSCALE_CFLAGS"
771     define HAVE_SWSCALE
772     if [ "$lavf" = "yes" ]; then
773         LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
774         CFLAGS="$CFLAGS $LAVF_CFLAGS"
775         define HAVE_LAVF
776     fi
777     if [ "$ffms" = "yes" ]; then
778         LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
779         CFLAGS="$CFLAGS $FFMS2_CFLAGS"
780         define HAVE_FFMS
781     fi
782 fi
783
784 GPAC_LIBS="-lgpac_static"
785 if [ $SYS = WINDOWS ]; then
786     GPAC_LIBS="$GPAC_LIBS -lwinmm"
787 fi
788 if [ "$gpac" = "auto" ] ; then
789     gpac="no"
790     if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
791         if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
792             gpac="yes"
793         else
794             echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
795         fi
796     fi
797 fi
798 if [ "$gpac" = "yes" ] ; then
799     define HAVE_GPAC
800     if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
801         define HAVE_GF_MALLOC
802     fi
803     LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
804 fi
805
806 if [ "$avs" = "auto" ] ; then
807     avs="no"
808     # cygwin can use avisynth if it can use LoadLibrary
809     if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibrary(0);") ; then
810         avs="yes"
811         define HAVE_AVS
812     fi
813 fi
814
815 cc_check "stdint.h" "" "uint32_t test_vec __attribute__ ((vector_size (16))) = {0,1,2,3};" && define HAVE_VECTOREXT
816
817 if [ "$pic" = "yes" ] ; then
818     CFLAGS="$CFLAGS -fPIC"
819     ASFLAGS="$ASFLAGS -DPIC"
820     # resolve textrels in the x86 asm
821     cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
822 fi
823
824 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
825     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
826     LDFLAGS="$LDFLAGS -s"
827 fi
828
829 if [ "$debug" = "yes" ]; then
830     CFLAGS="-O1 -g $CFLAGS"
831 elif [ $ARCH = ARM ]; then
832     # arm-gcc-4.2 produces incorrect output with -ffast-math
833     # and it doesn't save any speed anyway on 4.4, so disable it
834     CFLAGS="-O3 -fno-fast-math $CFLAGS"
835 else
836     CFLAGS="-O3 -ffast-math $CFLAGS"
837 fi
838
839 if cc_check '' -fno-tree-vectorize ; then
840     CFLAGS="$CFLAGS -fno-tree-vectorize"
841 fi
842
843 if [ $SYS = WINDOWS -a $ARCH = X86 -a $compiler = GNU ] ; then
844     # workaround gcc/ld bug with alignment of static variables/arrays that are initialized to zero
845     cc_check '' -fno-zero-initialized-in-bss && CFLAGS="$CFLAGS -fno-zero-initialized-in-bss"
846 fi
847
848 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
849     define fseek fseeko
850     define ftell ftello
851 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
852     define fseek fseeko64
853     define ftell ftello64
854 elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then
855     define fseek _fseeki64
856     define ftell _ftelli64
857 fi
858
859 if cc_check '' -Wshadow ; then
860     CFLAGS="-Wshadow $CFLAGS"
861 fi
862
863 if [ "$bit_depth" -gt "8" ]; then
864     define HIGH_BIT_DEPTH
865     ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH"
866 fi
867
868 ASFLAGS="$ASFLAGS -DBIT_DEPTH=$bit_depth"
869
870 [ $gpl = yes ] && define HAVE_GPL && x264_gpl=1 || x264_gpl=0
871
872 #define undefined vars as 0
873 for var in $CONFIG_HAVE; do
874     grep -q "HAVE_$var 1" config.h || define HAVE_$var 0
875 done
876
877 if [ $compiler = ICL ]; then
878     AR="xilib -nologo -out:"
879     DEPMM=-QMM
880     DEPMT=-QMT
881     HAVE_GETOPT_LONG=0
882     LD="xilink -out:"
883     LDFLAGS="-nologo -incremental:no $(icl_ldflags $LDFLAGS)"
884     LDFLAGSCLI="$(icl_ldflags $LDFLAGSCLI)"
885     LIBX264=libx264.lib
886     RANLIB=
887     STRIP=
888     if [ $debug = yes ]; then
889         LDFLAGS="-debug $LDFLAGS"
890         CFLAGS="-D_DEBUG $CFLAGS"
891     else
892         CFLAGS="-DNDEBUG $CFLAGS"
893     fi
894 else
895     AR="$AR rc "
896     DEPMM="-MM -g0"
897     DEPMT="-MT"
898     LD="$CC -o "
899     LIBX264=libx264.a
900 fi
901 if [ $compiler = GNU ]; then
902     PROF_GEN_CC="-fprofile-generate"
903     PROF_GEN_LD="-fprofile-generate"
904     PROF_USE_CC="-fprofile-use"
905     PROF_USE_LD="-fprofile-use"
906 else
907     CFLAGS="$(intel_cflags $CFLAGS)"
908     # icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP
909     [ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
910     PROF_GEN_CC="${QPRE}prof-gen ${QPRE}prof-dir."
911     PROF_GEN_LD=
912     PROF_USE_CC="${QPRE}prof-use ${QPRE}prof-dir."
913     PROF_USE_LD=
914 fi
915
916 rm -f conftest*
917
918 # generate exported config file
919
920 cat > x264_config.h << EOF
921 #define X264_BIT_DEPTH $bit_depth
922 #define X264_GPL       $x264_gpl
923 EOF
924
925 # generate config files
926
927 cat > config.mak << EOF
928 prefix=$prefix
929 exec_prefix=$exec_prefix
930 bindir=$bindir
931 libdir=$libdir
932 includedir=$includedir
933 ARCH=$ARCH
934 SYS=$SYS
935 CC=$CC
936 CFLAGS=$CFLAGS
937 DEPMM=$DEPMM
938 DEPMT=$DEPMT
939 LD=$LD
940 LDFLAGS=$LDFLAGS
941 LDFLAGSCLI=$LDFLAGSCLI
942 LIBX264=$LIBX264
943 AR=$AR
944 RANLIB=$RANLIB
945 STRIP=$STRIP
946 AS=$AS
947 ASFLAGS=$ASFLAGS
948 EXE=$EXE
949 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
950 DEVNULL=$DEVNULL
951 PROF_GEN_CC=$PROF_GEN_CC
952 PROF_GEN_LD=$PROF_GEN_LD
953 PROF_USE_CC=$PROF_USE_CC
954 PROF_USE_LD=$PROF_USE_LD
955 EOF
956
957 if [ $compiler = ICL ]; then
958     echo '%.o: %.c' >> config.mak
959     echo '      $(CC) $(CFLAGS) -c -Fo$@ $<' >> config.mak
960 fi
961
962 if [ "$shared" = "yes" ]; then
963     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
964     if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
965         echo "SONAME=libx264-$API.dll" >> config.mak
966         if [ $compiler = ICL ]; then
967             echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak
968             # GNU ld on windows defaults to exporting all global functions if there are no explicit __declspec(dllexport) declarations
969             # 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
970             echo 'SOFLAGS=-dll -def:x264.def -implib:$(IMPLIBNAME)' >> config.mak
971             echo "EXPORTS" > x264.def
972             grep "^\(int\|void\|x264_t\|extern\).*x264.*[\[(;]" x264.h | sed -e "s/.*\(x264.*\)[\[(].*/\1/;s/.*\(x264.*\);/\1/;s/open/open_$API/g" >> x264.def
973         else
974             echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
975             echo 'SOFLAGS=-shared -Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
976         fi
977     elif [ "$SYS" = "MACOSX" ]; then
978         echo "SOSUFFIX=dylib" >> config.mak
979         echo "SONAME=libx264.$API.dylib" >> config.mak
980         echo 'SOFLAGS=-shared -dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
981     elif [ "$SYS" = "SunOS" ]; then
982         echo "SOSUFFIX=so" >> config.mak
983         echo "SONAME=libx264.so.$API" >> config.mak
984         echo 'SOFLAGS=-shared -Wl,-h,$(SONAME)' >> config.mak
985     else
986         echo "SOSUFFIX=so" >> config.mak
987         echo "SONAME=libx264.so.$API" >> config.mak
988         echo 'SOFLAGS=-shared -Wl,-soname,$(SONAME)' >> config.mak
989     fi
990     echo 'default: $(SONAME)' >> config.mak
991 fi
992
993 ./version.sh >> config.h
994
995 pclibs="-L$libdir -lx264 $libpthread"
996
997 cat > x264.pc << EOF
998 prefix=$prefix
999 exec_prefix=$exec_prefix
1000 libdir=$libdir
1001 includedir=$includedir
1002
1003 Name: x264
1004 Description: H.264 (MPEG4 AVC) encoder library
1005 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
1006 Libs: $pclibs
1007 Cflags: -I$includedir
1008 EOF
1009
1010 filters="crop select_every"
1011 gpl_filters=""
1012 [ $swscale = yes ] && filters="resize $filters"
1013 [ $gpl = yes ] && filters="$filters $gpl_filters"
1014
1015 cat > conftest.log <<EOF
1016 Platform:   $ARCH
1017 System:     $SYS
1018 asm:        $asm
1019 avs:        $avs
1020 lavf:       $lavf
1021 ffms:       $ffms
1022 gpac:       $gpac
1023 gpl:        $gpl
1024 thread:     $thread
1025 filters:    $filters
1026 debug:      $debug
1027 gprof:      $gprof
1028 PIC:        $pic
1029 shared:     $shared
1030 visualize:  $vis
1031 bit depth:  $bit_depth
1032 EOF
1033
1034 echo >> config.log
1035 cat conftest.log >> config.log
1036 cat conftest.log
1037 rm conftest.log
1038
1039 echo
1040 echo "You can run 'make' or 'make fprofiled' now."
1041