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