scan-tools.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 "For older versions you might consider to use a disk image."
  36. echo "Example: sudo diskutil resizeVolume disk0s2 90G 1 jhfsx adk 30G"
  37. ;;
  38. esac
  39. exit 1
  40. fi
  41. rm -f FOO
  42. case $os in
  43. Linux)
  44. ;;
  45. FreeBSD)
  46. ;;
  47. MirBSD)
  48. ;;
  49. CYG*)
  50. ;;
  51. NetBSD)
  52. ;;
  53. OpenBSD)
  54. ;;
  55. Darwin*)
  56. ;;
  57. *)
  58. # unsupported
  59. echo "Building OpenADK on $os is currently unsupported."
  60. echo "Sorry."
  61. exit 1
  62. ;;
  63. esac
  64. set +e
  65. cat >Makefile <<'EOF'
  66. include ${TOPDIR}/prereq.mk
  67. all: run-test
  68. test: test.c
  69. ${CC_FOR_BUILD} ${CFLAGS_FOR_BUILD} -o $@ $^ ${LDADD}
  70. run-test: test
  71. ./test
  72. EOF
  73. cat >test.c <<-'EOF'
  74. #include <stdio.h>
  75. int
  76. main()
  77. {
  78. printf("Yay! Native compiler works.\n");
  79. return (0);
  80. }
  81. EOF
  82. X=$($makecmd TOPDIR=$topdir 2>&1)
  83. if [[ $X != *@(Native compiler works)* ]]; then
  84. echo "$X" | sed 's/^/| /'
  85. echo Cannot compile a simple test programme.
  86. echo You must install a host make and C compiler,
  87. echo usually GCC, to proceed.
  88. echo
  89. out=1
  90. fi
  91. rm test 2>/dev/null
  92. if ! which tar >/dev/null 2>&1; then
  93. echo You must install tar to continue.
  94. echo
  95. out=1
  96. fi
  97. if ! which gzip >/dev/null 2>&1; then
  98. echo You must install gzip to continue.
  99. echo
  100. out=1
  101. fi
  102. if ! which lzop >/dev/null 2>&1; then
  103. echo You must install lzop to continue.
  104. echo
  105. out=1
  106. fi
  107. if ! which lzma >/dev/null 2>&1; then
  108. echo You must install lzma to continue.
  109. echo
  110. out=1
  111. fi
  112. if ! which xz >/dev/null 2>&1; then
  113. echo You must install xz-utils to continue.
  114. echo
  115. out=1
  116. fi
  117. if ! which bzip2 >/dev/null 2>&1; then
  118. echo You must install bzip2 to continue.
  119. echo
  120. out=1
  121. fi
  122. if ! which patch >/dev/null 2>&1; then
  123. echo You must install patch to continue.
  124. echo
  125. out=1
  126. fi
  127. cat >test.c <<-'EOF'
  128. #include <stdio.h>
  129. #include <zlib.h>
  130. #ifndef STDIN_FILENO
  131. #define STDIN_FILENO 0
  132. #endif
  133. int
  134. main()
  135. {
  136. gzFile zstdin;
  137. char buf[1024];
  138. int i;
  139. zstdin = gzdopen(STDIN_FILENO, "rb");
  140. i = gzread(zstdin, buf, sizeof (buf));
  141. if ((i > 0) && (i < sizeof (buf)))
  142. buf[i] = '\0';
  143. buf[sizeof (buf) - 1] = '\0';
  144. printf("%s\n", buf);
  145. return (0);
  146. }
  147. EOF
  148. X=$(echo 'Yay! Native compiler works.' | gzip | \
  149. $makecmd TOPDIR=$topdir LDADD=-lz 2>&1)
  150. if [[ $X != *@(Native compiler works)* ]]; then
  151. echo "$X" | sed 's/^/| /'
  152. echo Cannot compile a libz test programm.
  153. echo You must install the zlib development package,
  154. echo usually called libz-dev, and the run-time library.
  155. echo
  156. out=1
  157. fi
  158. if [[ ! -s /usr/include/ncurses.h ]]; then
  159. if [[ ! -s /usr/include/curses.h ]]; then
  160. if [[ ! -s /usr/include/ncurses/ncurses.h ]]; then
  161. echo Install ncurses header files, please.
  162. echo
  163. out=1
  164. fi
  165. fi
  166. fi
  167. if ! which gawk >/dev/null 2>&1; then
  168. echo You must install GNU awk to continue.
  169. echo
  170. out=1
  171. fi
  172. if ! which sed >/dev/null 2>&1; then
  173. echo You must install GNU sed to continue.
  174. echo
  175. out=1
  176. fi
  177. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  178. if ! which gsed >/dev/null 2>&1; then
  179. echo You must install GNU sed to continue.
  180. echo
  181. out=1
  182. fi
  183. fi
  184. if ! which wget >/dev/null 2>&1; then
  185. echo You must install wget to continue.
  186. echo
  187. out=1
  188. fi
  189. if ! which perl >/dev/null 2>&1; then
  190. echo You must install perl to continue.
  191. echo
  192. out=1
  193. fi
  194. if ! which m4 >/dev/null 2>&1; then
  195. echo "You must install m4 (macro processor) to continue."
  196. echo
  197. out=1
  198. fi
  199. if ! which bc >/dev/null 2>&1; then
  200. echo "You need bc to continue."
  201. echo
  202. out=1
  203. fi
  204. if ! which xargs >/dev/null 2>&1; then
  205. echo "You need xargs to continue."
  206. echo
  207. out=1
  208. fi
  209. cd $topdir
  210. rm -rf tmp
  211. exit $out