Edk2Setup.bat: Support building platforms with Python source
[mirror_edk2.git] / edksetup.sh
CommitLineData
b9e16a84 1#
445bfd92 2# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
24542fb2 3# This program and the accompanying materials
b9e16a84 4# are licensed and made available under the terms and conditions of the BSD License
5# which accompanies this distribution. The full text of the license may be found at
6# http://opensource.org/licenses/bsd-license.php
7#
8# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
2b1473c1 10#
11# In *inux environment, the build tools's source is required and need to be compiled
445bfd92 12# firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
2b1473c1 13# to get how to setup build tool.
14#
b9e16a84 15# Setup the environment for unix-like systems running a bash-like shell.
6dbea978 16# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
2b1473c1 17#
6dbea978 18# CYGWIN users: Your path and filename related environment variables should be
19# set up in the unix style. This script will make the necessary conversions to
20# windows style.
2b1473c1 21#
445bfd92 22# 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
2b1473c1 23#
b9e16a84 24
729220ea
PP
25function HelpMsg()
26{
27 echo Please note: This script must be \'sourced\' so the environment can be changed.
28 echo ". edksetup.sh"
29 echo "source edksetup.sh"
1bb6bfaa 30 return 1
729220ea
PP
31}
32
d5493449
PB
33function SetWorkspace()
34{
35 #
36 # If WORKSPACE is already set, then we can return right now
37 #
38 if [ -n "$WORKSPACE" ]
39 then
40 return 0
41 fi
42
43 if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ]
44 then
45 echo Run this script from the base of your tree. For example:
46 echo " cd /Path/To/Edk/Root"
47 echo " . edksetup.sh"
48 return 1
49 fi
50
51 #
52 # Check for BaseTools/BuildEnv before dirtying the user's environment.
53 #
54 if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ]
55 then
56 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
57 echo Please point EDK_TOOLS_PATH at the directory that contains
58 echo the EDK2 BuildEnv script.
59 return 1
60 fi
61
62 #
63 # Set $WORKSPACE
64 #
65 export WORKSPACE=`pwd`
66
67 return 0
68}
69
729220ea
PP
70function SetupEnv()
71{
7bc14212
PB
72 if [ -n "$EDK_TOOLS_PATH" ]
73 then
74 . $EDK_TOOLS_PATH/BuildEnv $*
d5493449 75 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
729220ea 76 then
729220ea 77 . $WORKSPACE/BaseTools/BuildEnv $*
094a6739
LG
78 elif [ -n "$PACKAGES_PATH" ]
79 then
80 PATH_LIST=$PACKAGES_PATH
81 PATH_LIST=${PATH_LIST//:/ }
82 for DIR in $PATH_LIST
83 do
84 if [ -f "$DIR/BaseTools/BuildEnv" ]
85 then
86 export EDK_TOOLS_PATH=$DIR/BaseTools
87 . $DIR/BaseTools/BuildEnv $*
88 break
89 fi
90 done
7bc14212 91 else
d5493449 92 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
094a6739
LG
93 echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly
94 echo in your shell, or point EDK_TOOLS_PATH at the directory that contains
d5493449
PB
95 echo the EDK2 BuildEnv script.
96 return 1
729220ea
PP
97 fi
98}
99
100function SourceEnv()
101{
ef9086c3
JJ
102 if [ \
103 "$1" = "-?" -o \
104 "$1" = "-h" -o \
105 "$1" = "--help" \
106 ]
107 then
108 HelpMsg
ef9086c3 109 else
d5493449 110 SetWorkspace &&
ef9086c3
JJ
111 SetupEnv "$*"
112 fi
729220ea 113}
ef9086c3
JJ
114
115if [ $# -gt 1 ]
729220ea
PP
116then
117 HelpMsg
1bb6bfaa 118elif [ $# -eq 1 ] && [ "$1" != "BaseTools" ]
729220ea
PP
119then
120 HelpMsg
1bb6bfaa
LL
121fi
122
123RETVAL=$?
124if [ $RETVAL -ne 0 ]
125then
126 return $RETVAL
ef9086c3
JJ
127fi
128
729220ea 129SourceEnv "$*"
b9e16a84 130