configure 13 KB

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