Fix crash in --me esa/tesa introduced in r1058
[x262.git] / configure
1 #! /bin/sh
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"
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 ""
24 exit 1
25 fi
26
27 cc_check() {
28     cat > conftest.c << EOF
29 #include <$1>
30 int main () { $3 return 0; }
31 EOF
32     $CC conftest.c $CFLAGS $LDFLAGS $2 -o conftest 2>$DEVNULL
33     TMP="$?"
34     return $TMP
35 }
36
37 as_check() {
38     echo "$1" > conftest.asm
39     $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
40     TMP="$?"
41     return $TMP
42 }
43
44 rm -f config.h config.mak x264.pc conftest*
45
46 prefix='/usr/local'
47 exec_prefix='${prefix}'
48 bindir='${exec_prefix}/bin'
49 libdir='${exec_prefix}/lib'
50 includedir='${prefix}/include'
51 DEVNULL='/dev/null'
52
53 avis_input="auto"
54 mp4_output="auto"
55 pthread="auto"
56 asm="yes"
57 debug="no"
58 gprof="no"
59 pic="no"
60 vis="no"
61 shared="no"
62
63 CC="${CC-gcc}"
64 CFLAGS="$CFLAGS -Wall -I."
65 LDFLAGS="$LDFLAGS"
66 HAVE_GETOPT_LONG=1
67
68 AS="yasm"
69 ASFLAGS=""
70
71 EXE=""
72
73 # check whether 'echo -n' works as expected, otherwise try printf
74 if [ "x`echo -n houba`" = xhouba ]
75 then
76   ECHON="echo -n"
77 elif [ "x`printf houba`" = xhouba ]
78 then
79   ECHON="printf"
80 else
81   echo "Neither 'echo -n' nor 'printf' are working with your shell!"
82   exit 1
83 fi
84
85 # parse options
86
87 for opt do
88     optarg="${opt#*=}"
89     case "$opt" in
90         --prefix=*)
91             prefix="$optarg"
92             ;;
93         --exec-prefix=*)
94             exec_prefix="$optarg"
95             ;;
96         --bindir=*)
97             bindir="$optarg"
98             ;;
99         --libdir=*)
100             libdir="$optarg"
101             ;;
102         --includedir=*)
103             includedir="$optarg"
104             ;;
105         --enable-asm)
106             asm="yes"
107             ;;
108         --disable-asm)
109             asm="no"
110             ;;
111         --enable-avis-input)
112             avis_input="yes"
113             ;;
114         --disable-avis-input)
115             avis_input="no"
116             ;;
117         --enable-mp4-output)
118             mp4_output="yes"
119             ;;
120         --disable-mp4-output)
121             mp4_output="no"
122             ;;
123         --extra-asflags=*)
124             ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
125             ;;
126         --extra-cflags=*)
127             CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
128             ;;
129         --extra-ldflags=*)
130             LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
131             ;;
132         --enable-pthread)
133             pthread="auto" # can't skip detection, since it differs by OS
134             ;;
135         --disable-pthread)
136             pthread="no"
137             ;;
138         --enable-debug)
139             debug="yes"
140             ;;
141         --enable-gprof)
142             CFLAGS="$CFLAGS -pg"
143             LDFLAGS="$LDFLAGS -pg"
144             gprof="yes"
145             ;;
146         --enable-pic)
147             pic="yes"
148             ;;
149         --enable-shared)
150             shared="yes"
151             ;;
152         --enable-visualize)
153             LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
154             CFLAGS="$CFLAGS -DVISUALIZE=1"
155             vis="yes"
156             ;;
157         --host=*)
158             host="${opt#--host=}"
159             ;;
160         *)
161             echo "Unknown option $opt, ignored"
162             ;;
163     esac
164 done
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 -lmx"
187     if [ "$pic" = "no" ]; then
188         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     CFLAGS="$CFLAGS -mno-cygwin"
217     LDFLAGS="$LDFLAGS -mno-cygwin"
218     EXE=".exe"
219     DEVNULL="NUL"
220     ;;
221   mingw*)
222     SYS="MINGW"
223     EXE=".exe"
224     DEVNULL="NUL"
225     ;;
226   sunos*|solaris*)
227     SYS="SunOS"
228     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
229     LDFLAGS="$LDFLAGS -lm"
230     HAVE_GETOPT_LONG=0
231     ;;
232   *)
233     echo "Unknown system $host, edit the configure"
234     exit 1
235     ;;
236 esac
237
238 case $host_cpu in
239   i*86)
240     ARCH="X86"
241     ASFLAGS="-O2"
242     if [ "$SYS" = MACOSX ]; then
243       ASFLAGS="$ASFLAGS -f macho -DPREFIX"
244     elif [ "$SYS" = MINGW ]; then
245       ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
246     else
247       ASFLAGS="$ASFLAGS -f elf"
248     fi
249     ;;
250   x86_64)
251     ARCH="X86_64"
252     if [ "$SYS" = MACOSX ];then
253       ASFLAGS="-f macho64 -m amd64 -DPIC -DPREFIX"
254       CFLAGS="$CFLAGS -arch x86_64"
255       LDFLAGS="$LDFLAGS -arch x86_64"
256     else
257       ASFLAGS="-f elf -m amd64"
258     fi
259     ;;
260   powerpc|powerpc64)
261     ARCH="PPC"
262     if [ $SYS = MACOSX ]
263     then
264       ALTIVECFLAGS="$ALTIVECFLAGS -faltivec -fastf -mcpu=G4"
265     else
266       ALTIVECFLAGS="$ALTIVECFLAGS -maltivec -mabi=altivec"
267     fi
268     ;;
269   sparc)
270     if test "$(uname -m)" = "sun4u"; then
271       ARCH="UltraSparc"
272       CFLAGS="$CFLAGS -mcpu=ultrasparc"
273       LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
274       AS="as"
275       ASFLAGS="-xarch=v8plusa"
276     else
277       ARCH="Sparc"
278     fi
279     ;;
280   mips|mipsel|mips64|mips64el)
281     ARCH="MIPS"
282     ;;
283   arm*)
284     ARCH="ARM"
285     ;;
286   s390|s390x)
287     ARCH="S390"
288     ;;
289   parisc|parisc64)
290     ARCH="PARISC"
291     ;;
292   *)
293     ARCH="$(echo $host_cpu | tr a-z A-Z)"
294     ;;
295 esac
296
297 # check requirements
298
299 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" \) ] ; then
300     pic="yes"
301 fi
302
303 if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
304     if as_check "pinsrd xmm0, [esp], 0" ; then
305         CFLAGS="$CFLAGS -DHAVE_MMX"
306     else
307         VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
308         echo "Found $VER"
309         echo "Minimum version is yasm-0.6.1"
310         echo "If you really want to compile without asm, configure with --disable-asm."
311         exit 1
312     fi
313 else
314     AS=""
315 fi
316
317 CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"
318
319 echo "unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';" > conftest.c
320 $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
321 grep -q BIGE conftest.o && CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"
322
323 # autodetect options that weren't forced nor disabled
324
325 libpthread=""
326 if test "$pthread" = "auto" ; then
327     pthread="no"
328     case $SYS in
329         BEOS)
330             pthread="yes"
331             ;;
332         MINGW)
333             if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
334                 pthread="yes"
335                 libpthread="-lpthread"
336             elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
337                 pthread="yes"
338                 libpthread="-lpthreadGC2"
339             elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
340                 pthread="yes"
341                 libpthread="-lpthreadGC2 -lwsock32"
342                 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
343             fi
344             ;;
345         *)
346             cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
347             ;;
348     esac
349 fi
350 if test "$pthread" = "yes" ; then
351     CFLAGS="$CFLAGS -DHAVE_PTHREAD"
352     LDFLAGS="$LDFLAGS $libpthread"
353 fi
354
355 MP4_LDFLAGS="-lgpac_static"
356 if [ $SYS = MINGW ]; then
357     MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
358 fi
359 if [ "$mp4_output" = "auto" ] ; then
360     mp4_output="no"
361     cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
362 fi
363 if [ "$mp4_output" = "yes" ] ; then
364     echo "#define MP4_OUTPUT" >> config.h
365     LDFLAGS="$LDFLAGS $MP4_LDFLAGS"
366 fi
367
368 if [ "$avis_input" = "auto" ] ; then
369     if [ $SYS = MINGW ]; then
370         avis_input="yes"
371     else
372         avis_input="no";
373     fi
374 fi
375 if [ "$avis_input" = "yes" ] ; then
376     echo "#define AVIS_INPUT" >> config.h
377     LDFLAGS="$LDFLAGS -lvfw32"
378 fi
379
380 if [ "$pic" = "yes" ] ; then
381     CFLAGS="$CFLAGS -fPIC"
382     ASFLAGS="$ASFLAGS -DPIC"
383     # resolve textrels in the x86 asm
384     cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
385 fi
386
387 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
388     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
389     LDFLAGS="$LDFLAGS -s"
390 fi
391
392 if [ "$debug" = "yes" ]; then
393     CFLAGS="-O1 -g $CFLAGS"
394 else
395     CFLAGS="-O4 -ffast-math $CFLAGS"
396 fi
397
398 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
399     echo "#define fseek fseeko" >> config.h
400     echo "#define ftell ftello" >> config.h
401 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
402     echo "#define fseek fseeko64" >> config.h
403     echo "#define ftell ftello64" >> config.h
404 fi
405
406 rm -f conftest*
407
408 # generate config files
409
410 cat > config.mak << EOF
411 prefix=$prefix
412 exec_prefix=$exec_prefix
413 bindir=$bindir
414 libdir=$libdir
415 includedir=$includedir
416 ARCH=$ARCH
417 SYS=$SYS
418 CC=$CC
419 CFLAGS=$CFLAGS
420 ALTIVECFLAGS=$ALTIVECFLAGS
421 LDFLAGS=$LDFLAGS
422 AS=$AS
423 ASFLAGS=$ASFLAGS
424 EXE=$EXE
425 VIS=$vis
426 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
427 DEVNULL=$DEVNULL
428 ECHON=$ECHON
429 EOF
430
431 $ECHON 'CONFIGURE_ARGS=' >> config.mak
432 for A in "$@" ; do
433     $ECHON " '$A'" >> config.mak
434 done
435 echo '' >> config.mak
436
437 if [ "$shared" = "yes" ]; then
438     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
439     if [ "$SYS" = "MINGW" ]; then
440         echo "SONAME=libx264-$API.dll" >> config.mak
441         echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
442         echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
443     elif [ "$SYS" = "MACOSX" ]; then
444         echo "SOSUFFIX=dylib" >> config.mak
445         echo "SONAME=libx264.$API.dylib" >> config.mak
446         echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
447     else
448         echo "SOSUFFIX=so" >> config.mak
449         echo "SONAME=libx264.so.$API" >> config.mak
450         echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
451     fi
452     echo 'default: $(SONAME)' >> config.mak
453 fi
454
455 ./version.sh
456
457 pclibs="-L$libdir -lx264 $libpthread"
458
459 cat > x264.pc << EOF
460 prefix=$prefix
461 exec_prefix=$exec_prefix
462 libdir=$libdir
463 includedir=$includedir
464
465 Name: x264
466 Description: H.264 (MPEG4 AVC) encoder library
467 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
468 Libs: $pclibs
469 Cflags: -I$includedir
470 EOF
471
472
473 echo "Platform:   $ARCH"
474 echo "System:     $SYS"
475 echo "asm:        $asm"
476 echo "avis input: $avis_input"
477 echo "mp4 output: $mp4_output"
478 echo "pthread:    $pthread"
479 echo "debug:      $debug"
480 echo "gprof:      $gprof"
481 echo "PIC:        $pic"
482 echo "shared:     $shared"
483 echo "visualize:  $vis"
484 echo
485 echo "You can run 'make' or 'make fprofiled' now."
486