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