prereq.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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. fi
  176. printf " ---> checking if it is make 4.x.. "
  177. LC_ALL=C $makebin --version 2>/dev/null| grep -i "Make 4" >/dev/null
  178. if [ $? -eq 0 ]; then
  179. printf "yes\n"
  180. break
  181. else
  182. # we need to build GNU make
  183. printf "no\n"
  184. printf " ---> compiling missing GNU make.. "
  185. cd dl
  186. $FETCHCMD make-${makever}.tar.gz $mirror/make-${makever}.tar.gz
  187. if [ $? -ne 0 ]; then
  188. printf "ERROR: failed to download make from $mirror\n"
  189. exit 1
  190. fi
  191. cd ..
  192. mkdir tmp
  193. cd tmp
  194. tar xzf ../dl/make-${makever}.tar.gz
  195. cd make-$makever
  196. ./configure --prefix=$topdir/host_$gnu_host_name
  197. make
  198. make install
  199. cd ..
  200. cd ..
  201. rm -rf tmp
  202. (cd $topdir/host_$gnu_host_name/bin/; ln -sf make gnumake)
  203. MAKE=$topdir/host_$gnu_host_name/bin/make
  204. makebin=$topdir/host_$gnu_host_name/bin/make
  205. printf " done\n"
  206. fi
  207. else
  208. printf "not found\n"
  209. continue
  210. fi
  211. done
  212. # check for bash
  213. printf " ---> checking if bash is installed.. "
  214. if which bash >/dev/null; then
  215. printf "found\n"
  216. printf " ---> checking if it is bash 4.x or 5.x"
  217. LC_ALL=C bash --version 2>/dev/null| grep -i "version \(4\|5\)" >/dev/null
  218. if [ $? -eq 0 ]; then
  219. printf "yes\n"
  220. else
  221. # we need to build GNU bash 4.x
  222. printf "not found\n"
  223. printf " ---> compiling missing GNU bash.. "
  224. cd dl
  225. $FETCHCMD bash-${bashver}.tar.gz $mirror/bash-${bashver}.tar.gz
  226. if [ $? -ne 0 ]; then
  227. printf "ERROR: failed to download make from $mirror\n"
  228. exit 1
  229. fi
  230. cd ..
  231. mkdir tmp
  232. cd tmp
  233. tar xzf ../dl/bash-${bashver}.tar.gz
  234. cd bash-${bashver}
  235. ./configure --prefix=$topdir/host_$gnu_host_name/
  236. make
  237. make install
  238. cd ..
  239. cd ..
  240. rm -rf tmp
  241. printf " done\n"
  242. fi
  243. fi
  244. # skip the script if distclean / cleandir
  245. if [ "$target" = "distclean" -o "$target" = "cleandir" ]; then
  246. touch prereq.mk
  247. $makebin ADK_TOPDIR=$topdir -s -f Makefile.adk $flags $target
  248. exit 0
  249. fi
  250. printf " ---> checking if strings is installed.. "
  251. if ! which strings >/dev/null 2>&1; then
  252. echo You must install strings to continue.
  253. echo
  254. out=1
  255. printf "not found\n"
  256. fi
  257. printf "found\n"
  258. printf " ---> checking if perl is installed.. "
  259. if ! which perl >/dev/null 2>&1; then
  260. echo You must install perl to continue.
  261. echo
  262. out=1
  263. printf "not found\n"
  264. fi
  265. printf "found\n"
  266. printf " ---> checking if gzip is installed.. "
  267. if ! which gzip >/dev/null 2>&1; then
  268. echo You must install gzip to continue.
  269. echo
  270. out=1
  271. printf "not found\n"
  272. fi
  273. printf "found\n"
  274. printf " ---> checking if git is installed.. "
  275. if ! which git >/dev/null 2>&1; then
  276. echo You must install git to continue.
  277. echo
  278. out=1
  279. printf "not found\n"
  280. fi
  281. printf "found\n"
  282. # creating prereq.mk
  283. echo "ADK_TOPDIR:=$(readlink -nf . 2>/dev/null || pwd -P)" > $topdir/prereq.mk
  284. echo "BASH:=$(which bash)" >> $topdir/prereq.mk
  285. echo "SHELL:=$(which bash)" >> $topdir/prereq.mk
  286. echo "GMAKE:=$MAKE" >> $topdir/prereq.mk
  287. echo "MAKE:=$MAKE" >> $topdir/prereq.mk
  288. echo "FETCHCMD:=$FETCHCMD" >> $topdir/prereq.mk
  289. echo "SHA256:=$SHA256" >> $topdir/prereq.mk
  290. echo "GNU_HOST_NAME:=${gnu_host_name}" >> $topdir/prereq.mk
  291. echo "OS_FOR_BUILD:=${os}" >> $topdir/prereq.mk
  292. echo "ARCH_FOR_BUILD:=$(${CC} -dumpmachine | sed \
  293. -e 's/x86_64-linux-gnux32/x32/' \
  294. -e s'/-.*//' \
  295. -e 's/sparc.*/sparc/' \
  296. -e 's/armeb.*/armeb/g' \
  297. -e 's/arm.*/arm/g' \
  298. -e 's/m68k.*/m68k/' \
  299. -e 's/sh[234]/sh/' \
  300. -e 's/mips-.*/mips/' \
  301. -e 's/mipsel-.*/mipsel/' \
  302. -e 's/i[3-9]86/x86/' \
  303. )" >>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" >> $topdir/prereq.mk
  315. echo "HOST_CXXFLAGS:=-O0 -g0" >> $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 programm.
  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. # for make kernelconfig pkg-config is required to find ncurses
  388. if [ $os = "Darwin" ]; then
  389. printf " ---> checking if pkg-config is installed.. "
  390. if ! which pkg-config >/dev/null 2>&1; then
  391. printf "not found\n"
  392. out=1
  393. else
  394. printf "found\n"
  395. fi
  396. fi
  397. # error out on any required prerequisite
  398. if [ $out -ne 0 ]; then
  399. exit
  400. fi
  401. printf " ---> checking if bc is installed.. "
  402. host_build_bc=0
  403. if which bc >/dev/null 2>&1; then
  404. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  405. printf "not usable\n"
  406. host_build_bc=1
  407. else
  408. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  409. host_build_bc=1
  410. printf "not usable\n"
  411. fi
  412. printf "found\n"
  413. fi
  414. else
  415. printf "not found\n"
  416. host_build_bc=1
  417. fi
  418. printf " ---> checking if bison is installed.. "
  419. host_build_bison=0
  420. if ! which bison >/dev/null 2>&1; then
  421. printf "not found\n"
  422. host_build_bison=1
  423. else
  424. printf "found\n"
  425. fi
  426. printf " ---> checking if bzip2 is installed.. "
  427. host_build_bzip2=0
  428. if ! which bzip2 >/dev/null 2>&1; then
  429. printf "not found\n"
  430. host_build_bzip2=1
  431. else
  432. printf "found\n"
  433. fi
  434. printf " ---> checking if file is installed.. "
  435. host_build_file=0
  436. if ! which file >/dev/null 2>&1; then
  437. printf "not found\n"
  438. host_build_file=1
  439. else
  440. printf "found\n"
  441. fi
  442. printf " ---> checking if flex is installed.. "
  443. host_build_flex=0
  444. if ! which flex >/dev/null 2>&1; then
  445. printf "not found\n"
  446. host_build_flex=1
  447. else
  448. printf "found\n"
  449. fi
  450. host_build_m4=0
  451. if ! which m4 >/dev/null 2>&1; then
  452. host_build_m4=1
  453. fi
  454. host_build_mkimage=0
  455. if ! which mkimage >/dev/null 2>&1; then
  456. host_build_mkimage=1
  457. fi
  458. printf " ---> checking if mksh is installed.. "
  459. host_build_mksh=0
  460. if ! which mksh >/dev/null 2>&1; then
  461. printf "not found\n"
  462. host_build_mksh=1
  463. else
  464. printf "found\n"
  465. fi
  466. printf " ---> checking if patch is installed.. "
  467. host_build_patch=0
  468. if ! which patch >/dev/null 2>&1; then
  469. printf "not found\n"
  470. host_build_patch=1
  471. else
  472. printf "found\n"
  473. fi
  474. host_build_tar=0
  475. if which tar >/dev/null 2>&1; then
  476. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  477. host_build_tar=1
  478. fi
  479. else
  480. host_build_tar=1
  481. fi
  482. printf " ---> checking if xargs is installed.. "
  483. host_build_findutils=0
  484. if which xargs >/dev/null 2>&1; then
  485. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  486. printf "found but not usable\n"
  487. host_build_findutils=1
  488. else
  489. printf "found\n"
  490. fi
  491. else
  492. printf "not found\n"
  493. host_build_findutils=1
  494. fi
  495. printf " ---> checking if find is installed.. "
  496. if which find >/dev/null 2>&1; then
  497. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  498. printf "found but not usable\n"
  499. host_build_findutils=1
  500. else
  501. printf "found\n"
  502. fi
  503. else
  504. printf "not found\n"
  505. host_build_findutils=1
  506. fi
  507. printf " ---> checking if grep is installed.. "
  508. host_build_grep=0
  509. if which grep >/dev/null 2>&1; then
  510. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  511. printf "found but not usable\n"
  512. host_build_grep=1
  513. else
  514. printf "found\n"
  515. fi
  516. else
  517. printf "not found\n"
  518. host_build_grep=1
  519. fi
  520. printf " ---> checking if gawk is installed.. "
  521. host_build_gawk=0
  522. if ! which gawk >/dev/null 2>&1; then
  523. printf "not found\n"
  524. host_build_gawk=1
  525. else
  526. printf "found\n"
  527. fi
  528. printf " ---> checking if sed is installed.. "
  529. host_build_sed=0
  530. if which sed >/dev/null 2>&1; then
  531. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  532. printf "found but not usable\n"
  533. host_build_sed=1
  534. else
  535. printf "found\n"
  536. fi
  537. else
  538. printf "not found\n"
  539. host_build_sed=1
  540. fi
  541. printf " ---> checking if cpio is installed.. "
  542. host_build_cpio=0
  543. if ! which cpio >/dev/null 2>&1; then
  544. printf "not found\n"
  545. host_build_cpio=1
  546. else
  547. printf "found\n"
  548. fi
  549. printf " ---> checking if xz is installed.. "
  550. host_build_xz=0
  551. if ! which xz >/dev/null 2>&1; then
  552. printf "not found\n"
  553. host_build_xz=1
  554. else
  555. printf "found\n"
  556. fi
  557. # optional
  558. host_build_cdrtools=0
  559. if ! which mkisofs >/dev/null 2>&1; then
  560. host_build_cdrtools=1
  561. fi
  562. host_build_genext2fs=0
  563. if ! which genext2fs >/dev/null 2>&1; then
  564. host_build_genext2fs=1
  565. fi
  566. host_build_lzma=0
  567. if ! which lzma >/dev/null 2>&1; then
  568. host_build_lzma=1
  569. fi
  570. host_build_lz4=0
  571. if ! which lz4c >/dev/null 2>&1; then
  572. host_build_lz4=1
  573. fi
  574. host_build_lzop=0
  575. if ! which lzop >/dev/null 2>&1; then
  576. host_build_lzop=1
  577. fi
  578. host_build_qemu=0
  579. if ! which qemu-img >/dev/null 2>&1; then
  580. host_build_qemu=1
  581. fi
  582. host_build_coreutils=0
  583. if which tr >/dev/null 2>&1; then
  584. if ! tr --version 2>/dev/null|grep GNU >/dev/null;then
  585. host_build_coreutils=1
  586. fi
  587. fi
  588. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  589. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  590. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  591. # always required
  592. if [ $host_build_bc -eq 1 ]; then
  593. printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq
  594. fi
  595. if [ $host_build_bison -eq 1 ]; then
  596. printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq
  597. fi
  598. if [ $host_build_bzip2 -eq 1 ]; then
  599. printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq
  600. fi
  601. if [ $host_build_file -eq 1 ]; then
  602. printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq
  603. fi
  604. if [ $host_build_flex -eq 1 ]; then
  605. printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq
  606. fi
  607. if [ $host_build_gawk -eq 1 ]; then
  608. printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq
  609. fi
  610. if [ $host_build_grep -eq 1 ]; then
  611. printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq
  612. fi
  613. if [ $host_build_m4 -eq 1 ]; then
  614. printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq
  615. fi
  616. if [ $host_build_mkimage -eq 1 ]; then
  617. printf "\t%s\n" "select ADK_HOST_NEED_U_BOOT" >> $topdir/target/config/Config.in.prereq
  618. fi
  619. if [ $host_build_mksh -eq 1 ]; then
  620. printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq
  621. fi
  622. if [ $host_build_patch -eq 1 ]; then
  623. printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq
  624. fi
  625. if [ $host_build_findutils -eq 1 ]; then
  626. printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq
  627. fi
  628. if [ $host_build_sed -eq 1 ]; then
  629. printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq
  630. fi
  631. if [ $host_build_tar -eq 1 ]; then
  632. printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq
  633. fi
  634. if [ $host_build_coreutils -eq 1 ]; then
  635. printf "\t%s\n" "select ADK_HOST_BUILD_COREUTILS" >> $topdir/target/config/Config.in.prereq
  636. fi
  637. if [ $host_build_cpio -eq 1 ]; then
  638. printf "\t%s\n" "select ADK_HOST_BUILD_CPIO" >> $topdir/target/config/Config.in.prereq
  639. fi
  640. if [ $host_build_xz -eq 1 ]; then
  641. printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq
  642. fi
  643. # optional
  644. if [ $host_build_cdrtools -eq 1 ]; then
  645. printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq
  646. fi
  647. if [ $host_build_genext2fs -eq 1 ]; then
  648. printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq
  649. fi
  650. if [ $host_build_lzma -eq 1 ]; then
  651. printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq
  652. fi
  653. if [ $host_build_lz4 -eq 1 ]; then
  654. printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq
  655. fi
  656. if [ $host_build_lzop -eq 1 ]; then
  657. printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq
  658. fi
  659. if [ $host_build_qemu -eq 1 ]; then
  660. printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq
  661. fi
  662. # create Host OS symbols
  663. case $os in
  664. Linux)
  665. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  666. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  667. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  668. ;;
  669. Darwin)
  670. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  671. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  672. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  673. ;;
  674. OpenBSD)
  675. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  676. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  677. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  678. ;;
  679. FreeBSD)
  680. printf "\nconfig ADK_HOST_FREEBSD\n" >> $topdir/target/config/Config.in.prereq
  681. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  682. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  683. ;;
  684. NetBSD)
  685. printf "\nconfig ADK_HOST_NETBSD\n" >> $topdir/target/config/Config.in.prereq
  686. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  687. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  688. ;;
  689. MirBSD)
  690. printf "\nconfig ADK_HOST_MIRBSD\n" >> $topdir/target/config/Config.in.prereq
  691. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  692. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  693. ;;
  694. Cygwin*)
  695. printf "\nconfig ADK_HOST_CYGWIN\n" >> $topdir/target/config/Config.in.prereq
  696. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  697. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  698. ;;
  699. esac
  700. if [ "$target" = "defconfig" ]; then
  701. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  702. exit 0
  703. fi
  704. if [ ! -f $topdir/.config ]; then
  705. # create a config if no exist
  706. touch .firstrun
  707. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk menuconfig
  708. else
  709. # scan host-tool prerequisites of certain packages before building.
  710. . $topdir/.config
  711. if [ -n "$ADK_PACKAGE_KODI" ]; then
  712. NEED_JAVA="$NEED_JAVA kodi"
  713. fi
  714. if [ -n "$ADK_PACKAGE_ICU4C" ]; then
  715. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  716. fi
  717. if [ -n "$ADK_PACKAGE_XKEYBOARD_CONFIG" ]; then
  718. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  719. fi
  720. if [ -n "$ADK_PACKAGE_FONT_BH_100DPI" ]; then
  721. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-100dpi"
  722. fi
  723. if [ -n "$ADK_PACKAGE_FONT_BH_75DPI" ]; then
  724. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-75dpi"
  725. fi
  726. if [ -n "$ADK_PACKAGE_FONT_BH_TYPE1" ]; then
  727. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-type1"
  728. fi
  729. if [ -n "$ADK_PACKAGE_FONT_BH_TTF" ]; then
  730. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-ttf"
  731. fi
  732. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_100DPI" ]; then
  733. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-100dpi"
  734. fi
  735. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_75DPI" ]; then
  736. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-75dpi"
  737. fi
  738. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_100DPI" ]; then
  739. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  740. fi
  741. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_75DPI" ]; then
  742. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  743. fi
  744. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_TYPE1" ]; then
  745. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-type1"
  746. fi
  747. if [ -n "$ADK_PACKAGE_FONT_ADOBE_100DPI" ]; then
  748. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  749. fi
  750. if [ -n "$ADK_PACKAGE_FONT_ADOBE_75DPI" ]; then
  751. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  752. fi
  753. if [ -n "$ADK_PACKAGE_FONT_XFREE86_TYPE1" ]; then
  754. NEED_MKFONTDIR="$NEED_MKFONTDIR font-xfree86-type1"
  755. fi
  756. if [ -n "$ADK_PACKAGE_FONT_MISC_MISC" ]; then
  757. NEED_MKFONTDIR="$NEED_MKFONTDIR font-misc-misc"
  758. fi
  759. if [ -n "$ADK_PACKAGE_LIBERATION_FONTS_TTF" ]; then
  760. NEED_MKFONTSCALE="$NEED_MKFONTSCALE liberation-fonts-ttf"
  761. fi
  762. if [ -n "$NEED_MKFONTDIR" ]; then
  763. if ! which mkfontdir >/dev/null 2>&1; then
  764. printf "You need mkfontdir to build $NEED_MKFONTDIR \n"
  765. out=1
  766. fi
  767. fi
  768. if [ -n "$NEED_MKFONTSCALE" ]; then
  769. if ! which mkfontscale >/dev/null 2>&1; then
  770. printf "You need mkfontscale to build $NEED_MKFONTSCALE \n"
  771. out=1
  772. fi
  773. fi
  774. if [ -n "$NEED_XKBCOMP" ]; then
  775. if ! which xkbcomp >/dev/null 2>&1; then
  776. printf "You need xkbcomp to build $NEED_XKBCOMP \n"
  777. out=1
  778. fi
  779. fi
  780. if [ -n "$NEED_JAVA" ]; then
  781. if ! which java >/dev/null 2>&1; then
  782. printf "You need java to build $NEED_JAVA \n"
  783. out=1
  784. fi
  785. fi
  786. if [ -n "$NEED_STATIC_LIBSTDCXX" ]; then
  787. cat >test.c <<-'EOF'
  788. #include <stdio.h>
  789. int
  790. main()
  791. {
  792. return (0);
  793. }
  794. EOF
  795. if ! $CXX -static-libstdc++ -o test test.c 2>/dev/null ; then
  796. printf "You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX \n"
  797. out=1
  798. rm test test.c 2>/dev/null
  799. fi
  800. fi
  801. # error out
  802. if [ $out -ne 0 ]; then
  803. exit $out
  804. fi
  805. # start build
  806. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  807. fi