prereq.sh 23 KB

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