configure 12 KB

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