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