menu: fix input config for device names ending with space
[pcsx_rearmed.git] / configure
CommitLineData
4132e8ca 1#!/bin/sh
2# some elements originated from qemu configure
3set -e
4
5TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c"
6TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o"
07c13dfd 7TMPB="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}"
8trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM
4132e8ca 9rm -f config.log
10
11compile_object()
12{
07c13dfd 13 c="$CC $CFLAGS -c $TMPC -o $TMPO $@"
14 echo $c >> config.log
15 $c >> config.log 2>&1
16}
17
18compile_binary()
19{
20 c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $MAIN_LDLIBS $@"
4132e8ca 21 echo $c >> config.log
22 $c >> config.log 2>&1
23}
24
25check_define()
26{
00a212aa 27 $CC -E -dD $CFLAGS include/arm_features.h | grep -q $1 || return 1
4132e8ca 28 return 0
29}
30
31# setting options to "yes" or "no" will make that choice default,
32# "" means "autodetect".
33
38c2028e 34platform_list="generic pandora maemo caanoo libretro"
4132e8ca 35platform="generic"
61bc6d40 36builtin_gpu_list="peops unai neon"
37builtin_gpu=""
b68bf5c2 38sound_driver_list="oss alsa pulseaudio sdl libretro"
07c13dfd 39sound_drivers=""
dd4d5a35 40plugins="plugins/spunull/spunull.so \
41plugins/dfxvideo/gpu_peops.so plugins/gpu_unai/gpu_unai.so"
4132e8ca 42ram_fixed="no"
43drc_cache_base="no"
00a212aa 44have_armv5=""
4132e8ca 45have_armv6=""
46have_armv7=""
47have_arm_neon=""
48have_tslib=""
5b9aa749 49have_gles=""
5514a050 50have_c64x_dsp=""
4132e8ca 51enable_dynarec="yes"
f89fa2d9 52need_sdl="no"
955f9af0 53need_xlib="no"
cc56203b 54need_libpicofe="yes"
55need_warm="no"
5b9aa749 56CFLAGS_GLES=""
57LDLIBS_GLES=""
4132e8ca 58# these are for known platforms
59optimize_cortexa8="no"
60optimize_arm926ej="no"
61
62# hardcoded stuff
63CC="${CC-${CROSS_COMPILE}gcc}"
ac6575cd 64CXX="${CXX-${CROSS_COMPILE}g++}"
4132e8ca 65AS="${AS-${CROSS_COMPILE}as}"
66AR="${AS-${CROSS_COMPILE}ar}"
9aff1963 67MAIN_LDLIBS="$LDLIBS -ldl -lm -lpthread"
4132e8ca 68config_mak="config.mak"
69
07c13dfd 70fail()
71{
72 echo "$@"
73 exit 1
74}
75
4132e8ca 76# call during arg parsing, so that cmd line can override platform defaults
77set_platform()
78{
79 platform=$1
80 case "$platform" in
81 generic)
82 ;;
83 pandora)
07c13dfd 84 sound_drivers="oss alsa"
4132e8ca 85 ram_fixed="yes"
86 drc_cache_base="yes"
87 optimize_cortexa8="yes"
88 have_arm_neon="yes"
955f9af0 89 need_xlib="yes"
4132e8ca 90 ;;
91 maemo)
92 ram_fixed="yes"
93 drc_cache_base="yes"
94 optimize_cortexa8="yes"
95 have_arm_neon="yes"
96 ;;
97 caanoo)
07c13dfd 98 sound_drivers="oss"
4132e8ca 99 ram_fixed="yes"
100 drc_cache_base="yes"
101 optimize_arm926ej="yes"
cc56203b 102 need_warm="yes"
4132e8ca 103 ;;
38c2028e 104 libretro)
07c13dfd 105 sound_drivers="libretro"
cc56203b 106 need_libpicofe="no"
38c2028e 107 ;;
4132e8ca 108 *)
07c13dfd 109 fail "unsupported platform: $platform"
4132e8ca 110 ;;
111 esac
112}
113
114for opt do
115 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
116 case "$opt" in
117 --help|-h) show_help="yes"
118 ;;
119 --platform=*) set_platform "$optarg"
120 ;;
61bc6d40 121 --gpu=*) builtin_gpu="$optarg"
122 ;;
07c13dfd 123 --sound-drivers=*) sound_drivers="$optarg"
4132e8ca 124 ;;
125 --enable-neon) have_arm_neon="yes"
126 ;;
127 --disable-neon) have_arm_neon="no"
128 ;;
129 --disable-dynarec) enable_dynarec="no"
130 ;;
131 *) echo "ERROR: unknown option $opt"; show_help="yes"
132 ;;
133 esac
134done
135
136if [ "$show_help" = "yes" ]; then
137 echo "options:"
138 echo " --help print this message"
139 echo " --platform=NAME target platform [$platform]"
140 echo " available: $platform_list"
61bc6d40 141 echo " --gpu=NAME builtin gpu plugin [guessed]"
142 echo " available: $builtin_gpu_list"
07c13dfd 143 echo " --sound-drivers=LIST sound output drivers [guessed]"
4132e8ca 144 echo " available: $sound_driver_list"
145 echo " --enable-neon"
146 echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
147 echo " --disable-dynarec disable dynamic recompiler"
148 echo " (dynarec is only available and enabled on ARM)"
149 echo "influential environment variables:"
ac6575cd 150 echo " CROSS_COMPILE CC CXX AS AR CFLAGS ASFLAGS LDFLAGS LDLIBS"
4132e8ca 151 exit 1
152fi
153
07c13dfd 154# validate selections
61bc6d40 155if [ "x$builtin_gpu" != "x" ]; then
07c13dfd 156 if ! echo $builtin_gpu_list | grep -q "\<$builtin_gpu\>"; then
157 fail "unsupported builtin gpu plugin: $builtin_gpu"
158 fi
61bc6d40 159fi
160
07c13dfd 161if [ "x$sound_drivers" != "x" ]; then
162 for d in $sound_drivers; do
163 if ! echo $sound_driver_list | grep -q "\<$d\>"; then
164 fail "unsupported sound driver: $sound_driver"
165 fi
166 done
167fi
4132e8ca 168
cc56203b 169if [ "$need_libpicofe" = "yes" ]; then
170 if ! test -f "frontend/libpicofe/README"; then
171 fail "libpicofe is missing, please run 'git submodule init && git submodule update'"
172 fi
173fi
174
175if [ "$need_warm" = "yes" ]; then
176 if ! test -f "frontend/warm/README"; then
177 fail "wARM is missing, please run 'git submodule init && git submodule update'"
178 fi
179fi
180
00a212aa 181# basic compiler test
182cat > $TMPC <<EOF
183#include <zlib.h>
184int main(void) { return 0; }
185EOF
186if ! compile_binary; then
0dc1b4a9 187 fail "compiler test failed, please check config.log"
00a212aa 188fi
189
4132e8ca 190if [ -z "$ARCH" ]; then
0dc1b4a9 191 ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
4132e8ca 192fi
193
0dc1b4a9 194case "$ARCH" in
195arm*)
196 # ARM stuff
197 ARCH="arm"
198
4132e8ca 199 if [ "$optimize_cortexa8" = "yes" ]; then
4132e8ca 200 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
201 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
202 fi
203 if [ "$optimize_arm926ej" = "yes" ]; then
204 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
205 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
206 fi
207
208 if [ "x$have_arm_neon" = "x" ]; then
209 # detect NEON from user-supplied cflags to enable asm code
210 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
211 fi
4132e8ca 212 if [ "x$have_armv7" = "x" ]; then
00a212aa 213 if check_define HAVE_ARMV7; then
4132e8ca 214 have_armv7="yes"
00a212aa 215 have_armv6="yes"
216 have_armv5="yes"
4132e8ca 217 fi
218 fi
00a212aa 219 if [ "x$have_armv6" = "x" ]; then
220 if check_define HAVE_ARMV6; then
221 have_armv6="yes"
222 have_armv5="yes"
223 fi
224 fi
225 if [ "x$have_armv5" = "x" ]; then
226 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
227 fi
4132e8ca 228
61bc6d40 229 if [ "x$builtin_gpu" = "x" ]; then
230 if [ "$have_arm_neon" = "yes" ]; then
231 builtin_gpu="neon"
232 elif [ "$have_armv7" != "yes" ]; then
233 # pre-ARMv7 hardware is usually not fast enough for peops
234 builtin_gpu="unai"
235 else
236 builtin_gpu="peops"
237 fi
238 fi
239
e795af9e 240 # automatically set mfpu and mfloat-abi if they are not set
4132e8ca 241 if [ "$have_arm_neon" = "yes" ]; then
40cf6975 242 fpu="neon"
4132e8ca 243 elif [ "$have_armv6" = "yes" ]; then
40cf6975 244 fpu="vfp"
4132e8ca 245 fi
40cf6975 246 if [ "x$fpu" != "x" ]; then
247 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
248 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
249 floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true
250 if [ "$floatabi_set_by_gcc" != "yes" ]; then
251 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
252 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
253 fi
4132e8ca 254 fi
255
9f704290 256 # must disable thumb as recompiler can't handle it
96751f36 257 if check_define __thumb__; then
9f704290 258 CFLAGS="$CFLAGS -marm"
96751f36 259 fi
00a212aa 260
261 # warn about common mistakes
262 if [ "$have_armv5" != "yes" ]; then
263 if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
264 echo "Warning: compiling for ARMv4, is that really what you want?"
265 echo "You probably should specify -mcpu= or -march= like this:"
266 echo " CFLAGS=-march=armv6 ./configure ..."
267 fi
268 fi
269 if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then
270 echo "Warning: compiling for NEON, but not ARMv7?"
271 echo "You probably want to specify -mcpu= or -march= like this:"
272 echo " CFLAGS=-march=armv7-a ./configure ..."
273 fi
0dc1b4a9 274 ;;
275*)
4132e8ca 276 # dynarec only available on ARM
277 enable_dynarec="no"
0dc1b4a9 278 ;;
279esac
4132e8ca 280
61bc6d40 281if [ "x$builtin_gpu" = "x" ]; then
282 builtin_gpu="peops"
283fi
284
4132e8ca 285# supposedly we can avoid -fPIC on armv5 for slightly better performace?
286if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
287 PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
288fi
289
290if [ "$ram_fixed" = "yes" ]; then
291 CFLAGS="$CFLAGS -DRAM_FIXED"
292fi
293
38c2028e 294case "$platform" in
295generic)
f89fa2d9 296 need_sdl="yes"
38c2028e 297 ;;
298maemo)
7010034e 299 CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES"
38c2028e 300 ;;
301libretro)
302 CFLAGS="$CFLAGS -fPIC"
22fa3f2b 303 MAIN_LDFLAGS="$MAIN_LDFLAGS -shared -Wl,--no-undefined"
38c2028e 304 ;;
305esac
4132e8ca 306
07c13dfd 307# header/library presence tests
308check_zlib()
309{
310 cat > $TMPC <<EOF
311 #include <zlib.h>
791f6e3e 312 int main(void) { uncompress(0, 0, 0, 0); }
07c13dfd 313EOF
314 compile_binary
315}
316
07c13dfd 317check_libpng()
318{
319 cat > $TMPC <<EOF
320 #include <png.h>
321 void main() { png_init_io(0, 0); }
322EOF
323 compile_binary
324}
325
326check_oss()
327{
328 cat > $TMPC <<EOF
329 #include <sys/soundcard.h>
330 #include <sys/ioctl.h>
331 void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
332EOF
333 compile_binary
334}
335
336check_alsa()
337{
338 cat > $TMPC <<EOF
339 #include <alsa/asoundlib.h>
340 void main() { snd_pcm_open(0, 0, 0, 0); }
341EOF
342 compile_binary "$@"
343}
344
b68bf5c2 345check_pulseaudio()
346{
347 cat > $TMPC <<EOF
348 #include <pulse/pulseaudio.h>
349 void main() { pa_threaded_mainloop_new(); }
350EOF
351 compile_binary "$@"
352}
353
07c13dfd 354check_sdl()
355{
356 cat > $TMPC <<EOF
357 #include <SDL.h>
358 void main() { SDL_OpenAudio(0, 0); }
359EOF
360 compile_binary "$@"
361}
362
955f9af0 363check_xlib_headers()
364{
365 cat > $TMPC <<EOF
366 #include <X11/Xlib.h>
367 void *f() { return XOpenDisplay(0); }
368EOF
369 compile_object "$@"
370}
371
5514a050 372# see if we have c64_tools for TI C64x DSP
373check_c64_tools()
374{
375 cat > $TMPC <<EOF
376 #include <inc_libc64_mini.h>
377 int f() { return dsp_open(); }
378EOF
379 compile_object "$@"
380}
381
f89fa2d9 382MAIN_LDLIBS="$MAIN_LDLIBS -lz"
9f704290 383check_zlib || fail "please install zlib (libz-dev)"
f89fa2d9 384
f89fa2d9 385MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
9f704290 386check_libpng || fail "please install libpng (libpng-dev)"
07c13dfd 387
388# find what audio support we can compile
389if [ "x$sound_drivers" = "x" ]; then
390 if check_oss; then sound_drivers="$sound_drivers oss"; fi
f89fa2d9 391 if check_alsa -lasound; then
392 sound_drivers="$sound_drivers alsa"
393 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
394 fi
b68bf5c2 395 if check_pulseaudio -lpulse; then
396 sound_drivers="$sound_drivers pulseaudio"
397 MAIN_LDLIBS="-lpulse $MAIN_LDLIBS"
398 fi
9f704290 399 if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
f89fa2d9 400 sound_drivers="$sound_drivers sdl"
401 need_sdl="yes"
402 fi
403else
404 if echo $sound_drivers | grep -q "\<oss\>"; then
405 check_oss || fail "oss support is missing"
406 fi
407 if echo $sound_drivers | grep -q "\<alsa\>"; then
408 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
409 check_alsa || fail "please install libasound2-dev"
410 fi
b68bf5c2 411 if echo $sound_drivers | grep -q "\<pulseaudio\>"; then
412 MAIN_LDLIBS="-lpulse $MAIN_LDLIBS"
413 check_pulseaudio || fail "pulseaudio support is missing"
414 fi
07c13dfd 415fi
416
9f704290 417if [ "$need_sdl" = "yes" ]; then
418 which sdl-config > /dev/null || \
419 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
f89fa2d9 420 CFLAGS="$CFLAGS `sdl-config --cflags`"
421 MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
9f704290 422 check_sdl || fail "please install libsdl (libsdl1.2-dev)"
07c13dfd 423fi
424
4132e8ca 425# check for tslib (only headers needed)
426if [ "x$have_tslib" = "x" ]; then
427 cat > $TMPC <<EOF
428 #include <tslib.h>
429 void test(struct ts_sample sample) {}
430EOF
431 if compile_object; then
432 have_tslib="yes"
433 else
434 have_tslib="no"
435 fi
436fi
437
5b9aa749 438# check for VideoCore stuff for Raspberry Pi
439if [ -d /opt/vc/include -a -d /opt/vc/lib ]; then
237d1f6f 440 CFLAGS_GLES="$CFLAGS_GLES -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux"
5b9aa749 441 LDLIBS_GLES="$LDLIBS_GLES -L/opt/vc/lib"
cbcadc5f 442 if [ -f /opt/vc/lib/libbcm_host.so ]; then
443 LDLIBS_GLES="$LDLIBS_GLES -lbcm_host"
444 fi
955f9af0 445 need_xlib="yes"
5b9aa749 446fi
447
dd4d5a35 448# check for GLES headers
449cat > $TMPC <<EOF
450#include <GLES/gl.h>
dd4d5a35 451#include <EGL/egl.h>
5b9aa749 452int main(void) {
453 return (int)eglGetDisplay( (EGLNativeDisplayType)0 );
dd4d5a35 454}
455EOF
5b9aa749 456if compile_binary $CFLAGS_GLES -lEGL -lGLES_CM $LDLIBS_GLES; then
457 have_gles="yes"
458 LDLIBS_GLES="-lEGL -lGLES_CM $LDLIBS_GLES"
459elif compile_binary $CFLAGS_GLES -lEGL -lGLESv1_CM $LDLIBS_GLES; then
460 have_gles="yes"
461 LDLIBS_GLES="-lEGL -lGLESv1_CM $LDLIBS_GLES"
dd4d5a35 462fi
463
5514a050 464if check_c64_tools; then
465 have_c64x_dsp="yes"
466fi
467
5b9aa749 468if [ "$have_gles" = "yes" ]; then
469 plugins="$plugins plugins/gpu-gles/gpu_gles.so"
470fi
61bc6d40 471if [ "$have_arm_neon" = "yes" -a "$builtin_gpu" != "neon" ]; then
472 plugins="$plugins plugins/gpu_neon/gpu_neon.so"
473fi
474
955f9af0 475# check for xlib (only headers needed)
476if [ "x$need_xlib" = "xyes" ]; then
477 check_xlib_headers || fail "please install libx11-dev"
478fi
479
9f704290 480cat > $TMPC <<EOF
481void test(void *f, void *d) { fread(d, 1, 1, f); }
482EOF
483if compile_object -Wno-unused-result; then
484 CFLAGS="$CFLAGS -Wno-unused-result"
485fi
486
dd4d5a35 487# short plugin list for display
488for p in $plugins; do
489 p1=`basename $p`
490 plugins_short="$p1 $plugins_short"
491done
492
4132e8ca 493# set things that failed to autodetect to "no"
494test "x$have_armv6" != "x" || have_armv6="no"
495test "x$have_armv7" != "x" || have_armv7="no"
496test "x$have_arm_neon" != "x" || have_arm_neon="no"
00a212aa 497test "x$have_gles" != "x" || have_gles="no"
5514a050 498test "x$have_c64x_dsp" != "x" || have_c64x_dsp="no"
4132e8ca 499
500echo "architecture $ARCH"
501echo "platform $platform"
61bc6d40 502echo "built-in GPU $builtin_gpu"
07c13dfd 503echo "sound drivers $sound_drivers"
dd4d5a35 504echo "plugins $plugins_short"
4132e8ca 505echo "C compiler $CC"
506echo "C compiler flags $CFLAGS"
07c13dfd 507echo "libraries $MAIN_LDLIBS"
22fa3f2b 508echo "linker flags $LDFLAGS$MAIN_LDFLAGS"
4132e8ca 509echo "enable dynarec $enable_dynarec"
5514a050 510if [ "$ARCH" = "arm" ]; then
511 echo "ARMv7 optimizations $have_armv7"
512 echo "enable ARM NEON $have_arm_neon"
513 echo "TI C64x DSP support $have_c64x_dsp"
514fi
4132e8ca 515echo "tslib support $have_tslib"
2c616080 516if [ "$platform" = "generic" ]; then
517 echo "OpenGL ES output $have_gles"
518fi
4132e8ca 519
520echo "# Automatically generated by configure" > $config_mak
521printf "# Configured with:" >> $config_mak
522printf " '%s'" "$0" "$@" >> $config_mak
523echo >> $config_mak
524
525echo "CC = $CC" >> $config_mak
ac6575cd 526echo "CXX = $CXX" >> $config_mak
4132e8ca 527echo "AS = $AS" >> $config_mak
528echo "CFLAGS += $CFLAGS" >> $config_mak
529echo "ASFLAGS += $ASFLAGS" >> $config_mak
530echo "LDFLAGS += $LDFLAGS" >> $config_mak
22fa3f2b 531echo "MAIN_LDFLAGS += $MAIN_LDFLAGS" >> $config_mak
07c13dfd 532echo "MAIN_LDLIBS += $MAIN_LDLIBS" >> $config_mak
4132e8ca 533echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
534echo >> $config_mak
535
38c2028e 536if [ "$platform" = "libretro" ]; then
537 echo "TARGET = libretro.so" >> $config_mak
538fi
4132e8ca 539echo "ARCH = $ARCH" >> $config_mak
540echo "PLATFORM = $platform" >> $config_mak
61bc6d40 541echo "BUILTIN_GPU = $builtin_gpu" >> $config_mak
07c13dfd 542echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
ddd99692 543echo "PLUGINS = $plugins" >> $config_mak
4132e8ca 544if [ "$have_arm_neon" = "yes" ]; then
545 echo "HAVE_NEON = 1" >> $config_mak
546fi
547if [ "$have_tslib" = "yes" ]; then
548 echo "HAVE_TSLIB = 1" >> $config_mak
549fi
5b9aa749 550if [ "$have_gles" = "yes" ]; then
551 echo "HAVE_GLES = 1" >> $config_mak
552 echo "CFLAGS_GLES = $CFLAGS_GLES" >> $config_mak
553 echo "LDLIBS_GLES = $LDLIBS_GLES" >> $config_mak
554fi
4132e8ca 555if [ "$enable_dynarec" = "yes" ]; then
556 echo "USE_DYNAREC = 1" >> $config_mak
557fi
558if [ "$drc_cache_base" = "yes" ]; then
559 echo "DRC_CACHE_BASE = 1" >> $config_mak
560fi
5514a050 561if [ "$have_c64x_dsp" = "yes" ]; then
562 echo "HAVE_C64_TOOLS = 1" >> $config_mak
563fi
4132e8ca 564
2e6189bc 565# use pandora's skin (for now)
566test -e skin || ln -s frontend/pandora/skin skin
567
4132e8ca 568# vim:shiftwidth=2:expandtab