bump libpicofe for r-pi gl code
[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{
27 echo "" > $TMPC
28 $CC -E -dD $CFLAGS $TMPC | grep -q $1 || return 1
29 return 0
30}
31
32# setting options to "yes" or "no" will make that choice default,
33# "" means "autodetect".
34
38c2028e 35platform_list="generic pandora maemo caanoo libretro"
4132e8ca 36platform="generic"
61bc6d40 37builtin_gpu_list="peops unai neon"
38builtin_gpu=""
07c13dfd 39sound_driver_list="oss alsa sdl pulseaudio libretro"
40sound_drivers=""
dd4d5a35 41plugins="plugins/spunull/spunull.so \
42plugins/dfxvideo/gpu_peops.so plugins/gpu_unai/gpu_unai.so"
4132e8ca 43ram_fixed="no"
44drc_cache_base="no"
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
4132e8ca 178if [ -z "$ARCH" ]; then
179 ARCH=`$CC -v 2>&1 | grep -i 'target:' | awk '{print $2}' \
180 | awk -F '-' '{print $1}'`
181fi
182
183# ARM stuff
184if [ "$ARCH" = "arm" ]; then
185 if [ "$optimize_cortexa8" = "yes" ]; then
4132e8ca 186 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
187 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
188 fi
189 if [ "$optimize_arm926ej" = "yes" ]; then
190 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
191 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
192 fi
193
194 if [ "x$have_arm_neon" = "x" ]; then
195 # detect NEON from user-supplied cflags to enable asm code
196 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
197 fi
198 if [ "x$have_armv6" = "x" ]; then
199 have_armv6=`check_define __ARM_ARCH_6 && echo yes` || true
200 fi
201 if [ "x$have_armv7" = "x" ]; then
202 if check_define __ARM_ARCH_7A__; then
203 have_armv6="yes"
204 have_armv7="yes"
205 fi
206 fi
207
61bc6d40 208 if [ "x$builtin_gpu" = "x" ]; then
209 if [ "$have_arm_neon" = "yes" ]; then
210 builtin_gpu="neon"
211 elif [ "$have_armv7" != "yes" ]; then
212 # pre-ARMv7 hardware is usually not fast enough for peops
213 builtin_gpu="unai"
214 else
215 builtin_gpu="peops"
216 fi
217 fi
218
e795af9e 219 # automatically set mfpu and mfloat-abi if they are not set
4132e8ca 220 if [ "$have_arm_neon" = "yes" ]; then
40cf6975 221 fpu="neon"
4132e8ca 222 elif [ "$have_armv6" = "yes" ]; then
40cf6975 223 fpu="vfp"
4132e8ca 224 fi
40cf6975 225 if [ "x$fpu" != "x" ]; then
226 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
227 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
228 floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true
229 if [ "$floatabi_set_by_gcc" != "yes" ]; then
230 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
231 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
232 fi
4132e8ca 233 fi
234
9f704290 235 # must disable thumb as recompiler can't handle it
96751f36 236 if check_define __thumb__; then
9f704290 237 CFLAGS="$CFLAGS -marm"
96751f36 238 fi
4132e8ca 239else
240 # dynarec only available on ARM
241 enable_dynarec="no"
242fi
243
61bc6d40 244if [ "x$builtin_gpu" = "x" ]; then
245 builtin_gpu="peops"
246fi
247
4132e8ca 248# supposedly we can avoid -fPIC on armv5 for slightly better performace?
249if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
250 PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
251fi
252
253if [ "$ram_fixed" = "yes" ]; then
254 CFLAGS="$CFLAGS -DRAM_FIXED"
255fi
256
38c2028e 257case "$platform" in
258generic)
f89fa2d9 259 need_sdl="yes"
38c2028e 260 ;;
261maemo)
4132e8ca 262 maemo_cflags=`pkg-config --cflags hildon-1`
263 maemo_ldlibs=`pkg-config --libs hildon-1`
264 CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
07c13dfd 265 MAIN_LDLIBS="$MAIN_LDLIBS $maemo_ldlibs"
38c2028e 266 ;;
267libretro)
268 CFLAGS="$CFLAGS -fPIC"
22fa3f2b 269 MAIN_LDFLAGS="$MAIN_LDFLAGS -shared -Wl,--no-undefined"
38c2028e 270 ;;
271esac
4132e8ca 272
07c13dfd 273# header/library presence tests
274check_zlib()
275{
276 cat > $TMPC <<EOF
277 #include <zlib.h>
791f6e3e 278 int main(void) { uncompress(0, 0, 0, 0); }
07c13dfd 279EOF
280 compile_binary
281}
282
07c13dfd 283check_libpng()
284{
285 cat > $TMPC <<EOF
286 #include <png.h>
287 void main() { png_init_io(0, 0); }
288EOF
289 compile_binary
290}
291
292check_oss()
293{
294 cat > $TMPC <<EOF
295 #include <sys/soundcard.h>
296 #include <sys/ioctl.h>
297 void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
298EOF
299 compile_binary
300}
301
302check_alsa()
303{
304 cat > $TMPC <<EOF
305 #include <alsa/asoundlib.h>
306 void main() { snd_pcm_open(0, 0, 0, 0); }
307EOF
308 compile_binary "$@"
309}
310
311check_sdl()
312{
313 cat > $TMPC <<EOF
314 #include <SDL.h>
315 void main() { SDL_OpenAudio(0, 0); }
316EOF
317 compile_binary "$@"
318}
319
f89fa2d9 320MAIN_LDLIBS="$MAIN_LDLIBS -lz"
9f704290 321check_zlib || fail "please install zlib (libz-dev)"
f89fa2d9 322
f89fa2d9 323MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
9f704290 324check_libpng || fail "please install libpng (libpng-dev)"
07c13dfd 325
326# find what audio support we can compile
327if [ "x$sound_drivers" = "x" ]; then
328 if check_oss; then sound_drivers="$sound_drivers oss"; fi
f89fa2d9 329 if check_alsa -lasound; then
330 sound_drivers="$sound_drivers alsa"
331 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
332 fi
9f704290 333 if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
f89fa2d9 334 sound_drivers="$sound_drivers sdl"
335 need_sdl="yes"
336 fi
337else
338 if echo $sound_drivers | grep -q "\<oss\>"; then
339 check_oss || fail "oss support is missing"
340 fi
341 if echo $sound_drivers | grep -q "\<alsa\>"; then
342 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
343 check_alsa || fail "please install libasound2-dev"
344 fi
07c13dfd 345fi
346
9f704290 347if [ "$need_sdl" = "yes" ]; then
348 which sdl-config > /dev/null || \
349 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
f89fa2d9 350 CFLAGS="$CFLAGS `sdl-config --cflags`"
351 MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
9f704290 352 check_sdl || fail "please install libsdl (libsdl1.2-dev)"
07c13dfd 353fi
354
4132e8ca 355# check for tslib (only headers needed)
356if [ "x$have_tslib" = "x" ]; then
357 cat > $TMPC <<EOF
358 #include <tslib.h>
359 void test(struct ts_sample sample) {}
360EOF
361 if compile_object; then
362 have_tslib="yes"
363 else
364 have_tslib="no"
365 fi
366fi
367
5b9aa749 368# check for VideoCore stuff for Raspberry Pi
369if [ -d /opt/vc/include -a -d /opt/vc/lib ]; then
370 CFLAGS_GLES="$CFLAGS_GLES -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads"
371 LDLIBS_GLES="$LDLIBS_GLES -L/opt/vc/lib"
372fi
373
dd4d5a35 374# check for GLES headers
375cat > $TMPC <<EOF
376#include <GLES/gl.h>
dd4d5a35 377#include <EGL/egl.h>
5b9aa749 378int main(void) {
379 return (int)eglGetDisplay( (EGLNativeDisplayType)0 );
dd4d5a35 380}
381EOF
5b9aa749 382if compile_binary $CFLAGS_GLES -lEGL -lGLES_CM $LDLIBS_GLES; then
383 have_gles="yes"
384 LDLIBS_GLES="-lEGL -lGLES_CM $LDLIBS_GLES"
385elif compile_binary $CFLAGS_GLES -lEGL -lGLESv1_CM $LDLIBS_GLES; then
386 have_gles="yes"
387 LDLIBS_GLES="-lEGL -lGLESv1_CM $LDLIBS_GLES"
dd4d5a35 388fi
389
5b9aa749 390if [ "$have_gles" = "yes" ]; then
391 plugins="$plugins plugins/gpu-gles/gpu_gles.so"
392fi
61bc6d40 393if [ "$have_arm_neon" = "yes" -a "$builtin_gpu" != "neon" ]; then
394 plugins="$plugins plugins/gpu_neon/gpu_neon.so"
395fi
396
9f704290 397cat > $TMPC <<EOF
398void test(void *f, void *d) { fread(d, 1, 1, f); }
399EOF
400if compile_object -Wno-unused-result; then
401 CFLAGS="$CFLAGS -Wno-unused-result"
402fi
403
dd4d5a35 404# short plugin list for display
405for p in $plugins; do
406 p1=`basename $p`
407 plugins_short="$p1 $plugins_short"
408done
409
4132e8ca 410# set things that failed to autodetect to "no"
411test "x$have_armv6" != "x" || have_armv6="no"
412test "x$have_armv7" != "x" || have_armv7="no"
413test "x$have_arm_neon" != "x" || have_arm_neon="no"
414
415echo "architecture $ARCH"
416echo "platform $platform"
61bc6d40 417echo "built-in GPU $builtin_gpu"
07c13dfd 418echo "sound drivers $sound_drivers"
dd4d5a35 419echo "plugins $plugins_short"
4132e8ca 420echo "C compiler $CC"
421echo "C compiler flags $CFLAGS"
07c13dfd 422echo "libraries $MAIN_LDLIBS"
22fa3f2b 423echo "linker flags $LDFLAGS$MAIN_LDFLAGS"
4132e8ca 424echo "enable dynarec $enable_dynarec"
425echo "ARMv7 optimizations $have_armv7"
426echo "enable ARM NEON $have_arm_neon"
427echo "tslib support $have_tslib"
2c616080 428if [ "$platform" = "generic" ]; then
429 echo "OpenGL ES output $have_gles"
430fi
4132e8ca 431
432echo "# Automatically generated by configure" > $config_mak
433printf "# Configured with:" >> $config_mak
434printf " '%s'" "$0" "$@" >> $config_mak
435echo >> $config_mak
436
437echo "CC = $CC" >> $config_mak
ac6575cd 438echo "CXX = $CXX" >> $config_mak
4132e8ca 439echo "AS = $AS" >> $config_mak
440echo "CFLAGS += $CFLAGS" >> $config_mak
441echo "ASFLAGS += $ASFLAGS" >> $config_mak
442echo "LDFLAGS += $LDFLAGS" >> $config_mak
22fa3f2b 443echo "MAIN_LDFLAGS += $MAIN_LDFLAGS" >> $config_mak
07c13dfd 444echo "MAIN_LDLIBS += $MAIN_LDLIBS" >> $config_mak
4132e8ca 445echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
446echo >> $config_mak
447
38c2028e 448if [ "$platform" = "libretro" ]; then
449 echo "TARGET = libretro.so" >> $config_mak
450fi
4132e8ca 451echo "ARCH = $ARCH" >> $config_mak
452echo "PLATFORM = $platform" >> $config_mak
61bc6d40 453echo "BUILTIN_GPU = $builtin_gpu" >> $config_mak
07c13dfd 454echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
ddd99692 455echo "PLUGINS = $plugins" >> $config_mak
4132e8ca 456if [ "$have_arm_neon" = "yes" ]; then
457 echo "HAVE_NEON = 1" >> $config_mak
458fi
459if [ "$have_tslib" = "yes" ]; then
460 echo "HAVE_TSLIB = 1" >> $config_mak
461fi
5b9aa749 462if [ "$have_gles" = "yes" ]; then
463 echo "HAVE_GLES = 1" >> $config_mak
464 echo "CFLAGS_GLES = $CFLAGS_GLES" >> $config_mak
465 echo "LDLIBS_GLES = $LDLIBS_GLES" >> $config_mak
466fi
4132e8ca 467if [ "$enable_dynarec" = "yes" ]; then
468 echo "USE_DYNAREC = 1" >> $config_mak
469fi
470if [ "$drc_cache_base" = "yes" ]; then
471 echo "DRC_CACHE_BASE = 1" >> $config_mak
472fi
473
2e6189bc 474# use pandora's skin (for now)
475test -e skin || ln -s frontend/pandora/skin skin
476
4132e8ca 477# vim:shiftwidth=2:expandtab