scan-tools.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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) ];then
  8. makecmd=$(which make)
  9. else
  10. makecmd=$(which gmake)
  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. CYG*)
  38. # mkdir /openadk
  39. # mount -b -s -o managed "C:/openadk" "/openadk"
  40. # cd /
  41. # git clone git+ssh://openadk.org/git/openadk.git
  42. echo "Building OpenADK on $os is needs a managed mount point."
  43. echo '"mount -b -s -o managed "C:/openadk" "/openadk"'
  44. ;;
  45. NetBSD)
  46. echo "Building OpenADK on $os is currently unsupported."
  47. echo "Sorry."
  48. echo
  49. echo There are unresolved issues relating to ncurses not
  50. echo being included in NetBSD®, and these provided by pkgsrc®
  51. echo lack important header files.
  52. ;;
  53. OpenBSD)
  54. # supported with no extra quirks at the moment
  55. # although some packages' autoconf scripts may
  56. # not properly recognise OpenBSD
  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. HOSTCFLAGS+= -O2
  69. all: run-test
  70. test: test.c
  71. ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
  72. run-test: test
  73. ./test
  74. EOF
  75. cat >test.c <<-'EOF'
  76. #include <stdio.h>
  77. int
  78. main()
  79. {
  80. printf("Yay! Native compiler works.\n");
  81. return (0);
  82. }
  83. EOF
  84. X=$($makecmd TOPDIR=$topdir 2>&1)
  85. if [[ $X != *@(Native compiler works)* ]]; then
  86. echo "$X" | sed 's/^/| /'
  87. echo Cannot compile a simple test programme.
  88. echo You must install a host make and C compiler,
  89. echo usually GCC, to proceed.
  90. echo
  91. out=1
  92. fi
  93. rm test 2>/dev/null
  94. if ! which cpp >/dev/null 2>&1; then
  95. echo You must install a C preprocessor to continue.
  96. echo
  97. out=1
  98. fi
  99. if ! which flex >/dev/null 2>&1; then
  100. echo You must install flex to continue.
  101. echo
  102. out=1
  103. else
  104. echo '%%' | flex -
  105. if fgrep _POSIX_SOURCE lex.yy.c; then
  106. echo Your lexer \(flex\) contains a broken skeleton.
  107. if [[ $NO_ERROR = 1 ]]; then
  108. echo WARNING: continue at your own risk.
  109. echo Some packages may be broken.
  110. else
  111. echo You can continue the build by issuing \'make prereq-noerror\'
  112. echo However, several packages may faild to build correctly.
  113. out=1
  114. fi
  115. echo
  116. fi
  117. fi
  118. if ! which bison >/dev/null 2>&1; then
  119. echo You must install GNU bison to continue.
  120. echo
  121. out=1
  122. fi
  123. if ! which gperf >/dev/null 2>&1; then
  124. echo You must install gperf to continue.
  125. echo
  126. out=1
  127. fi
  128. if ! which tar >/dev/null 2>&1; then
  129. echo You must install GNU tar to continue.
  130. echo
  131. out=1
  132. fi
  133. if ! tar --version|grep GNU >/dev/null 2>&1;then
  134. if ! which gtar >/dev/null 2>&1; then
  135. echo You must install GNU tar to continue.
  136. echo
  137. out=1
  138. fi
  139. fi
  140. if ! which gzip >/dev/null 2>&1; then
  141. echo You must install gzip to continue.
  142. echo
  143. out=1
  144. fi
  145. if ! which bzip2 >/dev/null 2>&1; then
  146. echo You must install bzip2 to continue.
  147. echo
  148. out=1
  149. fi
  150. if ! which cpio >/dev/null 2>&1; then
  151. echo You must install cpio to continue.
  152. echo
  153. out=1
  154. fi
  155. if ! which unzip >/dev/null 2>&1; then
  156. echo You must install unzip to continue.
  157. echo
  158. out=1
  159. fi
  160. if ! which patch >/dev/null 2>&1; then
  161. echo You must install patch to continue.
  162. echo
  163. out=1
  164. fi
  165. cat >test.c <<-'EOF'
  166. #include <stdio.h>
  167. #include <zlib.h>
  168. #ifndef STDIN_FILENO
  169. #define STDIN_FILENO 0
  170. #endif
  171. int
  172. main()
  173. {
  174. gzFile zstdin;
  175. char buf[1024];
  176. int i;
  177. zstdin = gzdopen(STDIN_FILENO, "rb");
  178. i = gzread(zstdin, buf, sizeof (buf));
  179. if ((i > 0) && (i < sizeof (buf)))
  180. buf[i] = '\0';
  181. buf[sizeof (buf) - 1] = '\0';
  182. printf("%s\n", buf);
  183. return (0);
  184. }
  185. EOF
  186. X=$(echo 'Yay! Native compiler works.' | gzip | \
  187. $makecmd TOPDIR=$topdir LDADD=-lz 2>&1)
  188. if [[ $X != *@(Native compiler works)* ]]; then
  189. echo "$X" | sed 's/^/| /'
  190. echo Cannot compile a libz test programm.
  191. echo You must install the zlib development package,
  192. echo usually called libz-dev, and the run-time library.
  193. echo
  194. out=1
  195. fi
  196. [[ -s /usr/include/ncurses.h ]] || if [[ -s /usr/pkg/include/ncurses.h ]]; then
  197. echo 'HOSTCFLAGS+= -isystem /usr/pkg/include' >>$topdir/prereq.mk
  198. echo 'HOSTLDFLAGS+=-L/usr/pkg/lib -Wl,-rpath -Wl,/usr/pkg/lib' >>$topdir/prereq.mk
  199. else
  200. echo Install ncurses header files, please.
  201. echo
  202. out=1
  203. fi
  204. if ! which gawk >/dev/null 2>&1; then
  205. echo You must install GNU awk to continue.
  206. echo
  207. out=1
  208. fi
  209. if ! which sed >/dev/null 2>&1; then
  210. echo You must install GNU sed to continue.
  211. echo
  212. out=1
  213. fi
  214. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  215. if ! which gsed >/dev/null 2>&1; then
  216. echo You must install GNU sed to continue.
  217. echo
  218. out=1
  219. fi
  220. fi
  221. if ! which wget >/dev/null 2>&1; then
  222. echo You must install wget to continue.
  223. echo
  224. out=1
  225. fi
  226. if ! which autoconf >/dev/null 2>&1; then
  227. echo You must install autoconf to continue.
  228. echo
  229. out=1
  230. fi
  231. if ! which automake >/dev/null 2>&1; then
  232. echo You must install automake to continue.
  233. echo
  234. out=1
  235. fi
  236. if ! which libtool >/dev/null 2>&1; then
  237. echo You must install libtool to continue.
  238. echo
  239. out=1
  240. fi
  241. if ! which file >/dev/null 2>&1; then
  242. echo You must install \"file\" to continue.
  243. echo
  244. out=1
  245. fi
  246. cd $topdir
  247. rm -rf tmp
  248. exit $out