envsetup.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. function help() {
  2. cat <<EOF
  3. Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
  4. == before all ==
  5. - config: config <arch_name>
  6. == build project ==
  7. - mbase: Build ice_base.
  8. - mxfce: Build ice_xfce.
  9. - mgnome: Build ice_gnome.
  10. - msdk: Build SDK.
  11. == jump directory ==
  12. - ctarget: Jump to target directory.
  13. - cdeb: Jump to target deb directory.
  14. - cimage: Jump to target image directory.
  15. == grep file ==
  16. - cgrep: Greps on all local C/C++ files.
  17. Look at the source to view more functions. The complete list is:
  18. EOF
  19. T=$(gettop)
  20. local A
  21. A=""
  22. for i in `cat $T/openembedded-core/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
  23. A="$A $i"
  24. done
  25. echo $A
  26. }
  27. function cgrep()
  28. {
  29. find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
  30. }
  31. function gettop
  32. {
  33. local TOPFILE=openembedded-core/envsetup.sh
  34. if [ -n "$MPSOC_TOP" -a -f "$MPSOC_TOP/$TOPFILE" ] ; then
  35. # The following circumlocution ensures we remove symlinks from TOP.
  36. (\cd $MPSOC_TOP; PWD= /bin/pwd)
  37. else
  38. if [ -f $TOPFILE ] ; then
  39. # The following circumlocution (repeated below as well) ensures
  40. # that we record the true directory name and not one that is
  41. # faked up with symlink names.
  42. PWD= /bin/pwd
  43. else
  44. local here="${PWD}"
  45. while [ "${here}" != "/" ]; do
  46. if [ -f "${here}/${TOPFILE}" ]; then
  47. (\cd ${here}; PWD= /bin/pwd)
  48. break
  49. fi
  50. here="$(dirname ${here})"
  51. done
  52. fi
  53. fi
  54. }
  55. function mbase()
  56. {
  57. local T=$(gettop)
  58. [ -z "$T" ] \
  59. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  60. && return
  61. if [ "$1" ] ; then
  62. config $1
  63. fi
  64. export YOCTO_TARGET_IMAGE_DIR="thead-build/ice-base"
  65. echo -e
  66. echo "YOCTO_TARGET_IMAGE_DIR=$YOCTO_TARGET_IMAGE_DIR"
  67. echo -e
  68. if [ -e $T/openembedded-core/oe-init-build-env ] ; then
  69. source $T/openembedded-core/oe-init-build-env $T/$YOCTO_TARGET_IMAGE_DIR
  70. bitbake core-image-minimal
  71. fi
  72. }
  73. function msdk()
  74. {
  75. local T=$(gettop)
  76. [ -z "$T" ] \
  77. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  78. && return
  79. if [ "$1" ] ; then
  80. config $1
  81. fi
  82. export YOCTO_TARGET_IMAGE_DIR="thead-build/ice-base"
  83. echo -e
  84. echo "YOCTO_TARGET_IMAGE_DIR=$YOCTO_TARGET_IMAGE_DIR"
  85. echo -e
  86. if [ -e $T/openembedded-core/oe-init-build-env ] ; then
  87. source $T/openembedded-core/oe-init-build-env $T/$YOCTO_TARGET_IMAGE_DIR
  88. bitbake core-image-minimal -c populate_ext
  89. fi
  90. }
  91. function mxfce()
  92. {
  93. local T=$(gettop)
  94. [ -z "$T" ] \
  95. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  96. && return
  97. if [ "$1" ] ; then
  98. config $1
  99. fi
  100. export YOCTO_TARGET_IMAGE_DIR="thead-build/ice-xfce"
  101. echo -e
  102. echo "YOCTO_TARGET_IMAGE_DIR=$YOCTO_TARGET_IMAGE_DIR"
  103. echo -e
  104. if [ -e $T/openembedded-core/oe-init-build-env ] ; then
  105. source $T/openembedded-core/oe-init-build-env $T/$YOCTO_TARGET_IMAGE_DIR
  106. bitbake core-image-minimal-xfce
  107. fi
  108. }
  109. function mgnome()
  110. {
  111. local T=$(gettop)
  112. [ -z "$T" ] \
  113. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  114. && return
  115. if [ "$1" ] ; then
  116. config $1
  117. fi
  118. export YOCTO_TARGET_IMAGE_DIR="thead-build/ice-gnome"
  119. echo -e
  120. echo "YOCTO_TARGET_IMAGE_DIR=$YOCTO_TARGET_IMAGE_DIR"
  121. echo -e
  122. if [ -e $T/openembedded-core/oe-init-build-env ] ; then
  123. source $T/openembedded-core/oe-init-build-env $T/$YOCTO_TARGET_IMAGE_DIR
  124. bitbake core-image-gnome
  125. fi
  126. }
  127. function ctarget()
  128. {
  129. T=$(gettop)
  130. local T=$(gettop)
  131. [ -z "$T" ] \
  132. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  133. && return
  134. \cd $T/$YOCTO_TARGET_IMAGE_DIR
  135. }
  136. function cdeb()
  137. {
  138. T=$(gettop)
  139. local T=$(gettop)
  140. [ -z "$T" ] \
  141. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  142. && return
  143. \cd $T/$YOCTO_TARGET_IMAGE_DIR/tmp-glibc/deploy/deb
  144. }
  145. function cimage()
  146. {
  147. T=$(gettop)
  148. local T=$(gettop)
  149. [ -z "$T" ] \
  150. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  151. && return
  152. \cd $T/$YOCTO_TARGET_IMAGE_DIR/tmp-glibc/deploy/images
  153. }
  154. function gen_config_combo()
  155. {
  156. export ARCH_MENU_CHOICES=(riscv csky)
  157. }
  158. function print_config_menu()
  159. {
  160. local uname=$(uname)
  161. echo
  162. echo "You're building on" $uname
  163. echo
  164. echo "Config menu... pick a combo:"
  165. local i=1
  166. local choice
  167. for choice in ${ARCH_MENU_CHOICES[@]}
  168. do
  169. echo " $i. $choice"
  170. i=$(($i+1))
  171. done
  172. echo
  173. }
  174. function config
  175. {
  176. local T=$(gettop)
  177. [ -z "$T" ] && return -1
  178. local last=riscv
  179. # install config menu
  180. gen_config_combo
  181. # select platform
  182. local select
  183. if [ "$1" ] ; then
  184. select=$1
  185. else
  186. print_config_menu
  187. echo -n "Which would you like?"
  188. [ -n "${last}" ] && echo -n " [Default ${last}]"
  189. echo -n ": "
  190. read select
  191. fi
  192. if [ -z "${select}" ]; then
  193. select=${last}
  194. elif (echo -n $select | grep -q -e "^[0-9][0-9]*$"); then
  195. [ $select -le ${#ARCH_MENU_CHOICES[@]} ] \
  196. && select=${ARCH_MENU_CHOICES[$(($select-1))]}
  197. elif (echo -n $select | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$"); then
  198. select="$select"
  199. else
  200. echo
  201. echo "Invalid config combo: $select" >&2
  202. return 1
  203. fi
  204. # config info
  205. export YOCTO_BUILD_TOP=$(gettop)
  206. export YOCTO_TARGET_ARCH="$select"
  207. # Get the exact value of a build variable.
  208. echo -e
  209. echo "YOCTO_BUILD_TOP=$(gettop)"
  210. echo "YOCTO_TARGET_ARCH=${YOCTO_TARGET_ARCH}"
  211. echo -e
  212. rm -rf $T/meta-arch
  213. ln -s $T/meta-$YOCTO_TARGET_ARCH $T/meta-arch
  214. }
  215. function envsetup
  216. {
  217. if [ "x$SHELL" != "x/bin/bash" ]; then
  218. case `ps -o command -p $$` in
  219. *bash*)
  220. ;;
  221. *)
  222. echo -n "WARNING: Only bash is supported, "
  223. echo "use of other shell would lead to erroneous results"
  224. ;;
  225. esac
  226. fi
  227. # check top of SDK
  228. if [ ! -f "${PWD}/openembedded-core/envsetup.sh" ]; then
  229. echo "ERROR: Please source envsetup.sh in the root of SDK"
  230. return -1
  231. else
  232. export YOCTO_TOP="$(PWD= /bin/pwd)"
  233. fi
  234. # reset these variables.
  235. export VARIANT_CHOICES=yocto
  236. # Execute the contents of any vendorsetup.sh files we can find.
  237. local vendors vendor
  238. verdors="$(find -L target -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort)"
  239. for verdor in ${verdors}
  240. do
  241. source ${verdor}
  242. done
  243. echo "Setup env done! Please run config next."
  244. local T=$(gettop)
  245. [ -z "$T" ] \
  246. && echo "Couldn't locate the top of the tree. Try setting TOP." \
  247. && return
  248. export YOCTO_TARGET_IMAGE_DIR="thead-build/ice-base"
  249. if [ -e $T/openembedded-core/oe-init-build-env ] ; then
  250. source $T/openembedded-core/oe-init-build-env $T/$YOCTO_TARGET_IMAGE_DIR >/dev/null
  251. fi
  252. }
  253. #### MAIN ####
  254. envsetup