scan-tools.sh 8.9 KB

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