scan-tools.sh 9.5 KB

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