prereq.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. # detect operating system
  10. os=$(env uname)
  11. osver=$(env uname -r)
  12. printf " ---> $os $osver for build detected.\n"
  13. # check if the filesystem is case sensitive
  14. rm -f foo
  15. echo >FOO
  16. if [[ -e foo ]]; then
  17. printf "ERROR: OpenADK cannot be built in a case-insensitive file system."
  18. case $os in
  19. CYG*)
  20. printf "Building OpenADK on $os needs a small registry change."
  21. printf "http://cygwin.com/cygwin-ug-net/using-specialnames.html"
  22. ;;
  23. Darwin*)
  24. printf "Building OpenADK on $os needs a case-sensitive disk partition."
  25. printf "For Snow Leopard and above you can use diskutil to resize your existing disk."
  26. printf "Example: sudo diskutil resizeVolume disk0s2 90G 1 jhfsx adk 30G"
  27. printf "For older versions you might consider to use a disk image:"
  28. printf "hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 30g ~/openadk.dmg"
  29. ;;
  30. esac
  31. rm -f FOO
  32. exit 1
  33. fi
  34. rm -f FOO
  35. # relocation of topdir?
  36. olddir=$(grep "^ADK_TOPDIR" prereq.mk 2>/dev/null |cut -d '=' -f 2)
  37. newdir=$(pwd)
  38. if [ ! -z "$olddir" ]; then
  39. if [ "$olddir" != "$newdir" ]; then
  40. printf " ---> adk directory was relocated, fixing .."
  41. printf "old directory: $olddir"
  42. printf "new directory: $newdir"
  43. sed -i -e "s#$olddir#$newdir#g" $(find target_* -name \*.pc|xargs)
  44. sed -i -e "s#$olddir#$newdir#g" $(find target_*/scripts -type f|xargs)
  45. sed -i -e "s#$olddir#$newdir#" target_*/etc/ipkg.conf
  46. fi
  47. fi
  48. # do we have a download tool?
  49. tools="curl wget ftp lftp"
  50. for tool in $tools; do
  51. printf " ---> checking if $tool is installed.. "
  52. if which $tool >/dev/null; then
  53. printf "found\n"
  54. DLTOOL=$(which $tool)
  55. break
  56. else
  57. printf "not found\n"
  58. continue
  59. fi
  60. done
  61. if [ -z $DLTOOL ]; then
  62. printf "ERROR: no download tool found. Fatal error.\n"
  63. exit 1
  64. fi
  65. # do we have a checksum tool?
  66. tools="sha256sum sha256"
  67. for tool in $tools; do
  68. printf " ---> checking if $tool is installed.. "
  69. if which $tool >/dev/null 2>/dev/null; then
  70. printf "found\n"
  71. if [ $tool = "sha256" ]; then
  72. SHA256="$(which $tool) -q"
  73. else
  74. SHA256=$(which $tool)
  75. fi
  76. break
  77. else
  78. printf "not found\n"
  79. continue
  80. fi
  81. done
  82. if [ -z "$SHA256" ]; then
  83. printf "ERROR: no checksum tool found. Fatal error.\n"
  84. exit 1
  85. fi
  86. # create download dir
  87. if [ ! -d $topdir/dl ]; then
  88. mkdir -p $topdir/dl
  89. fi
  90. # check for GNU make
  91. makebins="gmake make"
  92. for makebin in $makebins; do
  93. printf " ---> checking if $makebin is installed.. "
  94. if which $makebin >/dev/null; then
  95. printf "found\n"
  96. printf " ---> checking if it is GNU make.. "
  97. $makebin --version 2>/dev/null| grep GNU >/dev/null
  98. if [ $? -eq 0 ]; then
  99. printf "yes\n"
  100. MAKE=$(which $makebin)
  101. break
  102. fi
  103. else
  104. printf "not found\n"
  105. continue
  106. fi
  107. done
  108. # skip the script if distclean / cleandir
  109. if [ "$target" = "distclean" -o "$target" = "cleandir" ]; then
  110. touch prereq.mk
  111. $makebin -s -f Makefile.adk $flags $target
  112. exit 0
  113. fi
  114. # check for c compiler
  115. compilerbins="cc gcc clang"
  116. for compilerbin in $compilerbins; do
  117. printf " ---> checking if $compilerbin is installed.. "
  118. if which $compilerbin >/dev/null; then
  119. printf "found\n"
  120. CC=$compilerbin
  121. break
  122. fi
  123. done
  124. # check for c++ compiler
  125. compilerbins="c++ g++ clang++"
  126. for compilerbin in $compilerbins; do
  127. printf " ---> checking if $compilerbin is installed.. "
  128. if which $compilerbin >/dev/null; then
  129. printf "found\n"
  130. CXX=$compilerbin
  131. break
  132. fi
  133. done
  134. if ! which perl >/dev/null 2>&1; then
  135. echo You must install perl to continue.
  136. echo
  137. out=1
  138. fi
  139. # creating prereq.mk
  140. echo "ADK_TOPDIR:=$(readlink -nf . 2>/dev/null || pwd -P)" > $topdir/prereq.mk
  141. echo "BASH:=$(which bash)" >> $topdir/prereq.mk
  142. echo "SHELL:=$BASH" >> $topdir/prereq.mk
  143. echo "GMAKE:=$MAKE" >> $topdir/prereq.mk
  144. echo "MAKE:=$MAKE" >> $topdir/prereq.mk
  145. echo "SHA256:=$SHA256" >> $topdir/prereq.mk
  146. echo "GNU_HOST_NAME:=$(${CC} -dumpmachine)" >> $topdir/prereq.mk
  147. echo "OS_FOR_BUILD:=${os}" >> $topdir/prereq.mk
  148. echo "ARCH_FOR_BUILD:=$(${CC} -dumpmachine | sed \
  149. -e 's/x86_64-linux-gnux32/x32/' \
  150. -e s'/-.*//' \
  151. -e 's/sparc.*/sparc/' \
  152. -e 's/armeb.*/armeb/g' \
  153. -e 's/arm.*/arm/g' \
  154. -e 's/m68k.*/m68k/' \
  155. -e 's/sh[234]/sh/' \
  156. -e 's/mips-.*/mips/' \
  157. -e 's/mipsel-.*/mipsel/' \
  158. -e 's/i[3-9]86/x86/' \
  159. )" >>prereq.mk
  160. if [ "$CC" = "clang" ]; then
  161. echo "HOST_CC:=${CC} -fbracket-depth=1024" >> $topdir/prereq.mk
  162. else
  163. echo "HOST_CC:=${CC}" >> $topdir/prereq.mk
  164. fi
  165. if [ "$CXX" = "clang++" ]; then
  166. echo "HOST_CXX:=${CXX} -fbracket-depth=1024" >> $topdir/prereq.mk
  167. else
  168. echo "HOST_CXX:=${CXX}" >> $topdir/prereq.mk
  169. fi
  170. echo 'LANGUAGE:=C' >> $topdir/prereq.mk
  171. echo 'LC_ALL:=C' >> $topdir/prereq.mk
  172. echo "_PATH:=$PATH" >> $topdir/prereq.mk
  173. echo "PATH:=${topdir}/scripts:/usr/sbin:$PATH" >> $topdir/prereq.mk
  174. echo "GIT:=$(which git 2>/dev/null)" >> $topdir/prereq.mk
  175. echo "export GIT SHA256" >> $topdir/prereq.mk
  176. # check if compiler works
  177. cat >Makefile.tmp <<'EOF'
  178. include ${ADK_TOPDIR}/prereq.mk
  179. all: run-test
  180. test: test.c
  181. ${HOST_CC} ${HOST_CFLAGS} -o $@ $^ ${LDADD}
  182. run-test: test
  183. ./test
  184. EOF
  185. cat >test.c <<-'EOF'
  186. #include <stdio.h>
  187. int
  188. main()
  189. {
  190. printf("Yay! Native compiler works.\n");
  191. return (0);
  192. }
  193. EOF
  194. X=$($MAKE --no-print-directory ADK_TOPDIR=$topdir -f Makefile.tmp HOST_CFLAGS=${HOST_CFLAGS} 2>&1)
  195. if [[ $X != *@(Native compiler works)* ]]; then
  196. echo "$X" | sed 's/^/| /'
  197. echo Cannot compile a simple test programme.
  198. echo You must install a host make and C compiler.
  199. echo
  200. out=1
  201. fi
  202. rm test.c test Makefile.tmp 2>/dev/null
  203. # error out on any required prerequisite
  204. if [ $out -ne 0 ]; then
  205. exit $out
  206. fi
  207. # always required, but can be provided by host
  208. host_build_bc=0
  209. if which bc >/dev/null 2>&1; then
  210. if ! echo quit|bc -q 2>/dev/null >/dev/null; then
  211. host_build_bc=1
  212. else
  213. if bc -v 2>&1| grep -q BSD >/dev/null 2>&1; then
  214. host_build_bc=1
  215. fi
  216. fi
  217. else
  218. host_build_bc=1
  219. fi
  220. host_build_bison=0
  221. if ! which bison >/dev/null 2>&1; then
  222. host_build_bison=1
  223. fi
  224. host_build_bzip2=0
  225. if ! which bzip2 >/dev/null 2>&1; then
  226. host_build_bzip2=1
  227. fi
  228. host_build_file=0
  229. if ! which file >/dev/null 2>&1; then
  230. host_build_file=1
  231. fi
  232. host_build_flex=0
  233. if ! which flex >/dev/null 2>&1; then
  234. host_build_flex=1
  235. fi
  236. host_build_m4=0
  237. if ! which m4 >/dev/null 2>&1; then
  238. host_build_m4=1
  239. fi
  240. host_build_mksh=0
  241. if ! which mksh >/dev/null 2>&1; then
  242. host_build_mksh=1
  243. fi
  244. host_build_patch=0
  245. if ! which patch >/dev/null 2>&1; then
  246. host_build_patch=1
  247. fi
  248. host_build_pkgconf=0
  249. if ! which pkgconf >/dev/null 2>&1; then
  250. host_build_pkgconf=1
  251. fi
  252. host_build_tar=0
  253. if which tar >/dev/null 2>&1; then
  254. if ! tar --version 2>/dev/null|grep GNU >/dev/null;then
  255. host_build_tar=1
  256. fi
  257. else
  258. host_build_tar=1
  259. fi
  260. host_build_findutils=0
  261. if ! which gxargs >/dev/null 2>&1; then
  262. if which xargs >/dev/null 2>&1; then
  263. if ! xargs --version 2>/dev/null|grep GNU >/dev/null;then
  264. host_build_findutils=1
  265. fi
  266. fi
  267. fi
  268. if which find >/dev/null 2>&1; then
  269. if ! find --version 2>/dev/null|grep GNU >/dev/null;then
  270. host_build_findutils=1
  271. fi
  272. fi
  273. host_build_grep=0
  274. if which grep >/dev/null 2>&1; then
  275. if ! grep --version 2>/dev/null|grep GNU >/dev/null;then
  276. host_build_grep=1
  277. fi
  278. fi
  279. host_build_gawk=0
  280. if ! which gawk >/dev/null 2>&1; then
  281. host_build_gawk=1
  282. fi
  283. host_build_sed=0
  284. if which sed >/dev/null 2>&1; then
  285. if ! sed --version 2>/dev/null|grep GNU >/dev/null;then
  286. host_build_sed=1
  287. fi
  288. fi
  289. host_build_xz=0
  290. if ! which xz >/dev/null 2>&1; then
  291. host_build_xz=1
  292. fi
  293. # optional
  294. host_build_cdrtools=0
  295. if ! which mkisofs >/dev/null 2>&1; then
  296. host_build_cdrtools=1
  297. fi
  298. host_build_ccache=0
  299. if ! which ccache >/dev/null 2>&1; then
  300. host_build_ccache=1
  301. fi
  302. host_build_genext2fs=0
  303. if ! which genext2fs >/dev/null 2>&1; then
  304. host_build_genext2fs=1
  305. fi
  306. host_build_lzma=0
  307. if ! which lzma >/dev/null 2>&1; then
  308. host_build_lzma=1
  309. fi
  310. host_build_lz4=0
  311. if ! which lz4c >/dev/null 2>&1; then
  312. host_build_lz4=1
  313. fi
  314. host_build_lzop=0
  315. if ! which lzop >/dev/null 2>&1; then
  316. host_build_lzop=1
  317. fi
  318. host_build_qemu=0
  319. if ! which qemu-img >/dev/null 2>&1; then
  320. host_build_qemu=1
  321. fi
  322. echo "config ADK_HOST_BUILD_TOOLS" > $topdir/target/config/Config.in.prereq
  323. printf "\t%s\n" "bool" >> $topdir/target/config/Config.in.prereq
  324. printf "\t%s\n" "default y" >> $topdir/target/config/Config.in.prereq
  325. # always required
  326. if [ $host_build_bc -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BC" >> $topdir/target/config/Config.in.prereq ;fi
  327. if [ $host_build_bison -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BISON" >> $topdir/target/config/Config.in.prereq ;fi
  328. if [ $host_build_bzip2 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_BZIP2" >> $topdir/target/config/Config.in.prereq ;fi
  329. if [ $host_build_file -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FILE" >> $topdir/target/config/Config.in.prereq ;fi
  330. if [ $host_build_flex -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FLEX" >> $topdir/target/config/Config.in.prereq ;fi
  331. if [ $host_build_gawk -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GAWK" >> $topdir/target/config/Config.in.prereq ;fi
  332. if [ $host_build_grep -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GREP" >> $topdir/target/config/Config.in.prereq ;fi
  333. if [ $host_build_m4 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_M4" >> $topdir/target/config/Config.in.prereq ;fi
  334. if [ $host_build_mksh -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_MKSH" >> $topdir/target/config/Config.in.prereq ;fi
  335. if [ $host_build_patch -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_PATCH" >> $topdir/target/config/Config.in.prereq ;fi
  336. if [ $host_build_pkgconf -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_PKGCONF" >> $topdir/target/config/Config.in.prereq ;fi
  337. if [ $host_build_findutils -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_FINDUTILS" >> $topdir/target/config/Config.in.prereq ;fi
  338. if [ $host_build_sed -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_SED" >> $topdir/target/config/Config.in.prereq ;fi
  339. if [ $host_build_tar -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_TAR" >> $topdir/target/config/Config.in.prereq ;fi
  340. if [ $host_build_xz -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_XZ" >> $topdir/target/config/Config.in.prereq ;fi
  341. # optional
  342. if [ $host_build_ccache -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_CCACHE if ADK_HOST_NEED_CCACHE" >> $topdir/target/config/Config.in.prereq ;fi
  343. if [ $host_build_cdrtools -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_CDRTOOLS if ADK_HOST_NEED_CDRTOOLS" >> $topdir/target/config/Config.in.prereq ;fi
  344. if [ $host_build_genext2fs -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_GENEXT2FS if ADK_HOST_NEED_GENEXT2FS" >> $topdir/target/config/Config.in.prereq ;fi
  345. if [ $host_build_lzma -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_LZMA if ADK_HOST_NEED_LZMA" >> $topdir/target/config/Config.in.prereq ;fi
  346. if [ $host_build_lz4 -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_LZ4 if ADK_HOST_NEED_LZ4" >> $topdir/target/config/Config.in.prereq ;fi
  347. if [ $host_build_lzop -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_LZOP if ADK_HOST_NEED_LZOP" >> $topdir/target/config/Config.in.prereq ;fi
  348. if [ $host_build_qemu -eq 1 ];then printf "\t%s\n" "select ADK_HOST_BUILD_QEMU if ADK_HOST_NEED_QEMU" >> $topdir/target/config/Config.in.prereq ;fi
  349. # create Host OS symbols
  350. case $os in
  351. Linux)
  352. printf "\nconfig ADK_HOST_LINUX\n" >> $topdir/target/config/Config.in.prereq
  353. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  354. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  355. ;;
  356. Darwin)
  357. printf "\nconfig ADK_HOST_DARWIN\n" >> $topdir/target/config/Config.in.prereq
  358. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  359. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  360. ;;
  361. OpenBSD)
  362. printf "\nconfig ADK_HOST_OPENBSD\n" >> $topdir/target/config/Config.in.prereq
  363. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  364. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  365. ;;
  366. FreeBSD)
  367. printf "\nconfig ADK_HOST_FREEBSD\n" >> $topdir/target/config/Config.in.prereq
  368. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  369. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  370. ;;
  371. NetBSD)
  372. printf "\nconfig ADK_HOST_NETBSD\n" >> $topdir/target/config/Config.in.prereq
  373. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  374. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  375. ;;
  376. MirBSD)
  377. printf "\nconfig ADK_HOST_MIRBSD\n" >> $topdir/target/config/Config.in.prereq
  378. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  379. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  380. ;;
  381. Cygwin*)
  382. printf "\nconfig ADK_HOST_CYGWIN\n" >> $topdir/target/config/Config.in.prereq
  383. printf "\tbool\n" >> $topdir/target/config/Config.in.prereq
  384. printf "\tdefault y\n" >> $topdir/target/config/Config.in.prereq
  385. ;;
  386. esac
  387. if [ ! -f $topdir/.config ]; then
  388. # create a config if no exist
  389. touch .firstrun
  390. $makebin --no-print-directory -f Makefile.adk menuconfig
  391. else
  392. # scan host-tool prerequisites of certain packages before building.
  393. . $topdir/.config
  394. if [[ -n $ADK_PACKAGE_KODI ]]; then
  395. NEED_JAVA="$NEED_JAVA kodi"
  396. fi
  397. if [[ -n $ADK_PACKAGE_ICU4C ]]; then
  398. NEED_STATIC_LIBSTDCXX="$NEED_STATIC_LIBSTDCXX icu4c"
  399. fi
  400. if [[ -n $ADK_PACKAGE_XKEYBOARD_CONFIG ]]; then
  401. NEED_XKBCOMP="$NEED_XKBCOMP xkeyboard-config"
  402. fi
  403. if [[ -n $ADK_PACKAGE_FONT_BITSTREAM_100DPI ]]; then
  404. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-100dpi"
  405. fi
  406. if [[ -n $ADK_PACKAGE_FONT_BITSTREAM_75DPI ]]; then
  407. NEED_MKFONTDIR="$NEED_MKFONTDIR font-bitstream-75dpi"
  408. fi
  409. if [[ -n $ADK_PACKAGE_FONT_ADOBE_100DPI ]]; then
  410. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-100dpi"
  411. fi
  412. if [[ -n $ADK_PACKAGE_FONT_ADOBE_75DPI ]]; then
  413. NEED_MKFONTDIR="$NEED_MKFONTDIR font-adobe-75dpi"
  414. fi
  415. if [[ -n $NEED_MKFONTDIR ]]; then
  416. if ! which mkfontdir >/dev/null 2>&1; then
  417. echo >&2 You need mkfontdir to build $NEED_MKFONTDIR
  418. out=1
  419. fi
  420. fi
  421. if [[ -n $NEED_XKBCOMP ]]; then
  422. if ! which xkbcomp >/dev/null 2>&1; then
  423. echo >&2 You need xkbcomp to build $NEED_XKBCOMP
  424. out=1
  425. fi
  426. fi
  427. if [[ -n $NEED_JAVA ]]; then
  428. if ! which java >/dev/null 2>&1; then
  429. echo >&2 You need java to build $NEED_JAVA
  430. out=1
  431. fi
  432. fi
  433. if [[ -n $NEED_STATIC_LIBSTDCXX ]]; then
  434. cat >test.c <<-'EOF'
  435. #include <stdio.h>
  436. int
  437. main()
  438. {
  439. return (0);
  440. }
  441. EOF
  442. if ! $CXX -static-libstdc++ -o test test.c ; then
  443. echo >&2 You need static version of libstdc++ installed to build $NEED_STATIC_LIBSTDCXX
  444. out=1
  445. rm test 2>/dev/null
  446. fi
  447. fi
  448. # error out
  449. if [ $out -ne 0 ]; then
  450. exit $out
  451. fi
  452. # start build
  453. $makebin --no-print-directory -f Makefile.adk $flags $target
  454. fi