d4d62665 |
1 | #!/bin/sh |
2 | # some elements originated from qemu configure |
3 | set -e |
4 | |
5 | TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c" |
6 | TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o" |
7 | TMPB="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}" |
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 | { |
20 | c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $MAIN_LDLIBS $@" |
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 | |
34 | platform_list="generic pandora" |
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="" |
42 | have_tslib="" |
43 | enable_dynarec="yes" |
44 | need_sdl="no" |
45 | need_xlib="no" |
46 | # these are for known platforms |
47 | optimize_cortexa8="no" |
48 | optimize_arm926ej="no" |
49 | |
50 | # hardcoded stuff |
51 | CC="${CC-${CROSS_COMPILE}gcc}" |
52 | CXX="${CXX-${CROSS_COMPILE}g++}" |
53 | AS="${AS-${CROSS_COMPILE}as}" |
54 | MAIN_LDLIBS="$LDLIBS -lm" |
55 | config_mak="config.mak" |
56 | |
57 | fail() |
58 | { |
59 | echo "$@" |
60 | exit 1 |
61 | } |
62 | |
63 | # call during arg parsing, so that cmd line can override platform defaults |
64 | set_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 | |
81 | for 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 |
99 | done |
100 | |
101 | if [ "$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 |
115 | fi |
116 | |
117 | # validate selections |
118 | if [ "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 |
124 | fi |
125 | |
126 | if [ "$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 |
130 | fi |
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 |
139 | cat > $TMPC <<EOF |
140 | int main(void) { return 0; } |
141 | EOF |
142 | if ! compile_binary; then |
143 | fail "compiler test failed, please check config.log" |
144 | fi |
145 | |
146 | if [ -z "$ARCH" ]; then |
147 | ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'` |
148 | fi |
149 | |
150 | case "$ARCH" in |
151 | arm*) |
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 | ;; |
224 | esac |
225 | |
226 | case "$platform" in |
227 | generic) |
228 | need_sdl="yes" |
229 | ;; |
230 | esac |
231 | |
232 | # header/library presence tests |
233 | check_zlib() |
234 | { |
235 | cat > $TMPC <<EOF |
236 | #include <zlib.h> |
237 | int main(void) { uncompress(0, 0, 0, 0); } |
238 | EOF |
239 | compile_binary |
240 | } |
241 | |
242 | check_libpng() |
243 | { |
244 | cat > $TMPC <<EOF |
245 | #include <png.h> |
246 | void main() { png_init_io(0, 0); } |
247 | EOF |
248 | compile_binary |
249 | } |
250 | |
251 | check_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); } |
257 | EOF |
258 | compile_binary |
259 | } |
260 | |
261 | check_alsa() |
262 | { |
263 | cat > $TMPC <<EOF |
264 | #include <alsa/asoundlib.h> |
265 | void main() { snd_pcm_open(0, 0, 0, 0); } |
266 | EOF |
267 | compile_binary "$@" |
268 | } |
269 | |
270 | check_sdl() |
271 | { |
272 | cat > $TMPC <<EOF |
273 | #include <SDL.h> |
274 | void main() { SDL_OpenAudio(0, 0); } |
275 | EOF |
276 | compile_binary "$@" |
277 | } |
278 | |
279 | #MAIN_LDLIBS="$MAIN_LDLIBS -lz" |
280 | #check_zlib || fail "please install zlib (libz-dev)" |
281 | |
282 | MAIN_LDLIBS="-lpng $MAIN_LDLIBS" |
283 | check_libpng || fail "please install libpng (libpng-dev)" |
284 | |
285 | # find what audio support we can compile |
286 | if [ "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 |
296 | else |
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 |
304 | fi |
305 | |
306 | if [ "$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)" |
312 | fi |
313 | |
314 | cat > $TMPC <<EOF |
315 | void test(void *f, void *d) { fread(d, 1, 1, f); } |
316 | EOF |
317 | if compile_object -Wno-unused-result; then |
318 | CFLAGS="$CFLAGS -Wno-unused-result" |
319 | fi |
320 | |
321 | # set things that failed to autodetect to "no" |
322 | test "x$have_armv6" != "x" || have_armv6="no" |
323 | test "x$have_armv7" != "x" || have_armv7="no" |
324 | test "x$have_arm_neon" != "x" || have_arm_neon="no" |
325 | |
326 | echo "architecture $ARCH" |
327 | echo "platform $platform" |
328 | echo "sound drivers $sound_drivers" |
329 | echo "C compiler $CC" |
330 | echo "C compiler flags $CFLAGS" |
331 | echo "libraries $MAIN_LDLIBS" |
332 | echo "linker flags $LDFLAGS" |
333 | echo "enable dynarec $enable_dynarec" |
334 | # echo "ARMv7 optimizations $have_armv7" |
335 | # echo "enable ARM NEON $have_arm_neon" |
336 | |
337 | echo "# Automatically generated by configure" > $config_mak |
338 | printf "# Configured with:" >> $config_mak |
339 | printf " '%s'" "$0" "$@" >> $config_mak |
340 | echo >> $config_mak |
341 | |
342 | echo "CC = $CC" >> $config_mak |
343 | echo "CXX = $CXX" >> $config_mak |
344 | echo "AS = $AS" >> $config_mak |
345 | echo "CFLAGS += $CFLAGS" >> $config_mak |
346 | echo "ASFLAGS += $ASFLAGS" >> $config_mak |
347 | echo "LDFLAGS += $LDFLAGS" >> $config_mak |
348 | echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak |
349 | echo >> $config_mak |
350 | |
351 | echo "ARCH = $ARCH" >> $config_mak |
352 | echo "PLATFORM = $platform" >> $config_mak |
353 | echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak |
354 | if [ "$have_arm_neon" = "yes" ]; then |
355 | echo "HAVE_NEON = 1" >> $config_mak |
356 | fi |
357 | if [ "$enable_dynarec" = "yes" ]; then |
358 | echo "USE_DYNAREC = 1" >> $config_mak |
359 | fi |
360 | |
361 | # use pandora's skin (for now) |
362 | test -e skin || ln -s platform/pandora/skin skin |
363 | |
364 | # vim:shiftwidth=2:expandtab |