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