prereq.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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 -s -o "
  47. ;;
  48. wget)
  49. FETCHCMD="$(which $tool) --no-check-certificate -q -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. compilerbins="clang cc gcc"
  103. for compilerbin in $compilerbins; do
  104. printf " ---> checking if $compilerbin is installed.. "
  105. if which $compilerbin >/dev/null; then
  106. printf "found\n"
  107. CC=$compilerbin
  108. CCFOUND=1
  109. break
  110. else
  111. printf "not found\n"
  112. continue
  113. fi
  114. done
  115. if [ -z "$CCFOUND" ]; then
  116. printf "ERROR: no C compiler found. Fatal error.\n"
  117. exit 1
  118. fi
  119. # check for c++ compiler
  120. compilerbins="clang++ c++ g++"
  121. for compilerbin in $compilerbins; do
  122. printf " ---> checking if $compilerbin is installed.. "
  123. if which $compilerbin >/dev/null; then
  124. printf "found\n"
  125. CXX=$compilerbin
  126. CXXFOUND=1
  127. break
  128. else
  129. printf "not found\n"
  130. continue
  131. fi
  132. done
  133. if [ -z "$CXXFOUND" ]; then
  134. printf "ERROR: no C++ compiler found. Fatal error.\n"
  135. exit 1
  136. fi
  137. gnu_host_name=$(${CC} -dumpmachine)
  138. # relocation of topdir?
  139. olddir=$(grep "^ADK_TOPDIR" prereq.mk 2>/dev/null |cut -d '=' -f 2)
  140. newdir=$(pwd)
  141. if [ ! -z "$olddir" ]; then
  142. if [ "$olddir" != "$newdir" ]; then
  143. printf " ---> adk directory was relocated, fixing .."
  144. sed -i -e "s#$olddir#$newdir#g" $(find target_* -name \*.pc|xargs) 2>/dev/null
  145. sed -i -e "s#$olddir#$newdir#g" $(find host_${gnu_host_name} -type f|xargs) 2>/dev/null
  146. sed -i -e "s#$olddir#$newdir#g" $(find target_*/scripts -type f|xargs) 2>/dev/null
  147. sed -i -e "s#$olddir#$newdir#" target_*/etc/ipkg.conf 2>/dev/null
  148. sleep 2
  149. printf "done\n"
  150. fi
  151. fi
  152. case :$PATH: in
  153. (*:$topdir/host_${gnu_host_name}/bin:*) ;;
  154. (*) export PATH=$topdir/host_${gnu_host_name}/bin:$PATH ;;
  155. esac
  156. # check for GNU make
  157. makebins="gmake make"
  158. for makebin in $makebins; do
  159. printf " ---> checking if $makebin is installed.. "
  160. if which $makebin >/dev/null 2>/dev/null; then
  161. printf "found\n"
  162. printf " ---> checking if it is GNU make.. "
  163. $makebin --version 2>/dev/null| grep GNU >/dev/null
  164. if [ $? -eq 0 ]; then
  165. printf "yes\n"
  166. MAKE=$(which $makebin)
  167. break
  168. else
  169. # we need to build GNU make
  170. printf "no\n"
  171. printf " ---> compiling missing GNU make.. "
  172. cd dl
  173. $FETCHCMD make-${makever}.tar.gz $mirror/make-${makever}.tar.gz
  174. if [ $? -ne 0 ]; then
  175. printf "ERROR: failed to download make from $mirror\n"
  176. exit 1
  177. fi
  178. cd ..
  179. mkdir tmp
  180. cd tmp
  181. tar xzf ../dl/make-${makever}.tar.gz
  182. cd make-$makever
  183. ./configure --prefix=$topdir/host_$gnu_host_name/
  184. make
  185. make install
  186. cd ..
  187. cd ..
  188. rm -rf tmp
  189. MAKE=$topdir/host_$gnu_host_name/bin/make
  190. makebin=$topdir/host_$gnu_host_name/bin/make
  191. printf " done\n"
  192. fi
  193. else
  194. printf "not found\n"
  195. continue
  196. fi
  197. done
  198. # check for bash
  199. printf " ---> checking if bash is installed.. "
  200. if which bash >/dev/null; then
  201. printf "found\n"
  202. printf " ---> checking if it is bash 4.x.. "
  203. bash --version 2>/dev/null| grep -i "Version 4" >/dev/null
  204. if [ $? -eq 0 ]; then
  205. printf "yes\n"
  206. else
  207. # we need to build GNU bash 4.x
  208. printf "not found\n"
  209. printf " ---> compiling missing GNU bash.. "
  210. cd dl
  211. $FETCHCMD bash-${bashver}.tar.gz $mirror/bash-${bashver}.tar.gz
  212. if [ $? -ne 0 ]; then
  213. printf "ERROR: failed to download make from $mirror\n"
  214. exit 1
  215. fi
  216. cd ..
  217. mkdir tmp
  218. cd tmp
  219. tar xzf ../dl/bash-${bashver}.tar.gz
  220. cd bash-${bashver}
  221. ./configure --prefix=$topdir/host_$gnu_host_name/
  222. make
  223. make install
  224. cd ..
  225. cd ..
  226. rm -rf tmp
  227. printf " done\n"
  228. fi
  229. fi
  230. # skip the script if distclean / cleandir
  231. if [ "$target" = "distclean" -o "$target" = "cleandir" ]; then
  232. touch prereq.mk
  233. $makebin ADK_TOPDIR=$topdir -s -f Makefile.adk $flags $target
  234. exit 0
  235. fi
  236. printf " ---> checking if strings is installed.. "
  237. if ! which strings >/dev/null 2>&1; then
  238. echo You must install strings to continue.
  239. echo
  240. out=1
  241. printf "not found\n"
  242. fi
  243. printf "found\n"
  244. printf " ---> checking if perl is installed.. "
  245. if ! which perl >/dev/null 2>&1; then
  246. echo You must install perl to continue.
  247. echo
  248. out=1
  249. printf "not found\n"
  250. fi
  251. printf "found\n"
  252. # creating prereq.mk
  253. echo "ADK_TOPDIR:=$(readlink -nf . 2>/dev/null || pwd -P)" > $topdir/prereq.mk
  254. echo "BASH:=$(which bash)" >> $topdir/prereq.mk
  255. echo "SHELL:=$(which bash)" >> $topdir/prereq.mk
  256. echo "GMAKE:=$MAKE" >> $topdir/prereq.mk
  257. echo "MAKE:=$MAKE" >> $topdir/prereq.mk
  258. echo "FETCHCMD:=$FETCHCMD" >> $topdir/prereq.mk
  259. echo "SHA256:=$SHA256" >> $topdir/prereq.mk
  260. echo "GNU_HOST_NAME:=${gnu_host_name}" >> $topdir/prereq.mk
  261. echo "OS_FOR_BUILD:=${os}" >> $topdir/prereq.mk
  262. echo "ARCH_FOR_BUILD:=$(${CC} -dumpmachine | sed \
  263. -e 's/x86_64-linux-gnux32/x32/' \
  264. -e s'/-.*//' \
  265. -e 's/sparc.*/sparc/' \
  266. -e 's/armeb.*/armeb/g' \
  267. -e 's/arm.*/arm/g' \
  268. -e 's/m68k.*/m68k/' \
  269. -e 's/sh[234]/sh/' \
  270. -e 's/mips-.*/mips/' \
  271. -e 's/mipsel-.*/mipsel/' \
  272. -e 's/i[3-9]86/x86/' \
  273. )" >>prereq.mk
  274. if [ "$CC" = "clang" ]; then
  275. echo "HOST_CC:=${CC} -fbracket-depth=1024" >> $topdir/prereq.mk
  276. else
  277. echo "HOST_CC:=${CC}" >> $topdir/prereq.mk
  278. fi
  279. if [ "$CXX" = "clang++" ]; then
  280. echo "HOST_CXX:=${CXX} -fbracket-depth=1024" >> $topdir/prereq.mk
  281. else
  282. echo "HOST_CXX:=${CXX}" >> $topdir/prereq.mk
  283. fi
  284. echo "HOST_CFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  285. echo "HOST_CXXFLAGS:=-O0 -g0" >> $topdir/prereq.mk
  286. echo 'LANGUAGE:=C' >> $topdir/prereq.mk
  287. echo 'LC_ALL:=C' >> $topdir/prereq.mk
  288. echo "_PATH:=$PATH" >> $topdir/prereq.mk
  289. echo "PATH:=${topdir}/scripts:/usr/sbin:$PATH" >> $topdir/prereq.mk
  290. echo "GIT:=$(which git 2>/dev/null)" >> $topdir/prereq.mk
  291. echo "export ADK_TOPDIR GIT SHA256 BASH SHELL" >> $topdir/prereq.mk
  292. # check if compiler works
  293. cat >Makefile.tmp <<'EOF'
  294. include ${ADK_TOPDIR}/prereq.mk
  295. all: test
  296. test: test.c
  297. @${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  298. EOF
  299. cat >test.c <<-'EOF'
  300. #include <stdio.h>
  301. int
  302. main()
  303. {
  304. printf("YES");
  305. return (0);
  306. }
  307. EOF
  308. $MAKE --no-print-directory ADK_TOPDIR=$topdir -f Makefile.tmp 2>&1
  309. X=$(./test)
  310. if [ $X != YES ]; then
  311. echo "$X" | sed 's/^/| /'
  312. echo Cannot compile a simple test programme.
  313. echo You must install a host make and C compiler.
  314. echo
  315. out=1
  316. fi
  317. rm test.c test Makefile.tmp 2>/dev/null
  318. # error out on any required prerequisite
  319. if [ $out -ne 0 ]; then
  320. exit $out
  321. fi
  322. host_build_bc=0
  323. if which bc >/dev/null 2>&1; then
  324. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  325. host_build_bc=1
  326. else
  327. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  328. host_build_bc=1
  329. fi
  330. fi
  331. else
  332. host_build_bc=1
  333. fi
  334. host_build_bison=0
  335. if ! which bison >/dev/null 2>&1; then
  336. host_build_bison=1
  337. fi
  338. host_build_bzip2=0
  339. if ! which bzip2 >/dev/null 2>&1; then
  340. host_build_bzip2=1
  341. fi
  342. host_build_file=0
  343. if ! which file >/dev/null 2>&1; then
  344. host_build_file=1
  345. fi
  346. host_build_flex=0
  347. if ! which flex >/dev/null 2>&1; then
  348. host_build_flex=1
  349. fi
  350. host_build_m4=0
  351. if ! which m4 >/dev/null 2>&1; then
  352. host_build_m4=1
  353. fi
  354. host_build_mksh=0
  355. if ! which mksh >/dev/null 2>&1; then
  356. host_build_mksh=1
  357. fi
  358. host_build_patch=0
  359. if ! which patch >/dev/null 2>&1; then
  360. host_build_patch=1
  361. fi
  362. host_build_pkgconf=0
  363. if ! which pkgconf >/dev/null 2>&1; then
  364. host_build_pkgconf=1
  365. fi
  366. host_build_tar=0
  367. if which tar >/dev/null 2>&1; then
  368. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  369. host_build_tar=1
  370. fi
  371. else
  372. host_build_tar=1
  373. fi
  374. host_build_findutils=0
  375. if which xargs >/dev/null 2>&1; then
  376. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  377. host_build_findutils=1
  378. fi
  379. fi
  380. if which find >/dev/null 2>&1; then
  381. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  382. host_build_findutils=1
  383. fi
  384. fi
  385. host_build_grep=0
  386. if which grep >/dev/null 2>&1; then
  387. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  388. host_build_grep=1
  389. fi
  390. fi
  391. host_build_gawk=0
  392. if ! which gawk >/dev/null 2>&1; then
  393. host_build_gawk=1
  394. fi
  395. host_build_sed=0
  396. if which sed >/dev/null 2>&1; then
  397. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  398. host_build_sed=1
  399. fi
  400. fi
  401. host_build_xz=0
  402. if ! which xz >/dev/null 2>&1; then
  403. host_build_xz=1
  404. fi
  405. # optional
  406. host_build_cdrtools=0
  407. if ! which mkisofs >/dev/null 2>&1; then
  408. host_build_cdrtools=1
  409. fi
  410. host_build_ccache=0
  411. if ! which ccache >/dev/null 2>&1; then
  412. host_build_ccache=1
  413. fi
  414. host_build_genext2fs=0
  415. if ! which genext2fs >/dev/null 2>&1; then
  416. host_build_genext2fs=1
  417. fi
  418. host_build_lzma=0
  419. if ! which lzma >/dev/null 2>&1; then
  420. host_build_lzma=1
  421. fi
  422. host_build_lz4=0
  423. if ! which lz4c >/dev/null 2>&1; then
  424. host_build_lz4=1
  425. fi
  426. host_build_lzop=0
  427. if ! which lzop >/dev/null 2>&1; then
  428. host_build_lzop=1
  429. fi
  430. host_build_qemu=0
  431. if ! which qemu-img >/dev/null 2>&1; then
  432. host_build_qemu=1
  433. fi
  434. host_build_coreutils=0
  435. if which tr >/dev/null 2>&1; then
  436. if ! tr --version 2>/dev/null|grep GNU >/dev/null;then
  437. host_build_coreutils=1
  438. fi
  439. fi
  440. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  441. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  442. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  443. # always required
  444. if [ $host_build_bc -eq 1 ]; then
  445. printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq
  446. fi
  447. if [ $host_build_bison -eq 1 ]; then
  448. printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq
  449. fi
  450. if [ $host_build_bzip2 -eq 1 ]; then
  451. printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq
  452. fi
  453. if [ $host_build_file -eq 1 ]; then
  454. printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq
  455. fi
  456. if [ $host_build_flex -eq 1 ]; then
  457. printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq
  458. fi
  459. if [ $host_build_gawk -eq 1 ]; then
  460. printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq
  461. fi
  462. if [ $host_build_grep -eq 1 ]; then
  463. printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq
  464. fi
  465. if [ $host_build_m4 -eq 1 ]; then
  466. printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq
  467. fi
  468. if [ $host_build_mksh -eq 1 ]; then
  469. printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq
  470. fi
  471. if [ $host_build_patch -eq 1 ]; then
  472. printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq
  473. fi
  474. if [ $host_build_pkgconf -eq 1 ]; then
  475. printf "\t%s\n" "select ADK_HOST_BUILD_PKGCONF" >> $topdir/target/config/Config.in.prereq
  476. fi
  477. if [ $host_build_findutils -eq 1 ]; then
  478. printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq
  479. fi
  480. if [ $host_build_sed -eq 1 ]; then
  481. printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq
  482. fi
  483. if [ $host_build_tar -eq 1 ]; then
  484. printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq
  485. fi
  486. if [ $host_build_xz -eq 1 ]; then
  487. printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq
  488. fi
  489. # optional
  490. if [ $host_build_ccache -eq 1 ]; then
  491. printf "\t%s\n" "select ADK_HOST_BUILD_CCACHE if ADK_HOST_NEED_CCACHE" >> $topdir/target/config/Config.in.prereq
  492. fi
  493. if [ $host_build_cdrtools -eq 1 ]; then
  494. printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq
  495. fi
  496. if [ $host_build_genext2fs -eq 1 ]; then
  497. printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq
  498. fi
  499. if [ $host_build_lzma -eq 1 ]; then
  500. printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq
  501. fi
  502. if [ $host_build_lz4 -eq 1 ]; then
  503. printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq
  504. fi
  505. if [ $host_build_lzop -eq 1 ]; then
  506. printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq
  507. fi
  508. if [ $host_build_qemu -eq 1 ]; then
  509. printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq
  510. fi
  511. if [ $host_build_coreutils -eq 1 ]; then
  512. printf "\t%s\n" "select ADK_HOST_BUILD_COREUTILS if ADK_HOST_NEED_COREUTILS" >> $topdir/target/config/Config.in.prereq
  513. fi
  514. # create Host OS symbols
  515. case $os in
  516. Linux)
  517. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  518. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  519. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  520. ;;
  521. Darwin)
  522. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  523. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  524. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  525. ;;
  526. OpenBSD)
  527. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  528. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  529. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  530. ;;
  531. FreeBSD)
  532. printf "\nconfig ADK_HOST_FREEBSD\n" >> $topdir/target/config/Config.in.prereq
  533. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  534. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  535. ;;
  536. NetBSD)
  537. printf "\nconfig ADK_HOST_NETBSD\n" >> $topdir/target/config/Config.in.prereq
  538. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  539. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  540. ;;
  541. MirBSD)
  542. printf "\nconfig ADK_HOST_MIRBSD\n" >> $topdir/target/config/Config.in.prereq
  543. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  544. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  545. ;;
  546. Cygwin*)
  547. printf "\nconfig ADK_HOST_CYGWIN\n" >> $topdir/target/config/Config.in.prereq
  548. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  549. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  550. ;;
  551. esac
  552. if [ "$target" = "defconfig" ]; then
  553. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  554. exit 0
  555. fi
  556. if [ ! -f $topdir/.config ]; then
  557. # create a config if no exist
  558. touch .firstrun
  559. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk menuconfig
  560. else
  561. # scan host-tool prerequisites of certain packages before building.
  562. . $topdir/.config
  563. if [ -n "$ADK_PACKAGE_KODI" ]; then
  564. NEED_JAVA="$NEED_JAVA kodi"
  565. fi
  566. if [ -n "$ADK_PACKAGE_ICU4C" ]; then
  567. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  568. fi
  569. if [ -n "$ADK_PACKAGE_XKEYBOARD_CONFIG" ]; then
  570. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  571. fi
  572. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_100DPI" ]; then
  573. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  574. fi
  575. if [ -n "$ADK_PACKAGE_FONT_BITSTREAM_75DPI" ]; then
  576. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  577. fi
  578. if [ -n "$ADK_PACKAGE_FONT_ADOBE_100DPI" ]; then
  579. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  580. fi
  581. if [ -n "$ADK_PACKAGE_FONT_ADOBE_75DPI" ]; then
  582. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  583. fi
  584. if [ -n "$NEED_MKFONTDIR" ]; then
  585. if ! which mkfontdir >/dev/null 2>&1; then
  586. printf "You need mkfontdir to build $NEED_MKFONTDIR"
  587. out=1
  588. fi
  589. fi
  590. if [ -n "$NEED_XKBCOMP" ]; then
  591. if ! which xkbcomp >/dev/null 2>&1; then
  592. printf "You need xkbcomp to build $NEED_XKBCOMP"
  593. out=1
  594. fi
  595. fi
  596. if [ -n "$NEED_JAVA" ]; then
  597. if ! which java >/dev/null 2>&1; then
  598. printf "You need java to build $NEED_JAVA"
  599. out=1
  600. fi
  601. fi
  602. if [ -n "$NEED_STATIC_LIBSTDCXX" ]; then
  603. cat >test.c <<-'EOF'
  604. #include <stdio.h>
  605. int
  606. main()
  607. {
  608. return (0);
  609. }
  610. EOF
  611. if ! $CXX -static-libstdc++ -o test test.c 2>/dev/null ; then
  612. printf "You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX"
  613. out=1
  614. rm test test.c 2>/dev/null
  615. fi
  616. fi
  617. # error out
  618. if [ $out -ne 0 ]; then
  619. exit $out
  620. fi
  621. # start build
  622. $makebin ADK_TOPDIR=$topdir --no-print-directory -f Makefile.adk $flags $target
  623. fi