configure 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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="sdl"
  39. have_armv5=""
  40. have_armv6=""
  41. have_armv7="yes"
  42. have_arm_oabi=""
  43. have_arm_neon="yes"
  44. have_libavcodec=""
  45. have_libchdr=""
  46. need_sdl="yes"
  47. need_xlib="no"
  48. need_zlib="no"
  49. # these are for known platforms
  50. optimize_cortexa8="no"
  51. optimize_cortexa7="no"
  52. optimize_arm1176jzf="no"
  53. optimize_arm926ej="no"
  54. optimize_arm920="no"
  55. # hardcoded stuff
  56. CC="${CC-${CROSS_COMPILE}gcc}"
  57. CXX="${CXX-${CROSS_COMPILE}g++}"
  58. AS="${AS-${CROSS_COMPILE}as}"
  59. STRIP="${STRIP-${CROSS_COMPILE}strip}"
  60. SYSROOT=`$CC $CFLAGS $LDFLAGS --print-sysroot 2> /dev/null || true`
  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*/sdl-config 2>/dev/null | grep /bin/sdl-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. #test -n "$SDL_CONFIG" || SDL_CONFIG="$(ls $SYSROOT/*/*bin*/sdl2-config 2>/dev/null | grep /bin/sdl2-config | head -n 1)"
  65. SDLVERSION=sdl && echo $SDL_CONFIG | grep -q sdl2 && SDLVERSION=sdl2
  66. MAIN_LDLIBS="$LDLIBS -lm"
  67. config_mak="config.mak"
  68. fail()
  69. {
  70. echo "$@"
  71. exit 1
  72. }
  73. # call during arg parsing, so that cmd line can override platform defaults
  74. set_platform()
  75. {
  76. platform=$1
  77. case "$platform" in
  78. rpi1)
  79. optimize_arm1176jzf="yes"
  80. ;;
  81. rpi2)
  82. optimize_cortexa7="yes"
  83. have_arm_neon="yes"
  84. ;;
  85. generic)
  86. ;;
  87. dingux)
  88. # dingoo a320, ritmix rzx-50, the like. all have Ingenic MIPS cpu <= JZ4755
  89. sound_drivers="sdl"
  90. # use static linking since the lib situation is ... let's say vague
  91. LDFLAGS="$LDFLAGS -static"
  92. # uses a predecessor of opendingux
  93. CFLAGS="$CFLAGS -D__DINGUX__ -march=mips32 -msoft-float"
  94. platform="opendingux"
  95. ;;
  96. retrofw)
  97. # devices using retrofw. AFAIK all have Ingenic MIPS JZ4760 with fpu
  98. sound_drivers="sdl"
  99. # uses it's own modified version of opendingux
  100. CFLAGS="$CFLAGS -D__RETROFW__ -march=mips32"
  101. platform="opendingux"
  102. ;;
  103. opendingux | gcw0 | rg350)
  104. # more modern devices using opendingux, with Ingenic MIPS JZ4770 or newer
  105. sound_drivers="sdl"
  106. # mostly based on opendingux for gcw0, save device type as C define.
  107. CFLAGS="$CFLAGS -D__`echo $platform | tr '[a-z]' '[A-Z]'`__ -march=mips32r2"
  108. platform="opendingux"
  109. ;;
  110. pandora)
  111. sound_drivers="oss alsa"
  112. optimize_cortexa8="yes"
  113. have_arm_neon="yes"
  114. have_libavcodec="yes"
  115. ;;
  116. gp2x | wiz | caanoo)
  117. sound_drivers="oss"
  118. optimize_arm920="yes"
  119. # compile for OABI if toolchain provides it (faster code on caanoo)
  120. have_arm_oabi="yes"
  121. # always use static linking, since caanoo doesn't have OABI libs. Moreover,
  122. # dynamic linking slows Wiz 1-10%, and libm on F100 isn't compatible
  123. LDFLAGS="$LDFLAGS -static"
  124. # unified binary for all of them. picodrive detects device type for itself.
  125. CFLAGS="$CFLAGS -D__GP2X__"
  126. platform="gp2x"
  127. ;;
  128. psp)
  129. # use newlib
  130. SYSLIBS="-lc -lpspuser -lpspkernel"
  131. CFLAGS="$CFLAGS -D__PSP__"
  132. ARCH=mipsel
  133. ;;
  134. *)
  135. fail "unsupported platform: $platform"
  136. ;;
  137. esac
  138. }
  139. for opt do
  140. optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
  141. case "$opt" in
  142. --help|-h) show_help="yes"
  143. ;;
  144. --platform=*) set_platform "$optarg"
  145. ;;
  146. --sound-drivers=*) sound_drivers="$optarg"
  147. ;;
  148. --with-libavcodec=*) have_libavcodec="$optarg"
  149. ;;
  150. *) echo "ERROR: unknown option $opt"; show_help="yes"
  151. ;;
  152. esac
  153. done
  154. if [ "$show_help" = "yes" ]; then
  155. echo "options:"
  156. echo " --help print this message"
  157. echo " --platform=NAME target platform [$platform]"
  158. echo " available: $platform_list"
  159. echo " --sound-drivers=LIST sound output drivers [guessed]"
  160. echo " available: $sound_driver_list"
  161. echo " --with-libavcodec=yes|no use libavcodec for mp3 decoding"
  162. echo "influential environment variables:"
  163. echo " CROSS_COMPILE CC CXX AS STRIP CFLAGS ASFLAGS LDFLAGS LDLIBS"
  164. exit 1
  165. fi
  166. # validate selections
  167. if [ "x$sound_drivers" != "x" ]; then
  168. for d in $sound_drivers; do
  169. if ! echo $sound_driver_list | grep -q "\<$d\>"; then
  170. fail "unsupported sound driver: $sound_driver"
  171. fi
  172. done
  173. fi
  174. if ! test -f "platform/libpicofe/README"; then
  175. fail "libpicofe is missing, please run 'git submodule update --init'"
  176. fi
  177. #if [ "$need_warm" = "yes" ]; then
  178. # if ! test -f "frontend/warm/README"; then
  179. # fail "wARM is missing, please run 'git submodule init && git submodule update'"
  180. # fi
  181. #fi
  182. if [ -z "$ARCH" ]; then
  183. ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
  184. fi
  185. # CPU/ABI stuff first, else compile test may fail
  186. case "$ARCH" in
  187. arm*)
  188. # ARM stuff
  189. ARCH="arm"
  190. if [ "$optimize_cortexa8" = "yes" ]; then
  191. CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
  192. ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
  193. fi
  194. if [ "$optimize_cortexa7" = "yes" ]; then
  195. CFLAGS="$CFLAGS -mcpu=cortex-a7"
  196. ASFLAGS="$ASFLAGS -mcpu=cortex-a7"
  197. fi
  198. if [ "$optimize_arm1176jzf" = "yes" ]; then
  199. CFLAGS="$CFLAGS -mcpu=arm1176jzf-s -mfloat-abi=hard"
  200. ASFLAGS="$ASFLAGS -mcpu=arm1176jzf-s -mfloat-abi=hard"
  201. fi
  202. if [ "$optimize_arm926ej" = "yes" ]; then
  203. CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
  204. ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
  205. fi
  206. if [ "$optimize_arm920" = "yes" ]; then
  207. CFLAGS="$CFLAGS -mcpu=arm920t -mtune=arm920t"
  208. ASFLAGS="$ASFLAGS -mcpu=arm920t -mfloat-abi=soft"
  209. fi
  210. if [ "x$have_arm_neon" = "x" ]; then
  211. # detect NEON from user-supplied cflags to enable asm code
  212. have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
  213. fi
  214. if [ "x$have_armv7" = "x" ]; then
  215. if check_define HAVE_ARMV7; then
  216. have_armv7="yes"
  217. have_armv6="yes"
  218. have_armv5="yes"
  219. fi
  220. fi
  221. if [ "x$have_armv6" = "x" ]; then
  222. if check_define HAVE_ARMV6; then
  223. have_armv6="yes"
  224. have_armv5="yes"
  225. fi
  226. fi
  227. if [ "x$have_armv5" = "x" ]; then
  228. have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
  229. fi
  230. # must disable thumb as recompiler can't handle it
  231. if check_define __thumb__; then
  232. CFLAGS="$CFLAGS -marm"
  233. fi
  234. # OABI/EABI selection
  235. if [ "$have_arm_oabi" = "yes" ] && check_option -mabi=apcs-gnu; then
  236. echo "$CFLAGS" | grep -q -- '-mabi=' || CFLAGS="$CFLAGS -mabi=apcs-gnu"
  237. echo "$CFLAGS" | grep -q -- '-m\(no-\)*thumb-interwork' || CFLAGS="$CFLAGS -mno-thumb-interwork"
  238. echo "$ASFLAGS" | grep -q -- '-mabi=' || ASFLAGS="$ASFLAGS -mabi=apcs-gnu"
  239. fi
  240. # automatically set mfpu and mfloat-abi if they are not set
  241. if [ "$have_arm_neon" = "yes" ]; then
  242. fpu="neon"
  243. abi="hard"
  244. elif [ "$have_armv6" = "yes" ]; then
  245. fpu="vfp"
  246. abi="softfp"
  247. elif check_option -mfpu=fpa; then
  248. fpu="fpa" # compatibility option for arm-linux-gnueabi-gcc on ubuntu
  249. abi="soft"
  250. fi
  251. if [ "x$fpu" != "x" ]; then
  252. echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
  253. echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
  254. echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=$abi"
  255. echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=$abi"
  256. fi
  257. # add -ldl for helix support
  258. need_dl=yes
  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. need_dl=yes
  355. else
  356. have_libavcodec="no"
  357. fi ;;
  358. *) have_libavcodec="no" ;;
  359. esac
  360. #if check_libchdr; then
  361. # have_libchdr="yes"
  362. # MAIN_LDLIBS="-lchdr $MAIN_LDLIBS"
  363. #fi
  364. # find what audio support we can compile
  365. if [ "x$sound_drivers" = "x" ]; then
  366. if check_oss; then sound_drivers="$sound_drivers oss"; fi
  367. if check_alsa -lasound; then
  368. sound_drivers="$sound_drivers alsa"
  369. MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
  370. fi
  371. if [ "$need_sdl" = "yes" ] || check_sdl `$SDL_CONFIG --cflags --libs`; then
  372. sound_drivers="$sound_drivers sdl"
  373. need_sdl="yes"
  374. fi
  375. else
  376. if echo $sound_drivers | grep -q "\<oss\>"; then
  377. check_oss || fail "oss support is missing"
  378. fi
  379. if echo $sound_drivers | grep -q "\<alsa\>"; then
  380. MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
  381. check_alsa -lasound || fail "please install libasound2-dev"
  382. fi
  383. fi
  384. if [ "$need_sdl" = "yes" ]; then
  385. [ -x "$SDL_CONFIG" ] || \
  386. fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
  387. CFLAGS="$CFLAGS `$SDL_CONFIG --cflags`"
  388. MAIN_LDLIBS="`$SDL_CONFIG --libs` $MAIN_LDLIBS"
  389. SYSLIBS="$SYSLIBS -ldl"
  390. need_dl=yes
  391. check_sdl `$SDL_CONFIG --libs` || fail "please install libsdl (libsdl1.2-dev)"
  392. if [ "$SDLVERSION" = "sdl2" ]; then
  393. CFLAGS="$CFLAGS -D__USE_SDL2__"
  394. fi
  395. fi
  396. # add -ldl if needed
  397. if [ "$need_dl" = "yes" ]; then
  398. case "$MAIN_LDLIBS" in
  399. *"-ldl"*) ;;
  400. *) MAIN_LDLIBS="$MAIN_LDLIBS -ldl" ;;
  401. esac
  402. fi
  403. if check_option -Wno-unused_result; then
  404. CFLAGS="$CFLAGS -Wno-unused-result"
  405. fi
  406. # set things that failed to autodetect to "no"
  407. test "x$have_armv6" != "x" || have_armv6="no"
  408. test "x$have_armv7" != "x" || have_armv7="no"
  409. test "x$have_libavcodec" != "x" || have_libavcodec="no"
  410. test "x$have_libchdr" != "x" || have_libchdr="no"
  411. echo "architecture $ARCH"
  412. echo "platform $platform"
  413. echo "sound drivers $sound_drivers"
  414. echo "C compiler $CC"
  415. echo "C compiler flags $CFLAGS"
  416. echo "libraries $MAIN_LDLIBS"
  417. echo "linker flags $LDFLAGS"
  418. echo "libavcodec (mp3) $have_libavcodec"
  419. #echo "libchdr $have_libchdr"
  420. # echo "ARMv7 optimizations $have_armv7"
  421. echo "# Automatically generated by configure" > $config_mak
  422. printf "# Configured with:" >> $config_mak
  423. printf " '%s'" "$0" "$@" >> $config_mak
  424. echo >> $config_mak
  425. echo "CC = $CC" >> $config_mak
  426. echo "CXX = $CXX" >> $config_mak
  427. echo "AS = $AS" >> $config_mak
  428. echo "STRIP = $STRIP" >> $config_mak
  429. echo "CFLAGS += $CFLAGS" >> $config_mak
  430. echo "ASFLAGS += $ASFLAGS" >> $config_mak
  431. echo "LDFLAGS += $LDFLAGS" >> $config_mak
  432. echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
  433. echo >> $config_mak
  434. echo "ARCH = $ARCH" >> $config_mak
  435. echo "PLATFORM = $platform" >> $config_mak
  436. echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
  437. if [ "$have_libavcodec" = "yes" ]; then
  438. echo "HAVE_LIBAVCODEC = 1" >> $config_mak
  439. fi
  440. if [ "$have_libchdr" = "yes" ]; then
  441. echo "HAVE_LIBCHDR = 1" >> $config_mak
  442. fi
  443. if [ "$need_zlib" = "yes" ]; then
  444. echo "PLATFORM_ZLIB = 1" >> $config_mak
  445. fi
  446. if [ "$ARCH" = "arm" -a "$have_armv6" != "yes" -a "$have_armv7" != "yes" ]; then
  447. # pass info to cyclone not to use newer arm arch instructions
  448. echo "HAVE_ARMv6 = 0" >> $config_mak
  449. fi
  450. # GP2X toolchains are too old for UAL asm,
  451. # so add this here to not litter main Makefile
  452. #if [ "$platform" = "gp2x" ]; then
  453. # echo >> $config_mak
  454. # echo '%.o: %.S' >> $config_mak
  455. # echo ' $(CC) $(CFLAGS) -E -c $^ -o /tmp/$(notdir $@).s' >> $config_mak
  456. # echo ' $(AS) $(ASFLAGS) /tmp/$(notdir $@).s -o $@' >> $config_mak
  457. #fi
  458. # use pandora's skin (for now)
  459. test -e skin || ln -s platform/pandora/skin skin
  460. # vim:shiftwidth=2:expandtab