cdrom: remove stopping on TN
[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=""
4132e8ca 50enable_dynarec="yes"
f89fa2d9 51need_sdl="no"
cc56203b 52need_libpicofe="yes"
53need_warm="no"
5b9aa749 54CFLAGS_GLES=""
55LDLIBS_GLES=""
4132e8ca 56# these are for known platforms
57optimize_cortexa8="no"
58optimize_arm926ej="no"
59
60# hardcoded stuff
61CC="${CC-${CROSS_COMPILE}gcc}"
ac6575cd 62CXX="${CXX-${CROSS_COMPILE}g++}"
4132e8ca 63AS="${AS-${CROSS_COMPILE}as}"
64AR="${AS-${CROSS_COMPILE}ar}"
f89fa2d9 65MAIN_LDLIBS="$LDLIBS -ldl -lm"
4132e8ca 66config_mak="config.mak"
67
07c13dfd 68fail()
69{
70 echo "$@"
71 exit 1
72}
73
4132e8ca 74# call during arg parsing, so that cmd line can override platform defaults
75set_platform()
76{
77 platform=$1
78 case "$platform" in
79 generic)
80 ;;
81 pandora)
07c13dfd 82 sound_drivers="oss alsa"
4132e8ca 83 ram_fixed="yes"
84 drc_cache_base="yes"
85 optimize_cortexa8="yes"
86 have_arm_neon="yes"
87 ;;
88 maemo)
89 ram_fixed="yes"
90 drc_cache_base="yes"
91 optimize_cortexa8="yes"
92 have_arm_neon="yes"
93 ;;
94 caanoo)
07c13dfd 95 sound_drivers="oss"
4132e8ca 96 ram_fixed="yes"
97 drc_cache_base="yes"
98 optimize_arm926ej="yes"
cc56203b 99 need_warm="yes"
4132e8ca 100 ;;
38c2028e 101 libretro)
07c13dfd 102 sound_drivers="libretro"
cc56203b 103 need_libpicofe="no"
38c2028e 104 ;;
4132e8ca 105 *)
07c13dfd 106 fail "unsupported platform: $platform"
4132e8ca 107 ;;
108 esac
109}
110
111for opt do
112 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
113 case "$opt" in
114 --help|-h) show_help="yes"
115 ;;
116 --platform=*) set_platform "$optarg"
117 ;;
61bc6d40 118 --gpu=*) builtin_gpu="$optarg"
119 ;;
07c13dfd 120 --sound-drivers=*) sound_drivers="$optarg"
4132e8ca 121 ;;
122 --enable-neon) have_arm_neon="yes"
123 ;;
124 --disable-neon) have_arm_neon="no"
125 ;;
126 --disable-dynarec) enable_dynarec="no"
127 ;;
128 *) echo "ERROR: unknown option $opt"; show_help="yes"
129 ;;
130 esac
131done
132
133if [ "$show_help" = "yes" ]; then
134 echo "options:"
135 echo " --help print this message"
136 echo " --platform=NAME target platform [$platform]"
137 echo " available: $platform_list"
61bc6d40 138 echo " --gpu=NAME builtin gpu plugin [guessed]"
139 echo " available: $builtin_gpu_list"
07c13dfd 140 echo " --sound-drivers=LIST sound output drivers [guessed]"
4132e8ca 141 echo " available: $sound_driver_list"
142 echo " --enable-neon"
143 echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
144 echo " --disable-dynarec disable dynamic recompiler"
145 echo " (dynarec is only available and enabled on ARM)"
146 echo "influential environment variables:"
ac6575cd 147 echo " CROSS_COMPILE CC CXX AS AR CFLAGS ASFLAGS LDFLAGS LDLIBS"
4132e8ca 148 exit 1
149fi
150
07c13dfd 151# validate selections
61bc6d40 152if [ "x$builtin_gpu" != "x" ]; then
07c13dfd 153 if ! echo $builtin_gpu_list | grep -q "\<$builtin_gpu\>"; then
154 fail "unsupported builtin gpu plugin: $builtin_gpu"
155 fi
61bc6d40 156fi
157
07c13dfd 158if [ "x$sound_drivers" != "x" ]; then
159 for d in $sound_drivers; do
160 if ! echo $sound_driver_list | grep -q "\<$d\>"; then
161 fail "unsupported sound driver: $sound_driver"
162 fi
163 done
164fi
4132e8ca 165
cc56203b 166if [ "$need_libpicofe" = "yes" ]; then
167 if ! test -f "frontend/libpicofe/README"; then
168 fail "libpicofe is missing, please run 'git submodule init && git submodule update'"
169 fi
170fi
171
172if [ "$need_warm" = "yes" ]; then
173 if ! test -f "frontend/warm/README"; then
174 fail "wARM is missing, please run 'git submodule init && git submodule update'"
175 fi
176fi
177
00a212aa 178# basic compiler test
179cat > $TMPC <<EOF
180#include <zlib.h>
181int main(void) { return 0; }
182EOF
183if ! compile_binary; then
0dc1b4a9 184 fail "compiler test failed, please check config.log"
00a212aa 185fi
186
4132e8ca 187if [ -z "$ARCH" ]; then
0dc1b4a9 188 ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
4132e8ca 189fi
190
0dc1b4a9 191case "$ARCH" in
192arm*)
193 # ARM stuff
194 ARCH="arm"
195
4132e8ca 196 if [ "$optimize_cortexa8" = "yes" ]; then
4132e8ca 197 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
198 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
199 fi
200 if [ "$optimize_arm926ej" = "yes" ]; then
201 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
202 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
203 fi
204
205 if [ "x$have_arm_neon" = "x" ]; then
206 # detect NEON from user-supplied cflags to enable asm code
207 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
208 fi
4132e8ca 209 if [ "x$have_armv7" = "x" ]; then
00a212aa 210 if check_define HAVE_ARMV7; then
4132e8ca 211 have_armv7="yes"
00a212aa 212 have_armv6="yes"
213 have_armv5="yes"
4132e8ca 214 fi
215 fi
00a212aa 216 if [ "x$have_armv6" = "x" ]; then
217 if check_define HAVE_ARMV6; then
218 have_armv6="yes"
219 have_armv5="yes"
220 fi
221 fi
222 if [ "x$have_armv5" = "x" ]; then
223 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
224 fi
4132e8ca 225
61bc6d40 226 if [ "x$builtin_gpu" = "x" ]; then
227 if [ "$have_arm_neon" = "yes" ]; then
228 builtin_gpu="neon"
229 elif [ "$have_armv7" != "yes" ]; then
230 # pre-ARMv7 hardware is usually not fast enough for peops
231 builtin_gpu="unai"
232 else
233 builtin_gpu="peops"
234 fi
235 fi
236
e795af9e 237 # automatically set mfpu and mfloat-abi if they are not set
4132e8ca 238 if [ "$have_arm_neon" = "yes" ]; then
40cf6975 239 fpu="neon"
4132e8ca 240 elif [ "$have_armv6" = "yes" ]; then
40cf6975 241 fpu="vfp"
4132e8ca 242 fi
40cf6975 243 if [ "x$fpu" != "x" ]; then
244 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
245 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
246 floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true
247 if [ "$floatabi_set_by_gcc" != "yes" ]; then
248 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
249 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
250 fi
4132e8ca 251 fi
252
9f704290 253 # must disable thumb as recompiler can't handle it
96751f36 254 if check_define __thumb__; then
9f704290 255 CFLAGS="$CFLAGS -marm"
96751f36 256 fi
00a212aa 257
258 # warn about common mistakes
259 if [ "$have_armv5" != "yes" ]; then
260 if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
261 echo "Warning: compiling for ARMv4, is that really what you want?"
262 echo "You probably should specify -mcpu= or -march= like this:"
263 echo " CFLAGS=-march=armv6 ./configure ..."
264 fi
265 fi
266 if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then
267 echo "Warning: compiling for NEON, but not ARMv7?"
268 echo "You probably want to specify -mcpu= or -march= like this:"
269 echo " CFLAGS=-march=armv7-a ./configure ..."
270 fi
0dc1b4a9 271 ;;
272*)
4132e8ca 273 # dynarec only available on ARM
274 enable_dynarec="no"
0dc1b4a9 275 ;;
276esac
4132e8ca 277
61bc6d40 278if [ "x$builtin_gpu" = "x" ]; then
279 builtin_gpu="peops"
280fi
281
4132e8ca 282# supposedly we can avoid -fPIC on armv5 for slightly better performace?
283if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
284 PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
285fi
286
287if [ "$ram_fixed" = "yes" ]; then
288 CFLAGS="$CFLAGS -DRAM_FIXED"
289fi
290
38c2028e 291case "$platform" in
292generic)
f89fa2d9 293 need_sdl="yes"
38c2028e 294 ;;
295maemo)
4132e8ca 296 maemo_cflags=`pkg-config --cflags hildon-1`
297 maemo_ldlibs=`pkg-config --libs hildon-1`
298 CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
07c13dfd 299 MAIN_LDLIBS="$MAIN_LDLIBS $maemo_ldlibs"
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
f89fa2d9 363MAIN_LDLIBS="$MAIN_LDLIBS -lz"
9f704290 364check_zlib || fail "please install zlib (libz-dev)"
f89fa2d9 365
f89fa2d9 366MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
9f704290 367check_libpng || fail "please install libpng (libpng-dev)"
07c13dfd 368
369# find what audio support we can compile
370if [ "x$sound_drivers" = "x" ]; then
371 if check_oss; then sound_drivers="$sound_drivers oss"; fi
f89fa2d9 372 if check_alsa -lasound; then
373 sound_drivers="$sound_drivers alsa"
374 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
375 fi
b68bf5c2 376 if check_pulseaudio -lpulse; then
377 sound_drivers="$sound_drivers pulseaudio"
378 MAIN_LDLIBS="-lpulse $MAIN_LDLIBS"
379 fi
9f704290 380 if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
f89fa2d9 381 sound_drivers="$sound_drivers sdl"
382 need_sdl="yes"
383 fi
384else
385 if echo $sound_drivers | grep -q "\<oss\>"; then
386 check_oss || fail "oss support is missing"
387 fi
388 if echo $sound_drivers | grep -q "\<alsa\>"; then
389 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
390 check_alsa || fail "please install libasound2-dev"
391 fi
b68bf5c2 392 if echo $sound_drivers | grep -q "\<pulseaudio\>"; then
393 MAIN_LDLIBS="-lpulse $MAIN_LDLIBS"
394 check_pulseaudio || fail "pulseaudio support is missing"
395 fi
07c13dfd 396fi
397
9f704290 398if [ "$need_sdl" = "yes" ]; then
399 which sdl-config > /dev/null || \
400 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
f89fa2d9 401 CFLAGS="$CFLAGS `sdl-config --cflags`"
402 MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
9f704290 403 check_sdl || fail "please install libsdl (libsdl1.2-dev)"
07c13dfd 404fi
405
4132e8ca 406# check for tslib (only headers needed)
407if [ "x$have_tslib" = "x" ]; then
408 cat > $TMPC <<EOF
409 #include <tslib.h>
410 void test(struct ts_sample sample) {}
411EOF
412 if compile_object; then
413 have_tslib="yes"
414 else
415 have_tslib="no"
416 fi
417fi
418
5b9aa749 419# check for VideoCore stuff for Raspberry Pi
420if [ -d /opt/vc/include -a -d /opt/vc/lib ]; then
421 CFLAGS_GLES="$CFLAGS_GLES -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads"
422 LDLIBS_GLES="$LDLIBS_GLES -L/opt/vc/lib"
423fi
424
dd4d5a35 425# check for GLES headers
426cat > $TMPC <<EOF
427#include <GLES/gl.h>
dd4d5a35 428#include <EGL/egl.h>
5b9aa749 429int main(void) {
430 return (int)eglGetDisplay( (EGLNativeDisplayType)0 );
dd4d5a35 431}
432EOF
5b9aa749 433if compile_binary $CFLAGS_GLES -lEGL -lGLES_CM $LDLIBS_GLES; then
434 have_gles="yes"
435 LDLIBS_GLES="-lEGL -lGLES_CM $LDLIBS_GLES"
436elif compile_binary $CFLAGS_GLES -lEGL -lGLESv1_CM $LDLIBS_GLES; then
437 have_gles="yes"
438 LDLIBS_GLES="-lEGL -lGLESv1_CM $LDLIBS_GLES"
dd4d5a35 439fi
440
5b9aa749 441if [ "$have_gles" = "yes" ]; then
442 plugins="$plugins plugins/gpu-gles/gpu_gles.so"
443fi
61bc6d40 444if [ "$have_arm_neon" = "yes" -a "$builtin_gpu" != "neon" ]; then
445 plugins="$plugins plugins/gpu_neon/gpu_neon.so"
446fi
447
9f704290 448cat > $TMPC <<EOF
449void test(void *f, void *d) { fread(d, 1, 1, f); }
450EOF
451if compile_object -Wno-unused-result; then
452 CFLAGS="$CFLAGS -Wno-unused-result"
453fi
454
dd4d5a35 455# short plugin list for display
456for p in $plugins; do
457 p1=`basename $p`
458 plugins_short="$p1 $plugins_short"
459done
460
4132e8ca 461# set things that failed to autodetect to "no"
462test "x$have_armv6" != "x" || have_armv6="no"
463test "x$have_armv7" != "x" || have_armv7="no"
464test "x$have_arm_neon" != "x" || have_arm_neon="no"
00a212aa 465test "x$have_gles" != "x" || have_gles="no"
4132e8ca 466
467echo "architecture $ARCH"
468echo "platform $platform"
61bc6d40 469echo "built-in GPU $builtin_gpu"
07c13dfd 470echo "sound drivers $sound_drivers"
dd4d5a35 471echo "plugins $plugins_short"
4132e8ca 472echo "C compiler $CC"
473echo "C compiler flags $CFLAGS"
07c13dfd 474echo "libraries $MAIN_LDLIBS"
22fa3f2b 475echo "linker flags $LDFLAGS$MAIN_LDFLAGS"
4132e8ca 476echo "enable dynarec $enable_dynarec"
477echo "ARMv7 optimizations $have_armv7"
478echo "enable ARM NEON $have_arm_neon"
479echo "tslib support $have_tslib"
2c616080 480if [ "$platform" = "generic" ]; then
481 echo "OpenGL ES output $have_gles"
482fi
4132e8ca 483
484echo "# Automatically generated by configure" > $config_mak
485printf "# Configured with:" >> $config_mak
486printf " '%s'" "$0" "$@" >> $config_mak
487echo >> $config_mak
488
489echo "CC = $CC" >> $config_mak
ac6575cd 490echo "CXX = $CXX" >> $config_mak
4132e8ca 491echo "AS = $AS" >> $config_mak
492echo "CFLAGS += $CFLAGS" >> $config_mak
493echo "ASFLAGS += $ASFLAGS" >> $config_mak
494echo "LDFLAGS += $LDFLAGS" >> $config_mak
22fa3f2b 495echo "MAIN_LDFLAGS += $MAIN_LDFLAGS" >> $config_mak
07c13dfd 496echo "MAIN_LDLIBS += $MAIN_LDLIBS" >> $config_mak
4132e8ca 497echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
498echo >> $config_mak
499
38c2028e 500if [ "$platform" = "libretro" ]; then
501 echo "TARGET = libretro.so" >> $config_mak
502fi
4132e8ca 503echo "ARCH = $ARCH" >> $config_mak
504echo "PLATFORM = $platform" >> $config_mak
61bc6d40 505echo "BUILTIN_GPU = $builtin_gpu" >> $config_mak
07c13dfd 506echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
ddd99692 507echo "PLUGINS = $plugins" >> $config_mak
4132e8ca 508if [ "$have_arm_neon" = "yes" ]; then
509 echo "HAVE_NEON = 1" >> $config_mak
510fi
511if [ "$have_tslib" = "yes" ]; then
512 echo "HAVE_TSLIB = 1" >> $config_mak
513fi
5b9aa749 514if [ "$have_gles" = "yes" ]; then
515 echo "HAVE_GLES = 1" >> $config_mak
516 echo "CFLAGS_GLES = $CFLAGS_GLES" >> $config_mak
517 echo "LDLIBS_GLES = $LDLIBS_GLES" >> $config_mak
518fi
4132e8ca 519if [ "$enable_dynarec" = "yes" ]; then
520 echo "USE_DYNAREC = 1" >> $config_mak
521fi
522if [ "$drc_cache_base" = "yes" ]; then
523 echo "DRC_CACHE_BASE = 1" >> $config_mak
524fi
525
2e6189bc 526# use pandora's skin (for now)
527test -e skin || ln -s frontend/pandora/skin skin
528
4132e8ca 529# vim:shiftwidth=2:expandtab