1
0

prereq.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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 "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. # error out on any required prerequisite
  382. if [ $out -ne 0 ]; then
  383. exit
  384. fi
  385. printf " ---> checking if bc is installed.. "
  386. host_build_bc=0
  387. if which bc >/dev/null 2>&1; then
  388. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  389. printf "not usable\n"
  390. host_build_bc=1
  391. else
  392. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  393. host_build_bc=1
  394. printf "not usable\n"
  395. fi
  396. printf "found\n"
  397. fi
  398. else
  399. printf "not found\n"
  400. host_build_bc=1
  401. fi
  402. printf " ---> checking if bison is installed.. "
  403. host_build_bison=0
  404. if ! which bison >/dev/null 2>&1; then
  405. printf "not found\n"
  406. host_build_bison=1
  407. else
  408. printf "found\n"
  409. fi
  410. printf " ---> checking if bzip2 is installed.. "
  411. host_build_bzip2=0
  412. if ! which bzip2 >/dev/null 2>&1; then
  413. printf "not found\n"
  414. host_build_bzip2=1
  415. else
  416. printf "found\n"
  417. fi
  418. printf " ---> checking if file is installed.. "
  419. host_build_file=0
  420. if ! which file >/dev/null 2>&1; then
  421. printf "not found\n"
  422. host_build_file=1
  423. else
  424. printf "found\n"
  425. fi
  426. printf " ---> checking if flex is installed.. "
  427. host_build_flex=0
  428. if ! which flex >/dev/null 2>&1; then
  429. printf "not found\n"
  430. host_build_flex=1
  431. else
  432. printf "found\n"
  433. fi
  434. host_build_m4=0
  435. if ! which m4 >/dev/null 2>&1; then
  436. host_build_m4=1
  437. fi
  438. host_build_mkimage=0
  439. if ! which mkimage >/dev/null 2>&1; then
  440. host_build_mkimage=1
  441. fi
  442. printf " ---> checking if mksh is installed.. "
  443. host_build_mksh=0
  444. if ! which mksh >/dev/null 2>&1; then
  445. printf "not found\n"
  446. host_build_mksh=1
  447. else
  448. printf "found\n"
  449. fi
  450. printf " ---> checking if patch is installed.. "
  451. host_build_patch=0
  452. if ! which patch >/dev/null 2>&1; then
  453. printf "not found\n"
  454. host_build_patch=1
  455. else
  456. printf "found\n"
  457. fi
  458. host_build_tar=0
  459. if which tar >/dev/null 2>&1; then
  460. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  461. host_build_tar=1
  462. fi
  463. else
  464. host_build_tar=1
  465. fi
  466. printf " ---> checking if xargs is installed.. "
  467. host_build_findutils=0
  468. if which xargs >/dev/null 2>&1; then
  469. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  470. printf "found but not usable\n"
  471. host_build_findutils=1
  472. else
  473. printf "found\n"
  474. fi
  475. else
  476. printf "not found\n"
  477. host_build_findutils=1
  478. fi
  479. printf " ---> checking if find is installed.. "
  480. if which find >/dev/null 2>&1; then
  481. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  482. printf "found but not usable\n"
  483. host_build_findutils=1
  484. else
  485. printf "found\n"
  486. fi
  487. else
  488. printf "not found\n"
  489. host_build_findutils=1
  490. fi
  491. printf " ---> checking if grep is installed.. "
  492. host_build_grep=0
  493. if which grep >/dev/null 2>&1; then
  494. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  495. printf "found but not usable\n"
  496. host_build_grep=1
  497. else
  498. printf "found\n"
  499. fi
  500. else
  501. printf "not found\n"
  502. host_build_grep=1
  503. fi
  504. printf " ---> checking if gawk is installed.. "
  505. host_build_gawk=0
  506. if ! which gawk >/dev/null 2>&1; then
  507. printf "not found\n"
  508. host_build_gawk=1
  509. else
  510. printf "found\n"
  511. fi
  512. printf " ---> checking if sed is installed.. "
  513. host_build_sed=0
  514. if which sed >/dev/null 2>&1; then
  515. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  516. printf "found but not usable\n"
  517. host_build_sed=1
  518. else
  519. printf "found\n"
  520. fi
  521. else
  522. printf "not found\n"
  523. host_build_sed=1
  524. fi
  525. printf " ---> checking if xz is installed.. "
  526. host_build_xz=0
  527. if ! which xz >/dev/null 2>&1; then
  528. printf "not found\n"
  529. host_build_xz=1
  530. else
  531. printf "found\n"
  532. fi
  533. # optional
  534. host_build_cdrtools=0
  535. if ! which mkisofs >/dev/null 2>&1; then
  536. host_build_cdrtools=1
  537. fi
  538. host_build_genext2fs=0
  539. if ! which genext2fs >/dev/null 2>&1; then
  540. host_build_genext2fs=1
  541. fi
  542. host_build_lzma=0
  543. if ! which lzma >/dev/null 2>&1; then
  544. host_build_lzma=1
  545. fi
  546. host_build_lz4=0
  547. if ! which lz4c >/dev/null 2>&1; then
  548. host_build_lz4=1
  549. fi
  550. host_build_lzop=0
  551. if ! which lzop >/dev/null 2>&1; then
  552. host_build_lzop=1
  553. fi
  554. host_build_qemu=0
  555. if ! which qemu-img >/dev/null 2>&1; then
  556. host_build_qemu=1
  557. fi
  558. host_build_coreutils=0
  559. if which tr >/dev/null 2>&1; then
  560. if ! tr --version 2>/dev/null|grep GNU >/dev/null;then
  561. host_build_coreutils=1
  562. fi
  563. fi
  564. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  565. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  566. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  567. # always required
  568. if [ $host_build_bc -eq 1 ]; then
  569. printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq
  570. fi
  571. if [ $host_build_bison -eq 1 ]; then
  572. printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq
  573. fi
  574. if [ $host_build_bzip2 -eq 1 ]; then
  575. printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq
  576. fi
  577. if [ $host_build_file -eq 1 ]; then
  578. printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq
  579. fi
  580. if [ $host_build_flex -eq 1 ]; then
  581. printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq
  582. fi
  583. if [ $host_build_gawk -eq 1 ]; then
  584. printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq
  585. fi
  586. if [ $host_build_grep -eq 1 ]; then
  587. printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq
  588. fi
  589. if [ $host_build_m4 -eq 1 ]; then
  590. printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq
  591. fi
  592. if [ $host_build_mkimage -eq 1 ]; then
  593. printf "\t%s\n" "select ADK_HOST_BUILD_U_BOOT" >> $topdir/target/config/Config.in.prereq
  594. fi
  595. if [ $host_build_mksh -eq 1 ]; then
  596. printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq
  597. fi
  598. if [ $host_build_patch -eq 1 ]; then
  599. printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq
  600. fi
  601. if [ $host_build_findutils -eq 1 ]; then
  602. printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq
  603. fi
  604. if [ $host_build_sed -eq 1 ]; then
  605. printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq
  606. fi
  607. if [ $host_build_tar -eq 1 ]; then
  608. printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq
  609. fi
  610. if [ $host_build_xz -eq 1 ]; then
  611. printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq
  612. fi
  613. # optional
  614. if [ $host_build_cdrtools -eq 1 ]; then
  615. printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq
  616. fi
  617. if [ $host_build_genext2fs -eq 1 ]; then
  618. printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq
  619. fi
  620. if [ $host_build_lzma -eq 1 ]; then
  621. printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq
  622. fi
  623. if [ $host_build_lz4 -eq 1 ]; then
  624. printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq
  625. fi
  626. if [ $host_build_lzop -eq 1 ]; then
  627. printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq
  628. fi
  629. if [ $host_build_qemu -eq 1 ]; then
  630. printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq
  631. fi
  632. if [ $host_build_coreutils -eq 1 ]; then
  633. printf "\t%s\n" "select ADK_HOST_BUILD_COREUTILS if ADK_HOST_NEED_COREUTILS" >> $topdir/target/config/Config.in.prereq
  634. fi
  635. # create Host OS symbols
  636. case $os in
  637. Linux)
  638. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  639. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  640. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  641. ;;
  642. Darwin)
  643. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  644. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  645. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  646. ;;
  647. OpenBSD)
  648. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  649. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  650. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  651. ;;
  652. FreeBSD)
  653. printf "\nconfig ADK_HOST_FREEBSD\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. NetBSD)
  658. printf "\nconfig ADK_HOST_NETBSD\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. MirBSD)
  663. printf "\nconfig ADK_HOST_MIRBSD\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. Cygwin*)
  668. printf "\nconfig ADK_HOST_CYGWIN\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. esac
  673. if [ "$target" = "defconfig" ]; then
  674. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  675. exit 0
  676. fi
  677. if [ ! -f $topdir/.config ]; then
  678. # create a config if no exist
  679. touch .firstrun
  680. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk menuconfig
  681. else
  682. # scan host-tool prerequisites of certain packages before building.
  683. . $topdir/.config
  684. if [ -n "$ADK_PACKAGE_KODI" ]; then
  685. NEED_JAVA="$NEED_JAVA kodi"
  686. fi
  687. if [ -n "$ADK_PACKAGE_ICU4C" ]; then
  688. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  689. fi
  690. if [ -n "$ADK_PACKAGE_XKEYBOARD_CONFIG" ]; then
  691. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  692. fi
  693. if [ -n "$ADK_PACKAGE_FONT_BH_100DPI" ]; then
  694. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-100dpi"
  695. fi
  696. if [ -n "$ADK_PACKAGE_FONT_BH_75DPI" ]; then
  697. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-75dpi"
  698. fi
  699. if [ -n "$ADK_PACKAGE_FONT_BH_TYPE1" ]; then
  700. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-type1"
  701. fi
  702. if [ -n "$ADK_PACKAGE_FONT_BH_TTF" ]; then
  703. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-ttf"
  704. fi
  705. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_100DPI" ]; then
  706. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-100dpi"
  707. fi
  708. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_75DPI" ]; then
  709. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-75dpi"
  710. fi
  711. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_100DPI" ]; then
  712. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  713. fi
  714. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_75DPI" ]; then
  715. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  716. fi
  717. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_TYPE1" ]; then
  718. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-type1"
  719. fi
  720. if [ -n "$ADK_PACKAGE_FONT_ADOBE_100DPI" ]; then
  721. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  722. fi
  723. if [ -n "$ADK_PACKAGE_FONT_ADOBE_75DPI" ]; then
  724. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  725. fi
  726. if [ -n "$ADK_PACKAGE_FONT_XFREE86_TYPE1" ]; then
  727. NEED_MKFONTDIR="$NEED_MKFONTDIR font-xfree86-type1"
  728. fi
  729. if [ -n "$ADK_PACKAGE_FONT_MISC_MISC" ]; then
  730. NEED_MKFONTDIR="$NEED_MKFONTDIR font-misc-misc"
  731. fi
  732. if [ -n "$ADK_PACKAGE_LIBERATION_FONTS_TTF" ]; then
  733. NEED_MKFONTSCALE="$NEED_MKFONTSCALE liberation-fonts-ttf"
  734. fi
  735. if [ -n "$NEED_MKFONTDIR" ]; then
  736. if ! which mkfontdir >/dev/null 2>&1; then
  737. printf "You need mkfontdir to build $NEED_MKFONTDIR \n"
  738. out=1
  739. fi
  740. fi
  741. if [ -n "$NEED_MKFONTSCALE" ]; then
  742. if ! which mkfontscale >/dev/null 2>&1; then
  743. printf "You need mkfontscale to build $NEED_MKFONTSCALE \n"
  744. out=1
  745. fi
  746. fi
  747. if [ -n "$NEED_XKBCOMP" ]; then
  748. if ! which xkbcomp >/dev/null 2>&1; then
  749. printf "You need xkbcomp to build $NEED_XKBCOMP \n"
  750. out=1
  751. fi
  752. fi
  753. if [ -n "$NEED_JAVA" ]; then
  754. if ! which java >/dev/null 2>&1; then
  755. printf "You need java to build $NEED_JAVA \n"
  756. out=1
  757. fi
  758. fi
  759. if [ -n "$NEED_STATIC_LIBSTDCXX" ]; then
  760. cat >test.c <<-'EOF'
  761. #include <stdio.h>
  762. int
  763. main()
  764. {
  765. return (0);
  766. }
  767. EOF
  768. if ! $CXX -static-libstdc++ -o test test.c 2>/dev/null ; then
  769. printf "You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX \n"
  770. out=1
  771. rm test test.c 2>/dev/null
  772. fi
  773. fi
  774. # error out
  775. if [ $out -ne 0 ]; then
  776. exit $out
  777. fi
  778. # start build
  779. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  780. fi