add configure, revive pnd build, unify/refactor things
[picodrive.git] / configure
CommitLineData
d4d62665 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 pico/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"
35platform="generic"
36sound_driver_list="oss alsa sdl"
37sound_drivers=""
38have_armv5=""
39have_armv6=""
40have_armv7=""
41have_arm_neon=""
42have_tslib=""
43enable_dynarec="yes"
44need_sdl="no"
45need_xlib="no"
46# these are for known platforms
47optimize_cortexa8="no"
48optimize_arm926ej="no"
49
50# hardcoded stuff
51CC="${CC-${CROSS_COMPILE}gcc}"
52CXX="${CXX-${CROSS_COMPILE}g++}"
53AS="${AS-${CROSS_COMPILE}as}"
54MAIN_LDLIBS="$LDLIBS -lm"
55config_mak="config.mak"
56
57fail()
58{
59 echo "$@"
60 exit 1
61}
62
63# call during arg parsing, so that cmd line can override platform defaults
64set_platform()
65{
66 platform=$1
67 case "$platform" in
68 generic)
69 ;;
70 pandora)
71 sound_drivers="oss alsa"
72 optimize_cortexa8="yes"
73 have_arm_neon="yes"
74 ;;
75 *)
76 fail "unsupported platform: $platform"
77 ;;
78 esac
79}
80
81for opt do
82 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
83 case "$opt" in
84 --help|-h) show_help="yes"
85 ;;
86 --platform=*) set_platform "$optarg"
87 ;;
88 --sound-drivers=*) sound_drivers="$optarg"
89 ;;
90 --enable-neon) have_arm_neon="yes"
91 ;;
92 --disable-neon) have_arm_neon="no"
93 ;;
94 --disable-dynarec) enable_dynarec="no"
95 ;;
96 *) echo "ERROR: unknown option $opt"; show_help="yes"
97 ;;
98 esac
99done
100
101if [ "$show_help" = "yes" ]; then
102 echo "options:"
103 echo " --help print this message"
104 echo " --platform=NAME target platform [$platform]"
105 echo " available: $platform_list"
106 echo " --sound-drivers=LIST sound output drivers [guessed]"
107 echo " available: $sound_driver_list"
108 echo " --enable-neon"
109 echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
110 echo " --disable-dynarec disable dynamic recompiler"
111 echo " (dynarec is only available and enabled on ARM)"
112 echo "influential environment variables:"
113 echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS"
114 exit 1
115fi
116
117# validate selections
118if [ "x$sound_drivers" != "x" ]; then
119 for d in $sound_drivers; do
120 if ! echo $sound_driver_list | grep -q "\<$d\>"; then
121 fail "unsupported sound driver: $sound_driver"
122 fi
123 done
124fi
125
126if [ "$need_libpicofe" = "yes" ]; then
127 if ! test -f "frontend/libpicofe/README"; then
128 fail "libpicofe is missing, please run 'git submodule init && git submodule update'"
129 fi
130fi
131
132#if [ "$need_warm" = "yes" ]; then
133# if ! test -f "frontend/warm/README"; then
134# fail "wARM is missing, please run 'git submodule init && git submodule update'"
135# fi
136#fi
137
138# basic compiler test
139cat > $TMPC <<EOF
140int main(void) { return 0; }
141EOF
142if ! compile_binary; then
143 fail "compiler test failed, please check config.log"
144fi
145
146if [ -z "$ARCH" ]; then
147 ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
148fi
149
150case "$ARCH" in
151arm*)
152 # ARM stuff
153 ARCH="arm"
154
155 if [ "$optimize_cortexa8" = "yes" ]; then
156 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
157 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
158 fi
159 if [ "$optimize_arm926ej" = "yes" ]; then
160 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
161 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
162 fi
163
164 if [ "x$have_arm_neon" = "x" ]; then
165 # detect NEON from user-supplied cflags to enable asm code
166 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
167 fi
168 if [ "x$have_armv7" = "x" ]; then
169 if check_define HAVE_ARMV7; then
170 have_armv7="yes"
171 have_armv6="yes"
172 have_armv5="yes"
173 fi
174 fi
175 if [ "x$have_armv6" = "x" ]; then
176 if check_define HAVE_ARMV6; then
177 have_armv6="yes"
178 have_armv5="yes"
179 fi
180 fi
181 if [ "x$have_armv5" = "x" ]; then
182 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
183 fi
184
185 # automatically set mfpu and mfloat-abi if they are not set
186 if [ "$have_arm_neon" = "yes" ]; then
187 fpu="neon"
188 elif [ "$have_armv6" = "yes" ]; then
189 fpu="vfp"
190 fi
191 if [ "x$fpu" != "x" ]; then
192 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
193 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
194 floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true
195 if [ "$floatabi_set_by_gcc" != "yes" ]; then
196 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
197 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
198 fi
199 fi
200
201 # must disable thumb as recompiler can't handle it
202 if check_define __thumb__; then
203 CFLAGS="$CFLAGS -marm"
204 fi
205
206 # warn about common mistakes
207 if [ "$have_armv5" != "yes" ]; then
208 if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
209 echo "Warning: compiling for ARMv4, is that really what you want?"
210 echo "You probably should specify -mcpu= or -march= like this:"
211 echo " CFLAGS=-march=armv6 ./configure ..."
212 fi
213 fi
214 if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then
215 echo "Warning: compiling for NEON, but not ARMv7?"
216 echo "You probably want to specify -mcpu= or -march= like this:"
217 echo " CFLAGS=-march=armv7-a ./configure ..."
218 fi
219 ;;
220*)
221 # dynarec only available on ARM
222 enable_dynarec="no"
223 ;;
224esac
225
226case "$platform" in
227generic)
228 need_sdl="yes"
229 ;;
230esac
231
232# header/library presence tests
233check_zlib()
234{
235 cat > $TMPC <<EOF
236 #include <zlib.h>
237 int main(void) { uncompress(0, 0, 0, 0); }
238EOF
239 compile_binary
240}
241
242check_libpng()
243{
244 cat > $TMPC <<EOF
245 #include <png.h>
246 void main() { png_init_io(0, 0); }
247EOF
248 compile_binary
249}
250
251check_oss()
252{
253 cat > $TMPC <<EOF
254 #include <sys/soundcard.h>
255 #include <sys/ioctl.h>
256 void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
257EOF
258 compile_binary
259}
260
261check_alsa()
262{
263 cat > $TMPC <<EOF
264 #include <alsa/asoundlib.h>
265 void main() { snd_pcm_open(0, 0, 0, 0); }
266EOF
267 compile_binary "$@"
268}
269
270check_sdl()
271{
272 cat > $TMPC <<EOF
273 #include <SDL.h>
274 void main() { SDL_OpenAudio(0, 0); }
275EOF
276 compile_binary "$@"
277}
278
279#MAIN_LDLIBS="$MAIN_LDLIBS -lz"
280#check_zlib || fail "please install zlib (libz-dev)"
281
282MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
283check_libpng || fail "please install libpng (libpng-dev)"
284
285# find what audio support we can compile
286if [ "x$sound_drivers" = "x" ]; then
287 if check_oss; then sound_drivers="$sound_drivers oss"; fi
288 if check_alsa -lasound; then
289 sound_drivers="$sound_drivers alsa"
290 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
291 fi
292 if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
293 sound_drivers="$sound_drivers sdl"
294 need_sdl="yes"
295 fi
296else
297 if echo $sound_drivers | grep -q "\<oss\>"; then
298 check_oss || fail "oss support is missing"
299 fi
300 if echo $sound_drivers | grep -q "\<alsa\>"; then
301 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
302 check_alsa || fail "please install libasound2-dev"
303 fi
304fi
305
306if [ "$need_sdl" = "yes" ]; then
307 which sdl-config > /dev/null || \
308 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
309 CFLAGS="$CFLAGS `sdl-config --cflags`"
310 MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
311 check_sdl || fail "please install libsdl (libsdl1.2-dev)"
312fi
313
314cat > $TMPC <<EOF
315void test(void *f, void *d) { fread(d, 1, 1, f); }
316EOF
317if compile_object -Wno-unused-result; then
318 CFLAGS="$CFLAGS -Wno-unused-result"
319fi
320
321# set things that failed to autodetect to "no"
322test "x$have_armv6" != "x" || have_armv6="no"
323test "x$have_armv7" != "x" || have_armv7="no"
324test "x$have_arm_neon" != "x" || have_arm_neon="no"
325
326echo "architecture $ARCH"
327echo "platform $platform"
328echo "sound drivers $sound_drivers"
329echo "C compiler $CC"
330echo "C compiler flags $CFLAGS"
331echo "libraries $MAIN_LDLIBS"
332echo "linker flags $LDFLAGS"
333echo "enable dynarec $enable_dynarec"
334# echo "ARMv7 optimizations $have_armv7"
335# echo "enable ARM NEON $have_arm_neon"
336
337echo "# Automatically generated by configure" > $config_mak
338printf "# Configured with:" >> $config_mak
339printf " '%s'" "$0" "$@" >> $config_mak
340echo >> $config_mak
341
342echo "CC = $CC" >> $config_mak
343echo "CXX = $CXX" >> $config_mak
344echo "AS = $AS" >> $config_mak
345echo "CFLAGS += $CFLAGS" >> $config_mak
346echo "ASFLAGS += $ASFLAGS" >> $config_mak
347echo "LDFLAGS += $LDFLAGS" >> $config_mak
348echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
349echo >> $config_mak
350
351echo "ARCH = $ARCH" >> $config_mak
352echo "PLATFORM = $platform" >> $config_mak
353echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
354if [ "$have_arm_neon" = "yes" ]; then
355 echo "HAVE_NEON = 1" >> $config_mak
356fi
357if [ "$enable_dynarec" = "yes" ]; then
358 echo "USE_DYNAREC = 1" >> $config_mak
359fi
360
361# use pandora's skin (for now)
362test -e skin || ln -s platform/pandora/skin skin
363
364# vim:shiftwidth=2:expandtab