]> git.proxmox.com Git - mirror_edk2.git/blob - edksetup.sh
BaseTools: Update windows and linux run scripts file to use Python3
[mirror_edk2.git] / edksetup.sh
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
26 SCRIPTNAME="edksetup.sh"
27 RECONFIG=FALSE
28
29 function HelpMsg()
30 {
31 echo "Usage: $SCRIPTNAME [Options]"
32 echo
33 echo "The system environment variable, WORKSPACE, is always set to the current"
34 echo "working directory."
35 echo
36 echo "Options: "
37 echo " --help, -h, -? Print this help screen and exit."
38 echo
39 echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the"
40 echo " template files from the BaseTools/Conf directory."
41 echo
42 echo Please note: This script must be \'sourced\' so the environment can be changed.
43 echo ". $SCRIPTNAME"
44 echo "source $SCRIPTNAME"
45 }
46
47 function SetWorkspace()
48 {
49 #
50 # If WORKSPACE is already set, then we can return right now
51 #
52 if [ -n "$WORKSPACE" ]
53 then
54 return 0
55 fi
56
57 if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ]
58 then
59 echo Run this script from the base of your tree. For example:
60 echo " cd /Path/To/Edk/Root"
61 echo " . edksetup.sh"
62 return 1
63 fi
64
65 #
66 # Check for BaseTools/BuildEnv before dirtying the user's environment.
67 #
68 if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ]
69 then
70 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
71 echo Please point EDK_TOOLS_PATH at the directory that contains
72 echo the EDK2 BuildEnv script.
73 return 1
74 fi
75
76 #
77 # Set $WORKSPACE
78 #
79 export WORKSPACE=`pwd`
80
81 return 0
82 }
83
84 function SetupEnv()
85 {
86 if [ -n "$EDK_TOOLS_PATH" ]
87 then
88 . $EDK_TOOLS_PATH/BuildEnv
89 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
90 then
91 . $WORKSPACE/BaseTools/BuildEnv
92 elif [ -n "$PACKAGES_PATH" ]
93 then
94 PATH_LIST=$PACKAGES_PATH
95 PATH_LIST=${PATH_LIST//:/ }
96 for DIR in $PATH_LIST
97 do
98 if [ -f "$DIR/BaseTools/BuildEnv" ]
99 then
100 export EDK_TOOLS_PATH=$DIR/BaseTools
101 . $DIR/BaseTools/BuildEnv
102 break
103 fi
104 done
105 else
106 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
107 echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly
108 echo in your shell, or point EDK_TOOLS_PATH at the directory that contains
109 echo the EDK2 BuildEnv script.
110 return 1
111 fi
112 }
113
114 function SetupPython3()
115 {
116 for python in $(whereis python3)
117 do
118 python=$(echo $python | grep "[[:digit:]]$" || true)
119 python_version=${python##*python}
120 if [ -z "${python_version}" ];then
121 continue
122 fi
123 if [ -z $origin_version ];then
124 origin_version=$python_version
125 export PYTHON3=$python
126 continue
127 fi
128 ret=`echo "$origin_version < $python_version" |bc`
129 if [ "$ret" -eq 1 ]; then
130 origin_version=$python_version
131 export PYTHON3=$python
132 fi
133 done
134 if [ -z "$origin_version" ] || [ `echo "$origin_version < 3.6" |bc` -eq 1 ]; then
135 echo
136 echo ERROR!!!, python version should greater than or equal to version 3.6.
137 echo
138 return 1
139 fi
140
141
142 }
143
144 function SourceEnv()
145 {
146 SetWorkspace &&
147 SetupEnv
148 SetupPython3
149 }
150
151 I=$#
152 while [ $I -gt 0 ]
153 do
154 case "$1" in
155 BaseTools)
156 # Ignore argument for backwards compatibility
157 shift
158 ;;
159 --reconfig)
160 RECONFIG=TRUE
161 shift
162 ;;
163 -?|-h|--help|*)
164 HelpMsg
165 break
166 ;;
167 esac
168 I=$(($I - 1))
169 done
170
171 if [ $I -gt 0 ]
172 then
173 return 1
174 fi
175
176 SourceEnv
177
178 unset SCRIPTNAME RECONFIG
179
180 return $?