configure 10 KB

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