frontend: initial libretro support
[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"
7trap "rm -f $TMPC $TMPO" EXIT INT QUIT TERM
8rm -f config.log
9
10compile_object()
11{
12 c="$CC $CFLAGS -c $TMPC -o $TMPO $1"
13 echo $c >> config.log
14 $c >> config.log 2>&1
15}
16
17check_define()
18{
19 echo "" > $TMPC
20 $CC -E -dD $CFLAGS $TMPC | grep -q $1 || return 1
21 return 0
22}
23
24# setting options to "yes" or "no" will make that choice default,
25# "" means "autodetect".
26
38c2028e 27platform_list="generic pandora maemo caanoo libretro"
4132e8ca 28platform="generic"
38c2028e 29sound_driver_list="oss alsa libretro none"
4132e8ca 30sound_driver="alsa"
dd4d5a35 31plugins="plugins/spunull/spunull.so \
32plugins/dfxvideo/gpu_peops.so plugins/gpu_unai/gpu_unai.so"
4132e8ca 33ram_fixed="no"
34drc_cache_base="no"
35have_armv6=""
36have_armv7=""
37have_arm_neon=""
38have_tslib=""
39enable_dynarec="yes"
40# these are for known platforms
41optimize_cortexa8="no"
42optimize_arm926ej="no"
43
44# hardcoded stuff
45CC="${CC-${CROSS_COMPILE}gcc}"
ac6575cd 46CXX="${CXX-${CROSS_COMPILE}g++}"
4132e8ca 47AS="${AS-${CROSS_COMPILE}as}"
48AR="${AS-${CROSS_COMPILE}ar}"
49config_mak="config.mak"
50
51# call during arg parsing, so that cmd line can override platform defaults
52set_platform()
53{
54 platform=$1
55 case "$platform" in
56 generic)
57 ;;
58 pandora)
59 sound_driver="oss"
60 ram_fixed="yes"
61 drc_cache_base="yes"
62 optimize_cortexa8="yes"
63 have_arm_neon="yes"
64 ;;
65 maemo)
66 ram_fixed="yes"
67 drc_cache_base="yes"
68 optimize_cortexa8="yes"
69 have_arm_neon="yes"
70 ;;
71 caanoo)
72 sound_driver="oss"
73 ram_fixed="yes"
74 drc_cache_base="yes"
75 optimize_arm926ej="yes"
76 ;;
38c2028e 77 libretro)
78 sound_driver="libretro"
79 ;;
4132e8ca 80 *)
81 echo "unsupported platform: $platform"
82 exit 1
83 ;;
84 esac
85}
86
87for opt do
88 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
89 case "$opt" in
90 --help|-h) show_help="yes"
91 ;;
92 --platform=*) set_platform "$optarg"
93 ;;
94 --sound-driver=*) sound_driver="$optarg"
95 ;;
96 --enable-neon) have_arm_neon="yes"
97 ;;
98 --disable-neon) have_arm_neon="no"
99 ;;
100 --disable-dynarec) enable_dynarec="no"
101 ;;
102 *) echo "ERROR: unknown option $opt"; show_help="yes"
103 ;;
104 esac
105done
106
107if [ "$show_help" = "yes" ]; then
108 echo "options:"
109 echo " --help print this message"
110 echo " --platform=NAME target platform [$platform]"
111 echo " available: $platform_list"
112 echo " --sound-driver=NAME sound output driver [$sound_driver]"
113 echo " available: $sound_driver_list"
114 echo " --enable-neon"
115 echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
116 echo " --disable-dynarec disable dynamic recompiler"
117 echo " (dynarec is only available and enabled on ARM)"
118 echo "influential environment variables:"
ac6575cd 119 echo " CROSS_COMPILE CC CXX AS AR CFLAGS ASFLAGS LDFLAGS LDLIBS"
4132e8ca 120 exit 1
121fi
122
123case "$sound_driver" in
38c2028e 124oss|alsa|libretro|none)
4132e8ca 125 ;;
126*)
127 echo "unsupported sound driver: $sound_driver"
128 exit 1
129 ;;
130esac
131
132if [ -z "$ARCH" ]; then
133 ARCH=`$CC -v 2>&1 | grep -i 'target:' | awk '{print $2}' \
134 | awk -F '-' '{print $1}'`
135fi
136
137# ARM stuff
138if [ "$ARCH" = "arm" ]; then
139 if [ "$optimize_cortexa8" = "yes" ]; then
140 # both: -mfpu=neon
141 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
142 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
143 fi
144 if [ "$optimize_arm926ej" = "yes" ]; then
145 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
146 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
147 fi
148
149 if [ "x$have_arm_neon" = "x" ]; then
150 # detect NEON from user-supplied cflags to enable asm code
151 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
152 fi
153 if [ "x$have_armv6" = "x" ]; then
154 have_armv6=`check_define __ARM_ARCH_6 && echo yes` || true
155 fi
156 if [ "x$have_armv7" = "x" ]; then
157 if check_define __ARM_ARCH_7A__; then
158 have_armv6="yes"
159 have_armv7="yes"
160 fi
161 fi
162
163 # set mfpu and mfloat-abi if they are not set
164 if [ "$have_arm_neon" = "yes" ]; then
165 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=neon"
166 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=neon"
167 elif [ "$have_armv6" = "yes" ]; then
168 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=vfp"
169 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=vfp"
170 fi
171 if [ "$have_armv6" = "yes" ]; then
172 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
173 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
174 fi
175
96751f36 176 # must disable -mthumb as recompiler can't handle it
177 if check_define __thumb__; then
178 CFLAGS="$CFLAGS -mno-thumb"
179 fi
180
4132e8ca 181 if [ "$have_armv7" = "yes" ]; then
182 ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=1"
183 else
184 ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=0"
185 fi
186else
187 # dynarec only available on ARM
188 enable_dynarec="no"
189fi
190
191if [ "$ARCH" = "x86_64" ]; then
192 # currently we are full of 32bit assumptions,
193 # at least savestate compatibility will break without these
194 CFLAGS="$CFLAGS -m32"
195 LDFLAGS="$LDFLAGS -m32"
196fi
197
198# supposedly we can avoid -fPIC on armv5 for slightly better performace?
199if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
200 PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
201fi
202
203if [ "$ram_fixed" = "yes" ]; then
204 CFLAGS="$CFLAGS -DRAM_FIXED"
205fi
206
38c2028e 207case "$platform" in
208generic)
7badc935 209 generic_cflags=`sdl-config --cflags`
210 generic_ldlibs=`sdl-config --libs`
211 CFLAGS="$CFLAGS $generic_cflags"
212 LDFLAGS="$LDFLAGS $generic_ldlibs"
38c2028e 213 ;;
214maemo)
4132e8ca 215 maemo_cflags=`pkg-config --cflags hildon-1`
216 maemo_ldlibs=`pkg-config --libs hildon-1`
217 CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
218 LDFLAGS="$LDFLAGS $maemo_ldlibs"
38c2028e 219 ;;
220libretro)
221 CFLAGS="$CFLAGS -fPIC"
222 LDFLAGS="$LDFLAGS -shared"
223 ;;
224esac
4132e8ca 225
226# check for tslib (only headers needed)
227if [ "x$have_tslib" = "x" ]; then
228 cat > $TMPC <<EOF
229 #include <tslib.h>
230 void test(struct ts_sample sample) {}
231EOF
232 if compile_object; then
233 have_tslib="yes"
234 else
235 have_tslib="no"
236 fi
237fi
238
dd4d5a35 239# check for GLES headers
240cat > $TMPC <<EOF
241#include <GLES/gl.h>
242#include <GLES/glext.h>
243#include <EGL/egl.h>
244void *test(void) {
245 return eglGetDisplay( (EGLNativeDisplayType)0 );
246}
247EOF
248if compile_object; then
249 plugins="$plugins plugins/gpu-gles/gpu_gles.so"
250fi
251
252# short plugin list for display
253for p in $plugins; do
254 p1=`basename $p`
255 plugins_short="$p1 $plugins_short"
256done
257
4132e8ca 258# set things that failed to autodetect to "no"
259test "x$have_armv6" != "x" || have_armv6="no"
260test "x$have_armv7" != "x" || have_armv7="no"
261test "x$have_arm_neon" != "x" || have_arm_neon="no"
262
263echo "architecture $ARCH"
264echo "platform $platform"
265echo "sound driver $sound_driver"
dd4d5a35 266echo "plugins $plugins_short"
4132e8ca 267echo "C compiler $CC"
268echo "C compiler flags $CFLAGS"
7badc935 269echo "linker flags $LDFLAGS"
4132e8ca 270echo "enable dynarec $enable_dynarec"
271echo "ARMv7 optimizations $have_armv7"
272echo "enable ARM NEON $have_arm_neon"
273echo "tslib support $have_tslib"
274
275echo "# Automatically generated by configure" > $config_mak
276printf "# Configured with:" >> $config_mak
277printf " '%s'" "$0" "$@" >> $config_mak
278echo >> $config_mak
279
280echo "CC = $CC" >> $config_mak
ac6575cd 281echo "CXX = $CXX" >> $config_mak
4132e8ca 282echo "AS = $AS" >> $config_mak
283echo "CFLAGS += $CFLAGS" >> $config_mak
284echo "ASFLAGS += $ASFLAGS" >> $config_mak
285echo "LDFLAGS += $LDFLAGS" >> $config_mak
286echo "LDLIBS += $LDLIBS" >> $config_mak
287echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
288echo >> $config_mak
289
38c2028e 290if [ "$platform" = "libretro" ]; then
291 echo "TARGET = libretro.so" >> $config_mak
292fi
4132e8ca 293echo "ARCH = $ARCH" >> $config_mak
294echo "PLATFORM = $platform" >> $config_mak
295case "$sound_driver" in
296oss)
297 echo "USE_OSS = 1" >> $config_mak
298 ;;
299alsa)
300 echo "USE_ALSA = 1" >> $config_mak
301 ;;
302none)
303 echo "USE_NO_SOUND = 1" >> $config_mak
304 ;;
305esac
dd4d5a35 306if [ "$ARCH" = "arm" ]; then
307 echo "PLUGINS = $plugins" >> $config_mak
308else
309 echo -n "PLUGINS =" >> $config_mak
310 for p in $plugins; do
311 echo -n " ${p}.${ARCH}" >> $config_mak
312 done
313 echo >> $config_mak
314fi
4132e8ca 315if [ "$have_armv6" = "yes" ]; then
316 echo "HAVE_ARMV6 = 1" >> $config_mak
317fi
318if [ "$have_armv7" = "yes" ]; then
319 echo "HAVE_ARMV7 = 1" >> $config_mak
320fi
321if [ "$have_arm_neon" = "yes" ]; then
322 echo "HAVE_NEON = 1" >> $config_mak
323fi
324if [ "$have_tslib" = "yes" ]; then
325 echo "HAVE_TSLIB = 1" >> $config_mak
326fi
327if [ "$enable_dynarec" = "yes" ]; then
328 echo "USE_DYNAREC = 1" >> $config_mak
329fi
330if [ "$drc_cache_base" = "yes" ]; then
331 echo "DRC_CACHE_BASE = 1" >> $config_mak
332fi
333
2e6189bc 334# use pandora's skin (for now)
335test -e skin || ln -s frontend/pandora/skin skin
336
4132e8ca 337# vim:shiftwidth=2:expandtab