frontend: some menu adjustments
[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"
31ram_fixed="no"
32drc_cache_base="no"
33have_armv6=""
34have_armv7=""
35have_arm_neon=""
36have_tslib=""
37enable_dynarec="yes"
38# these are for known platforms
39optimize_cortexa8="no"
40optimize_arm926ej="no"
41
42# hardcoded stuff
43CC="${CC-${CROSS_COMPILE}gcc}"
ac6575cd 44CXX="${CXX-${CROSS_COMPILE}g++}"
4132e8ca 45AS="${AS-${CROSS_COMPILE}as}"
46AR="${AS-${CROSS_COMPILE}ar}"
47config_mak="config.mak"
48
49# call during arg parsing, so that cmd line can override platform defaults
50set_platform()
51{
52 platform=$1
53 case "$platform" in
54 generic)
55 ;;
56 pandora)
57 sound_driver="oss"
58 ram_fixed="yes"
59 drc_cache_base="yes"
60 optimize_cortexa8="yes"
61 have_arm_neon="yes"
62 ;;
63 maemo)
64 ram_fixed="yes"
65 drc_cache_base="yes"
66 optimize_cortexa8="yes"
67 have_arm_neon="yes"
68 ;;
69 caanoo)
70 sound_driver="oss"
71 ram_fixed="yes"
72 drc_cache_base="yes"
73 optimize_arm926ej="yes"
74 ;;
75 *)
76 echo "unsupported platform: $platform"
77 exit 1
78 ;;
79 esac
80}
81
82for opt do
83 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
84 case "$opt" in
85 --help|-h) show_help="yes"
86 ;;
87 --platform=*) set_platform "$optarg"
88 ;;
89 --sound-driver=*) sound_driver="$optarg"
90 ;;
91 --enable-neon) have_arm_neon="yes"
92 ;;
93 --disable-neon) have_arm_neon="no"
94 ;;
95 --disable-dynarec) enable_dynarec="no"
96 ;;
97 *) echo "ERROR: unknown option $opt"; show_help="yes"
98 ;;
99 esac
100done
101
102if [ "$show_help" = "yes" ]; then
103 echo "options:"
104 echo " --help print this message"
105 echo " --platform=NAME target platform [$platform]"
106 echo " available: $platform_list"
107 echo " --sound-driver=NAME sound output driver [$sound_driver]"
108 echo " available: $sound_driver_list"
109 echo " --enable-neon"
110 echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
111 echo " --disable-dynarec disable dynamic recompiler"
112 echo " (dynarec is only available and enabled on ARM)"
113 echo "influential environment variables:"
ac6575cd 114 echo " CROSS_COMPILE CC CXX AS AR CFLAGS ASFLAGS LDFLAGS LDLIBS"
4132e8ca 115 exit 1
116fi
117
118case "$sound_driver" in
119oss|alsa|none)
120 ;;
121*)
122 echo "unsupported sound driver: $sound_driver"
123 exit 1
124 ;;
125esac
126
127if [ -z "$ARCH" ]; then
128 ARCH=`$CC -v 2>&1 | grep -i 'target:' | awk '{print $2}' \
129 | awk -F '-' '{print $1}'`
130fi
131
132# ARM stuff
133if [ "$ARCH" = "arm" ]; then
134 if [ "$optimize_cortexa8" = "yes" ]; then
135 # both: -mfpu=neon
136 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
137 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
138 fi
139 if [ "$optimize_arm926ej" = "yes" ]; then
140 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
141 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
142 fi
143
144 if [ "x$have_arm_neon" = "x" ]; then
145 # detect NEON from user-supplied cflags to enable asm code
146 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
147 fi
148 if [ "x$have_armv6" = "x" ]; then
149 have_armv6=`check_define __ARM_ARCH_6 && echo yes` || true
150 fi
151 if [ "x$have_armv7" = "x" ]; then
152 if check_define __ARM_ARCH_7A__; then
153 have_armv6="yes"
154 have_armv7="yes"
155 fi
156 fi
157
158 # set mfpu and mfloat-abi if they are not set
159 if [ "$have_arm_neon" = "yes" ]; then
160 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=neon"
161 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=neon"
162 elif [ "$have_armv6" = "yes" ]; then
163 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=vfp"
164 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=vfp"
165 fi
166 if [ "$have_armv6" = "yes" ]; then
167 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
168 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
169 fi
170
171 if [ "$have_armv7" = "yes" ]; then
172 ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=1"
173 else
174 ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=0"
175 fi
176else
177 # dynarec only available on ARM
178 enable_dynarec="no"
179fi
180
181if [ "$ARCH" = "x86_64" ]; then
182 # currently we are full of 32bit assumptions,
183 # at least savestate compatibility will break without these
184 CFLAGS="$CFLAGS -m32"
185 LDFLAGS="$LDFLAGS -m32"
186fi
187
188# supposedly we can avoid -fPIC on armv5 for slightly better performace?
189if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
190 PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
191fi
192
193if [ "$ram_fixed" = "yes" ]; then
194 CFLAGS="$CFLAGS -DRAM_FIXED"
195fi
196
7badc935 197if [ "$platform" = "generic" ]; then
198 generic_cflags=`sdl-config --cflags`
199 generic_ldlibs=`sdl-config --libs`
200 CFLAGS="$CFLAGS $generic_cflags"
201 LDFLAGS="$LDFLAGS $generic_ldlibs"
202elif [ "$platform" = "maemo" ]; then
4132e8ca 203 maemo_cflags=`pkg-config --cflags hildon-1`
204 maemo_ldlibs=`pkg-config --libs hildon-1`
205 CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
206 LDFLAGS="$LDFLAGS $maemo_ldlibs"
207fi
208
209# check for tslib (only headers needed)
210if [ "x$have_tslib" = "x" ]; then
211 cat > $TMPC <<EOF
212 #include <tslib.h>
213 void test(struct ts_sample sample) {}
214EOF
215 if compile_object; then
216 have_tslib="yes"
217 else
218 have_tslib="no"
219 fi
220fi
221
222# set things that failed to autodetect to "no"
223test "x$have_armv6" != "x" || have_armv6="no"
224test "x$have_armv7" != "x" || have_armv7="no"
225test "x$have_arm_neon" != "x" || have_arm_neon="no"
226
227echo "architecture $ARCH"
228echo "platform $platform"
229echo "sound driver $sound_driver"
230echo "C compiler $CC"
231echo "C compiler flags $CFLAGS"
7badc935 232echo "linker flags $LDFLAGS"
4132e8ca 233echo "enable dynarec $enable_dynarec"
234echo "ARMv7 optimizations $have_armv7"
235echo "enable ARM NEON $have_arm_neon"
236echo "tslib support $have_tslib"
237
238echo "# Automatically generated by configure" > $config_mak
239printf "# Configured with:" >> $config_mak
240printf " '%s'" "$0" "$@" >> $config_mak
241echo >> $config_mak
242
243echo "CC = $CC" >> $config_mak
ac6575cd 244echo "CXX = $CXX" >> $config_mak
4132e8ca 245echo "AS = $AS" >> $config_mak
246echo "CFLAGS += $CFLAGS" >> $config_mak
247echo "ASFLAGS += $ASFLAGS" >> $config_mak
248echo "LDFLAGS += $LDFLAGS" >> $config_mak
249echo "LDLIBS += $LDLIBS" >> $config_mak
250echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
251echo >> $config_mak
252
253echo "ARCH = $ARCH" >> $config_mak
254echo "PLATFORM = $platform" >> $config_mak
255case "$sound_driver" in
256oss)
257 echo "USE_OSS = 1" >> $config_mak
258 ;;
259alsa)
260 echo "USE_ALSA = 1" >> $config_mak
261 ;;
262none)
263 echo "USE_NO_SOUND = 1" >> $config_mak
264 ;;
265esac
266if [ "$have_armv6" = "yes" ]; then
267 echo "HAVE_ARMV6 = 1" >> $config_mak
268fi
269if [ "$have_armv7" = "yes" ]; then
270 echo "HAVE_ARMV7 = 1" >> $config_mak
271fi
272if [ "$have_arm_neon" = "yes" ]; then
273 echo "HAVE_NEON = 1" >> $config_mak
274fi
275if [ "$have_tslib" = "yes" ]; then
276 echo "HAVE_TSLIB = 1" >> $config_mak
277fi
278if [ "$enable_dynarec" = "yes" ]; then
279 echo "USE_DYNAREC = 1" >> $config_mak
280fi
281if [ "$drc_cache_base" = "yes" ]; then
282 echo "DRC_CACHE_BASE = 1" >> $config_mak
283fi
284
285# vim:shiftwidth=2:expandtab