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