configure 12 KB

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