3 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
5 echo "Usage: ./configure [options]"
7 echo "available options:"
9 echo " --help print this message"
10 echo " --disable-avs-input disables avisynth input (win32 only)"
11 echo " --disable-lavf-input disables libavformat input"
12 echo " --disable-ffms-input disables ffmpegsource input"
13 echo " --disable-mp4-output disables mp4 output (using gpac)"
14 echo " --disable-pthread disables multithreaded encoding"
15 echo " --disable-asm disables assembly optimizations on x86 and arm"
16 echo " --enable-debug adds -g, doesn't strip"
17 echo " --enable-gprof adds -pg, doesn't strip"
18 echo " --enable-visualize enables visualization (X11 only)"
19 echo " --enable-pic build position-independent code"
20 echo " --enable-shared build libx264.so"
21 echo " --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS"
22 echo " --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS"
23 echo " --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
24 echo " --host=HOST build programs to run on HOST"
25 echo " --cross-prefix=PREFIX use PREFIX for compilation tools"
32 [ -n "$1" ] && echo "#include <$1>" > conftest.c
33 echo "int main () { $3 return 0; }" >> conftest.c
34 $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest 2>$DEVNULL
38 echo "$1" > conftest.asm
39 $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
47 rm -f config.h config.mak x264.pc conftest*
50 exec_prefix='${prefix}'
51 bindir='${exec_prefix}/bin'
52 libdir='${exec_prefix}/lib'
53 includedir='${prefix}/include'
68 CFLAGS="$CFLAGS -Wall -I."
70 LDFLAGSCLI="$LDFLAGSCLI"
112 --disable-lavf-input)
118 --disable-ffms-input)
124 --disable-mp4-output)
128 ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
131 CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
134 LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
137 pthread="auto" # can't skip detection, since it differs by OS
147 LDFLAGS="$LDFLAGS -pg"
157 LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
158 CFLAGS="$CFLAGS -DVISUALIZE=1"
162 host="${opt#--host=}"
165 cross_prefix="${opt#--cross-prefix=}"
168 echo "Unknown option $opt, ignored"
173 CC="${CC-${cross_prefix}gcc}"
174 AR="${AR-${cross_prefix}ar}"
175 RANLIB="${RANLIB-${cross_prefix}ranlib}"
176 STRIP="${STRIP-${cross_prefix}strip}"
178 if [ "x$host" = x ]; then
179 host=`./config.guess`
181 # normalize a triplet into a quadruplet
182 host=`./config.sub $host`
185 host_cpu="${host%%-*}"
187 host_vendor="${host%%-*}"
193 CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
197 CFLAGS="$CFLAGS -falign-loops=16"
198 LDFLAGS="$LDFLAGS -lm"
199 if [ "$pic" = "no" ]; then
200 cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
205 LDFLAGS="$LDFLAGS -lm"
209 CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
210 LDFLAGS="$LDFLAGS -lm"
214 LDFLAGS="$LDFLAGS -lm"
218 CFLAGS="$CFLAGS -I/usr/X11R6/include"
219 LDFLAGS="$LDFLAGS -lm"
223 CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
224 LDFLAGS="$LDFLAGS -lm"
230 if cc_check "" -mno-cygwin; then
231 CFLAGS="$CFLAGS -mno-cygwin"
232 LDFLAGS="$LDFLAGS -mno-cygwin"
242 CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
243 LDFLAGS="$LDFLAGS -lm"
247 die "Unknown system $host, edit the configure"
255 ASFLAGS="$ASFLAGS -O2"
256 if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then
257 CFLAGS="$CFLAGS -march=i686"
259 if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then
260 CFLAGS="$CFLAGS -mfpmath=sse -msse"
262 if [ "$SYS" = MACOSX ]; then
263 ASFLAGS="$ASFLAGS -f macho -DPREFIX"
264 elif [ "$SYS" = MINGW ]; then
265 ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
267 ASFLAGS="$ASFLAGS -f elf"
273 if [ "$SYS" = MACOSX ];then
274 ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
275 if cc_check '' "-arch x86_64"; then
276 CFLAGS="$CFLAGS -arch x86_64"
277 LDFLAGS="$LDFLAGS -arch x86_64"
279 elif [ "$SYS" = MINGW ]; then
280 ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
282 ASFLAGS="$ASFLAGS -f elf -m amd64"
289 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
291 CFLAGS="$CFLAGS -maltivec -mabi=altivec -DHAVE_ALTIVEC_H"
295 if test "$(uname -m)" = "sun4u"; then
297 CFLAGS="$CFLAGS -mcpu=ultrasparc"
298 LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
299 AS="${cross_prefix}as"
300 ASFLAGS="$ASFLAGS -xarch=v8plusa"
305 mips|mipsel|mips64|mips64el)
310 AS="${AS-${cross_prefix}gcc}"
319 ARCH="$(echo $host_cpu | tr a-z A-Z)"
325 cc_check || die "No working C compiler found."
327 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" \) ] ; then
331 if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
332 if ! as_check "lzcnt eax, eax" ; then
333 VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
335 echo "Minimum version is yasm-0.6.2"
336 echo "If you really want to compile without asm, configure with --disable-asm."
339 if ! cc_check '' '' 'asm("pabsw %xmm0, %xmm0");' ; then
340 VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
342 echo "Minimum version is binutils-2.17"
343 echo "Your compiler can't handle inline SSSE3 asm."
344 echo "If you really want to compile without asm, configure with --disable-asm."
347 CFLAGS="$CFLAGS -DHAVE_MMX"
350 if [ $asm = yes -a $ARCH = ARM ] ; then
351 # set flags so neon is built by default
352 echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
354 if cc_check '' '' 'asm("rev ip, ip");' ; then CFLAGS="$CFLAGS -DHAVE_ARMV6"
355 cc_check '' '' 'asm("movt r0, #0");' && CFLAGS="$CFLAGS -DHAVE_ARMV6T2"
356 cc_check '' '' 'asm("vadd.i16 q0, q0, q0");' && CFLAGS="$CFLAGS -DHAVE_NEON"
357 ASFLAGS="$ASFLAGS $CFLAGS -c"
359 echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
360 echo "If you really want to run on such a CPU, configure with --disable-asm."
365 [ $asm = no ] && AS=""
366 [ "x$AS" = x ] && asm="no"
368 CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"
370 echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c
371 $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
372 if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then
373 CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"
374 elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then
375 die "endian test failed"
378 # autodetect options that weren't forced nor disabled
381 if test "$pthread" = "auto" ; then
388 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
390 libpthread="-lpthread"
391 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
393 libpthread="-lpthreadGC2"
394 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
396 libpthread="-lpthreadGC2 -lwsock32"
397 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
398 elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
400 libpthread="-lpthreadGC2 -lws2_32"
401 CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
405 cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
408 cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
412 if test "$pthread" = "yes" ; then
413 CFLAGS="$CFLAGS -DHAVE_PTHREAD"
414 LDFLAGS="$LDFLAGS $libpthread"
417 if [ "$lavf_input" = "auto" ] ; then
419 if [ `pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL` ] ; then
420 LAVF_LDFLAGS="$LAVF_LDFLAGS $(pkg-config --libs libavformat libavcodec libswscale)"
421 LAVF_CDFLAGS="$LAVF_CFLAGS $(pkg-config --cflags libavformat libavcodec libswscale)"
423 if [ -z "$LAVF_LDFLAGS" -a -z "$LAVF_CFLAGS" ]; then
424 LAVF_LDFLAGS="-lavformat -lswscale"
425 for lib in -lpostproc -lavcodec -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
426 cc_check "" $lib && LAVF_LDFLAGS="$LAVF_LDFLAGS $lib"
429 LAVF_LDFLAGS="-L. $LAVF_LDFLAGS"
430 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LDFLAGS" && \
431 cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LDFLAGS" ; then
432 # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351
433 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LDFLAGS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
435 echo "#define LAVF_INPUT" >> config.h
436 LDFLAGSCLI="$LDFLAGSCLI $LAVF_LDFLAGS"
437 [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
439 echo "Warning: libavformat is too old, update to ffmpeg r18351+"
444 if [ "$ffms_input" = "auto" ] ; then
446 if [ "$lavf_input" = "yes" ] ; then
447 if cc_check ffms.h -lFFMS2 "FFMS_DestroyVideoSource(0);" ; then
449 echo "#define FFMS_INPUT" >> config.h
450 LDFLAGSCLI="$LDFLAGSCLI -lFFMS2"
451 elif cc_check ffms.h "-lFFMS2 $LAVF_LDFLAGS -lstdc++" "FFMS_DestroyVideoSource(0);" ; then
453 echo "#define FFMS_INPUT" >> config.h
454 LDFLAGSCLI="-lFFMS2 $LDFLAGSCLI -lstdc++"
459 MP4_LDFLAGS="-lgpac_static"
460 if [ $SYS = MINGW ]; then
461 MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
463 if [ "$mp4_output" = "auto" ] ; then
465 cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
467 if [ "$mp4_output" = "yes" ] ; then
468 echo "#define MP4_OUTPUT" >> config.h
469 LDFLAGSCLI="$LDFLAGSCLI $MP4_LDFLAGS"
472 if [ "$avs_input" = "auto" ] ; then
474 if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then
476 echo "#define AVS_INPUT" >> config.h
477 echo "#define HAVE_AVISYNTH_C_H" >> config.h
478 elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
480 echo "#define AVS_INPUT" >> config.h
484 if [ "$pic" = "yes" ] ; then
485 CFLAGS="$CFLAGS -fPIC"
486 ASFLAGS="$ASFLAGS -DPIC"
487 # resolve textrels in the x86 asm
488 cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
491 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
492 CFLAGS="$CFLAGS -s -fomit-frame-pointer"
493 LDFLAGS="$LDFLAGS -s"
496 if [ "$debug" = "yes" ]; then
497 CFLAGS="-O1 -g $CFLAGS"
498 elif [ $ARCH = ARM ]; then
499 # arm-gcc-4.2 produces incorrect output with -ffast-math
500 # and it doesn't save any speed anyway on 4.4, so disable it
501 CFLAGS="-O4 -fno-fast-math $CFLAGS"
503 CFLAGS="-O4 -ffast-math $CFLAGS"
506 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
507 echo "#define fseek fseeko" >> config.h
508 echo "#define ftell ftello" >> config.h
509 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
510 echo "#define fseek fseeko64" >> config.h
511 echo "#define ftell ftello64" >> config.h
516 # generate config files
518 cat > config.mak << EOF
520 exec_prefix=$exec_prefix
523 includedir=$includedir
529 LDFLAGSCLI=$LDFLAGSCLI
537 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
541 if [ "$shared" = "yes" ]; then
542 API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
543 if [ "$SYS" = "MINGW" ]; then
544 echo "SONAME=libx264-$API.dll" >> config.mak
545 echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
546 echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
547 elif [ "$SYS" = "MACOSX" ]; then
548 echo "SOSUFFIX=dylib" >> config.mak
549 echo "SONAME=libx264.$API.dylib" >> config.mak
550 echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
551 elif [ "$SYS" = "SunOS" ]; then
552 echo "SOSUFFIX=so" >> config.mak
553 echo "SONAME=libx264.so.$API" >> config.mak
554 echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
556 echo "SOSUFFIX=so" >> config.mak
557 echo "SONAME=libx264.so.$API" >> config.mak
558 echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
560 echo 'default: $(SONAME)' >> config.mak
565 pclibs="-L$libdir -lx264 $libpthread"
569 exec_prefix=$exec_prefix
571 includedir=$includedir
574 Description: H.264 (MPEG4 AVC) encoder library
575 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
577 Cflags: -I$includedir
581 echo "Platform: $ARCH"
584 echo "avs input: $avs_input"
585 echo "lavf input: $lavf_input"
586 echo "ffms input: $ffms_input"
587 echo "mp4 output: $mp4_output"
588 echo "pthread: $pthread"
592 echo "shared: $shared"
593 echo "visualize: $vis"
595 echo "You can run 'make' or 'make fprofiled' now."