d4d62665 |
1 | #!/bin/sh |
2 | # some elements originated from qemu configure |
3 | set -e |
4 | |
5 | TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c" |
6 | TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o" |
7 | TMPB="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}" |
8 | trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM |
9 | rm -f config.log |
10 | |
11 | compile_object() |
12 | { |
13 | c="$CC $CFLAGS -c $TMPC -o $TMPO $@" |
14 | echo $c >> config.log |
15 | $c >> config.log 2>&1 |
16 | } |
17 | |
18 | compile_binary() |
19 | { |
20 | c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $MAIN_LDLIBS $@" |
21 | echo $c >> config.log |
22 | $c >> config.log 2>&1 |
23 | } |
24 | |
25 | check_define() |
26 | { |
27 | $CC -E -dD $CFLAGS pico/arm_features.h | grep -q $1 || return 1 |
28 | return 0 |
29 | } |
30 | |
31 | # setting options to "yes" or "no" will make that choice default, |
32 | # "" means "autodetect". |
33 | |
34 | platform_list="generic pandora" |
35 | platform="generic" |
36 | sound_driver_list="oss alsa sdl" |
37 | sound_drivers="" |
38 | have_armv5="" |
39 | have_armv6="" |
40 | have_armv7="" |
41 | have_arm_neon="" |
fc11dd05 |
42 | have_libavcodec="" |
d4d62665 |
43 | enable_dynarec="yes" |
44 | need_sdl="no" |
45 | need_xlib="no" |
46 | # these are for known platforms |
47 | optimize_cortexa8="no" |
48 | optimize_arm926ej="no" |
49 | |
50 | # hardcoded stuff |
51 | CC="${CC-${CROSS_COMPILE}gcc}" |
52 | CXX="${CXX-${CROSS_COMPILE}g++}" |
53 | AS="${AS-${CROSS_COMPILE}as}" |
54 | MAIN_LDLIBS="$LDLIBS -lm" |
55 | config_mak="config.mak" |
56 | |
57 | fail() |
58 | { |
59 | echo "$@" |
60 | exit 1 |
61 | } |
62 | |
63 | # call during arg parsing, so that cmd line can override platform defaults |
64 | set_platform() |
65 | { |
66 | platform=$1 |
67 | case "$platform" in |
68 | generic) |
69 | ;; |
70 | pandora) |
71 | sound_drivers="oss alsa" |
72 | optimize_cortexa8="yes" |
73 | have_arm_neon="yes" |
74 | ;; |
75 | *) |
76 | fail "unsupported platform: $platform" |
77 | ;; |
78 | esac |
79 | } |
80 | |
81 | for opt do |
82 | optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true |
83 | case "$opt" in |
84 | --help|-h) show_help="yes" |
85 | ;; |
86 | --platform=*) set_platform "$optarg" |
87 | ;; |
88 | --sound-drivers=*) sound_drivers="$optarg" |
89 | ;; |
90 | --enable-neon) have_arm_neon="yes" |
91 | ;; |
92 | --disable-neon) have_arm_neon="no" |
93 | ;; |
94 | --disable-dynarec) enable_dynarec="no" |
95 | ;; |
96 | *) echo "ERROR: unknown option $opt"; show_help="yes" |
97 | ;; |
98 | esac |
99 | done |
100 | |
101 | if [ "$show_help" = "yes" ]; then |
102 | echo "options:" |
103 | echo " --help print this message" |
104 | echo " --platform=NAME target platform [$platform]" |
105 | echo " available: $platform_list" |
106 | echo " --sound-drivers=LIST sound output drivers [guessed]" |
107 | echo " available: $sound_driver_list" |
108 | echo " --enable-neon" |
109 | echo " --disable-neon enable/disable ARM NEON optimizations [guessed]" |
110 | echo " --disable-dynarec disable dynamic recompiler" |
111 | echo " (dynarec is only available and enabled on ARM)" |
112 | echo "influential environment variables:" |
113 | echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS" |
114 | exit 1 |
115 | fi |
116 | |
117 | # validate selections |
118 | if [ "x$sound_drivers" != "x" ]; then |
119 | for d in $sound_drivers; do |
120 | if ! echo $sound_driver_list | grep -q "\<$d\>"; then |
121 | fail "unsupported sound driver: $sound_driver" |
122 | fi |
123 | done |
124 | fi |
125 | |
720bfc5d |
126 | if ! test -f "platform/libpicofe/README"; then |
127 | fail "libpicofe is missing, please run 'git submodule update --init'" |
d4d62665 |
128 | fi |
129 | |
130 | #if [ "$need_warm" = "yes" ]; then |
131 | # if ! test -f "frontend/warm/README"; then |
132 | # fail "wARM is missing, please run 'git submodule init && git submodule update'" |
133 | # fi |
134 | #fi |
135 | |
136 | # basic compiler test |
137 | cat > $TMPC <<EOF |
138 | int main(void) { return 0; } |
139 | EOF |
140 | if ! compile_binary; then |
141 | fail "compiler test failed, please check config.log" |
142 | fi |
143 | |
144 | if [ -z "$ARCH" ]; then |
145 | ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'` |
146 | fi |
147 | |
148 | case "$ARCH" in |
149 | arm*) |
150 | # ARM stuff |
151 | ARCH="arm" |
152 | |
153 | if [ "$optimize_cortexa8" = "yes" ]; then |
154 | CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8" |
155 | ASFLAGS="$ASFLAGS -mcpu=cortex-a8" |
156 | fi |
157 | if [ "$optimize_arm926ej" = "yes" ]; then |
158 | CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s" |
159 | ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp" |
160 | fi |
161 | |
162 | if [ "x$have_arm_neon" = "x" ]; then |
163 | # detect NEON from user-supplied cflags to enable asm code |
164 | have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true |
165 | fi |
166 | if [ "x$have_armv7" = "x" ]; then |
167 | if check_define HAVE_ARMV7; then |
168 | have_armv7="yes" |
169 | have_armv6="yes" |
170 | have_armv5="yes" |
171 | fi |
172 | fi |
173 | if [ "x$have_armv6" = "x" ]; then |
174 | if check_define HAVE_ARMV6; then |
175 | have_armv6="yes" |
176 | have_armv5="yes" |
177 | fi |
178 | fi |
179 | if [ "x$have_armv5" = "x" ]; then |
180 | have_armv5=`check_define HAVE_ARMV5 && echo yes` || true |
181 | fi |
182 | |
183 | # automatically set mfpu and mfloat-abi if they are not set |
184 | if [ "$have_arm_neon" = "yes" ]; then |
185 | fpu="neon" |
186 | elif [ "$have_armv6" = "yes" ]; then |
187 | fpu="vfp" |
188 | fi |
189 | if [ "x$fpu" != "x" ]; then |
190 | echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu" |
191 | echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu" |
192 | floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true |
193 | if [ "$floatabi_set_by_gcc" != "yes" ]; then |
194 | echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp" |
195 | echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp" |
196 | fi |
197 | fi |
198 | |
199 | # must disable thumb as recompiler can't handle it |
200 | if check_define __thumb__; then |
201 | CFLAGS="$CFLAGS -marm" |
202 | fi |
203 | |
204 | # warn about common mistakes |
205 | if [ "$have_armv5" != "yes" ]; then |
206 | if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then |
207 | echo "Warning: compiling for ARMv4, is that really what you want?" |
208 | echo "You probably should specify -mcpu= or -march= like this:" |
209 | echo " CFLAGS=-march=armv6 ./configure ..." |
210 | fi |
211 | fi |
212 | if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then |
213 | echo "Warning: compiling for NEON, but not ARMv7?" |
214 | echo "You probably want to specify -mcpu= or -march= like this:" |
215 | echo " CFLAGS=-march=armv7-a ./configure ..." |
216 | fi |
217 | ;; |
218 | *) |
219 | # dynarec only available on ARM |
220 | enable_dynarec="no" |
221 | ;; |
222 | esac |
223 | |
224 | case "$platform" in |
225 | generic) |
226 | need_sdl="yes" |
227 | ;; |
228 | esac |
229 | |
230 | # header/library presence tests |
231 | check_zlib() |
232 | { |
233 | cat > $TMPC <<EOF |
234 | #include <zlib.h> |
235 | int main(void) { uncompress(0, 0, 0, 0); } |
236 | EOF |
237 | compile_binary |
238 | } |
239 | |
240 | check_libpng() |
241 | { |
242 | cat > $TMPC <<EOF |
243 | #include <png.h> |
244 | void main() { png_init_io(0, 0); } |
245 | EOF |
246 | compile_binary |
247 | } |
248 | |
249 | check_oss() |
250 | { |
251 | cat > $TMPC <<EOF |
252 | #include <sys/soundcard.h> |
253 | #include <sys/ioctl.h> |
254 | void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); } |
255 | EOF |
256 | compile_binary |
257 | } |
258 | |
259 | check_alsa() |
260 | { |
261 | cat > $TMPC <<EOF |
262 | #include <alsa/asoundlib.h> |
263 | void main() { snd_pcm_open(0, 0, 0, 0); } |
264 | EOF |
265 | compile_binary "$@" |
266 | } |
267 | |
268 | check_sdl() |
269 | { |
270 | cat > $TMPC <<EOF |
271 | #include <SDL.h> |
272 | void main() { SDL_OpenAudio(0, 0); } |
273 | EOF |
274 | compile_binary "$@" |
275 | } |
276 | |
fc11dd05 |
277 | check_libavcodec() |
278 | { |
279 | cat > $TMPC <<EOF |
280 | #include <libavcodec/avcodec.h> |
281 | void main() { avcodec_decode_audio3(0, 0, 0, 0); } |
282 | EOF |
986d60fc |
283 | compile_object "$@" |
fc11dd05 |
284 | } |
285 | |
d4d62665 |
286 | #MAIN_LDLIBS="$MAIN_LDLIBS -lz" |
287 | #check_zlib || fail "please install zlib (libz-dev)" |
288 | |
289 | MAIN_LDLIBS="-lpng $MAIN_LDLIBS" |
290 | check_libpng || fail "please install libpng (libpng-dev)" |
291 | |
fc11dd05 |
292 | if check_libavcodec; then |
293 | have_libavcodec="yes" |
986d60fc |
294 | # add -ldl if needed |
295 | case "$MAIN_LDLIBS" in |
296 | *"-ldl"*) ;; |
297 | *) MAIN_LDLIBS="-ldl $MAIN_LDLIBS" ;; |
298 | esac |
fc11dd05 |
299 | fi |
300 | |
d4d62665 |
301 | # find what audio support we can compile |
302 | if [ "x$sound_drivers" = "x" ]; then |
303 | if check_oss; then sound_drivers="$sound_drivers oss"; fi |
304 | if check_alsa -lasound; then |
305 | sound_drivers="$sound_drivers alsa" |
306 | MAIN_LDLIBS="-lasound $MAIN_LDLIBS" |
307 | fi |
308 | if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then |
309 | sound_drivers="$sound_drivers sdl" |
310 | need_sdl="yes" |
311 | fi |
312 | else |
313 | if echo $sound_drivers | grep -q "\<oss\>"; then |
314 | check_oss || fail "oss support is missing" |
315 | fi |
316 | if echo $sound_drivers | grep -q "\<alsa\>"; then |
317 | MAIN_LDLIBS="-lasound $MAIN_LDLIBS" |
318 | check_alsa || fail "please install libasound2-dev" |
319 | fi |
320 | fi |
321 | |
322 | if [ "$need_sdl" = "yes" ]; then |
323 | which sdl-config > /dev/null || \ |
324 | fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)" |
325 | CFLAGS="$CFLAGS `sdl-config --cflags`" |
326 | MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS" |
327 | check_sdl || fail "please install libsdl (libsdl1.2-dev)" |
328 | fi |
329 | |
330 | cat > $TMPC <<EOF |
331 | void test(void *f, void *d) { fread(d, 1, 1, f); } |
332 | EOF |
333 | if compile_object -Wno-unused-result; then |
334 | CFLAGS="$CFLAGS -Wno-unused-result" |
335 | fi |
336 | |
337 | # set things that failed to autodetect to "no" |
338 | test "x$have_armv6" != "x" || have_armv6="no" |
339 | test "x$have_armv7" != "x" || have_armv7="no" |
340 | test "x$have_arm_neon" != "x" || have_arm_neon="no" |
fc11dd05 |
341 | test "x$have_libavcodec" != "x" || have_libavcodec="no" |
d4d62665 |
342 | |
343 | echo "architecture $ARCH" |
344 | echo "platform $platform" |
345 | echo "sound drivers $sound_drivers" |
346 | echo "C compiler $CC" |
347 | echo "C compiler flags $CFLAGS" |
348 | echo "libraries $MAIN_LDLIBS" |
349 | echo "linker flags $LDFLAGS" |
fc11dd05 |
350 | echo "libavcodec (mp3) $have_libavcodec" |
d4d62665 |
351 | echo "enable dynarec $enable_dynarec" |
352 | # echo "ARMv7 optimizations $have_armv7" |
353 | # echo "enable ARM NEON $have_arm_neon" |
354 | |
355 | echo "# Automatically generated by configure" > $config_mak |
356 | printf "# Configured with:" >> $config_mak |
357 | printf " '%s'" "$0" "$@" >> $config_mak |
358 | echo >> $config_mak |
359 | |
360 | echo "CC = $CC" >> $config_mak |
361 | echo "CXX = $CXX" >> $config_mak |
362 | echo "AS = $AS" >> $config_mak |
363 | echo "CFLAGS += $CFLAGS" >> $config_mak |
364 | echo "ASFLAGS += $ASFLAGS" >> $config_mak |
365 | echo "LDFLAGS += $LDFLAGS" >> $config_mak |
366 | echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak |
367 | echo >> $config_mak |
368 | |
369 | echo "ARCH = $ARCH" >> $config_mak |
370 | echo "PLATFORM = $platform" >> $config_mak |
371 | echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak |
fc11dd05 |
372 | if [ "$have_libavcodec" = "yes" ]; then |
373 | echo "HAVE_LIBAVCODEC = 1" >> $config_mak |
374 | fi |
d4d62665 |
375 | if [ "$have_arm_neon" = "yes" ]; then |
376 | echo "HAVE_NEON = 1" >> $config_mak |
377 | fi |
378 | if [ "$enable_dynarec" = "yes" ]; then |
379 | echo "USE_DYNAREC = 1" >> $config_mak |
380 | fi |
381 | |
382 | # use pandora's skin (for now) |
383 | test -e skin || ln -s platform/pandora/skin skin |
384 | |
385 | # vim:shiftwidth=2:expandtab |