1
0

prereq.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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 "GITOPTS:=" >> $topdir/prereq.mk
  316. echo "export ADK_TOPDIR GIT GITOPTS SHA256 BASH SHELL" >> $topdir/prereq.mk
  317. # create temporary Makefile
  318. cat >Makefile.tmp <<'EOF'
  319. include ${ADK_TOPDIR}/prereq.mk
  320. all: test
  321. test: test.c
  322. @${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  323. EOF
  324. # check if compiler works
  325. cat >test.c <<-'EOF'
  326. #include <stdio.h>
  327. int
  328. main()
  329. {
  330. printf("YES");
  331. return (0);
  332. }
  333. EOF
  334. printf " ---> checking if compiler is working.. "
  335. $MAKE --no-print-directory ADK_TOPDIR=$topdir -f Makefile.tmp >/dev/null 2>&1
  336. X=$(./test 2>/dev/null)
  337. if [ X$X != XYES ]; then
  338. echo Cannot compile a simple test programme.
  339. echo You must install a host make and C compiler.
  340. echo
  341. out=1
  342. else
  343. printf "okay\n"
  344. fi
  345. rm test.c test 2>/dev/null
  346. printf " ---> checking if zlib is installed.. "
  347. # check for zlib
  348. cat >test.c <<-'EOF'
  349. #include <stdio.h>
  350. #include <zlib.h>
  351. #ifndef STDIN_FILENO
  352. #define STDIN_FILENO 0
  353. #endif
  354. int
  355. main()
  356. {
  357. gzFile zstdin;
  358. char buf[1024];
  359. int i;
  360. zstdin = gzdopen(STDIN_FILENO, "rb");
  361. i = gzread(zstdin, buf, sizeof (buf));
  362. if ((i > 0) && (i < sizeof (buf)))
  363. buf[i] = '\0';
  364. buf[sizeof (buf) - 1] = '\0';
  365. printf("%s\n", buf);
  366. return (0);
  367. }
  368. EOF
  369. $MAKE --no-print-directory LDADD=-lz ADK_TOPDIR=$topdir -f Makefile.tmp >/dev/null 2>&1
  370. X=$(echo YES | gzip | ./test 2>/dev/null)
  371. if [ X$X != XYES ]; then
  372. echo Cannot compile a libz test programm.
  373. echo You must install the zlib development package,
  374. echo usually called libz-dev, and the run-time library.
  375. echo
  376. out=1
  377. else
  378. printf "found\n"
  379. fi
  380. rm test.c test 2>/dev/null
  381. rm Makefile.tmp 2>/dev/null
  382. # error out on any required prerequisite
  383. if [ $out -ne 0 ]; then
  384. exit
  385. fi
  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. host_build_bc=1
  390. else
  391. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  392. host_build_bc=1
  393. fi
  394. fi
  395. else
  396. host_build_bc=1
  397. fi
  398. host_build_bison=0
  399. if ! which bison >/dev/null 2>&1; then
  400. host_build_bison=1
  401. fi
  402. host_build_bzip2=0
  403. if ! which bzip2 >/dev/null 2>&1; then
  404. host_build_bzip2=1
  405. fi
  406. host_build_file=0
  407. if ! which file >/dev/null 2>&1; then
  408. host_build_file=1
  409. fi
  410. host_build_flex=0
  411. if ! which flex >/dev/null 2>&1; then
  412. host_build_flex=1
  413. fi
  414. host_build_m4=0
  415. if ! which m4 >/dev/null 2>&1; then
  416. host_build_m4=1
  417. fi
  418. host_build_mkimage=0
  419. if ! which mkimage >/dev/null 2>&1; then
  420. host_build_mkimage=1
  421. fi
  422. host_build_mksh=0
  423. if ! which mksh >/dev/null 2>&1; then
  424. host_build_mksh=1
  425. fi
  426. host_build_patch=0
  427. if ! which patch >/dev/null 2>&1; then
  428. host_build_patch=1
  429. fi
  430. host_build_pkgconf=0
  431. if ! which pkgconf >/dev/null 2>&1; then
  432. host_build_pkgconf=1
  433. fi
  434. host_build_tar=0
  435. if which tar >/dev/null 2>&1; then
  436. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  437. host_build_tar=1
  438. fi
  439. else
  440. host_build_tar=1
  441. fi
  442. host_build_findutils=0
  443. if which xargs >/dev/null 2>&1; then
  444. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  445. host_build_findutils=1
  446. fi
  447. fi
  448. if which find >/dev/null 2>&1; then
  449. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  450. host_build_findutils=1
  451. fi
  452. fi
  453. host_build_grep=0
  454. if which grep >/dev/null 2>&1; then
  455. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  456. host_build_grep=1
  457. fi
  458. fi
  459. host_build_gawk=0
  460. if ! which gawk >/dev/null 2>&1; then
  461. host_build_gawk=1
  462. fi
  463. host_build_sed=0
  464. if which sed >/dev/null 2>&1; then
  465. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  466. host_build_sed=1
  467. fi
  468. fi
  469. host_build_xz=0
  470. if ! which xz >/dev/null 2>&1; then
  471. host_build_xz=1
  472. fi
  473. # optional
  474. host_build_cdrtools=0
  475. if ! which mkisofs >/dev/null 2>&1; then
  476. host_build_cdrtools=1
  477. fi
  478. host_build_ccache=0
  479. if ! which ccache >/dev/null 2>&1; then
  480. host_build_ccache=1
  481. fi
  482. host_build_genext2fs=0
  483. if ! which genext2fs >/dev/null 2>&1; then
  484. host_build_genext2fs=1
  485. fi
  486. host_build_lzma=0
  487. if ! which lzma >/dev/null 2>&1; then
  488. host_build_lzma=1
  489. fi
  490. host_build_lz4=0
  491. if ! which lz4c >/dev/null 2>&1; then
  492. host_build_lz4=1
  493. fi
  494. host_build_lzop=0
  495. if ! which lzop >/dev/null 2>&1; then
  496. host_build_lzop=1
  497. fi
  498. host_build_qemu=0
  499. if ! which qemu-img >/dev/null 2>&1; then
  500. host_build_qemu=1
  501. fi
  502. host_build_coreutils=0
  503. if which tr >/dev/null 2>&1; then
  504. if ! tr --version 2>/dev/null|grep GNU >/dev/null;then
  505. host_build_coreutils=1
  506. fi
  507. fi
  508. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  509. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  510. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  511. # always required
  512. if [ $host_build_bc -eq 1 ]; then
  513. printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq
  514. fi
  515. if [ $host_build_bison -eq 1 ]; then
  516. printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq
  517. fi
  518. if [ $host_build_bzip2 -eq 1 ]; then
  519. printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq
  520. fi
  521. if [ $host_build_file -eq 1 ]; then
  522. printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq
  523. fi
  524. if [ $host_build_flex -eq 1 ]; then
  525. printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq
  526. fi
  527. if [ $host_build_gawk -eq 1 ]; then
  528. printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq
  529. fi
  530. if [ $host_build_grep -eq 1 ]; then
  531. printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq
  532. fi
  533. if [ $host_build_m4 -eq 1 ]; then
  534. printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq
  535. fi
  536. if [ $host_build_mkimage -eq 1 ]; then
  537. printf "\t%s\n" "select ADK_HOST_BUILD_U_BOOT" >> $topdir/target/config/Config.in.prereq
  538. fi
  539. if [ $host_build_mksh -eq 1 ]; then
  540. printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq
  541. fi
  542. if [ $host_build_patch -eq 1 ]; then
  543. printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq
  544. fi
  545. if [ $host_build_pkgconf -eq 1 ]; then
  546. printf "\t%s\n" "select ADK_HOST_BUILD_PKGCONF" >> $topdir/target/config/Config.in.prereq
  547. fi
  548. if [ $host_build_findutils -eq 1 ]; then
  549. printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq
  550. fi
  551. if [ $host_build_sed -eq 1 ]; then
  552. printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq
  553. fi
  554. if [ $host_build_tar -eq 1 ]; then
  555. printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq
  556. fi
  557. if [ $host_build_xz -eq 1 ]; then
  558. printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq
  559. fi
  560. # optional
  561. if [ $host_build_ccache -eq 1 ]; then
  562. printf "\t%s\n" "select ADK_HOST_BUILD_CCACHE if ADK_HOST_NEED_CCACHE" >> $topdir/target/config/Config.in.prereq
  563. fi
  564. if [ $host_build_cdrtools -eq 1 ]; then
  565. printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq
  566. fi
  567. if [ $host_build_genext2fs -eq 1 ]; then
  568. printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq
  569. fi
  570. if [ $host_build_lzma -eq 1 ]; then
  571. printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq
  572. fi
  573. if [ $host_build_lz4 -eq 1 ]; then
  574. printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq
  575. fi
  576. if [ $host_build_lzop -eq 1 ]; then
  577. printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq
  578. fi
  579. if [ $host_build_qemu -eq 1 ]; then
  580. printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq
  581. fi
  582. if [ $host_build_coreutils -eq 1 ]; then
  583. printf "\t%s\n" "select ADK_HOST_BUILD_COREUTILS if ADK_HOST_NEED_COREUTILS" >> $topdir/target/config/Config.in.prereq
  584. fi
  585. # create Host OS symbols
  586. case $os in
  587. Linux)
  588. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  589. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  590. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  591. ;;
  592. Darwin)
  593. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  594. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  595. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  596. ;;
  597. OpenBSD)
  598. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  599. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  600. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  601. ;;
  602. FreeBSD)
  603. printf "\nconfig ADK_HOST_FREEBSD\n" >> $topdir/target/config/Config.in.prereq
  604. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  605. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  606. ;;
  607. NetBSD)
  608. printf "\nconfig ADK_HOST_NETBSD\n" >> $topdir/target/config/Config.in.prereq
  609. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  610. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  611. ;;
  612. MirBSD)
  613. printf "\nconfig ADK_HOST_MIRBSD\n" >> $topdir/target/config/Config.in.prereq
  614. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  615. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  616. ;;
  617. Cygwin*)
  618. printf "\nconfig ADK_HOST_CYGWIN\n" >> $topdir/target/config/Config.in.prereq
  619. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  620. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  621. ;;
  622. esac
  623. if [ "$target" = "defconfig" ]; then
  624. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  625. exit 0
  626. fi
  627. if [ ! -f $topdir/.config ]; then
  628. # create a config if no exist
  629. touch .firstrun
  630. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk menuconfig
  631. else
  632. # scan host-tool prerequisites of certain packages before building.
  633. . $topdir/.config
  634. if [ -n "$ADK_PACKAGE_KODI" ]; then
  635. NEED_JAVA="$NEED_JAVA kodi"
  636. fi
  637. if [ -n "$ADK_PACKAGE_ICU4C" ]; then
  638. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  639. fi
  640. if [ -n "$ADK_PACKAGE_XKEYBOARD_CONFIG" ]; then
  641. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  642. fi
  643. if [ -n "$ADK_PACKAGE_FONT_BH_100DPI" ]; then
  644. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-100dpi"
  645. fi
  646. if [ -n "$ADK_PACKAGE_FONT_BH_75DPI" ]; then
  647. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-75dpi"
  648. fi
  649. if [ -n "$ADK_PACKAGE_FONT_BH_TYPE1" ]; then
  650. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-type1"
  651. fi
  652. if [ -n "$ADK_PACKAGE_FONT_BH_TTF" ]; then
  653. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-ttf"
  654. fi
  655. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_100DPI" ]; then
  656. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-100dpi"
  657. fi
  658. if [ -n "$ADK_PACKAGE_FONT_BH_LUCIDATYPEWRITER_75DPI" ]; then
  659. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bh-lucidatypewriter-75dpi"
  660. fi
  661. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_100DPI" ]; then
  662. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  663. fi
  664. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_75DPI" ]; then
  665. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  666. fi
  667. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_TYPE1" ]; then
  668. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-type1"
  669. fi
  670. if [ -n "$ADK_PACKAGE_FONT_ADOBE_100DPI" ]; then
  671. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  672. fi
  673. if [ -n "$ADK_PACKAGE_FONT_ADOBE_75DPI" ]; then
  674. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  675. fi
  676. if [ -n "$ADK_PACKAGE_FONT_XFREE86_TYPE1" ]; then
  677. NEED_MKFONTDIR="$NEED_MKFONTDIR font-xfree86-type1"
  678. fi
  679. if [ -n "$ADK_PACKAGE_FONT_MISC_MISC" ]; then
  680. NEED_MKFONTDIR="$NEED_MKFONTDIR font-misc-misc"
  681. fi
  682. if [ -n "$ADK_PACKAGE_LIBERATION_FONTS_TTF" ]; then
  683. NEED_MKFONTSCALE="$NEED_MKFONTSCALE liberation-fonts-ttf"
  684. fi
  685. if [ -n "$NEED_MKFONTDIR" ]; then
  686. if ! which mkfontdir >/dev/null 2>&1; then
  687. printf "You need mkfontdir to build $NEED_MKFONTDIR \n"
  688. out=1
  689. fi
  690. fi
  691. if [ -n "$NEED_MKFONTSCALE" ]; then
  692. if ! which mkfontscale >/dev/null 2>&1; then
  693. printf "You need mkfontscale to build $NEED_MKFONTSCALE \n"
  694. out=1
  695. fi
  696. fi
  697. if [ -n "$NEED_XKBCOMP" ]; then
  698. if ! which xkbcomp >/dev/null 2>&1; then
  699. printf "You need xkbcomp to build $NEED_XKBCOMP \n"
  700. out=1
  701. fi
  702. fi
  703. if [ -n "$NEED_JAVA" ]; then
  704. if ! which java >/dev/null 2>&1; then
  705. printf "You need java to build $NEED_JAVA \n"
  706. out=1
  707. fi
  708. fi
  709. if [ -n "$NEED_STATIC_LIBSTDCXX" ]; then
  710. cat >test.c <<-'EOF'
  711. #include <stdio.h>
  712. int
  713. main()
  714. {
  715. return (0);
  716. }
  717. EOF
  718. if ! $CXX -static-libstdc++ -o test test.c 2>/dev/null ; then
  719. printf "You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX \n"
  720. out=1
  721. rm test test.c 2>/dev/null
  722. fi
  723. fi
  724. # error out
  725. if [ $out -ne 0 ]; then
  726. exit $out
  727. fi
  728. # start build
  729. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  730. fi