configure 11 KB

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