]> git.sesse.net Git - x264/blob - configure
Support more recent GPAC versions
[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         if cpp_check libavcodec/avcodec.h "$LAVF_CFLAGS $LAVF_LIBS" "LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,64,0)" ; then
728             if [ "$swscale" = "yes" ]; then
729                 lavf="yes"
730             else
731                 echo "Warning: libavformat is not supported without swscale support"
732             fi
733         else
734             echo "Warning: libavcodec is too old, update to ffmpeg r22735+"
735         fi
736     fi
737 fi
738
739 if [ "$ffms" = "auto" ] ; then
740     ffms_major="2"; ffms_minor="14"; ffms_micro="0"; ffms_bump="0"
741     ffms="no"
742
743     if ${cross_prefix}pkg-config --exists ffms2 2>/dev/null; then
744         FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
745         FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
746     fi
747     [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
748
749     if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
750         ffms="yes"
751     elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
752         ffms="yes"
753         FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
754     fi
755
756     error="ffms must be at least version $ffms_major.$ffms_minor.$ffms_micro.$ffms_bump"
757     if [ $ffms = "yes" ] && ! cpp_check "ffms.h" "$FFMS2_CFLAGS" "FFMS_VERSION >= (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)" "$error"; then
758        ffms="no"
759        echo "Warning: $error"
760     fi
761     if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
762         echo "Warning: ffms is not supported without swscale support"
763         ffms="no"
764     fi
765 fi
766
767 if [ "$swscale" = "yes" ]; then
768     LDFLAGSCLI="$SWSCALE_LIBS $LDFLAGSCLI"
769     CFLAGS="$CFLAGS $SWSCALE_CFLAGS"
770     define HAVE_SWSCALE
771     if [ "$lavf" = "yes" ]; then
772         LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
773         CFLAGS="$CFLAGS $LAVF_CFLAGS"
774         define HAVE_LAVF
775     fi
776     if [ "$ffms" = "yes" ]; then
777         LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
778         CFLAGS="$CFLAGS $FFMS2_CFLAGS"
779         define HAVE_FFMS
780     fi
781 fi
782
783 if [ "$gpac" = "auto" ] ; then
784     gpac="no"
785     cc_check "" -lz && GPAC_LIBS="-lgpac_static -lz" || GPAC_LIBS="-lgpac_static"
786     if [ "$SYS" = "WINDOWS" ] ; then
787         GPAC_LIBS="$GPAC_LIBS -lwinmm"
788     fi
789     if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
790         if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
791             gpac="yes"
792         else
793             echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
794         fi
795     fi
796 fi
797 if [ "$gpac" = "yes" ] ; then
798     define HAVE_GPAC
799     if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
800         define HAVE_GF_MALLOC
801     fi
802     LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
803 fi
804
805 if [ "$avs" = "auto" ] ; then
806     avs="no"
807     # cygwin can use avisynth if it can use LoadLibrary
808     if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibrary(0);") ; then
809         avs="yes"
810         define HAVE_AVS
811     fi
812 fi
813
814 cc_check "stdint.h" "" "uint32_t test_vec __attribute__ ((vector_size (16))) = {0,1,2,3};" && define HAVE_VECTOREXT
815
816 if [ "$pic" = "yes" ] ; then
817     CFLAGS="$CFLAGS -fPIC"
818     ASFLAGS="$ASFLAGS -DPIC"
819     # resolve textrels in the x86 asm
820     cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
821 fi
822
823 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
824     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
825     LDFLAGS="$LDFLAGS -s"
826 fi
827
828 if [ "$debug" = "yes" ]; then
829     CFLAGS="-O1 -g $CFLAGS"
830 elif [ $ARCH = ARM ]; then
831     # arm-gcc-4.2 produces incorrect output with -ffast-math
832     # and it doesn't save any speed anyway on 4.4, so disable it
833     CFLAGS="-O3 -fno-fast-math $CFLAGS"
834 else
835     CFLAGS="-O3 -ffast-math $CFLAGS"
836 fi
837
838 if cc_check '' -fno-tree-vectorize ; then
839     CFLAGS="$CFLAGS -fno-tree-vectorize"
840 fi
841
842 if [ $SYS = WINDOWS -a $ARCH = X86 -a $compiler = GNU ] ; then
843     # workaround gcc/ld bug with alignment of static variables/arrays that are initialized to zero
844     cc_check '' -fno-zero-initialized-in-bss && CFLAGS="$CFLAGS -fno-zero-initialized-in-bss"
845 fi
846
847 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
848     define fseek fseeko
849     define ftell ftello
850 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
851     define fseek fseeko64
852     define ftell ftello64
853 elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then
854     define fseek _fseeki64
855     define ftell _ftelli64
856 fi
857
858 if cc_check '' -Wshadow ; then
859     CFLAGS="-Wshadow $CFLAGS"
860 fi
861
862 if [ "$bit_depth" -gt "8" ]; then
863     define HIGH_BIT_DEPTH
864     ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH"
865 fi
866
867 ASFLAGS="$ASFLAGS -DBIT_DEPTH=$bit_depth"
868
869 [ $gpl = yes ] && define HAVE_GPL && x264_gpl=1 || x264_gpl=0
870
871 #define undefined vars as 0
872 for var in $CONFIG_HAVE; do
873     grep -q "HAVE_$var 1" config.h || define HAVE_$var 0
874 done
875
876 if [ $compiler = ICL ]; then
877     AR="xilib -nologo -out:"
878     DEPMM=-QMM
879     DEPMT=-QMT
880     HAVE_GETOPT_LONG=0
881     LD="xilink -out:"
882     LDFLAGS="-nologo -incremental:no $(icl_ldflags $LDFLAGS)"
883     LDFLAGSCLI="$(icl_ldflags $LDFLAGSCLI)"
884     LIBX264=libx264.lib
885     RANLIB=
886     STRIP=
887     if [ $debug = yes ]; then
888         LDFLAGS="-debug $LDFLAGS"
889         CFLAGS="-D_DEBUG $CFLAGS"
890     else
891         CFLAGS="-DNDEBUG $CFLAGS"
892     fi
893 else
894     AR="$AR rc "
895     DEPMM="-MM -g0"
896     DEPMT="-MT"
897     LD="$CC -o "
898     LIBX264=libx264.a
899 fi
900 if [ $compiler = GNU ]; then
901     PROF_GEN_CC="-fprofile-generate"
902     PROF_GEN_LD="-fprofile-generate"
903     PROF_USE_CC="-fprofile-use"
904     PROF_USE_LD="-fprofile-use"
905 else
906     CFLAGS="$(intel_cflags $CFLAGS)"
907     # icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP
908     [ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
909     PROF_GEN_CC="${QPRE}prof-gen ${QPRE}prof-dir."
910     PROF_GEN_LD=
911     PROF_USE_CC="${QPRE}prof-use ${QPRE}prof-dir."
912     PROF_USE_LD=
913 fi
914
915 rm -f conftest*
916
917 # generate exported config file
918
919 cat > x264_config.h << EOF
920 #define X264_BIT_DEPTH $bit_depth
921 #define X264_GPL       $x264_gpl
922 EOF
923
924 # generate config files
925
926 cat > config.mak << EOF
927 prefix=$prefix
928 exec_prefix=$exec_prefix
929 bindir=$bindir
930 libdir=$libdir
931 includedir=$includedir
932 ARCH=$ARCH
933 SYS=$SYS
934 CC=$CC
935 CFLAGS=$CFLAGS
936 DEPMM=$DEPMM
937 DEPMT=$DEPMT
938 LD=$LD
939 LDFLAGS=$LDFLAGS
940 LDFLAGSCLI=$LDFLAGSCLI
941 LIBX264=$LIBX264
942 AR=$AR
943 RANLIB=$RANLIB
944 STRIP=$STRIP
945 AS=$AS
946 ASFLAGS=$ASFLAGS
947 EXE=$EXE
948 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
949 DEVNULL=$DEVNULL
950 PROF_GEN_CC=$PROF_GEN_CC
951 PROF_GEN_LD=$PROF_GEN_LD
952 PROF_USE_CC=$PROF_USE_CC
953 PROF_USE_LD=$PROF_USE_LD
954 EOF
955
956 if [ $compiler = ICL ]; then
957     echo '%.o: %.c' >> config.mak
958     echo '      $(CC) $(CFLAGS) -c -Fo$@ $<' >> config.mak
959 fi
960
961 if [ "$shared" = "yes" ]; then
962     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
963     if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
964         echo "SONAME=libx264-$API.dll" >> config.mak
965         if [ $compiler = ICL ]; then
966             echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak
967             # GNU ld on windows defaults to exporting all global functions if there are no explicit __declspec(dllexport) declarations
968             # 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
969             echo 'SOFLAGS=-dll -def:x264.def -implib:$(IMPLIBNAME)' >> config.mak
970             echo "EXPORTS" > x264.def
971             grep "^\(int\|void\|x264_t\|extern\).*x264.*[\[(;]" x264.h | sed -e "s/.*\(x264.*\)[\[(].*/\1/;s/.*\(x264.*\);/\1/;s/open/open_$API/g" >> x264.def
972         else
973             echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
974             echo 'SOFLAGS=-shared -Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
975         fi
976     elif [ "$SYS" = "MACOSX" ]; then
977         echo "SOSUFFIX=dylib" >> config.mak
978         echo "SONAME=libx264.$API.dylib" >> config.mak
979         echo 'SOFLAGS=-shared -dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
980     elif [ "$SYS" = "SunOS" ]; then
981         echo "SOSUFFIX=so" >> config.mak
982         echo "SONAME=libx264.so.$API" >> config.mak
983         echo 'SOFLAGS=-shared -Wl,-h,$(SONAME)' >> config.mak
984     else
985         echo "SOSUFFIX=so" >> config.mak
986         echo "SONAME=libx264.so.$API" >> config.mak
987         echo 'SOFLAGS=-shared -Wl,-soname,$(SONAME)' >> config.mak
988     fi
989     echo 'default: $(SONAME)' >> config.mak
990 fi
991
992 ./version.sh >> config.h
993
994 pclibs="-L$libdir -lx264 $libpthread"
995
996 cat > x264.pc << EOF
997 prefix=$prefix
998 exec_prefix=$exec_prefix
999 libdir=$libdir
1000 includedir=$includedir
1001
1002 Name: x264
1003 Description: H.264 (MPEG4 AVC) encoder library
1004 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
1005 Libs: $pclibs
1006 Cflags: -I$includedir
1007 EOF
1008
1009 filters="crop select_every"
1010 gpl_filters=""
1011 [ $swscale = yes ] && filters="resize $filters"
1012 [ $gpl = yes ] && filters="$filters $gpl_filters"
1013
1014 cat > conftest.log <<EOF
1015 Platform:   $ARCH
1016 System:     $SYS
1017 asm:        $asm
1018 avs:        $avs
1019 lavf:       $lavf
1020 ffms:       $ffms
1021 gpac:       $gpac
1022 gpl:        $gpl
1023 thread:     $thread
1024 filters:    $filters
1025 debug:      $debug
1026 gprof:      $gprof
1027 PIC:        $pic
1028 shared:     $shared
1029 visualize:  $vis
1030 bit depth:  $bit_depth
1031 EOF
1032
1033 echo >> config.log
1034 cat conftest.log >> config.log
1035 cat conftest.log
1036 rm conftest.log
1037
1038 echo
1039 echo "You can run 'make' or 'make fprofiled' now."
1040