configure 9.9 KB

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