prereq.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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=https://distfiles.openadk.org
  10. makever=4.2.1
  11. bashver=4.4.18
  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.\n"
  21. case $os in
  22. CYG*)
  23. printf "Building OpenADK on $os needs a small registry change.\n"
  24. printf "http://cygwin.com/cygwin-ug-net/using-specialnames.html\n"
  25. ;;
  26. Darwin*)
  27. printf "Building OpenADK on $os needs a case-sensitive disk partition.\n"
  28. printf "For Snow Leopard and above you can use diskutil to resize your existing disk.\n"
  29. printf "Example: sudo diskutil resizeVolume disk0s2 90G 1 jhfsx adk 30G\n"
  30. printf "For older versions you might consider to use a disk image:\n"
  31. printf "hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 30g ~/openadk.dmg\n"
  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) --progress-bar -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 2>/dev/null|xargs) 2>/dev/null
  153. sed -i -e "s#$olddir#$newdir#g" $(find host_${gnu_host_name} -type f 2>/dev/null|xargs) 2>/dev/null
  154. sed -i -e "s#$olddir#$newdir#g" $(find target_*/scripts -type f 2>/dev/null|xargs) 2>/dev/null
  155. sed -i -e "s#$olddir#$newdir#" target_*/etc/ipkg.conf 2>/dev/null
  156. sleep 1
  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. LC_ALL=C 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 "export ADK_TOPDIR GIT SHA256 BASH SHELL" >> $topdir/prereq.mk
  316. # create temporary Makefile
  317. cat >Makefile.tmp <<'EOF'
  318. include ${ADK_TOPDIR}/prereq.mk
  319. all: test
  320. test: test.c
  321. @${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  322. EOF
  323. # check if compiler works
  324. cat >test.c <<-'EOF'
  325. #include <stdio.h>
  326. int
  327. main()
  328. {
  329. printf("YES");
  330. return (0);
  331. }
  332. EOF
  333. printf " ---> checking if compiler is working.. "
  334. $MAKE --no-print-directory ADK_TOPDIR=$topdir -f Makefile.tmp >/dev/null 2>&1
  335. X=$(./test 2>/dev/null)
  336. if [ X$X != XYES ]; then
  337. echo Cannot compile a simple test programme.
  338. echo You must install a host make and C compiler.
  339. echo
  340. out=1
  341. else
  342. printf "okay\n"
  343. fi
  344. rm test.c test 2>/dev/null
  345. printf " ---> checking if zlib is installed.. "
  346. # check for zlib
  347. cat >test.c <<-'EOF'
  348. #include <stdio.h>
  349. #include <zlib.h>
  350. #ifndef STDIN_FILENO
  351. #define STDIN_FILENO 0
  352. #endif
  353. int
  354. main()
  355. {
  356. gzFile zstdin;
  357. char buf[1024];
  358. int i;
  359. zstdin = gzdopen(STDIN_FILENO, "rb");
  360. i = gzread(zstdin, buf, sizeof (buf));
  361. if ((i > 0) && (i < sizeof (buf)))
  362. buf[i] = '\0';
  363. buf[sizeof (buf) - 1] = '\0';
  364. printf("%s\n", buf);
  365. return (0);
  366. }
  367. EOF
  368. $MAKE --no-print-directory LDADD=-lz ADK_TOPDIR=$topdir -f Makefile.tmp >/dev/null 2>&1
  369. X=$(echo YES | gzip | ./test 2>/dev/null)
  370. if [ X$X != XYES ]; then
  371. echo Cannot compile a libz test programm.
  372. echo You must install the zlib development package,
  373. echo usually called libz-dev, and the run-time library.
  374. echo
  375. out=1
  376. else
  377. printf "found\n"
  378. fi
  379. rm test.c test 2>/dev/null
  380. rm Makefile.tmp 2>/dev/null
  381. # for make kernelconfig pkg-config is required to find ncurses
  382. if [ $os = "Darwin" ]; then
  383. printf " ---> checking if pkg-config is installed.. "
  384. if ! which pkg-config >/dev/null 2>&1; then
  385. printf "not found\n"
  386. out=1
  387. else
  388. printf "found\n"
  389. fi
  390. fi
  391. # error out on any required prerequisite
  392. if [ $out -ne 0 ]; then
  393. exit
  394. fi
  395. printf " ---> checking if bc is installed.. "
  396. host_build_bc=0
  397. if which bc >/dev/null 2>&1; then
  398. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  399. printf "not usable\n"
  400. host_build_bc=1
  401. else
  402. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  403. host_build_bc=1
  404. printf "not usable\n"
  405. fi
  406. printf "found\n"
  407. fi
  408. else
  409. printf "not found\n"
  410. host_build_bc=1
  411. fi
  412. printf " ---> checking if bison is installed.. "
  413. host_build_bison=0
  414. if ! which bison >/dev/null 2>&1; then
  415. printf "not found\n"
  416. host_build_bison=1
  417. else
  418. printf "found\n"
  419. fi
  420. printf " ---> checking if bzip2 is installed.. "
  421. host_build_bzip2=0
  422. if ! which bzip2 >/dev/null 2>&1; then
  423. printf "not found\n"
  424. host_build_bzip2=1
  425. else
  426. printf "found\n"
  427. fi
  428. printf " ---> checking if file is installed.. "
  429. host_build_file=0
  430. if ! which file >/dev/null 2>&1; then
  431. printf "not found\n"
  432. host_build_file=1
  433. else
  434. printf "found\n"
  435. fi
  436. printf " ---> checking if flex is installed.. "
  437. host_build_flex=0
  438. if ! which flex >/dev/null 2>&1; then
  439. printf "not found\n"
  440. host_build_flex=1
  441. else
  442. printf "found\n"
  443. fi
  444. host_build_m4=0
  445. if ! which m4 >/dev/null 2>&1; then
  446. host_build_m4=1
  447. fi
  448. host_build_mkimage=0
  449. if ! which mkimage >/dev/null 2>&1; then
  450. host_build_mkimage=1
  451. fi
  452. printf " ---> checking if mksh is installed.. "
  453. host_build_mksh=0
  454. if ! which mksh >/dev/null 2>&1; then
  455. printf "not found\n"
  456. host_build_mksh=1
  457. else
  458. printf "found\n"
  459. fi
  460. printf " ---> checking if patch is installed.. "
  461. host_build_patch=0
  462. if ! which patch >/dev/null 2>&1; then
  463. printf "not found\n"
  464. host_build_patch=1
  465. else
  466. printf "found\n"
  467. fi
  468. host_build_tar=0
  469. if which tar >/dev/null 2>&1; then
  470. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  471. host_build_tar=1
  472. fi
  473. else
  474. host_build_tar=1
  475. fi
  476. printf " ---> checking if xargs is installed.. "
  477. host_build_findutils=0
  478. if which xargs >/dev/null 2>&1; then
  479. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  480. printf "found but not usable\n"
  481. host_build_findutils=1
  482. else
  483. printf "found\n"
  484. fi
  485. else
  486. printf "not found\n"
  487. host_build_findutils=1
  488. fi
  489. printf " ---> checking if find is installed.. "
  490. if which find >/dev/null 2>&1; then
  491. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  492. printf "found but not usable\n"
  493. host_build_findutils=1
  494. else
  495. printf "found\n"
  496. fi
  497. else
  498. printf "not found\n"
  499. host_build_findutils=1
  500. fi
  501. printf " ---> checking if grep is installed.. "
  502. host_build_grep=0
  503. if which grep >/dev/null 2>&1; then
  504. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  505. printf "found but not usable\n"
  506. host_build_grep=1
  507. else
  508. printf "found\n"
  509. fi
  510. else
  511. printf "not found\n"
  512. host_build_grep=1
  513. fi
  514. printf " ---> checking if gawk is installed.. "
  515. host_build_gawk=0
  516. if ! which gawk >/dev/null 2>&1; then
  517. printf "not found\n"
  518. host_build_gawk=1
  519. else
  520. printf "found\n"
  521. fi
  522. printf " ---> checking if sed is installed.. "
  523. host_build_sed=0
  524. if which sed >/dev/null 2>&1; then
  525. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  526. printf "found but not usable\n"
  527. host_build_sed=1
  528. else
  529. printf "found\n"
  530. fi
  531. else
  532. printf "not found\n"
  533. host_build_sed=1
  534. fi
  535. printf " ---> checking if cpio is installed.. "
  536. host_build_cpio=0
  537. if ! which cpio >/dev/null 2>&1; then
  538. printf "not found\n"
  539. host_build_cpio=1
  540. else
  541. printf "found\n"
  542. fi
  543. printf " ---> checking if xz is installed.. "
  544. host_build_xz=0
  545. if ! which xz >/dev/null 2>&1; then
  546. printf "not found\n"
  547. host_build_xz=1
  548. else
  549. printf "found\n"
  550. fi
  551. # optional
  552. host_build_cdrtools=0
  553. if ! which mkisofs >/dev/null 2>&1; then
  554. host_build_cdrtools=1
  555. fi
  556. host_build_genext2fs=0
  557. if ! which genext2fs >/dev/null 2>&1; then
  558. host_build_genext2fs=1
  559. fi
  560. host_build_lzma=0
  561. if ! which lzma >/dev/null 2>&1; then
  562. host_build_lzma=1
  563. fi
  564. host_build_lz4=0
  565. if ! which lz4c >/dev/null 2>&1; then
  566. host_build_lz4=1
  567. fi
  568. host_build_lzop=0
  569. if ! which lzop >/dev/null 2>&1; then
  570. host_build_lzop=1
  571. fi
  572. host_build_qemu=0
  573. if ! which qemu-img >/dev/null 2>&1; then
  574. host_build_qemu=1
  575. fi
  576. host_build_coreutils=0
  577. if which tr >/dev/null 2>&1; then
  578. if ! tr --version 2>/dev/null|grep GNU >/dev/null;then
  579. host_build_coreutils=1
  580. fi
  581. fi
  582. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  583. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  584. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  585. # always required
  586. if [ $host_build_bc -eq 1 ]; then
  587. printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq
  588. fi
  589. if [ $host_build_bison -eq 1 ]; then
  590. printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq
  591. fi
  592. if [ $host_build_bzip2 -eq 1 ]; then
  593. printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq
  594. fi
  595. if [ $host_build_file -eq 1 ]; then
  596. printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq
  597. fi
  598. if [ $host_build_flex -eq 1 ]; then
  599. printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq
  600. fi
  601. if [ $host_build_gawk -eq 1 ]; then
  602. printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq
  603. fi
  604. if [ $host_build_grep -eq 1 ]; then
  605. printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq
  606. fi
  607. if [ $host_build_m4 -eq 1 ]; then
  608. printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq
  609. fi
  610. if [ $host_build_mkimage -eq 1 ]; then
  611. printf "\t%s\n" "select ADK_HOST_NEED_U_BOOT" >> $topdir/target/config/Config.in.prereq
  612. fi
  613. if [ $host_build_mksh -eq 1 ]; then
  614. printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq
  615. fi
  616. if [ $host_build_patch -eq 1 ]; then
  617. printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq
  618. fi
  619. if [ $host_build_findutils -eq 1 ]; then
  620. printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq
  621. fi
  622. if [ $host_build_sed -eq 1 ]; then
  623. printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq
  624. fi
  625. if [ $host_build_tar -eq 1 ]; then
  626. printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq
  627. fi
  628. if [ $host_build_coreutils -eq 1 ]; then
  629. printf "\t%s\n" "select ADK_HOST_BUILD_COREUTILS" >> $topdir/target/config/Config.in.prereq
  630. fi
  631. if [ $host_build_cpio -eq 1 ]; then
  632. printf "\t%s\n" "select ADK_HOST_BUILD_CPIO" >> $topdir/target/config/Config.in.prereq
  633. fi
  634. if [ $host_build_xz -eq 1 ]; then
  635. printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq
  636. fi
  637. # optional
  638. if [ $host_build_cdrtools -eq 1 ]; then
  639. printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq
  640. fi
  641. if [ $host_build_genext2fs -eq 1 ]; then
  642. printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq
  643. fi
  644. if [ $host_build_lzma -eq 1 ]; then
  645. printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq
  646. fi
  647. if [ $host_build_lz4 -eq 1 ]; then
  648. printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq
  649. fi
  650. if [ $host_build_lzop -eq 1 ]; then
  651. printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq
  652. fi
  653. if [ $host_build_qemu -eq 1 ]; then
  654. printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq
  655. fi
  656. # create Host OS symbols
  657. case $os in
  658. Linux)
  659. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  660. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  661. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  662. ;;
  663. Darwin)
  664. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  665. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  666. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  667. ;;
  668. OpenBSD)
  669. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  670. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  671. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  672. ;;
  673. FreeBSD)
  674. printf "\nconfig ADK_HOST_FREEBSD\n" >> $topdir/target/config/Config.in.prereq
  675. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  676. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  677. ;;
  678. NetBSD)
  679. printf "\nconfig ADK_HOST_NETBSD\n" >> $topdir/target/config/Config.in.prereq
  680. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  681. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  682. ;;
  683. MirBSD)
  684. printf "\nconfig ADK_HOST_MIRBSD\n" >> $topdir/target/config/Config.in.prereq
  685. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  686. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  687. ;;
  688. Cygwin*)
  689. printf "\nconfig ADK_HOST_CYGWIN\n" >> $topdir/target/config/Config.in.prereq
  690. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  691. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  692. ;;
  693. esac
  694. if [ "$target" = "defconfig" ]; then
  695. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  696. exit 0
  697. fi
  698. if [ ! -f $topdir/.config ]; then
  699. # create a config if no exist
  700. touch .firstrun
  701. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk menuconfig
  702. else
  703. # scan host-tool prerequisites of certain packages before building.
  704. . $topdir/.config
  705. if [ -n "$ADK_PACKAGE_KODI" ]; then
  706. NEED_JAVA="$NEED_JAVA kodi"
  707. fi
  708. if [ -n "$ADK_PACKAGE_ICU4C" ]; then
  709. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  710. fi
  711. if [ -n "$ADK_PACKAGE_XKEYBOARD_CONFIG" ]; then
  712. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  713. fi
  714. if [ -n "$ADK_PACKAGE_FONT_BH_100DPI" ]; then
  715. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-100dpi"
  716. fi
  717. if [ -n "$ADK_PACKAGE_FONT_BH_75DPI" ]; then
  718. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-75dpi"
  719. fi
  720. if [ -n "$ADK_PACKAGE_FONT_BH_TYPE1" ]; then
  721. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-type1"
  722. fi
  723. if [ -n "$ADK_PACKAGE_FONT_BH_TTF" ]; then
  724. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-ttf"
  725. fi
  726. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_100DPI" ]; then
  727. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-100dpi"
  728. fi
  729. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_75DPI" ]; then
  730. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-75dpi"
  731. fi
  732. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_100DPI" ]; then
  733. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  734. fi
  735. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_75DPI" ]; then
  736. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  737. fi
  738. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_TYPE1" ]; then
  739. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-type1"
  740. fi
  741. if [ -n "$ADK_PACKAGE_FONT_ADOBE_100DPI" ]; then
  742. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  743. fi
  744. if [ -n "$ADK_PACKAGE_FONT_ADOBE_75DPI" ]; then
  745. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  746. fi
  747. if [ -n "$ADK_PACKAGE_FONT_XFREE86_TYPE1" ]; then
  748. NEED_MKFONTDIR="$NEED_MKFONTDIR font-xfree86-type1"
  749. fi
  750. if [ -n "$ADK_PACKAGE_FONT_MISC_MISC" ]; then
  751. NEED_MKFONTDIR="$NEED_MKFONTDIR font-misc-misc"
  752. fi
  753. if [ -n "$ADK_PACKAGE_LIBERATION_FONTS_TTF" ]; then
  754. NEED_MKFONTSCALE="$NEED_MKFONTSCALE liberation-fonts-ttf"
  755. fi
  756. if [ -n "$NEED_MKFONTDIR" ]; then
  757. if ! which mkfontdir >/dev/null 2>&1; then
  758. printf "You need mkfontdir to build $NEED_MKFONTDIR \n"
  759. out=1
  760. fi
  761. fi
  762. if [ -n "$NEED_MKFONTSCALE" ]; then
  763. if ! which mkfontscale >/dev/null 2>&1; then
  764. printf "You need mkfontscale to build $NEED_MKFONTSCALE \n"
  765. out=1
  766. fi
  767. fi
  768. if [ -n "$NEED_XKBCOMP" ]; then
  769. if ! which xkbcomp >/dev/null 2>&1; then
  770. printf "You need xkbcomp to build $NEED_XKBCOMP \n"
  771. out=1
  772. fi
  773. fi
  774. if [ -n "$NEED_JAVA" ]; then
  775. if ! which java >/dev/null 2>&1; then
  776. printf "You need java to build $NEED_JAVA \n"
  777. out=1
  778. fi
  779. fi
  780. if [ -n "$NEED_STATIC_LIBSTDCXX" ]; then
  781. cat >test.c <<-'EOF'
  782. #include <stdio.h>
  783. int
  784. main()
  785. {
  786. return (0);
  787. }
  788. EOF
  789. if ! $CXX -static-libstdc++ -o test test.c 2>/dev/null ; then
  790. printf "You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX \n"
  791. out=1
  792. rm test test.c 2>/dev/null
  793. fi
  794. fi
  795. # error out
  796. if [ $out -ne 0 ]; then
  797. exit $out
  798. fi
  799. # start build
  800. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  801. fi