configure 14 KB

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