configure 12.8 KB
Newer Older
1
#!/bin/bash
2

Loren Merritt's avatar
Loren Merritt committed
3 4 5 6 7 8 9
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then

echo "Usage: ./configure [options]"
echo ""
echo "available options:"
echo ""
echo "  --help                   print this message"
10 11 12 13
echo "  --disable-avis-input     disables avisynth input (win32 only)"
echo "  --disable-mp4-output     disables mp4 output (using gpac)"
echo "  --disable-pthread        disables multithreaded encoding"
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"
Loren Merritt's avatar
Loren Merritt committed
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"
Loren Merritt's avatar
Loren Merritt committed
20 21
echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS"
echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
22
echo "  --host=HOST              build programs to run on HOST"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
23
echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools"
Loren Merritt's avatar
Loren Merritt committed
24 25 26 27
echo ""
exit 1
fi

28
cc_check() {
29 30 31
    rm -f conftest.c
    [ -n "$1" ] && echo "#include <$1>" > conftest.c
    echo "int main () { $3 return 0; }" >> conftest.c
32
    $CC conftest.c $CFLAGS $LDFLAGS $2 -o conftest 2>$DEVNULL
33 34
}

35 36 37 38 39
as_check() {
    echo "$1" > conftest.asm
    $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
}

40 41 42 43 44
die() {
    echo "$@"
    exit 1
}

45
rm -f config.h config.mak x264.pc conftest*
Loren Merritt's avatar
Loren Merritt committed
46

47
prefix='/usr/local'
Loren Merritt's avatar
Loren Merritt committed
48 49 50
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
libdir='${exec_prefix}/lib'
51
includedir='${prefix}/include'
52
DEVNULL='/dev/null'
53

54 55 56
avis_input="auto"
mp4_output="auto"
pthread="auto"
57
asm="yes"
58
debug="no"
59
gprof="no"
60
pic="no"
Loren Merritt's avatar
Loren Merritt committed
61
vis="no"
62
shared="no"
Loren Merritt's avatar
Loren Merritt committed
63

64
CFLAGS="$CFLAGS -Wall -I."
65
LDFLAGS="$LDFLAGS"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
66
ASFLAGS="$ASFLAGS"
67
HAVE_GETOPT_LONG=1
Anton Mitrofanov's avatar
Anton Mitrofanov committed
68
cross_prefix=""
69

Loren Merritt's avatar
Loren Merritt committed
70 71
EXE=""

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
# parse options

for opt do
    optarg="${opt#*=}"
    case "$opt" in
        --prefix=*)
            prefix="$optarg"
            ;;
        --exec-prefix=*)
            exec_prefix="$optarg"
            ;;
        --bindir=*)
            bindir="$optarg"
            ;;
        --libdir=*)
            libdir="$optarg"
            ;;
        --includedir=*)
            includedir="$optarg"
            ;;
92 93 94 95 96 97
        --enable-asm)
            asm="yes"
            ;;
        --disable-asm)
            asm="no"
            ;;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        --enable-avis-input)
            avis_input="yes"
            ;;
        --disable-avis-input)
            avis_input="no"
            ;;
        --enable-mp4-output)
            mp4_output="yes"
            ;;
        --disable-mp4-output)
            mp4_output="no"
            ;;
        --extra-asflags=*)
            ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
            ;;
        --extra-cflags=*)
            CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
            ;;
        --extra-ldflags=*)
            LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
            ;;
        --enable-pthread)
            pthread="auto" # can't skip detection, since it differs by OS
            ;;
        --disable-pthread)
            pthread="no"
            ;;
        --enable-debug)
            debug="yes"
            ;;
        --enable-gprof)
            CFLAGS="$CFLAGS -pg"
            LDFLAGS="$LDFLAGS -pg"
            gprof="yes"
            ;;
        --enable-pic)
            pic="yes"
            ;;
        --enable-shared)
            shared="yes"
            ;;
        --enable-visualize)
            LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
            CFLAGS="$CFLAGS -DVISUALIZE=1"
            vis="yes"
            ;;
        --host=*)
            host="${opt#--host=}"
            ;;
Anton Mitrofanov's avatar
Anton Mitrofanov committed
147 148 149
        --cross-prefix=*)
            cross_prefix="${opt#--cross-prefix=}"
            ;;
150 151 152 153 154 155
        *)
            echo "Unknown option $opt, ignored"
            ;;
    esac
done

Anton Mitrofanov's avatar
Anton Mitrofanov committed
156 157 158 159 160 161
CC="${CC-${cross_prefix}gcc}"
AR="${AR-${cross_prefix}ar}"
RANLIB="${RANLIB-${cross_prefix}ranlib}"
STRIP="${STRIP-${cross_prefix}strip}"
AS=""

162 163 164 165 166
if [ "x$host" = x ]; then
    host=`./config.guess`
fi
# normalize a triplet into a quadruplet
host=`./config.sub $host`
167

168
# split $host
Loren Merritt's avatar
Loren Merritt committed
169
host_cpu="${host%%-*}"
170
host="${host#*-}"
Loren Merritt's avatar
Loren Merritt committed
171
host_vendor="${host%%-*}"
172
host_os="${host#*-}"
173 174

case $host_os in
175
  beos*)
176 177 178
    SYS="BEOS"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    ;;
179
  darwin*)
180
    SYS="MACOSX"
181
    CFLAGS="$CFLAGS -falign-loops=16"
182
    LDFLAGS="$LDFLAGS -lm -lmx"
183 184 185
    if [ "$pic" = "no" ]; then
        CFLAGS="$CFLAGS -mdynamic-no-pic"
    fi
186
    ;;
187
  freebsd*)
188 189 190
    SYS="FREEBSD"
    LDFLAGS="$LDFLAGS -lm"
    ;;
191 192 193 194 195
  kfreebsd*-gnu)
    SYS="FREEBSD"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    LDFLAGS="$LDFLAGS -lm"
    ;;
196
  netbsd*)
197 198 199
    SYS="NETBSD"
    LDFLAGS="$LDFLAGS -lm"
    ;;
200
  openbsd*)
Loren Merritt's avatar
Loren Merritt committed
201 202 203 204
    SYS="OPENBSD"
    CFLAGS="$CFLAGS -I/usr/X11R6/include"
    LDFLAGS="$LDFLAGS -lm"
    ;;
Mike Frysinger's avatar
Mike Frysinger committed
205
  *linux*)
206 207 208 209
    SYS="LINUX"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    LDFLAGS="$LDFLAGS -lm"
    ;;
210
  cygwin*)
211
    SYS="MINGW"
Loren Merritt's avatar
Loren Merritt committed
212
    EXE=".exe"
213
    DEVNULL="NUL"
214 215 216 217
    if cc_check "" -mno-cygwin; then
        CFLAGS="$CFLAGS -mno-cygwin"
        LDFLAGS="$LDFLAGS -mno-cygwin"
    fi
Eric Petit's avatar
Eric Petit committed
218
    ;;
219
  mingw*)
220
    SYS="MINGW"
Loren Merritt's avatar
Loren Merritt committed
221
    EXE=".exe"
222
    DEVNULL="NUL"
Loren Merritt's avatar
Loren Merritt committed
223
    ;;
224
  sunos*|solaris*)
225 226 227 228 229
    SYS="SunOS"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    LDFLAGS="$LDFLAGS -lm"
    HAVE_GETOPT_LONG=0
    ;;
230
  *)
231
    die "Unknown system $host, edit the configure"
232 233 234
    ;;
esac

235
case $host_cpu in
236
  i*86)
237
    ARCH="X86"
238 239
    AS="yasm"
    ASFLAGS="$ASFLAGS -O2"
240 241 242
    if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then
      CFLAGS="$CFLAGS -march=i686"
    fi
243
    if [ "$SYS" = MACOSX ]; then
244
      ASFLAGS="$ASFLAGS -f macho -DPREFIX"
245
    elif [ "$SYS" = MINGW ]; then
246 247 248
      ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
    else
      ASFLAGS="$ASFLAGS -f elf"
249
    fi
250
    ;;
Måns Rullgård's avatar
Måns Rullgård committed
251 252
  x86_64)
    ARCH="X86_64"
253
    AS="yasm"
254
    if [ "$SYS" = MACOSX ];then
255
      ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
256 257
      CFLAGS="$CFLAGS -arch x86_64"
      LDFLAGS="$LDFLAGS -arch x86_64"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
258 259
    elif [ "$SYS" = MINGW ]; then
      ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
260
    else
Anton Mitrofanov's avatar
Anton Mitrofanov committed
261
      ASFLAGS="$ASFLAGS -f elf -m amd64"
262
    fi
Måns Rullgård's avatar
Måns Rullgård committed
263
    ;;
264
  powerpc|powerpc64)
265 266 267
    ARCH="PPC"
    if [ $SYS = MACOSX ]
    then
268
      ALTIVECFLAGS="$ALTIVECFLAGS -faltivec -fastf -mcpu=G4"
269
    else
270
      ALTIVECFLAGS="$ALTIVECFLAGS -maltivec -mabi=altivec -DHAVE_ALTIVEC_H"
271 272
    fi
    ;;
273 274 275 276 277
  sparc)
    if test "$(uname -m)" = "sun4u"; then
      ARCH="UltraSparc"
      CFLAGS="$CFLAGS -mcpu=ultrasparc"
      LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
278
      AS="${cross_prefix}as"
279
      ASFLAGS="$ASFLAGS -xarch=v8plusa"
280 281 282
    else
      ARCH="Sparc"
    fi
283
    ;;
284
  mips|mipsel|mips64|mips64el)
285 286
    ARCH="MIPS"
    ;;
287
  arm*)
288 289 290 291 292 293 294 295
    ARCH="ARM"
    ;;
  s390|s390x)
    ARCH="S390"
    ;;
  parisc|parisc64)
    ARCH="PARISC"
    ;;
296
  *)
297
    ARCH="$(echo $host_cpu | tr a-z A-Z)"
298 299 300
    ;;
esac

301 302
# check requirements

303 304
cc_check || die "No working C compiler found."

305 306 307 308
if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" \) ] ; then
    pic="yes"
fi

309
if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
310
    if ! as_check "pinsrd xmm0, [esp], 0" ; then
Fiona Glaser's avatar
Fiona Glaser committed
311
        VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
312
        echo "Found $VER"
Fiona Glaser's avatar
Fiona Glaser committed
313
        echo "Minimum version is yasm-0.6.1"
314 315
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
316
    fi
317 318 319 320 321 322 323 324 325
    if ! cc_check '' '' 'asm("pabsw %xmm0, %xmm0");' ; then
        VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
        echo "Found $VER"
        echo "Minimum version is binutils-2.17"
        echo "Your compiler can't handle inline SSSE3 asm."
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
    fi
    CFLAGS="$CFLAGS -DHAVE_MMX"
326
fi
327 328
[ $asm = no ] && AS=""
[ "x$AS" = x ] && asm="no"
329

330 331
CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"

332 333 334 335
echo "unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';" > conftest.c
$CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
grep -q BIGE conftest.o && CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"

336 337
# autodetect options that weren't forced nor disabled

338
libpthread=""
339
if test "$pthread" = "auto" ; then
340
    pthread="no"
341
    case $SYS in
342
        BEOS)
343 344
            pthread="yes"
            ;;
345
        MINGW)
346 347 348 349 350 351 352 353
            if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
                pthread="yes"
                libpthread="-lpthread"
            elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
                pthread="yes"
                libpthread="-lpthreadGC2"
            elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
                pthread="yes"
Loren Merritt's avatar
Loren Merritt committed
354
                libpthread="-lpthreadGC2 -lwsock32"
355
                CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
356 357 358 359
            elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
                pthread="yes"
                libpthread="-lpthreadGC2 -lws2_32"
                CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
360 361
            fi
            ;;
362 363 364
        OPENBSD)
            cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
            ;;
365
        *)
366
            cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
367 368 369 370
            ;;
    esac
fi
if test "$pthread" = "yes" ; then
371
    CFLAGS="$CFLAGS -DHAVE_PTHREAD"
372
    LDFLAGS="$LDFLAGS $libpthread"
373 374 375
fi

MP4_LDFLAGS="-lgpac_static"
376
if [ $SYS = MINGW ]; then
377 378 379 380 381 382 383
    MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
fi
if [ "$mp4_output" = "auto" ] ; then
    mp4_output="no"
    cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
fi
if [ "$mp4_output" = "yes" ] ; then
Loren Merritt's avatar
Loren Merritt committed
384
    echo "#define MP4_OUTPUT" >> config.h
385 386 387 388
    LDFLAGS="$LDFLAGS $MP4_LDFLAGS"
fi

if [ "$avis_input" = "auto" ] ; then
389
    if [ $SYS = MINGW ]; then
390 391 392 393 394 395
        avis_input="yes"
    else
        avis_input="no";
    fi
fi
if [ "$avis_input" = "yes" ] ; then
Anton Mitrofanov's avatar
Anton Mitrofanov committed
396 397 398 399 400 401 402 403 404
    if cc_check "stdlib.h" -lvfw32 ; then
        echo "#define AVIS_INPUT" >> config.h
        LDFLAGS="$LDFLAGS -lvfw32"
    elif cc_check "stdlib.h" -lavifil32 ; then
        echo "#define AVIS_INPUT" >> config.h
        LDFLAGS="$LDFLAGS -lavifil32"
    else
        avis_input="no";
    fi
405 406
fi

407 408
if [ "$pic" = "yes" ] ; then
    CFLAGS="$CFLAGS -fPIC"
Loren Merritt's avatar
Loren Merritt committed
409
    ASFLAGS="$ASFLAGS -DPIC"
410
    # resolve textrels in the x86 asm
411
    cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
412 413
fi

414
if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
Loren Merritt's avatar
Loren Merritt committed
415
    CFLAGS="$CFLAGS -s -fomit-frame-pointer"
416
    LDFLAGS="$LDFLAGS -s"
417 418
fi

Loren Merritt's avatar
Loren Merritt committed
419
if [ "$debug" = "yes" ]; then
420 421 422 423 424
    CFLAGS="-O1 -g $CFLAGS"
else
    CFLAGS="-O4 -ffast-math $CFLAGS"
fi

Loren Merritt's avatar
Loren Merritt committed
425 426 427 428 429 430 431 432
if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
    echo "#define fseek fseeko" >> config.h
    echo "#define ftell ftello" >> config.h
elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
    echo "#define fseek fseeko64" >> config.h
    echo "#define ftell ftello64" >> config.h
fi

433 434
rm -f conftest*

435 436
# generate config files

437
cat > config.mak << EOF
438
prefix=$prefix
Loren Merritt's avatar
Loren Merritt committed
439
exec_prefix=$exec_prefix
440 441 442
bindir=$bindir
libdir=$libdir
includedir=$includedir
443 444 445 446
ARCH=$ARCH
SYS=$SYS
CC=$CC
CFLAGS=$CFLAGS
447
ALTIVECFLAGS=$ALTIVECFLAGS
448
LDFLAGS=$LDFLAGS
Anton Mitrofanov's avatar
Anton Mitrofanov committed
449 450 451
AR=$AR
RANLIB=$RANLIB
STRIP=$STRIP
452 453
AS=$AS
ASFLAGS=$ASFLAGS
Loren Merritt's avatar
Loren Merritt committed
454
EXE=$EXE
Loren Merritt's avatar
Loren Merritt committed
455
VIS=$vis
456
HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
457
DEVNULL=$DEVNULL
458 459
EOF

460
if [ "$shared" = "yes" ]; then
461
    API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
Zuxy Meng's avatar
Zuxy Meng committed
462 463 464 465
    if [ "$SYS" = "MINGW" ]; then
        echo "SONAME=libx264-$API.dll" >> config.mak
        echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
        echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
466
    elif [ "$SYS" = "MACOSX" ]; then
467
        echo "SOSUFFIX=dylib" >> config.mak
468
        echo "SONAME=libx264.$API.dylib" >> config.mak
469
        echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
470 471 472 473
    elif [ "$SYS" = "SunOS" ]; then
        echo "SOSUFFIX=so" >> config.mak
        echo "SONAME=libx264.so.$API" >> config.mak
        echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
474
    else
475
        echo "SOSUFFIX=so" >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
476
        echo "SONAME=libx264.so.$API" >> config.mak
Loren Merritt's avatar
Loren Merritt committed
477
        echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
478
    fi
479 480 481
    echo 'default: $(SONAME)' >> config.mak
fi

482 483
./version.sh

484
pclibs="-L$libdir -lx264 $libpthread"
485

Loren Merritt's avatar
Loren Merritt committed
486 487 488 489 490 491 492 493
cat > x264.pc << EOF
prefix=$prefix
exec_prefix=$exec_prefix
libdir=$libdir
includedir=$includedir

Name: x264
Description: H.264 (MPEG4 AVC) encoder library
494
Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
495
Libs: $pclibs
Loren Merritt's avatar
Loren Merritt committed
496 497 498 499
Cflags: -I$includedir
EOF


Loren Merritt's avatar
Loren Merritt committed
500 501
echo "Platform:   $ARCH"
echo "System:     $SYS"
502
echo "asm:        $asm"
Loren Merritt's avatar
Loren Merritt committed
503 504
echo "avis input: $avis_input"
echo "mp4 output: $mp4_output"
Loren Merritt's avatar
Loren Merritt committed
505
echo "pthread:    $pthread"
506
echo "debug:      $debug"
507
echo "gprof:      $gprof"
508
echo "PIC:        $pic"
509
echo "shared:     $shared"
Loren Merritt's avatar
Loren Merritt committed
510
echo "visualize:  $vis"
511
echo
512
echo "You can run 'make' or 'make fprofiled' now."
513