scan-tools.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. # $Id: scan-tools.sh 436 2009-05-10 18:15:31Z wbx $
  2. #-
  3. # This file is part of the OpenADK project. OpenADK is copyrighted
  4. # material, please see the LICENCE file in the top-level directory.
  5. shopt -s extglob
  6. topdir=$(pwd)
  7. opath=$PATH
  8. out=0
  9. if [ -z $(which gmake) ];then
  10. makecmd=$(which make)
  11. else
  12. makecmd=$(which gmake)
  13. fi
  14. if [[ $NO_ERROR != @(0|1) ]]; then
  15. echo Please do not invoke this script directly!
  16. exit 1
  17. fi
  18. set -e
  19. rm -rf $topdir/tmp
  20. mkdir -p $topdir/tmp
  21. cd $topdir/tmp
  22. rm -f foo
  23. echo >FOO
  24. if [[ -e foo ]]; then
  25. cat >&2 <<-EOF
  26. ERROR: OpenADK cannot be built in a case-insensitive file system.
  27. EOF
  28. exit 1
  29. fi
  30. rm -f FOO
  31. os=$(uname)
  32. case $os in
  33. Linux)
  34. # supported with no extra quirks at the moment
  35. ;;
  36. FreeBSD)
  37. # supported with no extra quirks at the moment
  38. ;;
  39. CYG*)
  40. # mkdir /openadk
  41. # mount -b -s -o managed "C:/openadk" "/openadk"
  42. # cd /openadk
  43. # svn co svn+ssh://waldemar-brodkorb.de/svn .
  44. echo "Building OpenADK on $os is needs a managed mount point."
  45. echo '"mount -b -s -o managed "C:/openadk" "/openadk"'
  46. ;;
  47. NetBSD)
  48. echo "Building OpenADK on $os is currently unsupported."
  49. echo "Sorry."
  50. echo
  51. echo There are unresolved issues relating to ncurses not
  52. echo being included in NetBSD®, and these provided by pkgsrc®
  53. echo lack important header files.
  54. ;;
  55. OpenBSD)
  56. # supported with no extra quirks at the moment
  57. # although some packages' autoconf scripts may
  58. # not properly recognise OpenBSD
  59. ;;
  60. *)
  61. # unsupported
  62. echo "Building OpenADK on $os is currently unsupported."
  63. echo "Sorry."
  64. exit 1
  65. ;;
  66. esac
  67. set +e
  68. cat >Makefile <<'EOF'
  69. include ${TOPDIR}/prereq.mk
  70. HOSTCFLAGS+= -O2
  71. all: run-test
  72. test: test.c
  73. ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
  74. run-test: test
  75. ./test
  76. EOF
  77. cat >test.c <<-'EOF'
  78. #include <stdio.h>
  79. int
  80. main()
  81. {
  82. printf("Yay! Native compiler works.\n");
  83. return (0);
  84. }
  85. EOF
  86. X=$($makecmd TOPDIR=$topdir 2>&1)
  87. if [[ $X != *@(Native compiler works)* ]]; then
  88. echo "$X" | sed 's/^/| /'
  89. echo Cannot compile a simple test programme.
  90. echo You must install a host make and C compiler,
  91. echo usually GCC, to proceed.
  92. echo
  93. out=1
  94. fi
  95. rm test 2>/dev/null
  96. if ! which cpp >/dev/null 2>&1; then
  97. echo You must install a C preprocessor to continue.
  98. echo
  99. out=1
  100. fi
  101. if ! which flex >/dev/null 2>&1; then
  102. echo You must install flex to continue.
  103. echo
  104. out=1
  105. else
  106. echo '%%' | flex -
  107. if fgrep _POSIX_SOURCE lex.yy.c; then
  108. echo Your lexer \(flex\) contains a broken skeleton.
  109. if [[ $NO_ERROR = 1 ]]; then
  110. echo WARNING: continue at your own risk.
  111. echo Some packages may be broken.
  112. else
  113. echo You can continue the build by issuing \'make prereq-noerror\'
  114. echo However, several packages may faild to build correctly.
  115. out=1
  116. fi
  117. echo
  118. fi
  119. fi
  120. if ! which bison >/dev/null 2>&1; then
  121. echo You must install GNU bison to continue.
  122. echo
  123. out=1
  124. fi
  125. if ! which tar >/dev/null 2>&1; then
  126. echo You must install GNU tar to continue.
  127. echo
  128. out=1
  129. fi
  130. if ! tar --version|grep GNU >/dev/null 2>&1;then
  131. if ! which gtar >/dev/null 2>&1; then
  132. echo You must install GNU tar to continue.
  133. echo
  134. out=1
  135. fi
  136. fi
  137. if ! which gzip >/dev/null 2>&1; then
  138. echo You must install gzip to continue.
  139. echo
  140. out=1
  141. fi
  142. if ! which bzip2 >/dev/null 2>&1; then
  143. echo You must install bzip2 to continue.
  144. echo
  145. out=1
  146. fi
  147. if ! which cpio >/dev/null 2>&1; then
  148. echo You must install cpio to continue.
  149. echo
  150. out=1
  151. fi
  152. if ! which unzip >/dev/null 2>&1; then
  153. echo You must install unzip to continue.
  154. echo
  155. out=1
  156. fi
  157. if ! which patch >/dev/null 2>&1; then
  158. echo You must install patch to continue.
  159. echo
  160. out=1
  161. fi
  162. cat >test.c <<-'EOF'
  163. #include <stdio.h>
  164. #include <zlib.h>
  165. #ifndef STDIN_FILENO
  166. #define STDIN_FILENO 0
  167. #endif
  168. int
  169. main()
  170. {
  171. gzFile zstdin;
  172. char buf[1024];
  173. int i;
  174. zstdin = gzdopen(STDIN_FILENO, "rb");
  175. i = gzread(zstdin, buf, sizeof (buf));
  176. if ((i > 0) && (i < sizeof (buf)))
  177. buf[i] = '\0';
  178. buf[sizeof (buf) - 1] = '\0';
  179. printf("%s\n", buf);
  180. return (0);
  181. }
  182. EOF
  183. X=$(echo 'Yay! Native compiler works.' | gzip | \
  184. $makecmd TOPDIR=$topdir LDADD=-lz 2>&1)
  185. if [[ $X != *@(Native compiler works)* ]]; then
  186. echo "$X" | sed 's/^/| /'
  187. echo Cannot compile a libz test programm.
  188. echo You must install the zlib development package,
  189. echo usually called libz-dev, and the run-time library.
  190. echo
  191. out=1
  192. fi
  193. [[ -s /usr/include/ncurses.h ]] || if [[ -s /usr/pkg/include/ncurses.h ]]; then
  194. echo 'HOSTCFLAGS+= -isystem /usr/pkg/include' >>$topdir/prereq.mk
  195. echo 'HOSTLDFLAGS+=-L/usr/pkg/lib -Wl,-rpath -Wl,/usr/pkg/lib' >>$topdir/prereq.mk
  196. else
  197. echo Install ncurses header files, please.
  198. echo
  199. out=1
  200. fi
  201. if ! which gawk >/dev/null 2>&1; then
  202. echo You must install GNU awk to continue.
  203. echo
  204. out=1
  205. fi
  206. if ! which sed >/dev/null 2>&1; then
  207. echo You must install GNU sed to continue.
  208. echo
  209. out=1
  210. fi
  211. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  212. if ! which gsed >/dev/null 2>&1; then
  213. echo You must install GNU sed to continue.
  214. echo
  215. out=1
  216. fi
  217. fi
  218. if ! which wget >/dev/null 2>&1; then
  219. echo You must install wget to continue.
  220. echo
  221. out=1
  222. fi
  223. if ! which autoconf >/dev/null 2>&1; then
  224. echo You must install autoconf to continue.
  225. echo
  226. out=1
  227. fi
  228. if ! which automake >/dev/null 2>&1; then
  229. echo You must install automake to continue.
  230. echo
  231. out=1
  232. fi
  233. if ! which libtool >/dev/null 2>&1; then
  234. echo You must install libtool to continue.
  235. echo
  236. out=1
  237. fi
  238. if ! which file >/dev/null 2>&1; then
  239. echo You must install \"file\" to continue.
  240. echo
  241. out=1
  242. fi
  243. cd $topdir
  244. rm -rf tmp
  245. exit $out