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