download-dependencies 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/usr/bin/env bash
  2. # Download build dependencies for the build, notably:
  3. #
  4. # - required git submodules
  5. # - host packages
  6. #
  7. # Only needs to be run once before each type of build per-system.
  8. set -eux
  9. all=false
  10. apt_get=true
  11. baremetal=false
  12. baremetal_given=false
  13. buildroot=true
  14. buildroot_given=false
  15. linux=true
  16. linux_given=false
  17. interactive_pkgs=libsdl2-dev
  18. parsec_benchmark_given=false
  19. gem5=false
  20. gem5_given=false
  21. qemu=true
  22. qemu_given=false
  23. submodules_dir=submodules
  24. submodules=
  25. y=
  26. while [ $# -gt 0 ]; do
  27. case "$1" in
  28. --all)
  29. all=true
  30. shift
  31. ;;
  32. --baremetal)
  33. baremetal_given=true
  34. shift
  35. ;;
  36. --buildroot)
  37. buildroot_given=true
  38. shift
  39. ;;
  40. --gem5)
  41. gem5_given=true
  42. shift
  43. ;;
  44. --parsec-benchmark)
  45. parsec_benchmark_given=true
  46. shift
  47. ;;
  48. --qemu)
  49. qemu_given=true
  50. shift
  51. ;;
  52. --no-apt-get)
  53. apt_get=false
  54. shift
  55. ;;
  56. --travis)
  57. interactive_pkgs=
  58. y=-y
  59. shift
  60. ;;
  61. *)
  62. echo 'unknown option' 1>&2
  63. exit 2
  64. ;;
  65. esac
  66. done
  67. if ! "$all" && "$gem5_given" && ! "$qemu_given"; then
  68. qemu=false
  69. fi
  70. if "$all" || "$gem5_given"; then
  71. gem5=true
  72. fi
  73. if "$all" || "$baremetal_given"; then
  74. baremetal=true
  75. fi
  76. if ! "$all" && "$baremetal_given" && ! "$buildroot_given"; then
  77. buildroot=false
  78. fi
  79. if "$all" || "$parsec_benchmark_given"; then
  80. submodules="${submodules} parsec-benchmark"
  81. fi
  82. if "$apt_get"; then
  83. pkgs="\
  84. automake \
  85. bc \
  86. bison \
  87. build-essential \
  88. coreutils \
  89. cpio \
  90. expect \
  91. flex \
  92. gcc-aarch64-linux-gnu \
  93. gcc-arm-linux-gnueabihf \
  94. g++-aarch64-linux-gnu \
  95. g++-arm-linux-gnueabihf \
  96. git \
  97. libguestfs-tools \
  98. moreutils \
  99. rsync \
  100. tmux \
  101. unzip \
  102. vinagre \
  103. wget \
  104. "
  105. if "$gem5"; then
  106. pkgs="${pkgs} \
  107. ccache \
  108. diod \
  109. libgoogle-perftools-dev \
  110. protobuf-compiler \
  111. python-dev \
  112. python-pip \
  113. scons \
  114. "
  115. fi
  116. if "$baremetal"; then
  117. # http://crosstool-ng.github.io/docs/os-setup/
  118. pkgs="${pkgs} \
  119. bison \
  120. docbook2x \
  121. flex \
  122. gcc \
  123. gperf \
  124. help2man \
  125. libncurses5-dev \
  126. libtool-bin \
  127. make \
  128. python-dev \
  129. texinfo \
  130. "
  131. fi
  132. command -v apt-get >/dev/null 2>&1 || {
  133. cat <<EOF
  134. apt-get not found. You're on your own for installing dependencies.
  135. On Ubuntu they are:
  136. $pkgs
  137. EOF
  138. exit 0
  139. }
  140. # Without this started failing in kernel 4.15 with:
  141. # Makefile:932: *** "Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel". Stop.
  142. pkgs="$pkgs libelf-dev"
  143. # https://stackoverflow.com/questions/20010199/determining-if-a-process-runs-inside-lxc-docker
  144. if [ -f /.dockerenv ]; then
  145. # https://askubuntu.com/questions/909277/avoiding-user-interaction-with-tzdata-when-installing-certbot-in-a-docker-contai
  146. export DEBIAN_FRONTEND=noninteractive
  147. mysudo=
  148. # https://askubuntu.com/questions/496549/error-you-must-put-some-source-uris-in-your-sources-list
  149. sed -Ei 's/^# deb-src/deb-src/' /etc/apt/sources.list
  150. y=-y
  151. else
  152. mysudo=sudo
  153. fi
  154. $mysudo apt-get update $y
  155. # Building SDL for QEMU in Buildroot was rejected upstream because it adds many dependencies:
  156. # https://patchwork.ozlabs.org/patch/770684/
  157. # We are just using the host SDL for now, if it causes too much problems we might remove it.
  158. # libsdl2-dev needs to be installed separately from sudo apt-get build-dep qemu
  159. # because Ubuntu 16.04's QEMU uses SDL 1.
  160. $mysudo apt-get install $y \
  161. $pkgs \
  162. $interactive_pkgs \
  163. ;
  164. if "$qemu"; then
  165. $mysudo apt-get build-dep $y qemu
  166. fi
  167. if "$gem5"; then
  168. # Generate graphs of config.ini under m5out.
  169. # Not with pip directly:
  170. # https://stackoverflow.com/questions/49836676/error-after-upgrading-pip-cannot-import-name-main/51846054#51846054
  171. python -m pip install --user pydot
  172. fi
  173. fi
  174. ## Submodules
  175. if "$baremetal"; then
  176. submodules="${submodules} crosstool-ng"
  177. fi
  178. if "$buildroot"; then
  179. submodules="${submodules} buildroot"
  180. fi
  181. if "$qemu"; then
  182. submodules="${submodules} qemu"
  183. fi
  184. if "$gem5"; then
  185. submodules="${submodules} gem5"
  186. fi
  187. submodules="$(for submodule in ${submodules}; do printf "${submodules_dir}/${submodule} "; done)"
  188. # == Shallow cloning.
  189. #
  190. # TODO Ideally we should shallow clone --depth 1 all of them.
  191. #
  192. # However, most git servers out there are crap or craply configured
  193. # and don't allow shallow cloning except for branches.
  194. #
  195. # So for now, let's shallow clone only the Linux kernel, which has by far
  196. # the largest .git repo history, and full clone the others.
  197. #
  198. # Then we will maintain a GitHub Linux kernel mirror / fork that always has a
  199. # lkmc branch, and point to it, so that it will always succeed.
  200. #
  201. # See also:
  202. #
  203. # * https://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset
  204. # * https://stackoverflow.com/questions/2144406/git-shallow-submodules/47374702#47374702
  205. # * https://unix.stackexchange.com/questions/338578/why-is-the-git-clone-of-the-linux-kernel-source-code-much-larger-than-the-extrac
  206. #
  207. # == Other nice git options for when distros move to newer Git
  208. #
  209. # Currently not on Ubuntu 16.04:
  210. #
  211. # `--progress`: added on Git 2.10:
  212. #
  213. # * https://stackoverflow.com/questions/32944468/how-to-show-progress-for-submodule-fetching
  214. # * https://stackoverflow.com/questions/4640020/progress-indicator-for-git-clone
  215. #
  216. # `--jobs"`: https://stackoverflow.com/questions/26957237/how-to-make-git-clone-faster-with-multiple-threads/52327638#52327638
  217. #
  218. git submodule update --init --recursive -- ${submodules}
  219. if "$linux"; then
  220. git submodule update --depth 1 --init --recursive -- "${submodules_dir}/linux"
  221. fi