configure 13 KB

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