1
0

scan-tools.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. ;;
  44. MirBSD)
  45. ;;
  46. CYG*)
  47. ;;
  48. NetBSD)
  49. ;;
  50. OpenBSD)
  51. if ! which gmake >/dev/null 2>&1; then
  52. echo You must install GNU make to continue.
  53. echo
  54. out=1
  55. fi
  56. ;;
  57. Darwin*)
  58. clang=1
  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. if [ -z $(which gmake 2>/dev/null ) ];then
  69. makecmd=$(which make 2>/dev/null )
  70. else
  71. makecmd=$(which gmake 2>/dev/null )
  72. fi
  73. cat >Makefile <<'EOF'
  74. include ${ADK_TOPDIR}/prereq.mk
  75. all: run-test
  76. test: test.c
  77. ${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  78. run-test: test
  79. ./test
  80. EOF
  81. cat >test.c <<-'EOF'
  82. #include <stdio.h>
  83. int
  84. main()
  85. {
  86. printf("Yay! Native compiler works.\n");
  87. return (0);
  88. }
  89. EOF
  90. if [[ $clang -eq 0 ]]; then
  91. X=$($makecmd ADK_TOPDIR=$topdir LDADD=-lgcc 2>&1)
  92. if [[ $X != *@(Native compiler works)* ]]; then
  93. echo Cannot compile with shared libgcc use static one.
  94. HOST_CFLAGS=-static-libgcc
  95. echo "HOST_CFLAGS:=-O0 -g0 -static-libgcc" >> $topdir/prereq.mk
  96. echo "HOST_CXXFLAGS:=-O0 -g0 -static-libgcc" >> $topdir/prereq.mk
  97. else
  98. echo "HOST_CFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  99. echo "HOST_CXXFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  100. fi
  101. else
  102. echo "HOST_CFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  103. echo "HOST_CXXFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  104. fi
  105. X=$($makecmd ADK_TOPDIR=$topdir HOST_CFLAGS=${HOST_CFLAGS} 2>&1)
  106. if [[ $X != *@(Native compiler works)* ]]; then
  107. echo "$X" | sed 's/^/| /'
  108. echo Cannot compile a simple test programme.
  109. echo You must install a host make and C compiler,
  110. echo usually GCC, to proceed.
  111. echo
  112. out=1
  113. fi
  114. rm test 2>/dev/null
  115. if ! which shasum >/dev/null 2>&1; then
  116. if ! which sha256sum >/dev/null 2>&1; then
  117. if ! which cksum >/dev/null 2>&1; then
  118. echo You must install shasum or sha256sum or cksum to continue.
  119. echo
  120. out=1
  121. fi
  122. fi
  123. fi
  124. if ! which gzip >/dev/null 2>&1; then
  125. echo You must install gzip to continue.
  126. echo
  127. out=1
  128. fi
  129. cat >test.c <<-'EOF'
  130. #include <stdio.h>
  131. #include <zlib.h>
  132. #ifndef STDIN_FILENO
  133. #define STDIN_FILENO 0
  134. #endif
  135. int
  136. main()
  137. {
  138. gzFile zstdin;
  139. char buf[1024];
  140. int i;
  141. zstdin = gzdopen(STDIN_FILENO, "rb");
  142. i = gzread(zstdin, buf, sizeof (buf));
  143. if ((i > 0) && (i < sizeof (buf)))
  144. buf[i] = '\0';
  145. buf[sizeof (buf) - 1] = '\0';
  146. printf("%s\n", buf);
  147. return (0);
  148. }
  149. EOF
  150. X=$(echo 'Yay! Native compiler works.' | gzip | \
  151. $makecmd ADK_TOPDIR=$topdir LDADD=-lz HOST_CFLAGS=${HOST_CFLAGS} 2>&1)
  152. if [[ $X != *@(Native compiler works)* ]]; then
  153. echo "$X" | sed 's/^/| /'
  154. echo Cannot compile a libz test programm.
  155. echo You must install the zlib development package,
  156. echo usually called libz-dev, and the run-time library.
  157. echo
  158. out=1
  159. fi
  160. if [[ ! -s /usr/include/ncursesw/curses.h && \
  161. ! -s /usr/include/ncurses.h && \
  162. ! -s /usr/include/curses.h && \
  163. ! -s /usr/include/ncurses/ncurses.h && \
  164. ! -s /usr/local/opt/ncurses/include/ncursesw/ncurses.h ]]; then
  165. echo Install ncurses header files, please.
  166. echo
  167. out=1
  168. fi
  169. if ! which wget >/dev/null 2>&1; then
  170. echo You must install wget to continue.
  171. echo
  172. out=1
  173. fi
  174. if ! which perl >/dev/null 2>&1; then
  175. echo You must install perl to continue.
  176. echo
  177. out=1
  178. fi
  179. if ! which g++ >/dev/null 2>&1; then
  180. echo "You need a C++ compiler to continue."
  181. echo
  182. out=1
  183. fi
  184. # always required, but can be provided by host
  185. host_build_bc=0
  186. if which bc >/dev/null 2>&1; then
  187. if ! echo quit|bc -q 2>/dev/null >/dev/null;then
  188. host_build_bc=1
  189. fi
  190. else
  191. host_build_bc=1
  192. fi
  193. host_build_bison=0
  194. if ! which bison >/dev/null 2>&1; then
  195. host_build_bison=1
  196. fi
  197. host_build_bzip2=0
  198. if ! which bzip2 >/dev/null 2>&1; then
  199. host_build_bzip2=1
  200. fi
  201. host_build_file=0
  202. if ! which file >/dev/null 2>&1; then
  203. host_build_file=1
  204. fi
  205. host_build_flex=0
  206. if ! which flex >/dev/null 2>&1; then
  207. host_build_flex=1
  208. fi
  209. host_build_m4=0
  210. if ! which m4 >/dev/null 2>&1; then
  211. host_build_m4=1
  212. fi
  213. host_build_mksh=0
  214. if ! which mksh >/dev/null 2>&1; then
  215. host_build_mksh=1
  216. fi
  217. host_build_patch=0
  218. if ! which patch >/dev/null 2>&1; then
  219. host_build_patch=1
  220. fi
  221. host_build_pkgconf=0
  222. if ! which pkgconf >/dev/null 2>&1; then
  223. host_build_pkgconf=1
  224. fi
  225. host_build_tar=0
  226. if which tar >/dev/null 2>&1; then
  227. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  228. host_build_tar=1
  229. fi
  230. else
  231. host_build_tar=1
  232. fi
  233. host_build_findutils=0
  234. if ! which gxargs >/dev/null 2>&1; then
  235. if which xargs >/dev/null 2>&1; then
  236. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  237. host_build_findutils=1
  238. fi
  239. fi
  240. fi
  241. if which find >/dev/null 2>&1; then
  242. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  243. host_build_findutils=1
  244. fi
  245. fi
  246. host_build_grep=0
  247. if which grep >/dev/null 2>&1; then
  248. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  249. host_build_grep=1
  250. fi
  251. fi
  252. host_build_gawk=0
  253. if ! which gawk >/dev/null 2>&1; then
  254. host_build_gawk=1
  255. fi
  256. host_build_sed=0
  257. if which sed >/dev/null 2>&1; then
  258. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  259. host_build_sed=1
  260. fi
  261. fi
  262. host_build_xz=0
  263. if ! which xz >/dev/null 2>&1; then
  264. host_build_xz=1
  265. fi
  266. # optional
  267. host_build_cdrtools=0
  268. if ! which mkisofs >/dev/null 2>&1; then
  269. host_build_cdrtools=1
  270. fi
  271. host_build_ccache=0
  272. if ! which ccache >/dev/null 2>&1; then
  273. host_build_ccache=1
  274. fi
  275. host_build_genext2fs=0
  276. if ! which genext2fs >/dev/null 2>&1; then
  277. host_build_genext2fs=1
  278. fi
  279. host_build_lzma=0
  280. if ! which lzma >/dev/null 2>&1; then
  281. host_build_lzma=1
  282. fi
  283. host_build_lz4=0
  284. if ! which lz4c >/dev/null 2>&1; then
  285. host_build_lz4=1
  286. fi
  287. host_build_lzop=0
  288. if ! which lzop >/dev/null 2>&1; then
  289. host_build_lzop=1
  290. fi
  291. host_build_qemu=0
  292. if ! which qemu-img >/dev/null 2>&1; then
  293. host_build_qemu=1
  294. fi
  295. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  296. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  297. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  298. # always required
  299. if [ $host_build_bc -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq ;fi
  300. if [ $host_build_bison -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq ;fi
  301. if [ $host_build_bzip2 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq ;fi
  302. if [ $host_build_file -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq ;fi
  303. if [ $host_build_flex -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq ;fi
  304. if [ $host_build_gawk -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq ;fi
  305. if [ $host_build_grep -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq ;fi
  306. if [ $host_build_m4 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq ;fi
  307. if [ $host_build_mksh -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq ;fi
  308. if [ $host_build_patch -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq ;fi
  309. if [ $host_build_pkgconf -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_PKGCONF" >> $topdir/target/config/Config.in.prereq ;fi
  310. if [ $host_build_findutils -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq ;fi
  311. if [ $host_build_sed -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq ;fi
  312. if [ $host_build_tar -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq ;fi
  313. if [ $host_build_xz -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq ;fi
  314. # optional
  315. 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
  316. 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
  317. 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
  318. 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
  319. 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
  320. 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
  321. 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
  322. cd $topdir
  323. rm -rf tmp
  324. exit $out