scan-tools.sh 9.0 KB

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