blob: ec54f9ea4058aa131e268caf807bf16f73a775c9 [file] [log] [blame]
bbahnsenb9e16a82006-04-24 16:38:10 +00001#
Yonghong Zhu445bfd92016-09-14 13:27:06 +08002# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
Leif Lindholm44f79422016-10-20 15:47:31 +01003# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
hhtian24542fb2010-04-29 15:17:20 +00004# This program and the accompanying materials
bbahnsenb9e16a82006-04-24 16:38:10 +00005# 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.
klu22b1473c2009-07-08 05:54:53 +000011#
12# In *inux environment, the build tools's source is required and need to be compiled
Yonghong Zhu445bfd92016-09-14 13:27:06 +080013# firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
klu22b1473c2009-07-08 05:54:53 +000014# to get how to setup build tool.
15#
bbahnsenb9e16a82006-04-24 16:38:10 +000016# Setup the environment for unix-like systems running a bash-like shell.
bbahnsen6dbea972006-11-14 17:57:07 +000017# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
klu22b1473c2009-07-08 05:54:53 +000018#
bbahnsen6dbea972006-11-14 17:57:07 +000019# 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.
klu22b1473c2009-07-08 05:54:53 +000022#
Yonghong Zhu445bfd92016-09-14 13:27:06 +080023# 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
klu22b1473c2009-07-08 05:54:53 +000024#
bbahnsenb9e16a82006-04-24 16:38:10 +000025
Leif Lindholm44f79422016-10-20 15:47:31 +010026SCRIPTNAME="edksetup.sh"
Leif Lindholmc112e372016-10-20 16:29:46 +010027RECONFIG=FALSE
Leif Lindholm44f79422016-10-20 15:47:31 +010028
Parmeshwr Prasad729220e2014-01-28 02:18:23 +000029function HelpMsg()
30{
Leif Lindholm44f79422016-10-20 15:47:31 +010031 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
Leif Lindholmc112e372016-10-20 16:29:46 +010039 echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the"
40 echo " template files from the BaseTools/Conf directory."
41 echo
Parmeshwr Prasad729220e2014-01-28 02:18:23 +000042 echo Please note: This script must be \'sourced\' so the environment can be changed.
Leif Lindholm44f79422016-10-20 15:47:31 +010043 echo ". $SCRIPTNAME"
44 echo "source $SCRIPTNAME"
Parmeshwr Prasad729220e2014-01-28 02:18:23 +000045}
46
Paolo Bonzinid5493442014-07-28 17:37:40 +000047function 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 ]
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
Parmeshwr Prasad729220e2014-01-28 02:18:23 +000084function SetupEnv()
85{
Paolo Bonzini7bc14212014-07-28 17:37:35 +000086 if [ -n "$EDK_TOOLS_PATH" ]
Parmeshwr Prasad729220e2014-01-28 02:18:23 +000087 then
Leif Lindholm44f79422016-10-20 15:47:31 +010088 . $EDK_TOOLS_PATH/BuildEnv
Paolo Bonzinid5493442014-07-28 17:37:40 +000089 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
Paolo Bonzini7bc14212014-07-28 17:37:35 +000090 then
Leif Lindholm44f79422016-10-20 15:47:31 +010091 . $WORKSPACE/BaseTools/BuildEnv
Liming Gao094a6732015-10-08 09:29:56 +000092 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
Leif Lindholm44f79422016-10-20 15:47:31 +0100101 . $DIR/BaseTools/BuildEnv
Liming Gao094a6732015-10-08 09:29:56 +0000102 break
103 fi
104 done
Paolo Bonzini7bc14212014-07-28 17:37:35 +0000105 else
Paolo Bonzinid5493442014-07-28 17:37:40 +0000106 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
Liming Gao094a6732015-10-08 09:29:56 +0000107 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
Paolo Bonzinid5493442014-07-28 17:37:40 +0000109 echo the EDK2 BuildEnv script.
110 return 1
Parmeshwr Prasad729220e2014-01-28 02:18:23 +0000111 fi
112}
113
114function SourceEnv()
115{
Leif Lindholm44f79422016-10-20 15:47:31 +0100116 SetWorkspace &&
117 SetupEnv
Parmeshwr Prasad729220e2014-01-28 02:18:23 +0000118}
Jordan Justenef9086c2014-01-30 19:26:46 +0000119
Leif Lindholm44f79422016-10-20 15:47:31 +0100120I=$#
121while [ $I -gt 0 ]
122do
123 case "$1" in
124 BaseTools)
125 # Ignore argument for backwards compatibility
126 shift
127 ;;
Leif Lindholmc112e372016-10-20 16:29:46 +0100128 --reconfig)
129 RECONFIG=TRUE
130 shift
131 ;;
Leif Lindholm44f79422016-10-20 15:47:31 +0100132 -?|-h|--help|*)
133 HelpMsg
134 break
135 ;;
136 esac
137 I=$(($I - 1))
138done
139
140if [ $I -gt 0 ]
Parmeshwr Prasad729220e2014-01-28 02:18:23 +0000141then
Leif Lindholm44f79422016-10-20 15:47:31 +0100142 return 1
Leif Lindholm1bb6bfa2014-01-30 19:26:53 +0000143fi
144
Leif Lindholm44f79422016-10-20 15:47:31 +0100145SourceEnv
Jordan Justenef9086c2014-01-30 19:26:46 +0000146
Leif Lindholmc112e372016-10-20 16:29:46 +0100147unset SCRIPTNAME RECONFIG
148
Leif Lindholm44f79422016-10-20 15:47:31 +0100149return $?