prereq.sh 20 KB

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