]> git.sesse.net Git - x264/blob - configure
Fix bug in b-pyramid strict
[x264] / configure
1 #!/bin/bash
2
3 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
4
5 echo "Usage: ./configure [options]"
6 echo ""
7 echo "available options:"
8 echo ""
9 echo "  --help                   print this message"
10 echo "  --disable-avis-input     disables avisynth input (win32 only)"
11 echo "  --disable-mp4-output     disables mp4 output (using gpac)"
12 echo "  --disable-pthread        disables multithreaded encoding"
13 echo "  --disable-asm            disables assembly optimizations on x86 and arm"
14 echo "  --enable-debug           adds -g, doesn't strip"
15 echo "  --enable-gprof           adds -pg, doesn't strip"
16 echo "  --enable-visualize       enables visualization (X11 only)"
17 echo "  --enable-pic             build position-independent code"
18 echo "  --enable-shared          build libx264.so"
19 echo "  --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS"
20 echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS"
21 echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
22 echo "  --host=HOST              build programs to run on HOST"
23 echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools"
24 echo ""
25 exit 1
26 fi
27
28 cc_check() {
29     rm -f conftest.c
30     [ -n "$1" ] && echo "#include <$1>" > conftest.c
31     echo "int main () { $3 return 0; }" >> conftest.c
32     $CC conftest.c $CFLAGS $LDFLAGS $2 -o conftest 2>$DEVNULL
33 }
34
35 as_check() {
36     echo "$1" > conftest.asm
37     $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
38 }
39
40 die() {
41     echo "$@"
42     exit 1
43 }
44
45 rm -f config.h config.mak x264.pc conftest*
46
47 prefix='/usr/local'
48 exec_prefix='${prefix}'
49 bindir='${exec_prefix}/bin'
50 libdir='${exec_prefix}/lib'
51 includedir='${prefix}/include'
52 DEVNULL='/dev/null'
53
54 avis_input="auto"
55 mp4_output="auto"
56 pthread="auto"
57 asm="yes"
58 debug="no"
59 gprof="no"
60 pic="no"
61 vis="no"
62 shared="no"
63
64 CFLAGS="$CFLAGS -Wall -I."
65 LDFLAGS="$LDFLAGS"
66 ASFLAGS="$ASFLAGS"
67 HAVE_GETOPT_LONG=1
68 cross_prefix=""
69
70 EXE=""
71
72 # parse options
73
74 for opt do
75     optarg="${opt#*=}"
76     case "$opt" in
77         --prefix=*)
78             prefix="$optarg"
79             ;;
80         --exec-prefix=*)
81             exec_prefix="$optarg"
82             ;;
83         --bindir=*)
84             bindir="$optarg"
85             ;;
86         --libdir=*)
87             libdir="$optarg"
88             ;;
89         --includedir=*)
90             includedir="$optarg"
91             ;;
92         --enable-asm)
93             asm="yes"
94             ;;
95         --disable-asm)
96             asm="no"
97             ;;
98         --enable-avis-input)
99             avis_input="yes"
100             ;;
101         --disable-avis-input)
102             avis_input="no"
103             ;;
104         --enable-mp4-output)
105             mp4_output="yes"
106             ;;
107         --disable-mp4-output)
108             mp4_output="no"
109             ;;
110         --extra-asflags=*)
111             ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
112             ;;
113         --extra-cflags=*)
114             CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
115             ;;
116         --extra-ldflags=*)
117             LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
118             ;;
119         --enable-pthread)
120             pthread="auto" # can't skip detection, since it differs by OS
121             ;;
122         --disable-pthread)
123             pthread="no"
124             ;;
125         --enable-debug)
126             debug="yes"
127             ;;
128         --enable-gprof)
129             CFLAGS="$CFLAGS -pg"
130             LDFLAGS="$LDFLAGS -pg"
131             gprof="yes"
132             ;;
133         --enable-pic)
134             pic="yes"
135             ;;
136         --enable-shared)
137             shared="yes"
138             ;;
139         --enable-visualize)
140             LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
141             CFLAGS="$CFLAGS -DVISUALIZE=1"
142             vis="yes"
143             ;;
144         --host=*)
145             host="${opt#--host=}"
146             ;;
147         --cross-prefix=*)
148             cross_prefix="${opt#--cross-prefix=}"
149             ;;
150         *)
151             echo "Unknown option $opt, ignored"
152             ;;
153     esac
154 done
155
156 CC="${CC-${cross_prefix}gcc}"
157 AR="${AR-${cross_prefix}ar}"
158 RANLIB="${RANLIB-${cross_prefix}ranlib}"
159 STRIP="${STRIP-${cross_prefix}strip}"
160
161 if [ "x$host" = x ]; then
162     host=`./config.guess`
163 fi
164 # normalize a triplet into a quadruplet
165 host=`./config.sub $host`
166
167 # split $host
168 host_cpu="${host%%-*}"
169 host="${host#*-}"
170 host_vendor="${host%%-*}"
171 host_os="${host#*-}"
172
173 case $host_os in
174   beos*)
175     SYS="BEOS"
176     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
177     ;;
178   darwin*)
179     SYS="MACOSX"
180     CFLAGS="$CFLAGS -falign-loops=16"
181     LDFLAGS="$LDFLAGS -lm"
182     if [ "$pic" = "no" ]; then
183         CFLAGS="$CFLAGS -mdynamic-no-pic"
184     fi
185     ;;
186   freebsd*)
187     SYS="FREEBSD"
188     LDFLAGS="$LDFLAGS -lm"
189     ;;
190   kfreebsd*-gnu)
191     SYS="FREEBSD"
192     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
193     LDFLAGS="$LDFLAGS -lm"
194     ;;
195   netbsd*)
196     SYS="NETBSD"
197     LDFLAGS="$LDFLAGS -lm"
198     ;;
199   openbsd*)
200     SYS="OPENBSD"
201     CFLAGS="$CFLAGS -I/usr/X11R6/include"
202     LDFLAGS="$LDFLAGS -lm"
203     ;;
204   *linux*)
205     SYS="LINUX"
206     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
207     LDFLAGS="$LDFLAGS -lm"
208     ;;
209   cygwin*)
210     SYS="MINGW"
211     EXE=".exe"
212     DEVNULL="NUL"
213     if cc_check "" -mno-cygwin; then
214         CFLAGS="$CFLAGS -mno-cygwin"
215         LDFLAGS="$LDFLAGS -mno-cygwin"
216     fi
217     ;;
218   mingw*)
219     SYS="MINGW"
220     EXE=".exe"
221     DEVNULL="NUL"
222     ;;
223   sunos*|solaris*)
224     SYS="SunOS"
225     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
226     LDFLAGS="$LDFLAGS -lm"
227     HAVE_GETOPT_LONG=0
228     ;;
229   *)
230     die "Unknown system $host, edit the configure"
231     ;;
232 esac
233
234 case $host_cpu in
235   i*86)
236     ARCH="X86"
237     AS="yasm"
238     ASFLAGS="$ASFLAGS -O2"
239     if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then
240       CFLAGS="$CFLAGS -march=i686"
241     fi
242     if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then
243       CFLAGS="$CFLAGS -mfpmath=sse -msse"
244     fi
245     if [ "$SYS" = MACOSX ]; then
246       ASFLAGS="$ASFLAGS -f macho -DPREFIX"
247     elif [ "$SYS" = MINGW ]; then
248       ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
249     else
250       ASFLAGS="$ASFLAGS -f elf"
251     fi
252     ;;
253   x86_64)
254     ARCH="X86_64"
255     AS="yasm"
256     if [ "$SYS" = MACOSX ];then
257       ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
258       CFLAGS="$CFLAGS -arch x86_64"
259       LDFLAGS="$LDFLAGS -arch x86_64"
260     elif [ "$SYS" = MINGW ]; then
261       ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
262     else
263       ASFLAGS="$ASFLAGS -f elf -m amd64"
264     fi
265     ;;
266   powerpc|powerpc64)
267     ARCH="PPC"
268     if [ $SYS = MACOSX ]
269     then
270       ALTIVECFLAGS="$ALTIVECFLAGS -faltivec -fastf -mcpu=G4"
271     else
272       ALTIVECFLAGS="$ALTIVECFLAGS -maltivec -mabi=altivec -DHAVE_ALTIVEC_H"
273     fi
274     ;;
275   sparc)
276     if test "$(uname -m)" = "sun4u"; then
277       ARCH="UltraSparc"
278       CFLAGS="$CFLAGS -mcpu=ultrasparc"
279       LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
280       AS="${cross_prefix}as"
281       ASFLAGS="$ASFLAGS -xarch=v8plusa"
282     else
283       ARCH="Sparc"
284     fi
285     ;;
286   mips|mipsel|mips64|mips64el)
287     ARCH="MIPS"
288     ;;
289   arm*)
290     ARCH="ARM"
291     AS="${AS-${cross_prefix}gcc}"
292     ;;
293   s390|s390x)
294     ARCH="S390"
295     ;;
296   parisc|parisc64)
297     ARCH="PARISC"
298     ;;
299   *)
300     ARCH="$(echo $host_cpu | tr a-z A-Z)"
301     ;;
302 esac
303
304 # check requirements
305
306 cc_check || die "No working C compiler found."
307
308 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" \) ] ; then
309     pic="yes"
310 fi
311
312 if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
313     if ! as_check "lzcnt eax, eax" ; then
314         VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
315         echo "Found $VER"
316         echo "Minimum version is yasm-0.6.2"
317         echo "If you really want to compile without asm, configure with --disable-asm."
318         exit 1
319     fi
320     if ! cc_check '' '' 'asm("pabsw %xmm0, %xmm0");' ; then
321         VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
322         echo "Found $VER"
323         echo "Minimum version is binutils-2.17"
324         echo "Your compiler can't handle inline SSSE3 asm."
325         echo "If you really want to compile without asm, configure with --disable-asm."
326         exit 1
327     fi
328     CFLAGS="$CFLAGS -DHAVE_MMX"
329 fi
330
331 if [ $asm = yes -a $ARCH = ARM ] ; then
332     # set flags so neon is built by default
333     echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
334
335     if  cc_check '' '' 'asm("rev ip, ip");' ; then      CFLAGS="$CFLAGS -DHAVE_ARMV6"
336         cc_check '' '' 'asm("movt r0, #0");'         && CFLAGS="$CFLAGS -DHAVE_ARMV6T2"
337         cc_check '' '' 'asm("vadd.i16 q0, q0, q0");' && CFLAGS="$CFLAGS -DHAVE_NEON"
338         ASFLAGS="$ASFLAGS $CFLAGS -c"
339     else
340         echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
341         echo "If you really want to run on such a CPU, configure with --disable-asm."
342         exit 1
343     fi
344 fi
345
346 [ $asm = no ] && AS=""
347 [ "x$AS" = x ] && asm="no"
348
349 CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"
350
351 echo "unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';" > conftest.c
352 $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
353 grep -q BIGE conftest.o && CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"
354
355 # autodetect options that weren't forced nor disabled
356
357 libpthread=""
358 if test "$pthread" = "auto" ; then
359     pthread="no"
360     case $SYS in
361         BEOS)
362             pthread="yes"
363             ;;
364         MINGW)
365             if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
366                 pthread="yes"
367                 libpthread="-lpthread"
368             elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
369                 pthread="yes"
370                 libpthread="-lpthreadGC2"
371             elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
372                 pthread="yes"
373                 libpthread="-lpthreadGC2 -lwsock32"
374                 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
375             elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
376                 pthread="yes"
377                 libpthread="-lpthreadGC2 -lws2_32"
378                 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
379             fi
380             ;;
381         OPENBSD)
382             cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
383             ;;
384         *)
385             cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
386             ;;
387     esac
388 fi
389 if test "$pthread" = "yes" ; then
390     CFLAGS="$CFLAGS -DHAVE_PTHREAD"
391     LDFLAGS="$LDFLAGS $libpthread"
392 fi
393
394 MP4_LDFLAGS="-lgpac_static"
395 if [ $SYS = MINGW ]; then
396     MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
397 fi
398 if [ "$mp4_output" = "auto" ] ; then
399     mp4_output="no"
400     cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
401 fi
402 if [ "$mp4_output" = "yes" ] ; then
403     echo "#define MP4_OUTPUT" >> config.h
404     LDFLAGS="$LDFLAGS $MP4_LDFLAGS"
405 fi
406
407 if [ "$avis_input" = "auto" ] ; then
408     if [ $SYS = MINGW ]; then
409         avis_input="yes"
410     else
411         avis_input="no";
412     fi
413 fi
414 if [ "$avis_input" = "yes" ] ; then
415     if cc_check "stdlib.h" -lvfw32 ; then
416         echo "#define AVIS_INPUT" >> config.h
417         LDFLAGS="$LDFLAGS -lvfw32"
418     elif cc_check "stdlib.h" -lavifil32 ; then
419         echo "#define AVIS_INPUT" >> config.h
420         LDFLAGS="$LDFLAGS -lavifil32"
421     else
422         avis_input="no";
423     fi
424 fi
425
426 if [ "$pic" = "yes" ] ; then
427     CFLAGS="$CFLAGS -fPIC"
428     ASFLAGS="$ASFLAGS -DPIC"
429     # resolve textrels in the x86 asm
430     cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
431 fi
432
433 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
434     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
435     LDFLAGS="$LDFLAGS -s"
436 fi
437
438 if [ "$debug" = "yes" ]; then
439     CFLAGS="-O1 -g $CFLAGS"
440 elif [ $ARCH = ARM ]; then
441     # arm-gcc-4.2 produces incorrect output with -ffast-math
442     # and it doesn't save any speed anyway on 4.4, so disable it
443     CFLAGS="-O4 -fno-fast-math $CFLAGS"
444 else
445     CFLAGS="-O4 -ffast-math $CFLAGS"
446 fi
447
448 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
449     echo "#define fseek fseeko" >> config.h
450     echo "#define ftell ftello" >> config.h
451 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
452     echo "#define fseek fseeko64" >> config.h
453     echo "#define ftell ftello64" >> config.h
454 fi
455
456 rm -f conftest*
457
458 # generate config files
459
460 cat > config.mak << EOF
461 prefix=$prefix
462 exec_prefix=$exec_prefix
463 bindir=$bindir
464 libdir=$libdir
465 includedir=$includedir
466 ARCH=$ARCH
467 SYS=$SYS
468 CC=$CC
469 CFLAGS=$CFLAGS
470 ALTIVECFLAGS=$ALTIVECFLAGS
471 LDFLAGS=$LDFLAGS
472 AR=$AR
473 RANLIB=$RANLIB
474 STRIP=$STRIP
475 AS=$AS
476 ASFLAGS=$ASFLAGS
477 EXE=$EXE
478 VIS=$vis
479 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
480 DEVNULL=$DEVNULL
481 EOF
482
483 if [ "$shared" = "yes" ]; then
484     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
485     if [ "$SYS" = "MINGW" ]; then
486         echo "SONAME=libx264-$API.dll" >> config.mak
487         echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
488         echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
489     elif [ "$SYS" = "MACOSX" ]; then
490         echo "SOSUFFIX=dylib" >> config.mak
491         echo "SONAME=libx264.$API.dylib" >> config.mak
492         echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
493     elif [ "$SYS" = "SunOS" ]; then
494         echo "SOSUFFIX=so" >> config.mak
495         echo "SONAME=libx264.so.$API" >> config.mak
496         echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
497     else
498         echo "SOSUFFIX=so" >> config.mak
499         echo "SONAME=libx264.so.$API" >> config.mak
500         echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
501     fi
502     echo 'default: $(SONAME)' >> config.mak
503 fi
504
505 ./version.sh
506
507 pclibs="-L$libdir -lx264 $libpthread"
508
509 cat > x264.pc << EOF
510 prefix=$prefix
511 exec_prefix=$exec_prefix
512 libdir=$libdir
513 includedir=$includedir
514
515 Name: x264
516 Description: H.264 (MPEG4 AVC) encoder library
517 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
518 Libs: $pclibs
519 Cflags: -I$includedir
520 EOF
521
522
523 echo "Platform:   $ARCH"
524 echo "System:     $SYS"
525 echo "asm:        $asm"
526 echo "avis input: $avis_input"
527 echo "mp4 output: $mp4_output"
528 echo "pthread:    $pthread"
529 echo "debug:      $debug"
530 echo "gprof:      $gprof"
531 echo "PIC:        $pic"
532 echo "shared:     $shared"
533 echo "visualize:  $vis"
534 echo
535 echo "You can run 'make' or 'make fprofiled' now."
536