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