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