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