]> git.proxmox.com Git - mirror_edk2.git/blame - edksetup.sh
edksetup.sh: rework argument parsing and update usage information
[mirror_edk2.git] / edksetup.sh
CommitLineData
b9e16a84 1#
445bfd92 2# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
44f79425 3# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
24542fb2 4# This program and the accompanying materials
b9e16a84 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.
2b1473c1 11#
12# In *inux environment, the build tools's source is required and need to be compiled
445bfd92 13# firstly, please reference https://github.com/tianocore/tianocore.github.io/wiki/SourceForge-to-Github-Quick-Start
2b1473c1 14# to get how to setup build tool.
15#
b9e16a84 16# Setup the environment for unix-like systems running a bash-like shell.
6dbea978 17# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
2b1473c1 18#
6dbea978 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.
2b1473c1 22#
445bfd92 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
2b1473c1 24#
b9e16a84 25
44f79425
LL
26SCRIPTNAME="edksetup.sh"
27
729220ea
PP
28function HelpMsg()
29{
44f79425
LL
30 echo "Usage: $SCRIPTNAME [Options]"
31 echo
32 echo "The system environment variable, WORKSPACE, is always set to the current"
33 echo "working directory."
34 echo
35 echo "Options: "
36 echo " --help, -h, -? Print this help screen and exit."
37 echo
729220ea 38 echo Please note: This script must be \'sourced\' so the environment can be changed.
44f79425
LL
39 echo ". $SCRIPTNAME"
40 echo "source $SCRIPTNAME"
729220ea
PP
41}
42
d5493449
PB
43function SetWorkspace()
44{
45 #
46 # If WORKSPACE is already set, then we can return right now
47 #
48 if [ -n "$WORKSPACE" ]
49 then
50 return 0
51 fi
52
53 if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ]
54 then
55 echo Run this script from the base of your tree. For example:
56 echo " cd /Path/To/Edk/Root"
57 echo " . edksetup.sh"
58 return 1
59 fi
60
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 #
73 # Set $WORKSPACE
74 #
75 export WORKSPACE=`pwd`
76
77 return 0
78}
79
729220ea
PP
80function SetupEnv()
81{
7bc14212
PB
82 if [ -n "$EDK_TOOLS_PATH" ]
83 then
44f79425 84 . $EDK_TOOLS_PATH/BuildEnv
d5493449 85 elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
729220ea 86 then
44f79425 87 . $WORKSPACE/BaseTools/BuildEnv
094a6739
LG
88 elif [ -n "$PACKAGES_PATH" ]
89 then
90 PATH_LIST=$PACKAGES_PATH
91 PATH_LIST=${PATH_LIST//:/ }
92 for DIR in $PATH_LIST
93 do
94 if [ -f "$DIR/BaseTools/BuildEnv" ]
95 then
96 export EDK_TOOLS_PATH=$DIR/BaseTools
44f79425 97 . $DIR/BaseTools/BuildEnv
094a6739
LG
98 break
99 fi
100 done
7bc14212 101 else
d5493449 102 echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
094a6739
LG
103 echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly
104 echo in your shell, or point EDK_TOOLS_PATH at the directory that contains
d5493449
PB
105 echo the EDK2 BuildEnv script.
106 return 1
729220ea
PP
107 fi
108}
109
110function SourceEnv()
111{
44f79425
LL
112 SetWorkspace &&
113 SetupEnv
729220ea 114}
ef9086c3 115
44f79425
LL
116I=$#
117while [ $I -gt 0 ]
118do
119 case "$1" in
120 BaseTools)
121 # Ignore argument for backwards compatibility
122 shift
123 ;;
124 -?|-h|--help|*)
125 HelpMsg
126 break
127 ;;
128 esac
129 I=$(($I - 1))
130done
1bb6bfaa 131
44f79425 132if [ $I -gt 0 ]
1bb6bfaa 133then
44f79425 134 return 1
ef9086c3
JJ
135fi
136
44f79425 137SourceEnv
b9e16a84 138
44f79425 139return $?