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