frontend/pollux: wiz: move tables to upper memory to free some RAM
[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=""
49enable_dynarec="yes"
50# these are for known platforms
51optimize_cortexa8="no"
52optimize_arm926ej="no"
53
54# hardcoded stuff
55CC="${CC-${CROSS_COMPILE}gcc}"
ac6575cd 56CXX="${CXX-${CROSS_COMPILE}g++}"
4132e8ca 57AS="${AS-${CROSS_COMPILE}as}"
58AR="${AS-${CROSS_COMPILE}ar}"
07c13dfd 59MAIN_LDLIBS="$LDLIBS -ldl -lpng -lz"
4132e8ca 60config_mak="config.mak"
61
07c13dfd 62fail()
63{
64 echo "$@"
65 exit 1
66}
67
4132e8ca 68# call during arg parsing, so that cmd line can override platform defaults
69set_platform()
70{
71 platform=$1
72 case "$platform" in
73 generic)
74 ;;
75 pandora)
07c13dfd 76 sound_drivers="oss alsa"
4132e8ca 77 ram_fixed="yes"
78 drc_cache_base="yes"
79 optimize_cortexa8="yes"
80 have_arm_neon="yes"
81 ;;
82 maemo)
83 ram_fixed="yes"
84 drc_cache_base="yes"
85 optimize_cortexa8="yes"
86 have_arm_neon="yes"
87 ;;
88 caanoo)
07c13dfd 89 sound_drivers="oss"
4132e8ca 90 ram_fixed="yes"
91 drc_cache_base="yes"
92 optimize_arm926ej="yes"
93 ;;
38c2028e 94 libretro)
07c13dfd 95 sound_drivers="libretro"
38c2028e 96 ;;
4132e8ca 97 *)
07c13dfd 98 fail "unsupported platform: $platform"
4132e8ca 99 ;;
100 esac
101}
102
103for opt do
104 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
105 case "$opt" in
106 --help|-h) show_help="yes"
107 ;;
108 --platform=*) set_platform "$optarg"
109 ;;
61bc6d40 110 --gpu=*) builtin_gpu="$optarg"
111 ;;
07c13dfd 112 --sound-drivers=*) sound_drivers="$optarg"
4132e8ca 113 ;;
114 --enable-neon) have_arm_neon="yes"
115 ;;
116 --disable-neon) have_arm_neon="no"
117 ;;
118 --disable-dynarec) enable_dynarec="no"
119 ;;
120 *) echo "ERROR: unknown option $opt"; show_help="yes"
121 ;;
122 esac
123done
124
125if [ "$show_help" = "yes" ]; then
126 echo "options:"
127 echo " --help print this message"
128 echo " --platform=NAME target platform [$platform]"
129 echo " available: $platform_list"
61bc6d40 130 echo " --gpu=NAME builtin gpu plugin [guessed]"
131 echo " available: $builtin_gpu_list"
07c13dfd 132 echo " --sound-drivers=LIST sound output drivers [guessed]"
4132e8ca 133 echo " available: $sound_driver_list"
134 echo " --enable-neon"
135 echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
136 echo " --disable-dynarec disable dynamic recompiler"
137 echo " (dynarec is only available and enabled on ARM)"
138 echo "influential environment variables:"
ac6575cd 139 echo " CROSS_COMPILE CC CXX AS AR CFLAGS ASFLAGS LDFLAGS LDLIBS"
4132e8ca 140 exit 1
141fi
142
07c13dfd 143# validate selections
61bc6d40 144if [ "x$builtin_gpu" != "x" ]; then
07c13dfd 145 if ! echo $builtin_gpu_list | grep -q "\<$builtin_gpu\>"; then
146 fail "unsupported builtin gpu plugin: $builtin_gpu"
147 fi
61bc6d40 148fi
149
07c13dfd 150if [ "x$sound_drivers" != "x" ]; then
151 for d in $sound_drivers; do
152 if ! echo $sound_driver_list | grep -q "\<$d\>"; then
153 fail "unsupported sound driver: $sound_driver"
154 fi
155 done
156fi
4132e8ca 157
158if [ -z "$ARCH" ]; then
159 ARCH=`$CC -v 2>&1 | grep -i 'target:' | awk '{print $2}' \
160 | awk -F '-' '{print $1}'`
161fi
162
163# ARM stuff
164if [ "$ARCH" = "arm" ]; then
165 if [ "$optimize_cortexa8" = "yes" ]; then
166 # both: -mfpu=neon
167 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
168 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
169 fi
170 if [ "$optimize_arm926ej" = "yes" ]; then
171 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
172 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
173 fi
174
175 if [ "x$have_arm_neon" = "x" ]; then
176 # detect NEON from user-supplied cflags to enable asm code
177 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
178 fi
179 if [ "x$have_armv6" = "x" ]; then
180 have_armv6=`check_define __ARM_ARCH_6 && echo yes` || true
181 fi
182 if [ "x$have_armv7" = "x" ]; then
183 if check_define __ARM_ARCH_7A__; then
184 have_armv6="yes"
185 have_armv7="yes"
186 fi
187 fi
188
61bc6d40 189 if [ "x$builtin_gpu" = "x" ]; then
190 if [ "$have_arm_neon" = "yes" ]; then
191 builtin_gpu="neon"
192 elif [ "$have_armv7" != "yes" ]; then
193 # pre-ARMv7 hardware is usually not fast enough for peops
194 builtin_gpu="unai"
195 else
196 builtin_gpu="peops"
197 fi
198 fi
199
4132e8ca 200 # set mfpu and mfloat-abi if they are not set
201 if [ "$have_arm_neon" = "yes" ]; then
202 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=neon"
203 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=neon"
204 elif [ "$have_armv6" = "yes" ]; then
205 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=vfp"
206 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=vfp"
207 fi
208 if [ "$have_armv6" = "yes" ]; then
209 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
210 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
211 fi
212
96751f36 213 # must disable -mthumb as recompiler can't handle it
214 if check_define __thumb__; then
215 CFLAGS="$CFLAGS -mno-thumb"
216 fi
217
4132e8ca 218 if [ "$have_armv7" = "yes" ]; then
219 ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=1"
220 else
221 ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=0"
222 fi
223else
224 # dynarec only available on ARM
225 enable_dynarec="no"
226fi
227
61bc6d40 228if [ "x$builtin_gpu" = "x" ]; then
229 builtin_gpu="peops"
230fi
231
4132e8ca 232if [ "$ARCH" = "x86_64" ]; then
233 # currently we are full of 32bit assumptions,
234 # at least savestate compatibility will break without these
235 CFLAGS="$CFLAGS -m32"
236 LDFLAGS="$LDFLAGS -m32"
237fi
238
239# supposedly we can avoid -fPIC on armv5 for slightly better performace?
240if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
241 PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
242fi
243
244if [ "$ram_fixed" = "yes" ]; then
245 CFLAGS="$CFLAGS -DRAM_FIXED"
246fi
247
38c2028e 248case "$platform" in
249generic)
7badc935 250 generic_cflags=`sdl-config --cflags`
251 generic_ldlibs=`sdl-config --libs`
252 CFLAGS="$CFLAGS $generic_cflags"
07c13dfd 253 MAIN_LDLIBS="$MAIN_LDLIBS $generic_ldlibs"
38c2028e 254 ;;
255maemo)
4132e8ca 256 maemo_cflags=`pkg-config --cflags hildon-1`
257 maemo_ldlibs=`pkg-config --libs hildon-1`
258 CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
07c13dfd 259 MAIN_LDLIBS="$MAIN_LDLIBS $maemo_ldlibs"
38c2028e 260 ;;
261libretro)
262 CFLAGS="$CFLAGS -fPIC"
263 LDFLAGS="$LDFLAGS -shared"
264 ;;
265esac
4132e8ca 266
07c13dfd 267# header/library presence tests
268check_zlib()
269{
270 cat > $TMPC <<EOF
271 #include <zlib.h>
272 void main() { uncompress(0, 0, 0, 0); }
273EOF
274 compile_binary
275}
276
277check_bzlib()
278{
279 cat > $TMPC <<EOF
280 #include <bzlib.h>
281 void main() { BZ2_bzBuffToBuffDecompress(0, 0, 0, 0, 0, 0); }
282EOF
283 compile_object
284}
285
286check_libpng()
287{
288 cat > $TMPC <<EOF
289 #include <png.h>
290 void main() { png_init_io(0, 0); }
291EOF
292 compile_binary
293}
294
295check_oss()
296{
297 cat > $TMPC <<EOF
298 #include <sys/soundcard.h>
299 #include <sys/ioctl.h>
300 void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
301EOF
302 compile_binary
303}
304
305check_alsa()
306{
307 cat > $TMPC <<EOF
308 #include <alsa/asoundlib.h>
309 void main() { snd_pcm_open(0, 0, 0, 0); }
310EOF
311 compile_binary "$@"
312}
313
314check_sdl()
315{
316 cat > $TMPC <<EOF
317 #include <SDL.h>
318 void main() { SDL_OpenAudio(0, 0); }
319EOF
320 compile_binary "$@"
321}
322
323check_zlib || fail "please install libz-dev"
324check_bzlib || fail "please install libbz2-dev"
325check_libpng || fail "please install libpng-dev"
326
327# find what audio support we can compile
328if [ "x$sound_drivers" = "x" ]; then
329 if check_oss; then sound_drivers="$sound_drivers oss"; fi
330 if check_alsa -lasound; then sound_drivers="$sound_drivers alsa"; fi
331 if check_sdl; then sound_drivers="$sound_drivers sdl"; fi
332fi
333
334if echo $sound_drivers | grep -q "\<oss\>"; then
335 check_oss || fail "oss support missing"
336fi
337if echo $sound_drivers | grep -q "\<alsa\>"; then
338 MAIN_LDLIBS="$MAIN_LDLIBS -lasound"
339 check_alsa || fail "please install libasound2-dev"
340fi
341if echo $sound_drivers | grep -q "\<sdl\>"; then
342 echo $MAIN_LDLIBS | grep -qi SDL || CFLAGS="$CFLAGS `sdl-config --cflags`"
343 echo $MAIN_LDLIBS | grep -qi SDL || MAIN_LDLIBS="$MAIN_LDLIBS `sdl-config --libs`"
344 check_sdl || fail "please install libsdl1.2-dev"
345fi
346
4132e8ca 347# check for tslib (only headers needed)
348if [ "x$have_tslib" = "x" ]; then
349 cat > $TMPC <<EOF
350 #include <tslib.h>
351 void test(struct ts_sample sample) {}
352EOF
353 if compile_object; then
354 have_tslib="yes"
355 else
356 have_tslib="no"
357 fi
358fi
359
dd4d5a35 360# check for GLES headers
361cat > $TMPC <<EOF
362#include <GLES/gl.h>
363#include <GLES/glext.h>
364#include <EGL/egl.h>
365void *test(void) {
366 return eglGetDisplay( (EGLNativeDisplayType)0 );
367}
368EOF
369if compile_object; then
370 plugins="$plugins plugins/gpu-gles/gpu_gles.so"
371fi
372
61bc6d40 373if [ "$have_arm_neon" = "yes" -a "$builtin_gpu" != "neon" ]; then
374 plugins="$plugins plugins/gpu_neon/gpu_neon.so"
375fi
376
dd4d5a35 377# short plugin list for display
378for p in $plugins; do
379 p1=`basename $p`
380 plugins_short="$p1 $plugins_short"
381done
382
4132e8ca 383# set things that failed to autodetect to "no"
384test "x$have_armv6" != "x" || have_armv6="no"
385test "x$have_armv7" != "x" || have_armv7="no"
386test "x$have_arm_neon" != "x" || have_arm_neon="no"
387
388echo "architecture $ARCH"
389echo "platform $platform"
61bc6d40 390echo "built-in GPU $builtin_gpu"
07c13dfd 391echo "sound drivers $sound_drivers"
dd4d5a35 392echo "plugins $plugins_short"
4132e8ca 393echo "C compiler $CC"
394echo "C compiler flags $CFLAGS"
07c13dfd 395echo "libraries $MAIN_LDLIBS"
7badc935 396echo "linker flags $LDFLAGS"
4132e8ca 397echo "enable dynarec $enable_dynarec"
398echo "ARMv7 optimizations $have_armv7"
399echo "enable ARM NEON $have_arm_neon"
400echo "tslib support $have_tslib"
401
402echo "# Automatically generated by configure" > $config_mak
403printf "# Configured with:" >> $config_mak
404printf " '%s'" "$0" "$@" >> $config_mak
405echo >> $config_mak
406
407echo "CC = $CC" >> $config_mak
ac6575cd 408echo "CXX = $CXX" >> $config_mak
4132e8ca 409echo "AS = $AS" >> $config_mak
410echo "CFLAGS += $CFLAGS" >> $config_mak
411echo "ASFLAGS += $ASFLAGS" >> $config_mak
412echo "LDFLAGS += $LDFLAGS" >> $config_mak
07c13dfd 413echo "MAIN_LDLIBS += $MAIN_LDLIBS" >> $config_mak
4132e8ca 414echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
415echo >> $config_mak
416
38c2028e 417if [ "$platform" = "libretro" ]; then
418 echo "TARGET = libretro.so" >> $config_mak
419fi
4132e8ca 420echo "ARCH = $ARCH" >> $config_mak
421echo "PLATFORM = $platform" >> $config_mak
61bc6d40 422echo "BUILTIN_GPU = $builtin_gpu" >> $config_mak
07c13dfd 423echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
dd4d5a35 424if [ "$ARCH" = "arm" ]; then
425 echo "PLUGINS = $plugins" >> $config_mak
426else
427 echo -n "PLUGINS =" >> $config_mak
428 for p in $plugins; do
429 echo -n " ${p}.${ARCH}" >> $config_mak
430 done
431 echo >> $config_mak
432fi
4132e8ca 433if [ "$have_armv6" = "yes" ]; then
434 echo "HAVE_ARMV6 = 1" >> $config_mak
435fi
436if [ "$have_armv7" = "yes" ]; then
437 echo "HAVE_ARMV7 = 1" >> $config_mak
438fi
439if [ "$have_arm_neon" = "yes" ]; then
440 echo "HAVE_NEON = 1" >> $config_mak
441fi
442if [ "$have_tslib" = "yes" ]; then
443 echo "HAVE_TSLIB = 1" >> $config_mak
444fi
445if [ "$enable_dynarec" = "yes" ]; then
446 echo "USE_DYNAREC = 1" >> $config_mak
447fi
448if [ "$drc_cache_base" = "yes" ]; then
449 echo "DRC_CACHE_BASE = 1" >> $config_mak
450fi
451
2e6189bc 452# use pandora's skin (for now)
453test -e skin || ln -s frontend/pandora/skin skin
454
4132e8ca 455# vim:shiftwidth=2:expandtab