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