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