1
0

scan-tools.sh 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. clang=0
  8. if [[ $NO_ERROR != @(0|1) ]]; then
  9. echo Please do not invoke this script directly!
  10. exit 1
  11. fi
  12. set -e
  13. rm -rf $topdir/tmp
  14. mkdir -p $topdir/tmp
  15. cd $topdir/tmp
  16. os=$(uname)
  17. rm -f foo
  18. echo >FOO
  19. if [[ -e foo ]]; then
  20. cat >&2 <<-EOF
  21. ERROR: OpenADK cannot be built in a case-insensitive file system.
  22. EOF
  23. case $os in
  24. CYG*)
  25. echo "Building OpenADK on $os needs a small registry change."
  26. echo 'http://cygwin.com/cygwin-ug-net/using-specialnames.html'
  27. ;;
  28. Darwin*)
  29. echo "Building OpenADK on $os needs a case-sensitive disk partition."
  30. echo "For Snow Leopard and above you can use diskutil to resize your existing disk."
  31. echo "Example: sudo diskutil resizeVolume disk0s2 90G 1 jhfsx adk 30G"
  32. echo "For older versions you might consider to use a disk image:"
  33. echo "hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 30g ~/openadk.dmg"
  34. ;;
  35. esac
  36. exit 1
  37. fi
  38. rm -f FOO
  39. case $os in
  40. Linux)
  41. ;;
  42. FreeBSD)
  43. if ! which gmake >/dev/null 2>&1; then
  44. echo You must install GNU make to continue.
  45. echo
  46. out=1
  47. fi
  48. clang=1
  49. ;;
  50. MirBSD)
  51. ;;
  52. CYG*)
  53. ;;
  54. NetBSD)
  55. ;;
  56. OpenBSD)
  57. if ! which gmake >/dev/null 2>&1; then
  58. echo You must install GNU make to continue.
  59. echo
  60. out=1
  61. fi
  62. ;;
  63. Darwin*)
  64. clang=1
  65. ;;
  66. *)
  67. # unsupported
  68. echo "Building OpenADK on $os is currently unsupported."
  69. echo "Sorry."
  70. exit 1
  71. ;;
  72. esac
  73. set +e
  74. if [ -z $(which gmake 2>/dev/null ) ];then
  75. makecmd=$(which make 2>/dev/null )
  76. else
  77. makecmd=$(which gmake 2>/dev/null )
  78. fi
  79. cat >Makefile <<'EOF'
  80. include ${ADK_TOPDIR}/prereq.mk
  81. all: run-test
  82. test: test.c
  83. ${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  84. run-test: test
  85. ./test
  86. EOF
  87. cat >test.c <<-'EOF'
  88. #include <stdio.h>
  89. int
  90. main()
  91. {
  92. printf("Yay! Native compiler works.\n");
  93. return (0);
  94. }
  95. EOF
  96. if [[ $clang -eq 0 ]]; then
  97. X=$($makecmd ADK_TOPDIR=$topdir LDADD=-lgcc 2>&1)
  98. if [[ $X != *@(Native compiler works)* ]]; then
  99. echo Cannot compile with shared libgcc use static one.
  100. HOST_CFLAGS=-static-libgcc
  101. echo "HOST_CFLAGS:=-O0 -g0 -static-libgcc" >> $topdir/prereq.mk
  102. echo "HOST_CXXFLAGS:=-O0 -g0 -static-libgcc" >> $topdir/prereq.mk
  103. else
  104. echo "HOST_CFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  105. echo "HOST_CXXFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  106. fi
  107. else
  108. echo "HOST_CFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  109. echo "HOST_CXXFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  110. fi
  111. X=$($makecmd ADK_TOPDIR=$topdir HOST_CFLAGS=${HOST_CFLAGS} 2>&1)
  112. if [[ $X != *@(Native compiler works)* ]]; then
  113. echo "$X" | sed 's/^/| /'
  114. echo Cannot compile a simple test programme.
  115. echo You must install a host make and C compiler,
  116. echo usually GCC, to proceed.
  117. echo
  118. out=1
  119. fi
  120. rm test 2>/dev/null
  121. if ! which shasum >/dev/null 2>&1; then
  122. if ! which sha256sum >/dev/null 2>&1; then
  123. if ! which cksum >/dev/null 2>&1; then
  124. echo You must install shasum or sha256sum or cksum to continue.
  125. echo
  126. out=1
  127. fi
  128. fi
  129. fi
  130. if ! which gzip >/dev/null 2>&1; then
  131. echo You must install gzip to continue.
  132. echo
  133. out=1
  134. fi
  135. cat >test.c <<-'EOF'
  136. #include <stdio.h>
  137. #include <zlib.h>
  138. #ifndef STDIN_FILENO
  139. #define STDIN_FILENO 0
  140. #endif
  141. int
  142. main()
  143. {
  144. gzFile zstdin;
  145. char buf[1024];
  146. int i;
  147. zstdin = gzdopen(STDIN_FILENO, "rb");
  148. i = gzread(zstdin, buf, sizeof (buf));
  149. if ((i > 0) && (i < sizeof (buf)))
  150. buf[i] = '\0';
  151. buf[sizeof (buf) - 1] = '\0';
  152. printf("%s\n", buf);
  153. return (0);
  154. }
  155. EOF
  156. X=$(echo 'Yay! Native compiler works.' | gzip | \
  157. $makecmd ADK_TOPDIR=$topdir LDADD=-lz HOST_CFLAGS=${HOST_CFLAGS} 2>&1)
  158. if [[ $X != *@(Native compiler works)* ]]; then
  159. echo "$X" | sed 's/^/| /'
  160. echo Cannot compile a libz test programm.
  161. echo You must install the zlib development package,
  162. echo usually called libz-dev, and the run-time library.
  163. echo
  164. out=1
  165. fi
  166. if [[ ! -s /usr/include/ncursesw/curses.h && \
  167. ! -s /usr/include/ncurses.h && \
  168. ! -s /usr/include/curses.h && \
  169. ! -s /usr/include/ncurses/ncurses.h && \
  170. ! -s /usr/local/opt/ncurses/include/ncursesw/ncurses.h ]]; then
  171. echo Install ncurses header files, please.
  172. echo
  173. out=1
  174. fi
  175. if ! which wget >/dev/null 2>&1; then
  176. echo You must install wget to continue.
  177. echo
  178. out=1
  179. fi
  180. if ! which perl >/dev/null 2>&1; then
  181. echo You must install perl to continue.
  182. echo
  183. out=1
  184. fi
  185. if ! which g++ >/dev/null 2>&1; then
  186. if ! which clang++ >/dev/null 2>&1; then
  187. echo "You need a C++ compiler to continue."
  188. echo
  189. out=1
  190. fi
  191. fi
  192. # always required, but can be provided by host
  193. host_build_bc=0
  194. if which bc >/dev/null 2>&1; then
  195. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  196. host_build_bc=1
  197. else
  198. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  199. host_build_bc=1
  200. fi
  201. fi
  202. else
  203. host_build_bc=1
  204. fi
  205. host_build_bison=0
  206. if ! which bison >/dev/null 2>&1; then
  207. host_build_bison=1
  208. fi
  209. host_build_bzip2=0
  210. if ! which bzip2 >/dev/null 2>&1; then
  211. host_build_bzip2=1
  212. fi
  213. host_build_file=0
  214. if ! which file >/dev/null 2>&1; then
  215. host_build_file=1
  216. fi
  217. host_build_flex=0
  218. if ! which flex >/dev/null 2>&1; then
  219. host_build_flex=1
  220. fi
  221. host_build_m4=0
  222. if ! which m4 >/dev/null 2>&1; then
  223. host_build_m4=1
  224. fi
  225. host_build_mksh=0
  226. if ! which mksh >/dev/null 2>&1; then
  227. host_build_mksh=1
  228. fi
  229. host_build_patch=0
  230. if ! which patch >/dev/null 2>&1; then
  231. host_build_patch=1
  232. fi
  233. host_build_pkgconf=0
  234. if ! which pkgconf >/dev/null 2>&1; then
  235. host_build_pkgconf=1
  236. fi
  237. host_build_tar=0
  238. if which tar >/dev/null 2>&1; then
  239. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  240. host_build_tar=1
  241. fi
  242. else
  243. host_build_tar=1
  244. fi
  245. host_build_findutils=0
  246. if ! which gxargs >/dev/null 2>&1; then
  247. if which xargs >/dev/null 2>&1; then
  248. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  249. host_build_findutils=1
  250. fi
  251. fi
  252. fi
  253. if which find >/dev/null 2>&1; then
  254. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  255. host_build_findutils=1
  256. fi
  257. fi
  258. host_build_grep=0
  259. if which grep >/dev/null 2>&1; then
  260. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  261. host_build_grep=1
  262. fi
  263. fi
  264. host_build_gawk=0
  265. if ! which gawk >/dev/null 2>&1; then
  266. host_build_gawk=1
  267. fi
  268. host_build_sed=0
  269. if which sed >/dev/null 2>&1; then
  270. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  271. host_build_sed=1
  272. fi
  273. fi
  274. host_build_xz=0
  275. if ! which xz >/dev/null 2>&1; then
  276. host_build_xz=1
  277. fi
  278. # optional
  279. host_build_cdrtools=0
  280. if ! which mkisofs >/dev/null 2>&1; then
  281. host_build_cdrtools=1
  282. fi
  283. host_build_ccache=0
  284. if ! which ccache >/dev/null 2>&1; then
  285. host_build_ccache=1
  286. fi
  287. host_build_genext2fs=0
  288. if ! which genext2fs >/dev/null 2>&1; then
  289. host_build_genext2fs=1
  290. fi
  291. host_build_lzma=0
  292. if ! which lzma >/dev/null 2>&1; then
  293. host_build_lzma=1
  294. fi
  295. host_build_lz4=0
  296. if ! which lz4c >/dev/null 2>&1; then
  297. host_build_lz4=1
  298. fi
  299. host_build_lzop=0
  300. if ! which lzop >/dev/null 2>&1; then
  301. host_build_lzop=1
  302. fi
  303. host_build_qemu=0
  304. if ! which qemu-img >/dev/null 2>&1; then
  305. host_build_qemu=1
  306. fi
  307. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  308. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  309. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  310. # always required
  311. if [ $host_build_bc -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq ;fi
  312. if [ $host_build_bison -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq ;fi
  313. if [ $host_build_bzip2 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq ;fi
  314. if [ $host_build_file -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq ;fi
  315. if [ $host_build_flex -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq ;fi
  316. if [ $host_build_gawk -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq ;fi
  317. if [ $host_build_grep -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq ;fi
  318. if [ $host_build_m4 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq ;fi
  319. if [ $host_build_mksh -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq ;fi
  320. if [ $host_build_patch -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq ;fi
  321. if [ $host_build_pkgconf -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_PKGCONF" >> $topdir/target/config/Config.in.prereq ;fi
  322. if [ $host_build_findutils -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq ;fi
  323. if [ $host_build_sed -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq ;fi
  324. if [ $host_build_tar -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq ;fi
  325. if [ $host_build_xz -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq ;fi
  326. # optional
  327. if [ $host_build_ccache -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_CCACHE if ADK_HOST_NEED_CCACHE" >> $topdir/target/config/Config.in.prereq ;fi
  328. if [ $host_build_cdrtools -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq ;fi
  329. if [ $host_build_genext2fs -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq ;fi
  330. if [ $host_build_lzma -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq ;fi
  331. if [ $host_build_lz4 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq ;fi
  332. if [ $host_build_lzop -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq ;fi
  333. if [ $host_build_qemu -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq ;fi
  334. cd $topdir
  335. rm -rf tmp
  336. exit $out