]> git.sesse.net Git - ffmpeg/blob - configure
More fixes to compile and build on more platforms.
[ffmpeg] / configure
1 #!/bin/sh
2 #
3 # ffmpeg configure script (c) 2000, 2001, 2002 Fabrice Bellard
4 #
5 # set temporary file name
6 if test ! -z "$TMPDIR" ; then
7     TMPDIR1="${TMPDIR}"
8 elif test ! -z "$TEMPDIR" ; then
9     TMPDIR1="${TEMPDIR}"
10 else
11     TMPDIR1="/tmp"
12 fi
13
14 TMPC="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPO="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.o"
16 TMPS="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.S"
17 TMPH="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h"
18
19 # default parameters
20 prefix="/usr/local"
21 cross_prefix=""
22 cc="gcc"
23 ar="ar"
24 ranlib="ranlib"
25 make="make"
26 strip="strip"
27 cpu=`uname -m`
28 mmx="default"
29 altivec="default"
30 mmi="default"
31 case "$cpu" in
32   i386|i486|i586|i686|i86pc|BePC)
33     cpu="x86"
34   ;;
35   armv4l)
36     cpu="armv4l"
37   ;;
38   alpha)
39     cpu="alpha"
40   ;;
41   "Power Macintosh"|ppc)
42     cpu="powerpc"
43   ;;
44   mips)
45     cpu="mips"
46   ;;
47   *)
48     cpu="unknown"
49   ;;
50 esac
51 gprof="no"
52 v4l="yes"
53 audio_oss="yes"
54 audio_beos="no"
55 network="yes"
56 zlib="yes"
57 mp3lame="no"
58 vorbis="no"
59 a52="yes"
60 a52bin="no"
61 win32="no"
62 cygwin="no"
63 lshared="no"
64 extralibs="-lm"
65 simpleidct="yes"
66 bigendian="no"
67 vhook="no"
68 mpegaudio_hp="yes"
69 SHFLAGS=-shared
70 netserver="no"
71
72 # OS specific
73 targetos=`uname -s`
74 case $targetos in
75 BeOS)
76 prefix="/boot/home/config"
77 # helps building libavcodec
78 CFLAGS="-O3 -DPIC -fomit-frame-pointer"
79 # 3 gcc releases known for BeOS, each with ugly bugs
80 gcc_version="$($cc -v 2>&1 | grep version | cut -d ' ' -f3-)"
81 case "$gcc_version" in
82 2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
83 mmx="no"
84 ;;
85 *20010315*) echo "BeBits gcc"
86 CFLAGS="$CFLAGS -fno-expensive-optimizations"
87 ;;
88 esac
89 SHFLAGS=-nostart
90 # disable linux things
91 audio_oss="no"
92 v4l="no"
93 # enable beos things
94 audio_beos="yes"
95 # no need for libm, but the inet stuff
96 # Check for BONE
97 if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then
98 extralibs="-lbind -lsocket"
99 else
100 netserver="yes"
101 extralibs="-lnet"
102 fi ;;
103 FreeBSD)
104 v4l="no"
105 audio_oss="yes"
106 make="gmake"
107 LDFLAGS="-export-dynamic"
108 ;;
109 BSD/OS)
110 v4l="no"
111 audio_oss="yes"
112 extralibs="-lpoll -lgnugetopt -lm"
113 make="gmake"
114 ;;
115 Darwin)
116 cc="cc"
117 v4l="no"
118 audio_oss="no"
119 CFLAGS="-no-cpp-precomp -pipe -O3 -fomit-frame-pointer -mdynamic-no-pic"
120 SHFLAGS="-dynamiclib"
121 extralibs=""
122 darwin="yes"
123 strip="strip -x"
124 ;;
125 CYGWIN*)
126 v4l="no"
127 audio_oss="yes"
128 extralibs=""
129 cygwin="yes"
130 test -f /usr/include/inttypes.h || \
131 test -f /usr/local/include/inttypes.h || \
132 echo "Missing inttypes.h, please copy cygwin_inttypes.h to" \
133      "/usr/include/inttypes.h !!!"
134 ;;
135 Linux)
136 LDFLAGS=-rdynamic
137 ;;
138 *) ;;
139 esac
140
141 # find source path
142 # XXX: we assume an absolute path is given when launching configure, 
143 # except in './configure' case.
144 source_path=${0%configure}
145 source_path=${source_path%/}
146 source_path_used="yes"
147 if test -z "$source_path" -o "$source_path" = "." ; then
148     source_path=`pwd`
149     source_path_used="no"
150 fi
151
152 cat > $TMPC << EOF
153 #include <dlfcn.h>
154 int main( void ) { return (int) dlopen("foo", 0); }
155 EOF
156
157 ldl=-ldl
158
159 if $cc -o $TMPO $TMPC -ldl 2> /dev/null  ; then
160 vhook=yes
161 fi
162
163 if $cc -o $TMPO $TMPC 2> /dev/null  ; then
164 vhook=yes
165 ldl=""
166 fi
167
168 cat > $TMPC << EOF
169 #include <X11/Xlib.h>
170 #include <Imlib2.h>
171 int main( void ) { return (int) imlib_load_font("foo"); }
172 EOF
173
174 imlib2=no
175 if $cc -o $TMPO $TMPC -lImlib2 2> /dev/null  ; then
176 imlib2=yes
177 fi
178
179 for opt do
180   case "$opt" in
181   --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
182   ;;
183   --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
184   ;;
185   --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
186   ;;
187   --cc=*) cc=`echo $opt | cut -d '=' -f 2`
188   ;;
189   --make=*) make=`echo $opt | cut -d '=' -f 2`
190   ;;
191   --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
192   ;;
193   --extra-ldflags=*) LDFLAGS=${opt#--extra-ldflags=}
194   ;;
195   --extra-libs=*) extralibs=${opt#--extra-libs=}
196   ;;
197   --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
198   ;;
199   --disable-mmx) mmx="no"
200   ;;
201   --disable-altivec) altivec="no"
202   ;;
203   --enable-gprof) gprof="yes"
204   ;;
205   --disable-v4l) v4l="no"
206   ;;
207   --disable-audio-oss) audio_oss="no"
208   ;;
209   --disable-audio-beos) audio_beos="no"
210   ;;
211   --disable-network) network="no"
212   ;;
213   --disable-zlib) zlib="no"
214   ;;
215   --disable-a52) a52="no"
216   ;;
217   --enable-a52bin) a52bin="yes" ; extralibs="$ldl $extralibs"
218   ;;
219   --enable-mp3lame) mp3lame="yes"
220   ;;
221   --enable-vorbis) vorbis="yes"
222   ;;
223   --disable-vhook) vhook="no"
224   ;;
225   --disable-simple_idct) simpleidct="no"
226   ;;
227   --enable-win32) win32="yes"
228   ;;
229   --enable-shared) lshared="yes"
230   ;;
231   --disable-mpegaudio-hp) mpegaudio_hp="no"
232   ;;
233   esac
234 done
235
236 # compute mmx state
237 if test $mmx = "default"; then
238     if test $cpu = "x86"; then
239         mmx="yes"
240     else
241         mmx="no"
242     fi
243 fi
244
245 # Can only do AltiVec on PowerPC
246 if test $altivec = "default"; then
247     if test $cpu = "powerpc"; then
248         altivec="yes"
249     else
250         altivec="no"
251     fi
252 fi
253
254 # See does our compiler support Motorola AltiVec C API
255 if test $altivec = "yes"; then
256 cat > $TMPC << EOF
257 int main(void) {
258     vector signed int v1, v2, v3;
259     v1 = vec_add(v2,v3);
260     return 0;
261 }
262 EOF
263 $cc -o $TMPO $TMPC -faltivec 2> /dev/null || altivec="no"
264 fi
265
266 # Can only do mmi on mips
267 if test $mmi = "default"; then
268     if test $cpu = "mips"; then
269         mmi="yes"
270     else
271         mmi="no"
272     fi
273 fi
274
275 # See does our compiler support mmi
276 if test $mmi = "yes"; then
277 cat > $TMPC << EOF
278 int main(void) {
279     __asm__ ("lq \$2, 0(\$2)");
280     return 0;
281 }
282 EOF
283 $cc -o $TMPO $TMPC 2> /dev/null || mmi="no"
284 fi
285
286 # Checking for CFLAGS
287 if test -z "$CFLAGS"; then
288     CFLAGS="-O3"
289 fi
290
291 if test "$win32" = "yes" ; then
292     cross_prefix="i386-mingw32msvc-"
293     v4l="no"
294     audio_oss="no"
295     network="no"
296 fi
297
298 cc="${cross_prefix}${cc}"
299 ar="${cross_prefix}${ar}"
300 ranlib="${cross_prefix}${ranlib}"
301 strip="${cross_prefix}${strip}"
302
303 if test -z "$cross_prefix" ; then
304
305 # ---
306 # big/little endian test
307 cat > $TMPC << EOF
308 #include <inttypes.h>
309 int main(int argc, char ** argv){
310         volatile uint32_t i=0x01234567;
311         return (*((uint8_t*)(&i))) == 0x67;
312 }
313 EOF
314
315 if $cc -o $TMPO $TMPC 2>/dev/null ; then
316 $TMPO && bigendian="yes"
317 else
318 echo big/little test failed
319 fi
320
321 else
322
323 # if cross compiling, cannot launch a program, so make a static guess
324 if test "$cpu" = "powerpc" -o "$cpu" = "mips" ; then
325     bigendian="yes"
326 fi
327
328 fi
329
330 # ---
331 # check availability of some header files
332
333 cat > $TMPC << EOF
334 #include <malloc.h>
335 int main( void ) { return 0; }
336 EOF
337
338 _memalign=no
339 _malloc_h=no
340 if $cc -o $TMPO $TMPC 2> /dev/null ; then
341 _malloc_h=yes
342 _memalign=yes
343 # check for memalign - atmos
344 cat > $TMPC << EOF
345 #include <malloc.h>
346 int main ( void ) {
347 char *string = NULL;
348 string = memalign(64, sizeof(char));
349 return 0;
350 }
351 EOF
352 $cc -o $TMPO $TMPC 2> /dev/null || _memalign=no
353 fi
354
355 cat > $TMPC << EOF
356 #define _GNU_SOURCE
357 #include <time.h>
358 int main( void ) { return *strptime("", "", 0); }
359 EOF
360
361 strptime=no
362 if $cc -o $TMPO $TMPC 2> /dev/null ; then
363   strptime=yes
364 fi
365
366 if test "$zlib" = "yes"; then
367 # check for zlib - mmu_man
368 cat > $TMPC << EOF
369 #include <zlib.h>
370 int main ( void ) {
371 if (zlibVersion() != ZLIB_VERSION)
372    puts("zlib version differs !!!");
373    return 1;
374 return 0;
375 }
376 EOF
377 $cc -o $TMPO $TMPC -lz 2> /dev/null || zlib="no"
378 # $TMPO 2> /dev/null > /dev/null || zlib="no"
379 # XXX: more tests needed - runtime test
380 fi
381 if test "$zlib" = "yes"; then
382 extralibs="$extralibs -lz"
383 fi
384
385 # test for lrintf in math.h
386 cat > $TMPC << EOF
387 #define _ISOC9X_SOURCE  1
388 #include <math.h>
389 int main( void ) { return (lrintf(3.999f) > 0)?0:1; }
390 EOF
391
392 have_lrintf="no"
393 if $cc $extralibs -o $TMPO $TMPC 2> /dev/null ; then
394   have_lrintf="yes"
395   $TMPO 2> /dev/null > /dev/null || have_lrintf="no"
396 fi
397
398 _restrict=
399 for restrict_keyword in restrict __restrict__ __restrict; do
400   echo "void foo(char * $restrict_keyword p);" > $TMPC
401   if $cc -c -o $TMPO $TMPC 2> /dev/null; then
402     _restrict=$restrict_keyword
403     break;
404   fi
405 done
406
407 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
408 cat << EOF
409
410 Usage: configure [options]
411 Options: [defaults in brackets after descriptions]
412
413 EOF
414 echo "Standard options:"
415 echo "  --help                   print this message"
416 echo "  --prefix=PREFIX          install in PREFIX [$prefix]"
417 echo "  --enable-mp3lame         enable mp3 encoding via libmp3lame [default=no]"
418 echo "  --enable-vorbis          enable vorbis support via libvorbisenc [default=no]"
419 echo "  --enable-win32           enable win32 cross compile"
420 echo "  --disable-a52            disable GPL'ed A52 support [default=no]"
421 echo "  --enable-a52bin          open liba52.so.0 at runtime [default=no]"
422 echo "  --enable-shared          build shared libraries [default=no]"
423 echo ""
424 echo "Advanced options (experts only):"
425 echo "  --source-path=PATH       path of source code [$source_path]"
426 echo "  --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]"
427 echo "  --cc=CC                  use C compiler CC [$cc]"
428 echo "  --make=MAKE              use specified make [$make]"
429 echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]"
430 echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
431 echo "  --extra-libs=ELIBS       add ELIBS [$ELIBS]"
432 echo "  --cpu=CPU                force cpu to CPU  [$cpu]"
433 echo "  --disable-mmx            disable mmx usage"
434 echo "  --disable-altivec        disable AltiVec usage"
435 echo "  --disable-audio-oss      disable OSS audio support [default=no]"
436 echo "  --disable-audio-beos     disable BeOS audio support [default=no]"
437 echo "  --disable-v4l            disable video4linux grabbing [default=no]"
438 echo "  --disable-network        disable network support [default=no]"
439 echo "  --disable-zlib           disable zlib [default=no]"
440 echo "  --disable-simple_idct    disable simple IDCT routines [default=no]"
441 echo "  --disable-vhook          disable video hooking support"
442 echo "  --enable-gprof           enable profiling with gprof [$gprof]"
443 echo "  --disable-mpegaudio-hp   faster (but less accurate)"
444 echo "                           mpegaudio decoding [default=no]"
445 echo ""
446 echo "NOTE: The object files are build at the place where configure is launched"
447 exit 1
448 fi
449
450 echo "Install prefix   $prefix"
451 echo "Source path      $source_path"
452 echo "C compiler       $cc"
453 echo "make             $make"
454 echo "CPU              $cpu"
455 echo "Big Endian       $bigendian"
456 if test $cpu = "x86"; then
457 echo "MMX enabled      $mmx"
458 fi
459 if test $cpu = "mips"; then
460 echo "MMI enabled      $mmi"
461 fi
462 if test $cpu = "powerpc"; then
463 echo "AltiVec enabled  $altivec"
464 fi
465 echo "gprof enabled    $gprof"
466 echo "zlib enabled     $zlib"
467 echo "mp3lame enabled  $mp3lame"
468 echo "vorbis enabled   $vorbis"
469 echo "a52 support      $a52"
470 echo "a52 dlopened     $a52bin"
471 echo "Video hooking    $vhook"
472
473 if test "$vhook" = "yes" ; then
474 echo "Imlib2 support   $imlib2"
475 fi
476
477 echo "Creating config.mak and config.h"
478
479 echo "# Automatically generated by configure - do not modify" > config.mak
480 echo "/* Automatically generated by configure - do not modify */" > $TMPH
481
482 echo "prefix=$prefix" >> config.mak
483 echo "MAKE=$make" >> config.mak
484 echo "CC=$cc" >> config.mak
485 echo "AR=$ar" >> config.mak
486 echo "RANLIB=$ranlib" >> config.mak
487 echo "STRIP=$strip" >> config.mak
488 echo "OPTFLAGS=$CFLAGS" >> config.mak
489 echo "LDFLAGS=$LDFLAGS" >> config.mak
490 echo "SHFLAGS=$SHFLAGS" >> config.mak
491 if test "$cpu" = "x86" ; then
492   echo "TARGET_ARCH_X86=yes" >> config.mak
493   echo "#define ARCH_X86 1" >> $TMPH
494 elif test "$cpu" = "armv4l" ; then
495   echo "TARGET_ARCH_ARMV4L=yes" >> config.mak
496   echo "#define ARCH_ARMV4L 1" >> $TMPH
497 elif test "$cpu" = "alpha" ; then
498   echo "TARGET_ARCH_ALPHA=yes" >> config.mak
499   echo "#define ARCH_ALPHA 1" >> $TMPH
500 elif test "$cpu" = "sparc64" ; then
501   echo "TARGET_ARCH_SPARC64=yes" >> config.mak
502   echo "#define ARCH_SPARC64 1" >> $TMPH
503 elif test "$cpu" = "powerpc" ; then
504   echo "TARGET_ARCH_POWERPC=yes" >> config.mak
505   echo "#define ARCH_POWERPC 1" >> $TMPH
506 elif test "$cpu" = "mips" ; then
507   echo "TARGET_ARCH_MIPS=yes" >> config.mak
508   echo "#define ARCH_MIPS 1" >> $TMPH
509 fi
510 if test "$bigendian" = "yes" ; then
511   echo "WORDS_BIGENDIAN=yes" >> config.mak
512   echo "#define WORDS_BIGENDIAN 1" >> $TMPH
513 fi
514 if test "$mmx" = "yes" ; then
515   echo "TARGET_MMX=yes" >> config.mak
516   echo "#define HAVE_MMX 1" >> $TMPH
517 fi
518 if test "$mmi" = "yes" ; then
519   echo "TARGET_MMI=yes" >> config.mak
520   echo "#define HAVE_MMI 1" >> $TMPH
521 fi
522 if test "$altivec" = "yes" ; then
523   echo "TARGET_ALTIVEC=yes" >> config.mak
524   echo "#define HAVE_ALTIVEC 1" >> $TMPH
525 fi
526 if test "$gprof" = "yes" ; then
527   echo "TARGET_GPROF=yes" >> config.mak
528   echo "#define HAVE_GPROF 1" >> $TMPH
529 fi
530 if test "$strptime" = "yes" ; then
531   echo "#define HAVE_STRPTIME 1" >> $TMPH
532 else
533   echo "BUILD_STRPTIME=yes" >> config.mak
534 fi
535 if test "$imlib2" = "yes" ; then
536   echo "HAVE_IMLIB2=yes" >> config.mak
537 fi
538 if test "$have_lrintf" = "yes" ; then
539   echo "#define HAVE_LRINTF 1" >> $TMPH
540 fi
541 if test "$vhook" = "yes" ; then
542   echo "BUILD_VHOOK=yes" >> config.mak
543   echo "#define HAVE_VHOOK 1" >> $TMPH
544   extralibs="$extralibs $ldl"
545 fi
546 if test "$lshared" = "yes" ; then
547   echo "BUILD_SHARED=yes" >> config.mak
548   echo "PIC=-fPIC" >> config.mak
549 fi
550 echo "EXTRALIBS=$extralibs" >> config.mak
551 echo -n "VERSION=" >>config.mak
552 head $source_path/VERSION >>config.mak
553 echo "" >>config.mak
554 # if you do not want to use encoders, disable that.
555 echo "#define CONFIG_ENCODERS 1" >> $TMPH
556 echo "CONFIG_ENCODERS=yes" >> config.mak
557
558 # if you do not want to use decoders, disable that.
559 echo "#define CONFIG_DECODERS 1" >> $TMPH
560 echo "CONFIG_DECODERS=yes" >> config.mak
561
562 # AC3
563 if test "$a52" = "yes" ; then
564   echo "#define CONFIG_AC3 1" >> $TMPH
565   echo "CONFIG_AC3=yes" >> config.mak
566
567   if test "$a52bin" = "yes" ; then
568     echo "#define CONFIG_A52BIN 1" >> $TMPH
569     echo "CONFIG_A52BIN=yes" >> config.mak
570   fi
571 fi
572
573 # mpeg audio high precision mode
574 if test "$mpegaudio_hp" = "yes" ; then
575   echo "#define CONFIG_MPEGAUDIO_HP 1" >> $TMPH
576 fi
577
578 if test "$v4l" = "yes" ; then
579   echo "#define CONFIG_VIDEO4LINUX 1" >> $TMPH
580   echo "CONFIG_VIDEO4LINUX=yes" >> config.mak
581 fi
582
583 if test "$audio_oss" = "yes" ; then
584   echo "#define CONFIG_AUDIO_OSS 1" >> $TMPH
585   echo "CONFIG_AUDIO_OSS=yes" >> config.mak
586 fi
587
588 if test "$audio_beos" = "yes" ; then
589   echo "#define CONFIG_AUDIO_BEOS 1" >> $TMPH
590   echo "CONFIG_AUDIO_BEOS=yes" >> config.mak
591 fi
592
593 if test "$network" = "yes" ; then
594   echo "#define CONFIG_NETWORK 1" >> $TMPH
595   echo "CONFIG_NETWORK=yes" >> config.mak
596 fi
597
598 if test "$zlib" = "yes" ; then
599   echo "#define CONFIG_ZLIB 1" >> $TMPH
600   echo "CONFIG_ZLIB=yes" >> config.mak
601 fi
602
603 if test "$mp3lame" = "yes" ; then
604   echo "#define CONFIG_MP3LAME 1" >> $TMPH
605   echo "CONFIG_MP3LAME=yes" >> config.mak
606 fi
607
608 if test "$vorbis" = "yes" ; then
609   echo "#define CONFIG_VORBIS 1" >> $TMPH
610   echo "CONFIG_VORBIS=yes" >> config.mak
611 fi
612
613 if test "$win32" = "yes" ; then
614   echo "#define CONFIG_WIN32 1" >> $TMPH
615   echo "CONFIG_WIN32=yes" >> config.mak
616 fi
617
618 if test "$cygwin" = "yes" ; then
619   # setup correct exesuffix
620   echo "CONFIG_WIN32=yes" >> config.mak
621 fi
622
623 if test "$darwin" = "yes"; then
624   echo "#define CONFIG_DARWIN 1"  >> $TMPH
625   echo "CONFIG_DARWIN=yes" >> config.mak
626 fi
627
628 if test "$_malloc_h" = "yes" ; then
629   echo "#define HAVE_MALLOC_H 1" >> $TMPH
630 else
631   echo "#undef  HAVE_MALLOC_H" >> $TMPH
632 fi
633
634 if test "$_memalign" = "yes" ; then
635   echo "#define HAVE_MEMALIGN 1" >> $TMPH
636 else
637   echo "#undef  HAVE_MEMALIGN" >> $TMPH
638 fi
639
640 if test "$netserver" = "yes" ; then
641   echo "#define CONFIG_BEOS_NETSERVER 1" >> $TMPH
642   echo "CONFIG_BEOS_NETSERVER=yes" >> config.mak
643 fi
644
645 if test "$simpleidct" = "yes" ; then
646   echo "#define SIMPLE_IDCT 1" >> $TMPH
647 fi
648
649 echo "#define restrict $_restrict" >> $TMPH
650
651 # build tree in object directory if source path is different from current one
652 if test "$source_path_used" = "yes" ; then
653     DIRS="libav libavcodec libavcodec/alpha libavcodec/armv4l libavcodec/i386 \
654           libavcodec/ppc libavcodec/liba52 libavcodec/mlib tests"
655     FILES="Makefile libav/Makefile libavcodec/Makefile tests/Makefile"
656     for dir in $DIRS ; do
657             mkdir -p $dir
658     done
659     for f in $FILES ; do
660         ln -sf $source_path/$f $f
661     done
662 fi
663 echo "SRC_PATH=$source_path" >> config.mak
664
665 diff $TMPH config.h >/dev/null 2>&1
666 if test $? -ne 0 ; then
667         mv -f $TMPH config.h
668 else
669         echo "config.h is unchanged"
670 fi
671
672 rm -f $TMPO $TMPC $TMPS $TMPH