]> git.sesse.net Git - x264/blob - configure
01f6cb144d1e855a94e90ac471d8d7cd08629572
[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-vfw             compiles the VfW frontend"
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 $CFLAGS $LDFLAGS $2 conftest.c -o conftest 2>$DEVNULL
33     TMP="$?"
34     rm -f conftest.c conftest*
35     return $TMP
36 }
37
38 rm -f config.h config.mak x264.pc
39
40 prefix='/usr/local'
41 exec_prefix='${prefix}'
42 bindir='${exec_prefix}/bin'
43 libdir='${exec_prefix}/lib'
44 includedir='${prefix}/include'
45 DEVNULL='/dev/null'
46
47 avis_input="auto"
48 mp4_output="auto"
49 pthread="auto"
50 debug="no"
51 gprof="no"
52 pic="no"
53 vfw="no"
54 vis="no"
55 shared="no"
56
57 CC="${CC-gcc}"
58 CFLAGS="-Wall -I. -O4 -ffast-math -D__X264__"
59 LDFLAGS=""
60 HAVE_GETOPT_LONG=1
61
62 AS="nasm"
63 ASFLAGS=""
64
65 EXE=""
66
67 UNAMES="`uname -s`"
68 case "$UNAMES" in
69   BeOS)
70     SYS="BEOS"
71     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
72     ;;
73   Darwin)
74     SYS="MACOSX"
75     CFLAGS="$CFLAGS -falign-loops=16"
76     LDFLAGS="$LDFLAGS -lm -lmx"
77     ;;
78   FreeBSD)
79     SYS="FREEBSD"
80     LDFLAGS="$LDFLAGS -lm"
81     ;;
82   NetBSD)
83     SYS="NETBSD"
84     LDFLAGS="$LDFLAGS -lm"
85     ;;
86   OpenBSD)
87     SYS="OPENBSD"
88     CFLAGS="$CFLAGS -I/usr/X11R6/include"
89     LDFLAGS="$LDFLAGS -lm"
90     ;;
91   Linux)
92     SYS="LINUX"
93     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
94     LDFLAGS="$LDFLAGS -lm"
95     ;;
96   CYGWIN*)
97     SYS="CYGWIN"
98     CFLAGS="$CFLAGS -mno-cygwin"
99     LDFLAGS="$LDFLAGS -mno-cygwin"
100     EXE=".exe"
101     DEVNULL="NUL"
102     ;;
103   MINGW*)
104     SYS="MINGW"
105     EXE=".exe"
106     DEVNULL="NUL"
107     ;;
108   SunOS)
109     SYS="SunOS"
110     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
111     LDFLAGS="$LDFLAGS -lm"
112     HAVE_GETOPT_LONG=0
113     ;;
114   *)
115     echo "Unknown system $UNAMES, edit the configure"
116     exit 1
117     ;;
118 esac
119
120 UNAMEM="`uname -m`"
121 case "$UNAMEM" in
122   i386|i486|i586|i686|BePC)
123     ARCH="X86"
124     CFLAGS="$CFLAGS -DHAVE_MMXEXT -DHAVE_SSE2"
125     AS="nasm"
126     ASFLAGS="-O2"
127     if [ "$SYS" = MACOSX ]; then
128       ASFLAGS="$ASFLAGS -f macho -DPREFIX"
129     elif [ "$SYS" = CYGWIN -o "$SYS" = MINGW ]; then
130       ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
131     elif [ "$SYS" = NETBSD ]; then
132       ASFLAGS="$ASFLAGS -f aoutb"
133     else
134       ASFLAGS="$ASFLAGS -f elf"
135     fi
136     ;;
137   x86_64)
138     ARCH="X86_64"
139     CFLAGS="$CFLAGS -DHAVE_MMXEXT -DHAVE_SSE2"
140     AS="yasm"
141     ASFLAGS="-f elf -m amd64"
142     ;;
143   "Power Macintosh"|ppc|ppc64)
144     ARCH="PPC"
145     if [ $SYS = MACOSX ]
146     then
147       CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
148     else
149       CFLAGS="$CFLAGS -maltivec -mabi=altivec"
150     fi
151     ;;
152   sun4m|sun4d|sparc|sparc64)
153     ARCH="Sparc"
154     ;;
155   sun4u)
156     ARCH="UltraSparc"
157     CFLAGS="$CFLAGS -mcpu=ultrasparc"
158     LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
159     AS="as"
160     ASFLAGS="-xarch=v8plusa"
161     ;;
162   ia64)
163     ARCH="IA64"
164     ;;
165   alpha)
166     ARCH="ALPHA"
167     ;;
168   mips|mipsel|mips64)
169     ARCH="MIPS"
170     ;;
171   m68k)
172     ARCH="M68K"
173     ;;
174   arm|armv5tel|armv4l)
175     ARCH="ARM"
176     ;;
177   s390|s390x)
178     ARCH="S390"
179     ;;
180   parisc|parisc64)
181     ARCH="PARISC"
182     ;;
183   *)
184     echo "Unknown platform $UNAMEM, edit the configure"
185     exit 1
186     ;;
187 esac
188
189 CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"
190
191 # parse options
192
193 for opt do
194     optarg="${opt#*=}"
195     case "$opt" in
196         --prefix=*)
197             prefix="$optarg"
198             ;;
199         --exec-prefix=*)
200             exec_prefix="$optarg"
201             ;;
202         --bindir=*)
203             bindir="$optarg"
204             ;;
205         --libdir=*)
206             libdir="$optarg"
207             ;;
208         --includedir=*)
209             includedir="$optarg"
210             ;;
211         --enable-avis-input)
212             avis_input="yes"
213             ;;
214         --disable-avis-input)
215             avis_input="no"
216             ;;
217         --enable-mp4-output)
218             mp4_output="yes"
219             ;;
220         --disable-mp4-output)
221             mp4_output="no"
222             ;;
223         --extra-asflags=*)
224             ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
225             ;;
226         --extra-cflags=*)
227             CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
228             VFW_CFLAGS="${opt#--extra-cflags=}"
229             ;;
230         --extra-ldflags=*)
231             LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
232             VFW_LDFLAGS="${opt#--extra-ldflags=}"
233             ;;
234         --enable-pthread)
235             pthread="yes"
236             ;;
237         --disable-pthread)
238             pthread="no"
239             ;;
240         --enable-debug)
241             CFLAGS="$CFLAGS -g"
242             debug="yes"
243             ;;
244         --enable-gprof)
245             CFLAGS="$CFLAGS -pg"
246             LDFLAGS="$LDFLAGS -pg"
247             gprof="yes"
248             ;;
249         --enable-pic)
250             pic="yes"
251             ;;
252         --enable-vfw)
253             vfw="yes"
254             ;;
255         --disable-vfw)
256             vfw="no"
257             ;;
258         --enable-shared)
259             shared="yes"
260             if [ $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" ] ; then
261                 pic="yes"
262             fi
263             ;;
264         --enable-visualize)
265             LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
266             CFLAGS="$CFLAGS -DVISUALIZE=1"
267             vis="yes"
268             ;;
269         *)
270             echo "Unknown option $opt, ignored"
271             ;;
272     esac
273 done
274
275 # autodetect options that weren't forced nor disabled
276
277 if test "$pthread" = "auto" ; then
278     case $SYS in
279         MINGW|CYGWIN|BEOS)
280             pthread="yes"
281             ;;
282         *)
283             pthread="no"
284             cc_check pthread.h -lpthread && pthread="yes"
285             ;;
286     esac
287 fi
288 if test "$pthread" = "yes" ; then
289     CFLAGS="$CFLAGS -DHAVE_PTHREAD"
290     case $SYS in
291         MINGW|CYGWIN|BEOS)
292             ;;
293         *) LDFLAGS="$LDFLAGS -lpthread"
294             ;;
295     esac
296 fi
297
298 MP4_LDFLAGS="-lgpac_static"
299 if [ $SYS = CYGWIN -o $SYS = MINGW ]; then
300     MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
301 fi
302 if [ "$mp4_output" = "auto" ] ; then
303     mp4_output="no"
304     cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
305 fi
306 if [ "$mp4_output" = "yes" ] ; then
307     echo "#define MP4_OUTPUT" >> config.h
308     LDFLAGS="$LDFLAGS $MP4_LDFLAGS"
309 fi
310
311 if [ "$avis_input" = "auto" ] ; then
312     if [ $SYS = CYGWIN -o $SYS = MINGW ]; then
313         avis_input="yes"
314     else
315         avis_input="no";
316     fi
317 fi
318 if [ "$avis_input" = "yes" ] ; then
319     echo "#define AVIS_INPUT" >> config.h
320     LDFLAGS="$LDFLAGS -lvfw32"
321 fi
322
323 if [ "$pic" = "yes" ] ; then
324     CFLAGS="$CFLAGS -fPIC"
325     ASFLAGS="$ASFLAGS -D__PIC__"
326 fi
327
328 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
329     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
330     LDFLAGS="$LDFLAGS -s"
331     VFW_LDFLAGS="$VFW_LDFLAGS -s"
332 fi
333
334 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
335     echo "#define fseek fseeko" >> config.h
336     echo "#define ftell ftello" >> config.h
337 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
338     echo "#define fseek fseeko64" >> config.h
339     echo "#define ftell ftello64" >> config.h
340 fi
341
342 # generate config files
343
344 cat > config.mak << EOF
345 prefix=$prefix
346 exec_prefix=$exec_prefix
347 bindir=$bindir
348 libdir=$libdir
349 includedir=$includedir
350 ARCH=$ARCH
351 SYS=$SYS
352 CC=$CC
353 CFLAGS=$CFLAGS
354 LDFLAGS=$LDFLAGS
355 AS=$AS
356 ASFLAGS=$ASFLAGS
357 VFW=$vfw
358 EXE=$EXE
359 VIS=$vis
360 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
361 DEVNULL=$DEVNULL
362 EOF
363
364 echo -n 'CONFIGURE_ARGS=' >> config.mak
365 for A in "$@" ; do
366     echo -n " '$A'" >> config.mak
367 done
368 echo '' >> config.mak
369
370 cp config.mak gtk/config.mak
371
372 if [ "$vfw" = "yes" ]; then
373     rm -f vfw/build/cygwin/config.mak
374     cat > vfw/build/cygwin/config.mak << EOF
375 CFLAGS=$VFW_CFLAGS
376 LDFLAGS=$VFW_LDFLAGS
377 EOF
378     echo "default: x264vfw.dll" >> config.mak
379 fi
380
381 if [ "$shared" = "yes" ]; then
382     API=`grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' '`
383     echo "SONAME=libx264.so.$API" >> config.mak
384     echo 'default: $(SONAME)' >> config.mak
385 fi
386
387 ./version.sh
388
389 pclibs="-L$libdir -lx264"
390 if test "$pthread" = "yes" ; then
391   case $SYS in
392     MINGW|CYGWIN|BEOS)
393       ;;
394     *) pclibs="$pclibs -lpthread"
395       ;;
396   esac
397 fi
398
399 cat > x264.pc << EOF
400 prefix=$prefix
401 exec_prefix=$exec_prefix
402 libdir=$libdir
403 includedir=$includedir
404
405 Name: x264
406 Description: H.264 (MPEG4 AVC) encoder library
407 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
408 Libs: $pclibs
409 Cflags: -I$includedir
410 EOF
411
412
413 echo "Platform:   $ARCH"
414 echo "System:     $SYS"
415 echo "avis input: $avis_input"
416 echo "mp4 output: $mp4_output"
417 echo "pthread:    $pthread"
418 echo "vfw:        $vfw"
419 echo "debug:      $debug"
420 echo "gprof:      $gprof"
421 echo "PIC:        $pic"
422 echo "shared:     $shared"
423 echo "visualize:  $vis"
424 echo
425 echo "You can run 'make' or 'make fprofiled' now."
426