configure 9.7 KB

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