scan-tools.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. shopt -s extglob
  4. topdir=$(pwd)
  5. opath=$PATH
  6. out=0
  7. if [ -z $(which gmake 2>/dev/null ) ];then
  8. makecmd=$(which make 2>/dev/null )
  9. else
  10. makecmd=$(which gmake 2>/dev/null )
  11. fi
  12. if [[ $NO_ERROR != @(0|1) ]]; then
  13. echo Please do not invoke this script directly!
  14. exit 1
  15. fi
  16. set -e
  17. rm -rf $topdir/tmp
  18. mkdir -p $topdir/tmp
  19. cd $topdir/tmp
  20. os=$(uname)
  21. rm -f foo
  22. echo >FOO
  23. if [[ -e foo ]]; then
  24. cat >&2 <<-EOF
  25. ERROR: OpenADK cannot be built in a case-insensitive file system.
  26. EOF
  27. case $os in
  28. CYG*)
  29. echo "Building OpenADK on $os needs a small registry change."
  30. echo 'http://cygwin.com/cygwin-ug-net/using-specialnames.html'
  31. ;;
  32. Darwin*)
  33. echo "Building OpenADK on $os needs a case-sensitive disk partition."
  34. echo "For Snow Leopard and above you can use diskutil to resize your existing disk."
  35. echo "Example: sudo diskutil resizeVolume disk0s2 90G 1 jhfsx adk 30G"
  36. echo "For older versions you might consider to use a disk image:"
  37. echo "hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 30g ~/openadk.dmg"
  38. ;;
  39. esac
  40. exit 1
  41. fi
  42. rm -f FOO
  43. case $os in
  44. Linux)
  45. ;;
  46. FreeBSD)
  47. ;;
  48. MirBSD)
  49. ;;
  50. CYG*)
  51. ;;
  52. NetBSD)
  53. ;;
  54. OpenBSD)
  55. ;;
  56. Darwin*)
  57. ;;
  58. *)
  59. # unsupported
  60. echo "Building OpenADK on $os is currently unsupported."
  61. echo "Sorry."
  62. exit 1
  63. ;;
  64. esac
  65. set +e
  66. cat >Makefile <<'EOF'
  67. include ${TOPDIR}/prereq.mk
  68. all: run-test
  69. test: test.c
  70. ${CC_FOR_BUILD} ${CFLAGS_FOR_BUILD} -o $@ $^ ${LDADD}
  71. run-test: test
  72. ./test
  73. EOF
  74. cat >test.c <<-'EOF'
  75. #include <stdio.h>
  76. int
  77. main()
  78. {
  79. printf("Yay! Native compiler works.\n");
  80. return (0);
  81. }
  82. EOF
  83. X=$($makecmd TOPDIR=$topdir 2>&1)
  84. if [[ $X != *@(Native compiler works)* ]]; then
  85. echo "$X" | sed 's/^/| /'
  86. echo Cannot compile a simple test programme.
  87. echo You must install a host make and C compiler,
  88. echo usually GCC, to proceed.
  89. echo
  90. out=1
  91. fi
  92. rm test 2>/dev/null
  93. if ! which tar >/dev/null 2>&1; then
  94. echo You must install tar to continue.
  95. echo
  96. out=1
  97. fi
  98. if ! which gzip >/dev/null 2>&1; then
  99. echo You must install gzip to continue.
  100. echo
  101. out=1
  102. fi
  103. if ! which patch >/dev/null 2>&1; then
  104. echo You must install patch to continue.
  105. echo
  106. out=1
  107. fi
  108. cat >test.c <<-'EOF'
  109. #include <stdio.h>
  110. #include <zlib.h>
  111. #ifndef STDIN_FILENO
  112. #define STDIN_FILENO 0
  113. #endif
  114. int
  115. main()
  116. {
  117. gzFile zstdin;
  118. char buf[1024];
  119. int i;
  120. zstdin = gzdopen(STDIN_FILENO, "rb");
  121. i = gzread(zstdin, buf, sizeof (buf));
  122. if ((i > 0) && (i < sizeof (buf)))
  123. buf[i] = '\0';
  124. buf[sizeof (buf) - 1] = '\0';
  125. printf("%s\n", buf);
  126. return (0);
  127. }
  128. EOF
  129. X=$(echo 'Yay! Native compiler works.' | gzip | \
  130. $makecmd TOPDIR=$topdir LDADD=-lz 2>&1)
  131. if [[ $X != *@(Native compiler works)* ]]; then
  132. echo "$X" | sed 's/^/| /'
  133. echo Cannot compile a libz test programm.
  134. echo You must install the zlib development package,
  135. echo usually called libz-dev, and the run-time library.
  136. echo
  137. out=1
  138. fi
  139. if [[ ! -s /usr/include/ncurses.h ]]; then
  140. if [[ ! -s /usr/include/curses.h ]]; then
  141. if [[ ! -s /usr/include/ncurses/ncurses.h ]]; then
  142. echo Install ncurses header files, please.
  143. echo
  144. out=1
  145. fi
  146. fi
  147. fi
  148. if ! which gawk >/dev/null 2>&1; then
  149. echo You must install GNU awk to continue.
  150. echo
  151. out=1
  152. fi
  153. if ! which sed >/dev/null 2>&1; then
  154. echo You must install GNU sed to continue.
  155. echo
  156. out=1
  157. fi
  158. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  159. if ! which gsed >/dev/null 2>&1; then
  160. echo You must install GNU sed to continue.
  161. echo
  162. out=1
  163. fi
  164. fi
  165. if ! which wget >/dev/null 2>&1; then
  166. echo You must install wget to continue.
  167. echo
  168. out=1
  169. fi
  170. if ! which perl >/dev/null 2>&1; then
  171. echo You must install perl to continue.
  172. echo
  173. out=1
  174. fi
  175. if ! which xargs >/dev/null 2>&1; then
  176. echo "You need xargs to continue."
  177. echo
  178. out=1
  179. fi
  180. if ! which g++ >/dev/null 2>&1; then
  181. echo "You need g++ (GNU C++ compiler) to continue."
  182. echo
  183. out=1
  184. fi
  185. if ! which git >/dev/null 2>&1; then
  186. echo "You need git to continue."
  187. echo
  188. out=1
  189. fi
  190. cd $topdir
  191. rm -rf tmp
  192. exit $out