]> git.sesse.net Git - x264/blob - configure
d08c548b8e4bab3e00dd23753ab640345f8aa22b
[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. -Wno-strict-aliasing"
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       CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
271     else
272       CFLAGS="$CFLAGS -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 "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c
352 $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
353 if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then
354     CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"
355 elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then
356     die "endian test failed"
357 fi
358
359 # autodetect options that weren't forced nor disabled
360
361 libpthread=""
362 if test "$pthread" = "auto" ; then
363     pthread="no"
364     case $SYS in
365         BEOS)
366             pthread="yes"
367             ;;
368         MINGW)
369             if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
370                 pthread="yes"
371                 libpthread="-lpthread"
372             elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
373                 pthread="yes"
374                 libpthread="-lpthreadGC2"
375             elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
376                 pthread="yes"
377                 libpthread="-lpthreadGC2 -lwsock32"
378                 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
379             elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
380                 pthread="yes"
381                 libpthread="-lpthreadGC2 -lws2_32"
382                 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
383             fi
384             ;;
385         OPENBSD)
386             cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
387             ;;
388         *)
389             cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
390             ;;
391     esac
392 fi
393 if test "$pthread" = "yes" ; then
394     CFLAGS="$CFLAGS -DHAVE_PTHREAD"
395     LDFLAGS="$LDFLAGS $libpthread"
396 fi
397
398 MP4_LDFLAGS="-lgpac_static"
399 if [ $SYS = MINGW ]; then
400     MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
401 fi
402 if [ "$mp4_output" = "auto" ] ; then
403     mp4_output="no"
404     cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
405 fi
406 if [ "$mp4_output" = "yes" ] ; then
407     echo "#define MP4_OUTPUT" >> config.h
408     LDFLAGS="$LDFLAGS $MP4_LDFLAGS"
409 fi
410
411 if [ "$avis_input" = "auto" ] ; then
412     if [ $SYS = MINGW ]; then
413         avis_input="yes"
414     else
415         avis_input="no";
416     fi
417 fi
418 if [ "$avis_input" = "yes" ] ; then
419     if cc_check "stdlib.h" -lvfw32 ; then
420         echo "#define AVIS_INPUT" >> config.h
421         LDFLAGS="$LDFLAGS -lvfw32"
422     elif cc_check "stdlib.h" -lavifil32 ; then
423         echo "#define AVIS_INPUT" >> config.h
424         LDFLAGS="$LDFLAGS -lavifil32"
425     else
426         avis_input="no";
427     fi
428 fi
429
430 if [ "$pic" = "yes" ] ; then
431     CFLAGS="$CFLAGS -fPIC"
432     ASFLAGS="$ASFLAGS -DPIC"
433     # resolve textrels in the x86 asm
434     cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
435 fi
436
437 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
438     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
439     LDFLAGS="$LDFLAGS -s"
440 fi
441
442 if [ "$debug" = "yes" ]; then
443     CFLAGS="-O1 -g $CFLAGS"
444 elif [ $ARCH = ARM ]; then
445     # arm-gcc-4.2 produces incorrect output with -ffast-math
446     # and it doesn't save any speed anyway on 4.4, so disable it
447     CFLAGS="-O4 -fno-fast-math $CFLAGS"
448 else
449     CFLAGS="-O4 -ffast-math $CFLAGS"
450 fi
451
452 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
453     echo "#define fseek fseeko" >> config.h
454     echo "#define ftell ftello" >> config.h
455 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
456     echo "#define fseek fseeko64" >> config.h
457     echo "#define ftell ftello64" >> config.h
458 fi
459
460 rm -f conftest*
461
462 # generate config files
463
464 cat > config.mak << EOF
465 prefix=$prefix
466 exec_prefix=$exec_prefix
467 bindir=$bindir
468 libdir=$libdir
469 includedir=$includedir
470 ARCH=$ARCH
471 SYS=$SYS
472 CC=$CC
473 CFLAGS=$CFLAGS
474 LDFLAGS=$LDFLAGS
475 AR=$AR
476 RANLIB=$RANLIB
477 STRIP=$STRIP
478 AS=$AS
479 ASFLAGS=$ASFLAGS
480 EXE=$EXE
481 VIS=$vis
482 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
483 DEVNULL=$DEVNULL
484 EOF
485
486 if [ "$shared" = "yes" ]; then
487     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
488     if [ "$SYS" = "MINGW" ]; then
489         echo "SONAME=libx264-$API.dll" >> config.mak
490         echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
491         echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
492     elif [ "$SYS" = "MACOSX" ]; then
493         echo "SOSUFFIX=dylib" >> config.mak
494         echo "SONAME=libx264.$API.dylib" >> config.mak
495         echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
496     elif [ "$SYS" = "SunOS" ]; then
497         echo "SOSUFFIX=so" >> config.mak
498         echo "SONAME=libx264.so.$API" >> config.mak
499         echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
500     else
501         echo "SOSUFFIX=so" >> config.mak
502         echo "SONAME=libx264.so.$API" >> config.mak
503         echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
504     fi
505     echo 'default: $(SONAME)' >> config.mak
506 fi
507
508 ./version.sh
509
510 pclibs="-L$libdir -lx264 $libpthread"
511
512 cat > x264.pc << EOF
513 prefix=$prefix
514 exec_prefix=$exec_prefix
515 libdir=$libdir
516 includedir=$includedir
517
518 Name: x264
519 Description: H.264 (MPEG4 AVC) encoder library
520 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
521 Libs: $pclibs
522 Cflags: -I$includedir
523 EOF
524
525
526 echo "Platform:   $ARCH"
527 echo "System:     $SYS"
528 echo "asm:        $asm"
529 echo "avis input: $avis_input"
530 echo "mp4 output: $mp4_output"
531 echo "pthread:    $pthread"
532 echo "debug:      $debug"
533 echo "gprof:      $gprof"
534 echo "PIC:        $pic"
535 echo "shared:     $shared"
536 echo "visualize:  $vis"
537 echo
538 echo "You can run 'make' or 'make fprofiled' now."
539