configure 14 KB

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