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