prereq.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. #!/bin/sh
  2. # This file is part of the OpenADK project. OpenADK is copyrighted
  3. # material, please see the LICENCE file in the top-level directory.
  4. # resolve prerequisites for OpenADK build
  5. topdir=$(pwd)
  6. target="$@"
  7. flags="$MAKEFLAGS"
  8. out=0
  9. mirror=http://distfiles.openadk.org
  10. makever=4.1
  11. bashver=4.3.30
  12. dlverbose=0
  13. # detect operating system
  14. os=$(env uname)
  15. osver=$(env uname -r)
  16. printf " ---> $os $osver for build detected.\n"
  17. # check if the filesystem is case sensitive
  18. rm -f foo
  19. echo >FOO
  20. if [ -e foo ]; then
  21. printf "ERROR: OpenADK cannot be built in a case-insensitive file system."
  22. case $os in
  23. CYG*)
  24. printf "Building OpenADK on $os needs a small registry change."
  25. printf "http://cygwin.com/cygwin-ug-net/using-specialnames.html"
  26. ;;
  27. Darwin*)
  28. printf "Building OpenADK on $os needs a case-sensitive disk partition."
  29. printf "For Snow Leopard and above you can use diskutil to resize your existing disk."
  30. printf "Example: sudo diskutil resizeVolume disk0s2 90G 1 jhfsx adk 30G"
  31. printf "For older versions you might consider to use a disk image:"
  32. printf "hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 30g ~/openadk.dmg"
  33. ;;
  34. esac
  35. rm -f FOO
  36. exit 1
  37. fi
  38. rm -f FOO
  39. # do we have a download tool?
  40. tools="curl wget"
  41. for tool in $tools; do
  42. printf " ---> checking if $tool is installed.. "
  43. if which $tool >/dev/null; then
  44. printf "found\n"
  45. case $tool in
  46. curl)
  47. FETCHCMD="$(which $tool) -L -k -f -\# -o "
  48. ;;
  49. wget)
  50. FETCHCMD="$(which $tool) --no-check-certificate -O "
  51. ;;
  52. esac
  53. break
  54. else
  55. printf "not found\n"
  56. continue
  57. fi
  58. done
  59. if [ -z "$FETCHCMD" ]; then
  60. printf "ERROR: no download tool found. Fatal error.\n"
  61. exit 1
  62. fi
  63. # do we have a checksum tool?
  64. tools="sha256sum sha256 cksum shasum"
  65. for tool in $tools; do
  66. printf " ---> checking if $tool is installed.. "
  67. if which $tool >/dev/null 2>/dev/null; then
  68. printf "found\n"
  69. # check if cksum is usable
  70. case $tool in
  71. sha256sum)
  72. SHA256=$(which $tool)
  73. ;;
  74. sha256)
  75. SHA256="$(which $tool) -q"
  76. ;;
  77. cksum)
  78. if cksum -q >/dev/null 2>/dev/null; then
  79. SHA256="$(which $tool) -q -a sha256"
  80. else
  81. continue
  82. fi
  83. ;;
  84. shasum)
  85. SHA256="$(which $tool) -a 256"
  86. ;;
  87. esac
  88. break
  89. else
  90. printf "not found\n"
  91. continue
  92. fi
  93. done
  94. if [ -z "$SHA256" ]; then
  95. printf "ERROR: no checksum tool found. Fatal error.\n"
  96. exit 1
  97. fi
  98. # create download dir
  99. if [ ! -d $topdir/dl ]; then
  100. mkdir -p $topdir/dl
  101. fi
  102. # check for c compiler
  103. compilerbins="clang cc gcc"
  104. for compilerbin in $compilerbins; do
  105. printf " ---> checking if $compilerbin is installed.. "
  106. if which $compilerbin >/dev/null; then
  107. printf "found\n"
  108. CC=$compilerbin
  109. CCFOUND=1
  110. break
  111. else
  112. printf "not found\n"
  113. continue
  114. fi
  115. done
  116. if [ -z "$CCFOUND" ]; then
  117. printf "ERROR: no C compiler found. Fatal error.\n"
  118. exit 1
  119. fi
  120. # check for c++ compiler
  121. compilerbins="clang++ c++ g++"
  122. for compilerbin in $compilerbins; do
  123. printf " ---> checking if $compilerbin is installed.. "
  124. if which $compilerbin >/dev/null; then
  125. printf "found\n"
  126. CXX=$compilerbin
  127. CXXFOUND=1
  128. break
  129. else
  130. printf "not found\n"
  131. continue
  132. fi
  133. done
  134. if [ -z "$CXXFOUND" ]; then
  135. printf "ERROR: no C++ compiler found. Fatal error.\n"
  136. exit 1
  137. fi
  138. gnu_host_name=$(${CC} -dumpmachine)
  139. # relocation of topdir?
  140. olddir=$(grep "^ADK_TOPDIR" prereq.mk 2>/dev/null |cut -d '=' -f 2)
  141. newdir=$(pwd)
  142. if [ ! -z "$olddir" ]; then
  143. if [ "$olddir" != "$newdir" ]; then
  144. printf " ---> adk directory was relocated, fixing .."
  145. sed -i -e "s#$olddir#$newdir#g" $(find target_* -name \*.pc|xargs) 2>/dev/null
  146. sed -i -e "s#$olddir#$newdir#g" $(find host_${gnu_host_name} -type f|xargs) 2>/dev/null
  147. sed -i -e "s#$olddir#$newdir#g" $(find target_*/scripts -type f|xargs) 2>/dev/null
  148. sed -i -e "s#$olddir#$newdir#" target_*/etc/ipkg.conf 2>/dev/null
  149. sleep 2
  150. printf "done\n"
  151. fi
  152. fi
  153. case :$PATH: in
  154. (*:$topdir/host_${gnu_host_name}/bin:*) ;;
  155. (*) export PATH=$topdir/host_${gnu_host_name}/bin:$PATH ;;
  156. esac
  157. # check for GNU make
  158. makebins="gmake make"
  159. for makebin in $makebins; do
  160. printf " ---> checking if $makebin is installed.. "
  161. if which $makebin >/dev/null 2>/dev/null; then
  162. printf "found\n"
  163. printf " ---> checking if it is GNU make.. "
  164. $makebin --version 2>/dev/null| grep GNU >/dev/null
  165. if [ $? -eq 0 ]; then
  166. printf "yes\n"
  167. MAKE=$(which $makebin)
  168. break
  169. else
  170. # we need to build GNU make
  171. printf "no\n"
  172. printf " ---> compiling missing GNU make.. "
  173. cd dl
  174. $FETCHCMD make-${makever}.tar.gz $mirror/make-${makever}.tar.gz
  175. if [ $? -ne 0 ]; then
  176. printf "ERROR: failed to download make from $mirror\n"
  177. exit 1
  178. fi
  179. cd ..
  180. mkdir tmp
  181. cd tmp
  182. tar xzf ../dl/make-${makever}.tar.gz
  183. cd make-$makever
  184. ./configure --prefix=$topdir/host_$gnu_host_name/
  185. make
  186. make install
  187. cd ..
  188. cd ..
  189. rm -rf tmp
  190. MAKE=$topdir/host_$gnu_host_name/bin/make
  191. makebin=$topdir/host_$gnu_host_name/bin/make
  192. printf " done\n"
  193. fi
  194. else
  195. printf "not found\n"
  196. continue
  197. fi
  198. done
  199. # check for bash
  200. printf " ---> checking if bash is installed.. "
  201. if which bash >/dev/null; then
  202. printf "found\n"
  203. printf " ---> checking if it is bash 4.x.. "
  204. bash --version 2>/dev/null| grep -i "Version 4" >/dev/null
  205. if [ $? -eq 0 ]; then
  206. printf "yes\n"
  207. else
  208. # we need to build GNU bash 4.x
  209. printf "not found\n"
  210. printf " ---> compiling missing GNU bash.. "
  211. cd dl
  212. $FETCHCMD bash-${bashver}.tar.gz $mirror/bash-${bashver}.tar.gz
  213. if [ $? -ne 0 ]; then
  214. printf "ERROR: failed to download make from $mirror\n"
  215. exit 1
  216. fi
  217. cd ..
  218. mkdir tmp
  219. cd tmp
  220. tar xzf ../dl/bash-${bashver}.tar.gz
  221. cd bash-${bashver}
  222. ./configure --prefix=$topdir/host_$gnu_host_name/
  223. make
  224. make install
  225. cd ..
  226. cd ..
  227. rm -rf tmp
  228. printf " done\n"
  229. fi
  230. fi
  231. # skip the script if distclean / cleandir
  232. if [ "$target" = "distclean" -o "$target" = "cleandir" ]; then
  233. touch prereq.mk
  234. $makebin ADK_TOPDIR=$topdir -s -f Makefile.adk $flags $target
  235. exit 0
  236. fi
  237. printf " ---> checking if strings is installed.. "
  238. if ! which strings >/dev/null 2>&1; then
  239. echo You must install strings to continue.
  240. echo
  241. out=1
  242. printf "not found\n"
  243. fi
  244. printf "found\n"
  245. printf " ---> checking if perl is installed.. "
  246. if ! which perl >/dev/null 2>&1; then
  247. echo You must install perl to continue.
  248. echo
  249. out=1
  250. printf "not found\n"
  251. fi
  252. printf "found\n"
  253. printf " ---> checking if gzip is installed.. "
  254. if ! which gzip >/dev/null 2>&1; then
  255. echo You must install gzip to continue.
  256. echo
  257. out=1
  258. printf "not found\n"
  259. fi
  260. printf "found\n"
  261. printf " ---> checking if git is installed.. "
  262. if ! which git >/dev/null 2>&1; then
  263. echo You must install git to continue.
  264. echo
  265. out=1
  266. printf "not found\n"
  267. fi
  268. printf "found\n"
  269. # creating prereq.mk
  270. echo "ADK_TOPDIR:=$(readlink -nf . 2>/dev/null || pwd -P)" > $topdir/prereq.mk
  271. echo "BASH:=$(which bash)" >> $topdir/prereq.mk
  272. echo "SHELL:=$(which bash)" >> $topdir/prereq.mk
  273. echo "GMAKE:=$MAKE" >> $topdir/prereq.mk
  274. echo "MAKE:=$MAKE" >> $topdir/prereq.mk
  275. echo "FETCHCMD:=$FETCHCMD" >> $topdir/prereq.mk
  276. echo "SHA256:=$SHA256" >> $topdir/prereq.mk
  277. echo "GNU_HOST_NAME:=${gnu_host_name}" >> $topdir/prereq.mk
  278. echo "OS_FOR_BUILD:=${os}" >> $topdir/prereq.mk
  279. echo "ARCH_FOR_BUILD:=$(${CC} -dumpmachine | sed \
  280. -e 's/x86_64-linux-gnux32/x32/' \
  281. -e s'/-.*//' \
  282. -e 's/sparc.*/sparc/' \
  283. -e 's/armeb.*/armeb/g' \
  284. -e 's/arm.*/arm/g' \
  285. -e 's/m68k.*/m68k/' \
  286. -e 's/sh[234]/sh/' \
  287. -e 's/mips-.*/mips/' \
  288. -e 's/mipsel-.*/mipsel/' \
  289. -e 's/i[3-9]86/x86/' \
  290. )" >>prereq.mk
  291. if [ "$CC" = "clang" ]; then
  292. echo "HOST_CC:=${CC} -fbracket-depth=1024" >> $topdir/prereq.mk
  293. else
  294. echo "HOST_CC:=${CC}" >> $topdir/prereq.mk
  295. fi
  296. if [ "$CXX" = "clang++" ]; then
  297. echo "HOST_CXX:=${CXX} -fbracket-depth=1024" >> $topdir/prereq.mk
  298. else
  299. echo "HOST_CXX:=${CXX}" >> $topdir/prereq.mk
  300. fi
  301. echo "HOST_CFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  302. echo "HOST_CXXFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  303. echo 'LANGUAGE:=C' >> $topdir/prereq.mk
  304. echo 'LC_ALL:=C' >> $topdir/prereq.mk
  305. echo "_PATH:=$PATH" >> $topdir/prereq.mk
  306. echo "PATH:=${topdir}/scripts:/usr/sbin:$PATH" >> $topdir/prereq.mk
  307. echo "GIT:=$(which git 2>/dev/null)" >> $topdir/prereq.mk
  308. if [ $dlverbose -eq 0 ]; then
  309. echo "GITOPTS:=--quiet" >> $topdir/prereq.mk
  310. fi
  311. echo "export ADK_TOPDIR GIT GITOPTS SHA256 BASH SHELL" >> $topdir/prereq.mk
  312. # create temporary Makefile
  313. cat >Makefile.tmp <<'EOF'
  314. include ${ADK_TOPDIR}/prereq.mk
  315. all: test
  316. test: test.c
  317. @${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  318. EOF
  319. # check if compiler works
  320. cat >test.c <<-'EOF'
  321. #include <stdio.h>
  322. int
  323. main()
  324. {
  325. printf("YES");
  326. return (0);
  327. }
  328. EOF
  329. $MAKE --no-print-directory ADK_TOPDIR=$topdir -f Makefile.tmp 2>&1
  330. X=$(./test)
  331. if [ $X != YES ]; then
  332. echo "$X" | sed 's/^/| /'
  333. echo Cannot compile a simple test programme.
  334. echo You must install a host make and C compiler.
  335. echo
  336. out=1
  337. fi
  338. rm test.c test 2>/dev/null
  339. # check for zlib
  340. cat >test.c <<-'EOF'
  341. #include <stdio.h>
  342. #include <zlib.h>
  343. #ifndef STDIN_FILENO
  344. #define STDIN_FILENO 0
  345. #endif
  346. int
  347. main()
  348. {
  349. gzFile zstdin;
  350. char buf[1024];
  351. int i;
  352. zstdin = gzdopen(STDIN_FILENO, "rb");
  353. i = gzread(zstdin, buf, sizeof (buf));
  354. if ((i > 0) && (i < sizeof (buf)))
  355. buf[i] = '\0';
  356. buf[sizeof (buf) - 1] = '\0';
  357. printf("%s\n", buf);
  358. return (0);
  359. }
  360. EOF
  361. $MAKE --no-print-directory LDADD=-lz ADK_TOPDIR=$topdir -f Makefile.tmp 2>&1
  362. X=$(echo YES | gzip | ./test)
  363. if [ $X != YES ]; then
  364. echo "$X" | sed 's/^/| /'
  365. echo Cannot compile a libz test programm.
  366. echo You must install the zlib development package,
  367. echo usually called libz-dev, and the run-time library.
  368. echo
  369. out=1
  370. fi
  371. rm test.c test 2>/dev/null
  372. rm Makefile.tmp 2>/dev/null
  373. # error out on any required prerequisite
  374. if [ $out -ne 0 ]; then
  375. exit $out
  376. fi
  377. host_build_bc=0
  378. if which bc >/dev/null 2>&1; then
  379. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  380. host_build_bc=1
  381. else
  382. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  383. host_build_bc=1
  384. fi
  385. fi
  386. else
  387. host_build_bc=1
  388. fi
  389. host_build_bison=0
  390. if ! which bison >/dev/null 2>&1; then
  391. host_build_bison=1
  392. fi
  393. host_build_bzip2=0
  394. if ! which bzip2 >/dev/null 2>&1; then
  395. host_build_bzip2=1
  396. fi
  397. host_build_file=0
  398. if ! which file >/dev/null 2>&1; then
  399. host_build_file=1
  400. fi
  401. host_build_flex=0
  402. if ! which flex >/dev/null 2>&1; then
  403. host_build_flex=1
  404. fi
  405. host_build_m4=0
  406. if ! which m4 >/dev/null 2>&1; then
  407. host_build_m4=1
  408. fi
  409. host_build_mkimage=0
  410. if ! which mkimage >/dev/null 2>&1; then
  411. host_build_mkimage=1
  412. fi
  413. host_build_mksh=0
  414. if ! which mksh >/dev/null 2>&1; then
  415. host_build_mksh=1
  416. fi
  417. host_build_patch=0
  418. if ! which patch >/dev/null 2>&1; then
  419. host_build_patch=1
  420. fi
  421. host_build_pkgconf=0
  422. if ! which pkgconf >/dev/null 2>&1; then
  423. host_build_pkgconf=1
  424. fi
  425. host_build_tar=0
  426. if which tar >/dev/null 2>&1; then
  427. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  428. host_build_tar=1
  429. fi
  430. else
  431. host_build_tar=1
  432. fi
  433. host_build_findutils=0
  434. if which xargs >/dev/null 2>&1; then
  435. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  436. host_build_findutils=1
  437. fi
  438. fi
  439. if which find >/dev/null 2>&1; then
  440. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  441. host_build_findutils=1
  442. fi
  443. fi
  444. host_build_grep=0
  445. if which grep >/dev/null 2>&1; then
  446. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  447. host_build_grep=1
  448. fi
  449. fi
  450. host_build_gawk=0
  451. if ! which gawk >/dev/null 2>&1; then
  452. host_build_gawk=1
  453. fi
  454. host_build_sed=0
  455. if which sed >/dev/null 2>&1; then
  456. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  457. host_build_sed=1
  458. fi
  459. fi
  460. host_build_xz=0
  461. if ! which xz >/dev/null 2>&1; then
  462. host_build_xz=1
  463. fi
  464. # optional
  465. host_build_cdrtools=0
  466. if ! which mkisofs >/dev/null 2>&1; then
  467. host_build_cdrtools=1
  468. fi
  469. host_build_ccache=0
  470. if ! which ccache >/dev/null 2>&1; then
  471. host_build_ccache=1
  472. fi
  473. host_build_genext2fs=0
  474. if ! which genext2fs >/dev/null 2>&1; then
  475. host_build_genext2fs=1
  476. fi
  477. host_build_lzma=0
  478. if ! which lzma >/dev/null 2>&1; then
  479. host_build_lzma=1
  480. fi
  481. host_build_lz4=0
  482. if ! which lz4c >/dev/null 2>&1; then
  483. host_build_lz4=1
  484. fi
  485. host_build_lzop=0
  486. if ! which lzop >/dev/null 2>&1; then
  487. host_build_lzop=1
  488. fi
  489. host_build_qemu=0
  490. if ! which qemu-img >/dev/null 2>&1; then
  491. host_build_qemu=1
  492. fi
  493. host_build_coreutils=0
  494. if which tr >/dev/null 2>&1; then
  495. if ! tr --version 2>/dev/null|grep GNU >/dev/null;then
  496. host_build_coreutils=1
  497. fi
  498. fi
  499. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  500. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  501. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  502. # always required
  503. if [ $host_build_bc -eq 1 ]; then
  504. printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq
  505. fi
  506. if [ $host_build_bison -eq 1 ]; then
  507. printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq
  508. fi
  509. if [ $host_build_bzip2 -eq 1 ]; then
  510. printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq
  511. fi
  512. if [ $host_build_file -eq 1 ]; then
  513. printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq
  514. fi
  515. if [ $host_build_flex -eq 1 ]; then
  516. printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq
  517. fi
  518. if [ $host_build_gawk -eq 1 ]; then
  519. printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq
  520. fi
  521. if [ $host_build_grep -eq 1 ]; then
  522. printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq
  523. fi
  524. if [ $host_build_m4 -eq 1 ]; then
  525. printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq
  526. fi
  527. if [ $host_build_mkimage -eq 1 ]; then
  528. printf "\t%s\n" "select ADK_HOST_BUILD_U_BOOT" >> $topdir/target/config/Config.in.prereq
  529. fi
  530. if [ $host_build_mksh -eq 1 ]; then
  531. printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq
  532. fi
  533. if [ $host_build_patch -eq 1 ]; then
  534. printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq
  535. fi
  536. if [ $host_build_pkgconf -eq 1 ]; then
  537. printf "\t%s\n" "select ADK_HOST_BUILD_PKGCONF" >> $topdir/target/config/Config.in.prereq
  538. fi
  539. if [ $host_build_findutils -eq 1 ]; then
  540. printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq
  541. fi
  542. if [ $host_build_sed -eq 1 ]; then
  543. printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq
  544. fi
  545. if [ $host_build_tar -eq 1 ]; then
  546. printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq
  547. fi
  548. if [ $host_build_xz -eq 1 ]; then
  549. printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq
  550. fi
  551. # optional
  552. if [ $host_build_ccache -eq 1 ]; then
  553. printf "\t%s\n" "select ADK_HOST_BUILD_CCACHE if ADK_HOST_NEED_CCACHE" >> $topdir/target/config/Config.in.prereq
  554. fi
  555. if [ $host_build_cdrtools -eq 1 ]; then
  556. printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq
  557. fi
  558. if [ $host_build_genext2fs -eq 1 ]; then
  559. printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq
  560. fi
  561. if [ $host_build_lzma -eq 1 ]; then
  562. printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq
  563. fi
  564. if [ $host_build_lz4 -eq 1 ]; then
  565. printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq
  566. fi
  567. if [ $host_build_lzop -eq 1 ]; then
  568. printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq
  569. fi
  570. if [ $host_build_qemu -eq 1 ]; then
  571. printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq
  572. fi
  573. if [ $host_build_coreutils -eq 1 ]; then
  574. printf "\t%s\n" "select ADK_HOST_BUILD_COREUTILS if ADK_HOST_NEED_COREUTILS" >> $topdir/target/config/Config.in.prereq
  575. fi
  576. # create Host OS symbols
  577. case $os in
  578. Linux)
  579. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  580. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  581. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  582. ;;
  583. Darwin)
  584. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  585. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  586. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  587. ;;
  588. OpenBSD)
  589. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  590. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  591. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  592. ;;
  593. FreeBSD)
  594. printf "\nconfig ADK_HOST_FREEBSD\n" >> $topdir/target/config/Config.in.prereq
  595. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  596. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  597. ;;
  598. NetBSD)
  599. printf "\nconfig ADK_HOST_NETBSD\n" >> $topdir/target/config/Config.in.prereq
  600. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  601. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  602. ;;
  603. MirBSD)
  604. printf "\nconfig ADK_HOST_MIRBSD\n" >> $topdir/target/config/Config.in.prereq
  605. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  606. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  607. ;;
  608. Cygwin*)
  609. printf "\nconfig ADK_HOST_CYGWIN\n" >> $topdir/target/config/Config.in.prereq
  610. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  611. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  612. ;;
  613. esac
  614. if [ "$target" = "defconfig" ]; then
  615. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  616. exit 0
  617. fi
  618. if [ ! -f $topdir/.config ]; then
  619. # create a config if no exist
  620. touch .firstrun
  621. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk menuconfig
  622. else
  623. # scan host-tool prerequisites of certain packages before building.
  624. . $topdir/.config
  625. if [ -n "$ADK_PACKAGE_KODI" ]; then
  626. NEED_JAVA="$NEED_JAVA kodi"
  627. fi
  628. if [ -n "$ADK_PACKAGE_ICU4C" ]; then
  629. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  630. fi
  631. if [ -n "$ADK_PACKAGE_XKEYBOARD_CONFIG" ]; then
  632. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  633. fi
  634. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_100DPI" ]; then
  635. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  636. fi
  637. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_75DPI" ]; then
  638. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  639. fi
  640. if [ -n "$ADK_PACKAGE_FONT_ADOBE_100DPI" ]; then
  641. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  642. fi
  643. if [ -n "$ADK_PACKAGE_FONT_ADOBE_75DPI" ]; then
  644. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  645. fi
  646. if [ -n "$NEED_MKFONTDIR" ]; then
  647. if ! which mkfontdir >/dev/null 2>&1; then
  648. printf "You need mkfontdir to build $NEED_MKFONTDIR \n"
  649. out=1
  650. fi
  651. fi
  652. if [ -n "$NEED_XKBCOMP" ]; then
  653. if ! which xkbcomp >/dev/null 2>&1; then
  654. printf "You need xkbcomp to build $NEED_XKBCOMP \n"
  655. out=1
  656. fi
  657. fi
  658. if [ -n "$NEED_JAVA" ]; then
  659. if ! which java >/dev/null 2>&1; then
  660. printf "You need java to build $NEED_JAVA \n"
  661. out=1
  662. fi
  663. fi
  664. if [ -n "$NEED_STATIC_LIBSTDCXX" ]; then
  665. cat >test.c <<-'EOF'
  666. #include <stdio.h>
  667. int
  668. main()
  669. {
  670. return (0);
  671. }
  672. EOF
  673. if ! $CXX -static-libstdc++ -o test test.c 2>/dev/null ; then
  674. printf "You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX \n"
  675. out=1
  676. rm test test.c 2>/dev/null
  677. fi
  678. fi
  679. # error out
  680. if [ $out -ne 0 ]; then
  681. exit $out
  682. fi
  683. # start build
  684. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  685. fi