prereq.sh 22 KB

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