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