edksetup.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #
  2. # Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
  3. # Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
  4. # SPDX-License-Identifier: BSD-2-Clause-Patent
  5. #
  6. # In *inux environment, the build tools's source is required and need to be compiled
  7. # firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
  8. # to get how to setup build tool.
  9. #
  10. # Setup the environment for unix-like systems running a bash-like shell.
  11. # This file must be "sourced" not merely executed. For example: ". edksetup.sh"
  12. #
  13. # CYGWIN users: Your path and filename related environment variables should be
  14. # set up in the unix style. This script will make the necessary conversions to
  15. # windows style.
  16. #
  17. # Please reference edk2 user manual for more detail descriptions at https://github.com/tianocore-docs/Docs/raw/master/User_Docs/EDK_II_UserManual_0_7.pdf
  18. #
  19. SCRIPTNAME="edksetup.sh"
  20. RECONFIG=FALSE
  21. function HelpMsg()
  22. {
  23. echo "Usage: $SCRIPTNAME [Options]"
  24. echo
  25. echo "The system environment variable, WORKSPACE, is always set to the current"
  26. echo "working directory."
  27. echo
  28. echo "Options: "
  29. echo " --help, -h, -? Print this help screen and exit."
  30. echo
  31. echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the"
  32. echo " template files from the BaseTools/Conf directory."
  33. echo
  34. echo Please note: This script must be \'sourced\' so the environment can be changed.
  35. echo ". $SCRIPTNAME"
  36. echo "source $SCRIPTNAME"
  37. }
  38. function SetWorkspace()
  39. {
  40. #
  41. # If WORKSPACE is already set, then we can return right now
  42. #
  43. export PYTHONHASHSEED=1
  44. if [ -n "$WORKSPACE" ]
  45. then
  46. return 0
  47. fi
  48. if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ]
  49. then
  50. echo Run this script from the base of your tree. For example:
  51. echo " cd /Path/To/Edk/Root"
  52. echo " . edksetup.sh"
  53. return 1
  54. fi
  55. #
  56. # Check for BaseTools/BuildEnv before dirtying the user's environment.
  57. #
  58. if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ]
  59. then
  60. echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
  61. echo Please point EDK_TOOLS_PATH at the directory that contains
  62. echo the EDK2 BuildEnv script.
  63. return 1
  64. fi
  65. #
  66. # Set $WORKSPACE
  67. #
  68. export WORKSPACE=`pwd`
  69. return 0
  70. }
  71. function SetupEnv()
  72. {
  73. if [ -n "$EDK_TOOLS_PATH" ]
  74. then
  75. . $EDK_TOOLS_PATH/BuildEnv
  76. elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
  77. then
  78. . $WORKSPACE/BaseTools/BuildEnv
  79. elif [ -n "$PACKAGES_PATH" ]
  80. then
  81. PATH_LIST=$PACKAGES_PATH
  82. PATH_LIST=${PATH_LIST//:/ }
  83. for DIR in $PATH_LIST
  84. do
  85. if [ -f "$DIR/BaseTools/BuildEnv" ]
  86. then
  87. export EDK_TOOLS_PATH=$DIR/BaseTools
  88. . $DIR/BaseTools/BuildEnv
  89. break
  90. fi
  91. done
  92. else
  93. echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
  94. echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly
  95. echo in your shell, or point EDK_TOOLS_PATH at the directory that contains
  96. echo the EDK2 BuildEnv script.
  97. return 1
  98. fi
  99. }
  100. function SetupPython3()
  101. {
  102. if [ $origin_version ];then
  103. origin_version=
  104. fi
  105. for python in $(whereis python3)
  106. do
  107. python=$(echo $python | grep "[[:digit:]]$" || true)
  108. python_version=${python##*python}
  109. if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
  110. continue
  111. fi
  112. if [ -z $origin_version ];then
  113. origin_version=$python_version
  114. export PYTHON_COMMAND=$python
  115. continue
  116. fi
  117. ret=`echo "$origin_version < $python_version" |bc`
  118. if [ "$ret" -eq 1 ]; then
  119. origin_version=$python_version
  120. export PYTHON_COMMAND=$python
  121. fi
  122. done
  123. return 0
  124. }
  125. function SetupPython()
  126. {
  127. if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then
  128. if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then
  129. return 0
  130. else
  131. echo $PYTHON_COMMAND Cannot be used to build or execute the python tools.
  132. return 1
  133. fi
  134. fi
  135. if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
  136. then
  137. SetupPython3
  138. fi
  139. if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ]
  140. then
  141. if [ $origin_version ];then
  142. origin_version=
  143. fi
  144. for python in $(whereis python2)
  145. do
  146. python=$(echo $python | grep "[[:digit:]]$" || true)
  147. python_version=${python##*python}
  148. if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
  149. continue
  150. fi
  151. if [ -z $origin_version ]
  152. then
  153. origin_version=$python_version
  154. export PYTHON_COMMAND=$python
  155. continue
  156. fi
  157. ret=`echo "$origin_version < $python_version" |bc`
  158. if [ "$ret" -eq 1 ]; then
  159. origin_version=$python_version
  160. export PYTHON_COMMAND=$python
  161. fi
  162. done
  163. return 0
  164. fi
  165. SetupPython3
  166. }
  167. function TestUtilModule()
  168. {
  169. if ( $PYTHON_COMMAND -c "import distutils.util" >/dev/null 2>&1 );then
  170. return 1
  171. else
  172. echo Error: "No module named 'distutils.util"
  173. return 0
  174. fi
  175. }
  176. function SourceEnv()
  177. {
  178. SetWorkspace &&
  179. SetupEnv &&
  180. SetupPython &&
  181. TestUtilModule
  182. }
  183. I=$#
  184. while [ $I -gt 0 ]
  185. do
  186. case "$1" in
  187. BaseTools)
  188. # Ignore argument for backwards compatibility
  189. shift
  190. ;;
  191. --reconfig)
  192. RECONFIG=TRUE
  193. shift
  194. ;;
  195. -?|-h|--help|*)
  196. HelpMsg
  197. break
  198. ;;
  199. esac
  200. I=$(($I - 1))
  201. done
  202. if [ $I -gt 0 ]
  203. then
  204. return 1
  205. fi
  206. SourceEnv
  207. unset SCRIPTNAME RECONFIG
  208. return $?