]> git.proxmox.com Git - mirror_edk2.git/blob - edksetup.sh
bfa54ddf708883e18abb9ed51f8c4bdb11ae5f07
[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 export PYTHONHASHSEED=1
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 SetupPython()
115 {
116 if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
117 then
118 if [ $origin_version ];then
119 origin_version=
120 fi
121 for python in $(whereis python3)
122 do
123 python=$(echo $python | grep "[[:digit:]]$" || true)
124 python_version=${python##*python}
125 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
126 continue
127 fi
128 if [ -z $origin_version ];then
129 origin_version=$python_version
130 export PYTHON=$python
131 continue
132 fi
133 ret=`echo "$origin_version < $python_version" |bc`
134 if [ "$ret" -eq 1 ]; then
135 origin_version=$python_version
136 export PYTHON=$python
137 fi
138 done
139 fi
140
141 if [ -z $PYTHON3_ENABLE ] || [ $PYTHON3_ENABLE != TRUE ]
142 then
143 if [ $origin_version ];then
144 origin_version=
145 fi
146 for python in $(whereis python2)
147 do
148 python=$(echo $python | grep "[[:digit:]]$" || true)
149 python_version=${python##*python}
150 if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
151 continue
152 fi
153 if [ -z $origin_version ]
154 then
155 origin_version=$python_version
156 export PYTHON=$python
157 continue
158 fi
159 ret=`echo "$origin_version < $python_version" |bc`
160 if [ "$ret" -eq 1 ]; then
161 origin_version=$python_version
162 export PYTHON=$python
163 fi
164 done
165 fi
166 }
167
168 function SourceEnv()
169 {
170 SetWorkspace &&
171 SetupEnv
172 SetupPython
173 }
174
175 I=$#
176 while [ $I -gt 0 ]
177 do
178 case "$1" in
179 BaseTools)
180 # Ignore argument for backwards compatibility
181 shift
182 ;;
183 --reconfig)
184 RECONFIG=TRUE
185 shift
186 ;;
187 -?|-h|--help|*)
188 HelpMsg
189 break
190 ;;
191 esac
192 I=$(($I - 1))
193 done
194
195 if [ $I -gt 0 ]
196 then
197 return 1
198 fi
199
200 SourceEnv
201
202 unset SCRIPTNAME RECONFIG
203
204 return $?