configure 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. #!/bin/sh
  2. # some elements originated from qemu configure
  3. set -e
  4. TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c"
  5. TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o"
  6. TMPB="/tmp/pcsx-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 $MAIN_LDLIBS $@"
  18. echo $c >> config.log
  19. $c >> config.log 2>&1
  20. }
  21. check_define()
  22. {
  23. $CC -E -dD $CFLAGS pico/arm_features.h | grep -q $1 || return 1
  24. return 0
  25. }
  26. # setting options to "yes" or "no" will make that choice default,
  27. # "" means "autodetect".
  28. platform_list="generic pandora"
  29. platform="generic"
  30. sound_driver_list="oss alsa sdl"
  31. sound_drivers=""
  32. have_armv5=""
  33. have_armv6=""
  34. have_armv7=""
  35. have_arm_neon=""
  36. have_tslib=""
  37. enable_dynarec="yes"
  38. need_sdl="no"
  39. need_xlib="no"
  40. # these are for known platforms
  41. optimize_cortexa8="no"
  42. optimize_arm926ej="no"
  43. # hardcoded stuff
  44. CC="${CC-${CROSS_COMPILE}gcc}"
  45. CXX="${CXX-${CROSS_COMPILE}g++}"
  46. AS="${AS-${CROSS_COMPILE}as}"
  47. MAIN_LDLIBS="$LDLIBS -lm"
  48. config_mak="config.mak"
  49. fail()
  50. {
  51. echo "$@"
  52. exit 1
  53. }
  54. # call during arg parsing, so that cmd line can override platform defaults
  55. set_platform()
  56. {
  57. platform=$1
  58. case "$platform" in
  59. generic)
  60. ;;
  61. pandora)
  62. sound_drivers="oss alsa"
  63. optimize_cortexa8="yes"
  64. have_arm_neon="yes"
  65. ;;
  66. *)
  67. fail "unsupported platform: $platform"
  68. ;;
  69. esac
  70. }
  71. for opt do
  72. optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
  73. case "$opt" in
  74. --help|-h) show_help="yes"
  75. ;;
  76. --platform=*) set_platform "$optarg"
  77. ;;
  78. --sound-drivers=*) sound_drivers="$optarg"
  79. ;;
  80. --enable-neon) have_arm_neon="yes"
  81. ;;
  82. --disable-neon) have_arm_neon="no"
  83. ;;
  84. --disable-dynarec) enable_dynarec="no"
  85. ;;
  86. *) echo "ERROR: unknown option $opt"; show_help="yes"
  87. ;;
  88. esac
  89. done
  90. if [ "$show_help" = "yes" ]; then
  91. echo "options:"
  92. echo " --help print this message"
  93. echo " --platform=NAME target platform [$platform]"
  94. echo " available: $platform_list"
  95. echo " --sound-drivers=LIST sound output drivers [guessed]"
  96. echo " available: $sound_driver_list"
  97. echo " --enable-neon"
  98. echo " --disable-neon enable/disable ARM NEON optimizations [guessed]"
  99. echo " --disable-dynarec disable dynamic recompiler"
  100. echo " (dynarec is only available and enabled on ARM)"
  101. echo "influential environment variables:"
  102. echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS"
  103. exit 1
  104. fi
  105. # validate selections
  106. if [ "x$sound_drivers" != "x" ]; then
  107. for d in $sound_drivers; do
  108. if ! echo $sound_driver_list | grep -q "\<$d\>"; then
  109. fail "unsupported sound driver: $sound_driver"
  110. fi
  111. done
  112. fi
  113. if [ "$need_libpicofe" = "yes" ]; then
  114. if ! test -f "frontend/libpicofe/README"; then
  115. fail "libpicofe is missing, please run 'git submodule init && git submodule update'"
  116. fi
  117. fi
  118. #if [ "$need_warm" = "yes" ]; then
  119. # if ! test -f "frontend/warm/README"; then
  120. # fail "wARM is missing, please run 'git submodule init && git submodule update'"
  121. # fi
  122. #fi
  123. # basic compiler test
  124. cat > $TMPC <<EOF
  125. int main(void) { return 0; }
  126. EOF
  127. if ! compile_binary; then
  128. fail "compiler test failed, please check config.log"
  129. fi
  130. if [ -z "$ARCH" ]; then
  131. ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
  132. fi
  133. case "$ARCH" in
  134. arm*)
  135. # ARM stuff
  136. ARCH="arm"
  137. if [ "$optimize_cortexa8" = "yes" ]; then
  138. CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
  139. ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
  140. fi
  141. if [ "$optimize_arm926ej" = "yes" ]; then
  142. CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
  143. ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
  144. fi
  145. if [ "x$have_arm_neon" = "x" ]; then
  146. # detect NEON from user-supplied cflags to enable asm code
  147. have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
  148. fi
  149. if [ "x$have_armv7" = "x" ]; then
  150. if check_define HAVE_ARMV7; then
  151. have_armv7="yes"
  152. have_armv6="yes"
  153. have_armv5="yes"
  154. fi
  155. fi
  156. if [ "x$have_armv6" = "x" ]; then
  157. if check_define HAVE_ARMV6; then
  158. have_armv6="yes"
  159. have_armv5="yes"
  160. fi
  161. fi
  162. if [ "x$have_armv5" = "x" ]; then
  163. have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
  164. fi
  165. # automatically set mfpu and mfloat-abi if they are not set
  166. if [ "$have_arm_neon" = "yes" ]; then
  167. fpu="neon"
  168. elif [ "$have_armv6" = "yes" ]; then
  169. fpu="vfp"
  170. fi
  171. if [ "x$fpu" != "x" ]; then
  172. echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
  173. echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
  174. floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true
  175. if [ "$floatabi_set_by_gcc" != "yes" ]; then
  176. echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
  177. echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
  178. fi
  179. fi
  180. # must disable thumb as recompiler can't handle it
  181. if check_define __thumb__; then
  182. CFLAGS="$CFLAGS -marm"
  183. fi
  184. # warn about common mistakes
  185. if [ "$have_armv5" != "yes" ]; then
  186. if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
  187. echo "Warning: compiling for ARMv4, is that really what you want?"
  188. echo "You probably should specify -mcpu= or -march= like this:"
  189. echo " CFLAGS=-march=armv6 ./configure ..."
  190. fi
  191. fi
  192. if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then
  193. echo "Warning: compiling for NEON, but not ARMv7?"
  194. echo "You probably want to specify -mcpu= or -march= like this:"
  195. echo " CFLAGS=-march=armv7-a ./configure ..."
  196. fi
  197. ;;
  198. *)
  199. # dynarec only available on ARM
  200. enable_dynarec="no"
  201. ;;
  202. esac
  203. case "$platform" in
  204. generic)
  205. need_sdl="yes"
  206. ;;
  207. esac
  208. # header/library presence tests
  209. check_zlib()
  210. {
  211. cat > $TMPC <<EOF
  212. #include <zlib.h>
  213. int main(void) { uncompress(0, 0, 0, 0); }
  214. EOF
  215. compile_binary
  216. }
  217. check_libpng()
  218. {
  219. cat > $TMPC <<EOF
  220. #include <png.h>
  221. void main() { png_init_io(0, 0); }
  222. EOF
  223. compile_binary
  224. }
  225. check_oss()
  226. {
  227. cat > $TMPC <<EOF
  228. #include <sys/soundcard.h>
  229. #include <sys/ioctl.h>
  230. void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
  231. EOF
  232. compile_binary
  233. }
  234. check_alsa()
  235. {
  236. cat > $TMPC <<EOF
  237. #include <alsa/asoundlib.h>
  238. void main() { snd_pcm_open(0, 0, 0, 0); }
  239. EOF
  240. compile_binary "$@"
  241. }
  242. check_sdl()
  243. {
  244. cat > $TMPC <<EOF
  245. #include <SDL.h>
  246. void main() { SDL_OpenAudio(0, 0); }
  247. EOF
  248. compile_binary "$@"
  249. }
  250. #MAIN_LDLIBS="$MAIN_LDLIBS -lz"
  251. #check_zlib || fail "please install zlib (libz-dev)"
  252. MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
  253. check_libpng || fail "please install libpng (libpng-dev)"
  254. # find what audio support we can compile
  255. if [ "x$sound_drivers" = "x" ]; then
  256. if check_oss; then sound_drivers="$sound_drivers oss"; fi
  257. if check_alsa -lasound; then
  258. sound_drivers="$sound_drivers alsa"
  259. MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
  260. fi
  261. if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
  262. sound_drivers="$sound_drivers sdl"
  263. need_sdl="yes"
  264. fi
  265. else
  266. if echo $sound_drivers | grep -q "\<oss\>"; then
  267. check_oss || fail "oss support is missing"
  268. fi
  269. if echo $sound_drivers | grep -q "\<alsa\>"; then
  270. MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
  271. check_alsa || fail "please install libasound2-dev"
  272. fi
  273. fi
  274. if [ "$need_sdl" = "yes" ]; then
  275. which sdl-config > /dev/null || \
  276. fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
  277. CFLAGS="$CFLAGS `sdl-config --cflags`"
  278. MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
  279. check_sdl || fail "please install libsdl (libsdl1.2-dev)"
  280. fi
  281. cat > $TMPC <<EOF
  282. void test(void *f, void *d) { fread(d, 1, 1, f); }
  283. EOF
  284. if compile_object -Wno-unused-result; then
  285. CFLAGS="$CFLAGS -Wno-unused-result"
  286. fi
  287. # set things that failed to autodetect to "no"
  288. test "x$have_armv6" != "x" || have_armv6="no"
  289. test "x$have_armv7" != "x" || have_armv7="no"
  290. test "x$have_arm_neon" != "x" || have_arm_neon="no"
  291. echo "architecture $ARCH"
  292. echo "platform $platform"
  293. echo "sound drivers $sound_drivers"
  294. echo "C compiler $CC"
  295. echo "C compiler flags $CFLAGS"
  296. echo "libraries $MAIN_LDLIBS"
  297. echo "linker flags $LDFLAGS"
  298. echo "enable dynarec $enable_dynarec"
  299. # echo "ARMv7 optimizations $have_armv7"
  300. # echo "enable ARM NEON $have_arm_neon"
  301. echo "# Automatically generated by configure" > $config_mak
  302. printf "# Configured with:" >> $config_mak
  303. printf " '%s'" "$0" "$@" >> $config_mak
  304. echo >> $config_mak
  305. echo "CC = $CC" >> $config_mak
  306. echo "CXX = $CXX" >> $config_mak
  307. echo "AS = $AS" >> $config_mak
  308. echo "CFLAGS += $CFLAGS" >> $config_mak
  309. echo "ASFLAGS += $ASFLAGS" >> $config_mak
  310. echo "LDFLAGS += $LDFLAGS" >> $config_mak
  311. echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
  312. echo >> $config_mak
  313. echo "ARCH = $ARCH" >> $config_mak
  314. echo "PLATFORM = $platform" >> $config_mak
  315. echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
  316. if [ "$have_arm_neon" = "yes" ]; then
  317. echo "HAVE_NEON = 1" >> $config_mak
  318. fi
  319. if [ "$enable_dynarec" = "yes" ]; then
  320. echo "USE_DYNAREC = 1" >> $config_mak
  321. fi
  322. # use pandora's skin (for now)
  323. test -e skin || ln -s platform/pandora/skin skin
  324. # vim:shiftwidth=2:expandtab