scan-tools.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. rm -f foo
  21. echo >FOO
  22. if [[ -e foo ]]; then
  23. cat >&2 <<-EOF
  24. ERROR: OpenADK cannot be built in a case-insensitive file system.
  25. EOF
  26. exit 1
  27. fi
  28. rm -f FOO
  29. os=$(uname)
  30. case $os in
  31. Linux)
  32. # supported with no extra quirks at the moment
  33. ;;
  34. FreeBSD)
  35. # supported with no extra quirks at the moment
  36. ;;
  37. MirBSD)
  38. # supported with no extra quirks at the moment
  39. ;;
  40. CYG*)
  41. echo "Building OpenADK on $os needs a small registry change."
  42. echo 'http://cygwin.com/cygwin-ug-net/using-specialnames.html'
  43. sleep 5
  44. ;;
  45. NetBSD)
  46. # supported with no extra quirks at the moment
  47. ;;
  48. OpenBSD)
  49. # supported with no extra quirks at the moment
  50. # although some packages' autoconf scripts may
  51. # not properly recognise OpenBSD
  52. ;;
  53. *)
  54. # unsupported
  55. echo "Building OpenADK on $os is currently unsupported."
  56. echo "Sorry."
  57. exit 1
  58. ;;
  59. esac
  60. set +e
  61. cat >Makefile <<'EOF'
  62. include ${TOPDIR}/prereq.mk
  63. HOSTCFLAGS+= -O2
  64. all: run-test
  65. test: test.c
  66. ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
  67. run-test: test
  68. ./test
  69. EOF
  70. cat >test.c <<-'EOF'
  71. #include <stdio.h>
  72. int
  73. main()
  74. {
  75. printf("Yay! Native compiler works.\n");
  76. return (0);
  77. }
  78. EOF
  79. X=$($makecmd TOPDIR=$topdir 2>&1)
  80. if [[ $X != *@(Native compiler works)* ]]; then
  81. echo "$X" | sed 's/^/| /'
  82. echo Cannot compile a simple test programme.
  83. echo You must install a host make and C compiler,
  84. echo usually GCC, to proceed.
  85. echo
  86. out=1
  87. fi
  88. rm test 2>/dev/null
  89. if ! which tar >/dev/null 2>&1; then
  90. echo You must install GNU tar to continue.
  91. echo
  92. out=1
  93. fi
  94. if ! (tar --version | grep GNU) >/dev/null 2>&1;then
  95. if ! which gtar >/dev/null 2>&1; then
  96. echo You must install GNU tar to continue.
  97. echo
  98. out=1
  99. fi
  100. fi
  101. if ! which gzip >/dev/null 2>&1; then
  102. echo You must install gzip to continue.
  103. echo
  104. out=1
  105. fi
  106. if ! which lzma >/dev/null 2>&1; then
  107. echo You must install lzma to continue.
  108. echo
  109. out=1
  110. fi
  111. if ! which bzip2 >/dev/null 2>&1; then
  112. echo You must install bzip2 to continue.
  113. echo
  114. out=1
  115. fi
  116. if ! which cpio >/dev/null 2>&1; then
  117. echo You must install cpio to continue.
  118. echo
  119. out=1
  120. fi
  121. if ! which unzip >/dev/null 2>&1; then
  122. echo You must install unzip to continue.
  123. echo
  124. out=1
  125. fi
  126. if ! which patch >/dev/null 2>&1; then
  127. echo You must install patch to continue.
  128. echo
  129. out=1
  130. fi
  131. cat >test.c <<-'EOF'
  132. #include <stdio.h>
  133. #include <zlib.h>
  134. #ifndef STDIN_FILENO
  135. #define STDIN_FILENO 0
  136. #endif
  137. int
  138. main()
  139. {
  140. gzFile zstdin;
  141. char buf[1024];
  142. int i;
  143. zstdin = gzdopen(STDIN_FILENO, "rb");
  144. i = gzread(zstdin, buf, sizeof (buf));
  145. if ((i > 0) && (i < sizeof (buf)))
  146. buf[i] = '\0';
  147. buf[sizeof (buf) - 1] = '\0';
  148. printf("%s\n", buf);
  149. return (0);
  150. }
  151. EOF
  152. X=$(echo 'Yay! Native compiler works.' | gzip | \
  153. $makecmd TOPDIR=$topdir LDADD=-lz 2>&1)
  154. if [[ $X != *@(Native compiler works)* ]]; then
  155. echo "$X" | sed 's/^/| /'
  156. echo Cannot compile a libz test programm.
  157. echo You must install the zlib development package,
  158. echo usually called libz-dev, and the run-time library.
  159. echo
  160. out=1
  161. fi
  162. if [[ ! -s /usr/include/ncurses.h ]]; then
  163. if [[ ! -s /usr/include/curses.h ]]; then
  164. echo Install ncurses header files, please.
  165. echo
  166. out=1
  167. fi
  168. fi
  169. if ! which gawk >/dev/null 2>&1; then
  170. echo You must install GNU awk to continue.
  171. echo
  172. out=1
  173. fi
  174. if ! which sed >/dev/null 2>&1; then
  175. echo You must install GNU sed to continue.
  176. echo
  177. out=1
  178. fi
  179. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  180. if ! which gsed >/dev/null 2>&1; then
  181. echo You must install GNU sed to continue.
  182. echo
  183. out=1
  184. fi
  185. fi
  186. if ! which wget >/dev/null 2>&1; then
  187. echo You must install wget to continue.
  188. echo
  189. out=1
  190. fi
  191. if ! which file >/dev/null 2>&1; then
  192. echo You must install \"file\" to continue.
  193. echo
  194. out=1
  195. fi
  196. if ! which perl >/dev/null 2>&1; then
  197. echo You must install perl to continue.
  198. echo
  199. out=1
  200. fi
  201. cd $topdir
  202. rm -rf tmp
  203. exit $out