prereq.sh 25 KB

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