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