edksetup.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 ./$SCRIPTNAME ] && [ -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 " . $SCRIPTNAME"
  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. if [[ "$origin_version" < "$python_version" ]]; then
  118. origin_version=$python_version
  119. export PYTHON_COMMAND=$python
  120. fi
  121. done
  122. return 0
  123. }
  124. function SetupPython()
  125. {
  126. if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then
  127. if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then
  128. return 0
  129. else
  130. echo $PYTHON_COMMAND Cannot be used to build or execute the python tools.
  131. return 1
  132. fi
  133. fi
  134. if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
  135. then
  136. SetupPython3
  137. fi
  138. if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ]
  139. then
  140. if [ $origin_version ];then
  141. origin_version=
  142. fi
  143. for python in $(whereis python2)
  144. do
  145. python=$(echo $python | grep "[[:digit:]]$" || true)
  146. python_version=${python##*python}
  147. if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
  148. continue
  149. fi
  150. if [ -z $origin_version ]
  151. then
  152. origin_version=$python_version
  153. export PYTHON_COMMAND=$python
  154. continue
  155. fi
  156. if [[ "$origin_version" < "$python_version" ]]; then
  157. origin_version=$python_version
  158. export PYTHON_COMMAND=$python
  159. fi
  160. done
  161. return 0
  162. fi
  163. SetupPython3
  164. }
  165. function SourceEnv()
  166. {
  167. SetWorkspace &&
  168. SetupEnv
  169. SetupPython
  170. }
  171. I=$#
  172. while [ $I -gt 0 ]
  173. do
  174. case "$1" in
  175. BaseTools)
  176. # Ignore argument for backwards compatibility
  177. shift
  178. ;;
  179. --reconfig)
  180. RECONFIG=TRUE
  181. shift
  182. ;;
  183. *)
  184. HelpMsg
  185. break
  186. ;;
  187. esac
  188. I=$((I - 1))
  189. done
  190. if [ $I -gt 0 ]
  191. then
  192. return 1
  193. fi
  194. SourceEnv
  195. unset SCRIPTNAME RECONFIG
  196. return $?