58e7df943e6ba61cb191c80cdaa7e51bbf433d12
[x262.git] / 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-visualize       enables visualization (X11 only)"
16 echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS"
17 echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
18 echo ""
19 exit 1
20 fi
21
22 prefix='/usr/local'
23 eprefix='${prefix}'
24 bindir='${eprefix}/bin'
25 libdir='${eprefix}/lib'
26 includedir='${prefix}/include'
27
28 avis_input="no"
29 mp4_output="no"
30 pthread="no"
31 debug="no"
32 vfw="no"
33 vis="no"
34
35 CC="gcc"
36 CFLAGS="-Wall -I. -O4 -ffast-math -D__X264__"
37 LDFLAGS=""
38 HAVE_GETOPT_LONG=1
39
40 AS="nasm"
41 ASFLAGS="-f elf"
42
43 EXE=""
44
45 UNAMES="`uname -s`"
46 case "$UNAMES" in
47   BeOS)
48     SYS="BEOS"
49     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
50     ;;
51   Darwin)
52     SYS="MACOSX"
53     CFLAGS="$CFLAGS -falign-loops=16"
54     LDFLAGS="$LDFLAGS -lm -lmx"
55     ;;
56   FreeBSD)
57     SYS="FREEBSD"
58     LDFLAGS="$LDFLAGS -lm"
59     ;;
60   Linux)
61     SYS="LINUX"
62     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
63     LDFLAGS="$LDFLAGS -lm"
64     ;;
65   CYGWIN*)
66     SYS="CYGWIN"
67     CFLAGS="$CFLAGS -mno-cygwin"
68     LDFLAGS="$LDFLAGS -mno-cygwin"
69     ASFLAGS="-f win32 -DPREFIX"
70     EXE=".exe"
71     ;;
72   MINGW*)
73     SYS="MINGW"
74     ASFLAGS="-f win32 -DPREFIX"
75     EXE=".exe"
76     ;;
77   SunOS)
78     SYS="SunOS"
79     CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
80     LDFLAGS="$LDFLAGS -lm"
81     HAVE_GETOPT_LONG=0
82     ;;
83   *)
84     echo "Unknown system $UNAMES, edit the configure"
85     exit 1
86     ;;
87 esac
88
89 UNAMEM="`uname -m`"
90 case "$UNAMEM" in
91   i386|i486|i586|i686|BePC)
92     ARCH="X86"
93     CFLAGS="$CFLAGS -DHAVE_MMXEXT -DHAVE_SSE2"
94     ;;
95   x86_64)
96     ARCH="X86_64"
97     CFLAGS="$CFLAGS -DHAVE_MMXEXT -DHAVE_SSE2"
98     AS="yasm"
99     ASFLAGS="-f elf -m amd64"
100     ;;
101   "Power Macintosh"|ppc)
102     ARCH="PPC"
103     if [ $SYS = MACOSX ]
104     then
105       CFLAGS="$CFLAGS -faltivec"
106     else
107       CFLAGS="$CFLAGS -maltivec -mabi=altivec"
108     fi
109     ;;
110   sun4m|sun4d)
111     ARCH="Sparc"
112     ;;
113   sun4u)
114     ARCH="UltraSparc"
115     CFLAGS="$CFLAGS -mcpu=ultrasparc"
116     LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
117     AS="as"
118     ASFLAGS="-xarch=v8plusa"
119     ;;
120   *)
121     echo "Unknown platform $UNAMEM, edit the configure"
122     exit 1
123     ;;
124 esac
125
126 CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"
127
128 # parse options
129
130 for opt do
131     optarg="${opt#*=}"
132     case "$opt" in
133         --prefix=*)
134             prefix="$optarg"
135             ;;
136         --exec-prefix=*)
137             eprefix="$optarg"
138             ;;
139         --bindir=*)
140             bindir="$optarg"
141             ;;
142         --libdir=*)
143             libdir="$optarg"
144             ;;
145         --includedir=*)
146             includedir="$optarg"
147             ;;
148         --enable-avis-input)
149             if [ $SYS = CYGWIN -o $SYS = MINGW ]; then
150                 CFLAGS="$CFLAGS -DAVIS_INPUT"
151                 LDFLAGS="$LDFLAGS -lvfw32"
152                 avis_input="yes"
153             fi
154             ;;
155         --enable-mp4-output)
156             CFLAGS="$CFLAGS -DMP4_OUTPUT"
157             LDFLAGS="$LDFLAGS -lm4systems_static"
158             if [ $SYS = CYGWIN -o $SYS = MINGW ]; then
159                 LDFLAGS="$LDFLAGS -lwinmm"
160             fi
161             mp4_output="yes"
162             ;;
163         --extra-cflags=*)
164             CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
165             VFW_CFLAGS="${opt#--extra-cflags=}"
166             ;;
167         --extra-ldflags=*)
168             LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
169             VFW_LDFLAGS="${opt#--extra-ldflags=}"
170             ;;
171         --enable-pthread)
172             CFLAGS="$CFLAGS -DHAVE_PTHREAD=1"
173             pthread="yes"
174             case $SYS in
175               MINGW|CYGWIN|BEOS)
176                 ;;
177               *)
178                 LDFLAGS="$LDFLAGS -lpthread"
179                 ;;
180             esac
181             ;;
182         --enable-debug)
183             CFLAGS="$CFLAGS -g"
184             debug="yes"
185             ;;
186         --enable-vfw)
187             vfw="yes"
188             ;;
189         --enable-visualize)
190             LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
191             CFLAGS="$CFLAGS -DVISUALIZE=1"
192             vis="yes"
193             ;;
194         *)
195             echo "Unknown option $opt, ignored"
196             ;;
197     esac
198 done
199
200 VFWFLAGS=
201 if [ "$debug" != "yes" ]; then
202     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
203     LDFLAGS="$LDFLAGS -s"
204     VFW_LDFLAGS="$VFW_LDFLAGS -s"
205 fi
206
207 rm -f config.mak
208 cat > config.mak << EOF
209 prefix=$prefix
210 eprefix=$eprefix
211 bindir=$bindir
212 libdir=$libdir
213 includedir=$includedir
214 ARCH=$ARCH
215 SYS=$SYS
216 CC=$CC
217 CFLAGS=$CFLAGS
218 LDFLAGS=$LDFLAGS
219 AS=$AS
220 ASFLAGS=$ASFLAGS
221 VFW=$vfw
222 EXE=$EXE
223 VIS=$vis
224 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
225 EOF
226
227 if [ "$vfw" = "yes" ]; then
228     rm -f vfw/build/cygwin/config.mak
229     cat > vfw/build/cygwin/config.mak << EOF
230 CFLAGS=$VFW_CFLAGS
231 LDFLAGS=$VFW_LDFLAGS
232 EOF
233     echo "default: x264vfw.dll" >> config.mak
234 fi
235
236 echo "Platform:   $ARCH"
237 echo "System:     $SYS"
238 echo "avis input: $avis_input"
239 echo "mp4 output: $mp4_output"
240 echo "pthread:    $pthread"
241 echo "vfw:        $vfw"
242 echo "debug:      $debug"
243 echo "visualize:  $vis"
244 echo
245 echo "You can run 'make' now."
246