edksetup.sh 5.6 KB

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