configure 10.7 KB
Newer Older
1 2
#! /bin/sh

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
echo "  --enable-avis-input      enables avisynth input (win32 only)"
Loren Merritt's avatar
Loren Merritt committed
11
echo "  --enable-mp4-output      enables mp4 output (using gpac)"
12
echo "  --enable-gtk             build GTK+ interface"
Loren Merritt's avatar
Loren Merritt committed
13
echo "  --enable-pthread         enables multithreaded encoding"
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 22 23 24 25
echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS"
echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
echo ""
exit 1
fi

26 27 28 29
cc_check() {
    rm -f conftest*
    cat > conftest.c << EOF
#include <$1>
Loren Merritt's avatar
Loren Merritt committed
30
int main () { $3 return 0; }
31
EOF
32
    $CC conftest.c $CFLAGS $LDFLAGS $2 -o conftest 2>$DEVNULL
33
    TMP="$?"
34
    rm -f conftest*
35 36 37
    return $TMP
}

38 39 40 41 42 43 44 45 46
as_check() {
    rm -f conftest*
    echo "$1" > conftest.asm
    $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
    TMP="$?"
    rm -f conftest*
    return $TMP
}

Loren Merritt's avatar
Loren Merritt committed
47 48
rm -f config.h config.mak x264.pc

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

56 57 58
avis_input="auto"
mp4_output="auto"
pthread="auto"
59
debug="no"
60
gprof="no"
61
pic="no"
62
gtk="no"
Loren Merritt's avatar
Loren Merritt committed
63
vis="no"
64
shared="no"
Loren Merritt's avatar
Loren Merritt committed
65

66
CC="${CC-gcc}"
67
CFLAGS="$CFLAGS -Wall -I."
68
LDFLAGS="$LDFLAGS"
69
HAVE_GETOPT_LONG=1
70

Loren Merritt's avatar
Loren Merritt committed
71
AS="yasm"
72
ASFLAGS=""
73

Loren Merritt's avatar
Loren Merritt committed
74 75
EXE=""

76 77 78 79 80 81 82 83 84 85 86 87
# check whether 'echo -n' works as expected, otherwise try printf
if [ "x`echo -n houba`" = xhouba ]
then
  ECHON="echo -n"
elif [ "x`printf houba`" = xhouba ]
then
  ECHON="printf"
else
  echo "Neither 'echo -n' nor 'printf' are working with your shell!"
  exit 1
fi

88 89 90 91
MACHINE="$(./config.guess)"

case "${MACHINE#*-*-}" in
  beos*)
92 93 94
    SYS="BEOS"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    ;;
95
  darwin*)
96
    SYS="MACOSX"
97
    CFLAGS="$CFLAGS -falign-loops=16"
98 99
    LDFLAGS="$LDFLAGS -lm -lmx"
    ;;
100
  freebsd*)
101 102 103
    SYS="FREEBSD"
    LDFLAGS="$LDFLAGS -lm"
    ;;
104 105 106 107 108
  kfreebsd*-gnu)
    SYS="FREEBSD"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    LDFLAGS="$LDFLAGS -lm"
    ;;
109
  netbsd*)
110 111 112
    SYS="NETBSD"
    LDFLAGS="$LDFLAGS -lm"
    ;;
113
  openbsd*)
Loren Merritt's avatar
Loren Merritt committed
114 115 116 117
    SYS="OPENBSD"
    CFLAGS="$CFLAGS -I/usr/X11R6/include"
    LDFLAGS="$LDFLAGS -lm"
    ;;
118
  linux*)
119 120 121 122
    SYS="LINUX"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    LDFLAGS="$LDFLAGS -lm"
    ;;
123
  cygwin*)
Eric Petit's avatar
Eric Petit committed
124 125 126
    SYS="CYGWIN"
    CFLAGS="$CFLAGS -mno-cygwin"
    LDFLAGS="$LDFLAGS -mno-cygwin"
Loren Merritt's avatar
Loren Merritt committed
127
    EXE=".exe"
128
    DEVNULL="NUL"
Eric Petit's avatar
Eric Petit committed
129
    ;;
130
  mingw*)
131
    SYS="MINGW"
Loren Merritt's avatar
Loren Merritt committed
132
    EXE=".exe"
133
    DEVNULL="NUL"
Loren Merritt's avatar
Loren Merritt committed
134
    ;;
135
  sunos*|solaris*)
136 137 138 139 140
    SYS="SunOS"
    CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
    LDFLAGS="$LDFLAGS -lm"
    HAVE_GETOPT_LONG=0
    ;;
141
  *)
142
    echo "Unknown system $MACHINE, edit the configure"
143 144 145 146
    exit 1
    ;;
esac

147 148
case "${MACHINE%%-*}" in
  i*86)
149
    ARCH="X86"
Loren Merritt's avatar
Loren Merritt committed
150
    AS="yasm"
151
    ASFLAGS="-O2"
152
    if [ "$SYS" = MACOSX ]; then
153 154 155
      ASFLAGS="$ASFLAGS -f macho -DPREFIX"
    elif [ "$SYS" = CYGWIN -o "$SYS" = MINGW ]; then
      ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
Måns Rullgård's avatar
Måns Rullgård committed
156
    elif [ "$SYS" = NETBSD ]; then
157 158 159
      ASFLAGS="$ASFLAGS -f aoutb"
    else
      ASFLAGS="$ASFLAGS -f elf"
160
    fi
Loren Merritt's avatar
Loren Merritt committed
161
    as_check || AS="nasm"
162
    ;;
Måns Rullgård's avatar
Måns Rullgård committed
163 164
  x86_64)
    ARCH="X86_64"
Loren Merritt's avatar
Loren Merritt committed
165 166
    AS="yasm"
    ASFLAGS="-f elf -m amd64"
Måns Rullgård's avatar
Måns Rullgård committed
167
    ;;
168
  powerpc|powerpc64)
169 170 171
    ARCH="PPC"
    if [ $SYS = MACOSX ]
    then
172
      ALTIVECFLAGS="$ALTIVECFLAGS -faltivec -fastf -mcpu=G4"
173
    else
174
      ALTIVECFLAGS="$ALTIVECFLAGS -maltivec -mabi=altivec"
175 176
    fi
    ;;
177 178 179 180 181 182 183 184 185 186
  sparc)
    if test "$(uname -m)" = "sun4u"; then
      ARCH="UltraSparc"
      CFLAGS="$CFLAGS -mcpu=ultrasparc"
      LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
      AS="as"
      ASFLAGS="-xarch=v8plusa"
    else
      ARCH="Sparc"
    fi
187
    ;;
188
  mips|mipsel|mips64|mips64el)
189 190
    ARCH="MIPS"
    ;;
191
  arm*)
192 193 194 195 196 197 198 199
    ARCH="ARM"
    ;;
  s390|s390x)
    ARCH="S390"
    ;;
  parisc|parisc64)
    ARCH="PARISC"
    ;;
200
  *)
201
    ARCH="$(echo ${MACHINE%%-*} | tr a-z A-Z)"
202 203 204
    ;;
esac

205 206 207 208 209 210 211 212 213 214 215
# check requirements

if [ $SYS = MACOSX -a $ARCH = X86 ]
then
  # we want Apple's nasm from Xcode 2.4.1 or later
  NASM_BUILD_REQUIRED=11
  NASM_BUILD=`nasm -v|grep "Apple Computer"|sed 's/.*build \([0-9]*\).*/\1/'`
  if [ $NASM_BUILD -lt $NASM_BUILD_REQUIRED ]
  then
    echo "Your version of 'nasm' is too old."
    echo "Please install Xcode 2.4.1 or later."
216
    AS=""
217 218 219
  fi
fi

Loren Merritt's avatar
Loren Merritt committed
220
if [ $ARCH = X86 -o $ARCH = X86_64 ] ; then
221 222
    if as_check ; then
        CFLAGS="$CFLAGS -DHAVE_MMX"
223 224 225 226 227
    fi
    if as_check "pabsw xmm0, xmm0" ; then
        ASFLAGS="$ASFLAGS -DHAVE_SSE3"
        CFLAGS="$CFLAGS -DHAVE_SSE3"
    fi
228 229 230 231 232
    if ! as_check ; then
        echo "No suitable assembler found.  x264 will be several times slower."
        echo "Please install 'yasm' to get MMX/SSE optimized code."
        AS=""
    fi
233 234
fi

235 236
CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"

Loren Merritt's avatar
Loren Merritt committed
237 238 239
# parse options

for opt do
240
    optarg="${opt#*=}"
Loren Merritt's avatar
Loren Merritt committed
241
    case "$opt" in
242 243 244 245
        --prefix=*)
            prefix="$optarg"
            ;;
        --exec-prefix=*)
Loren Merritt's avatar
Loren Merritt committed
246
            exec_prefix="$optarg"
247 248 249 250 251 252 253 254 255 256
            ;;
        --bindir=*)
            bindir="$optarg"
            ;;
        --libdir=*)
            libdir="$optarg"
            ;;
        --includedir=*)
            includedir="$optarg"
            ;;
Loren Merritt's avatar
Loren Merritt committed
257
        --enable-avis-input)
258 259 260 261
            avis_input="yes"
            ;;
        --disable-avis-input)
            avis_input="no"
Loren Merritt's avatar
Loren Merritt committed
262 263
            ;;
        --enable-mp4-output)
264
            mp4_output="yes"
Loren Merritt's avatar
Loren Merritt committed
265
            ;;
266 267 268
        --disable-mp4-output)
            mp4_output="no"
            ;;
269 270 271
        --extra-asflags=*)
            ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
            ;;
Loren Merritt's avatar
Loren Merritt committed
272 273
        --extra-cflags=*)
            CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
Loren Merritt's avatar
Loren Merritt committed
274
            ;;
Loren Merritt's avatar
Loren Merritt committed
275 276
        --extra-ldflags=*)
            LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
Loren Merritt's avatar
Loren Merritt committed
277
            ;;
Loren Merritt's avatar
Loren Merritt committed
278
        --enable-pthread)
279
            pthread="auto" # can't skip detection, since it differs by OS
280 281 282
            ;;
        --disable-pthread)
            pthread="no"
Loren Merritt's avatar
Loren Merritt committed
283
            ;;
284 285 286
        --enable-debug)
            debug="yes"
            ;;
287 288 289 290 291
        --enable-gprof)
            CFLAGS="$CFLAGS -pg"
            LDFLAGS="$LDFLAGS -pg"
            gprof="yes"
            ;;
292 293 294
        --enable-pic)
            pic="yes"
            ;;
295 296 297 298 299 300
        --enable-gtk)
            gtk="yes"
            ;;
        --disable-gtk)
            gtk="no"
            ;;
301 302 303 304 305 306
        --enable-shared)
            shared="yes"
            if [ $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" ] ; then
                pic="yes"
            fi
            ;;
Loren Merritt's avatar
Loren Merritt committed
307 308 309 310 311
        --enable-visualize)
            LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
            CFLAGS="$CFLAGS -DVISUALIZE=1"
            vis="yes"
            ;;
Loren Merritt's avatar
Loren Merritt committed
312 313 314 315 316 317
        *)
            echo "Unknown option $opt, ignored"
            ;;
    esac
done

318 319
# autodetect options that weren't forced nor disabled

320
libpthread=""
321
if test "$pthread" = "auto" ; then
322
    pthread="no"
323
    case $SYS in
324
        BEOS)
325 326
            pthread="yes"
            ;;
327 328 329 330 331 332 333 334 335 336 337 338 339
        MINGW|CYGWIN)
            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"
                libpthread="-lpthreadGC2 -lwsock32"\
                CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
            fi
            ;;
340
        *)
341
            cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
342 343 344 345
            ;;
    esac
fi
if test "$pthread" = "yes" ; then
346
    CFLAGS="$CFLAGS -DHAVE_PTHREAD"
347
    LDFLAGS="$LDFLAGS $libpthread"
348 349 350 351 352 353 354 355 356 357 358
fi

MP4_LDFLAGS="-lgpac_static"
if [ $SYS = CYGWIN -o $SYS = MINGW ]; then
    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
359
    echo "#define MP4_OUTPUT" >> config.h
360 361 362 363 364 365 366 367 368 369 370
    LDFLAGS="$LDFLAGS $MP4_LDFLAGS"
fi

if [ "$avis_input" = "auto" ] ; then
    if [ $SYS = CYGWIN -o $SYS = MINGW ]; then
        avis_input="yes"
    else
        avis_input="no";
    fi
fi
if [ "$avis_input" = "yes" ] ; then
Loren Merritt's avatar
Loren Merritt committed
371
    echo "#define AVIS_INPUT" >> config.h
372 373 374
    LDFLAGS="$LDFLAGS -lvfw32"
fi

375 376 377 378 379
if [ "$pic" = "yes" ] ; then
    CFLAGS="$CFLAGS -fPIC"
    ASFLAGS="$ASFLAGS -D__PIC__"
fi

380
if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
Loren Merritt's avatar
Loren Merritt committed
381
    CFLAGS="$CFLAGS -s -fomit-frame-pointer"
382
    LDFLAGS="$LDFLAGS -s"
383 384
fi

Loren Merritt's avatar
Loren Merritt committed
385
if [ "$debug" = "yes" ]; then
386 387 388 389 390
    CFLAGS="-O1 -g $CFLAGS"
else
    CFLAGS="-O4 -ffast-math $CFLAGS"
fi

Loren Merritt's avatar
Loren Merritt committed
391 392 393 394 395 396 397 398
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

399 400
# generate config files

401
cat > config.mak << EOF
402
prefix=$prefix
Loren Merritt's avatar
Loren Merritt committed
403
exec_prefix=$exec_prefix
404 405 406
bindir=$bindir
libdir=$libdir
includedir=$includedir
407 408 409 410
ARCH=$ARCH
SYS=$SYS
CC=$CC
CFLAGS=$CFLAGS
411
ALTIVECFLAGS=$ALTIVECFLAGS
412 413 414
LDFLAGS=$LDFLAGS
AS=$AS
ASFLAGS=$ASFLAGS
415
GTK=$gtk
Loren Merritt's avatar
Loren Merritt committed
416
EXE=$EXE
Loren Merritt's avatar
Loren Merritt committed
417
VIS=$vis
418
HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
419
DEVNULL=$DEVNULL
420
ECHON=$ECHON
421 422
EOF

423
$ECHON 'CONFIGURE_ARGS=' >> config.mak
424
for A in "$@" ; do
425
    $ECHON " '$A'" >> config.mak
426 427 428
done
echo '' >> config.mak

Loren Merritt's avatar
Loren Merritt committed
429 430
cp config.mak gtk/config.mak

431
if [ "$shared" = "yes" ]; then
432
    API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
433 434
    echo "SONAME=libx264.so.$API" >> config.mak
    echo 'default: $(SONAME)' >> config.mak
435 436 437 438 439 440 441 442
    if [ "$gtk" = "yes" ]; then
        echo "SONAMEGTK=libx264gtk.so.$API" >> gtk/config.mak
    fi
fi

if [ "$gtk" = "yes" ]; then
    echo 'default: libx264gtk.a' >> config.mak
    echo 'install: install-gtk' >> config.mak
443 444
fi

445 446
./version.sh

447
pclibs="-L$libdir -lx264 $libpthread"
448

Loren Merritt's avatar
Loren Merritt committed
449 450 451 452 453 454 455 456
cat > x264.pc << EOF
prefix=$prefix
exec_prefix=$exec_prefix
libdir=$libdir
includedir=$includedir

Name: x264
Description: H.264 (MPEG4 AVC) encoder library
457
Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
458
Libs: $pclibs
Loren Merritt's avatar
Loren Merritt committed
459 460 461 462
Cflags: -I$includedir
EOF


Loren Merritt's avatar
Loren Merritt committed
463 464 465 466
echo "Platform:   $ARCH"
echo "System:     $SYS"
echo "avis input: $avis_input"
echo "mp4 output: $mp4_output"
Loren Merritt's avatar
Loren Merritt committed
467
echo "pthread:    $pthread"
468
echo "gtk:        $gtk"
469
echo "debug:      $debug"
470
echo "gprof:      $gprof"
471
echo "PIC:        $pic"
472
echo "shared:     $shared"
Loren Merritt's avatar
Loren Merritt committed
473
echo "visualize:  $vis"
474
echo
475
echo "You can run 'make' or 'make fprofiled' now."
476