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