#使用帮助 function HelpMsg() { echo "Usage: $SCRIPTNAME [Options]" echo echo "The system environment variable, WORKSPACE, is always set to the current" echo "working directory." echo echo "Options: " echo " --help, -h, -? Print this help screen and exit." echo echo " --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the" echo " template files from the BaseTools/Conf directory." echo echo Please note: This script must be \'sourced\' so the environment can be changed. echo ". $SCRIPTNAME" echo "source $SCRIPTNAME" } # 设定工作目录 function SetWorkspace() { # # If WORKSPACE is already set, then we can return right now # if [ -n "$WORKSPACE" ] then return 0 fi
if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ] then echo Run this script from the base of your tree. For example: echo " cd /Path/To/Edk/Root" echo " . edksetup.sh" return 1 fi
# # Check for BaseTools/BuildEnv before dirtying the user's environment. # if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ] then echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set. echo Please point EDK_TOOLS_PATH at the directory that contains echo the EDK2 BuildEnv script. return 1 fi
# # Set $WORKSPACE # export WORKSPACE=`pwd`
return 0 }
# 设定环境变量 function SetupEnv() { # !!环境变量的重要内容在BuildEnv里面!! if [ -n "$EDK_TOOLS_PATH" ] then . $EDK_TOOLS_PATH/BuildEnv elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ] then . $WORKSPACE/BaseTools/BuildEnv elif [ -n "$PACKAGES_PATH" ] then PATH_LIST=$PACKAGES_PATH PATH_LIST=${PATH_LIST//:/ } for DIR in $PATH_LIST do if [ -f "$DIR/BaseTools/BuildEnv" ] then export EDK_TOOLS_PATH=$DIR/BaseTools . $DIR/BaseTools/BuildEnv break fi done else echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set. echo Please check that WORKSPACE or PACKAGES_PATH is not set incorrectly echo in your shell, or point EDK_TOOLS_PATH at the directory that contains echo the EDK2 BuildEnv script. return 1 fi }
# 设定环境变量和工作目录的入口 function SourceEnv() { SetWorkspace && SetupEnv }
# 文件运行的入口,获取运行参数并按需执行 I=$# while [ $I -gt 0 ] do case "$1" in BaseTools) # Ignore argument for backwards compatibility shift ;; --reconfig) RECONFIG=TRUE shift ;; -?|-h|--help|*) HelpMsg break ;; esac I=$(($I - 1)) done
# # If WORKSPACE is already set, then we can return right now # if [ -n "$WORKSPACE" ] then return 0 fi
# # Set $WORKSPACE # export WORKSPACE=`pwd`
return 0
}
# 恢复配置 RestorePreviousConfiguration() { # # Restore previous configuration # if [ -z "$CONF_PATH" ] then export CONF_PATH=$WORKSPACE/Conf if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ] then PATH_LIST=${PACKAGES_PATH//:/ } for DIR in $PATH_LIST do if [ -d $DIR/Conf ] then export CONF_PATH=$DIR/Conf break fi done fi fi PREVIOUS_CONF_FILE=$CONF_PATH/BuildEnv.sh if [ -e $PREVIOUS_CONF_FILE ] then echo Loading previous configuration from $PREVIOUS_CONF_FILE . $PREVIOUS_CONF_FILE fi }
# 存储当前配置信息 StoreCurrentConfiguration() { # # Write configuration to a shell script to allow for configuration to be # easily reloaded. # OUTPUT_FILE=$CONF_PATH/BuildEnv.sh #echo Storing current configuration into $OUTPUT_FILE echo "# Auto-generated by ${BASH_SOURCE[0]}" >| $OUTPUT_FILE GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE GenerateShellCodeToUpdatePath $OUTPUT_FILE }
# 设定配置信息的目录 SetEdkToolsPath() {
# # If EDK_TOOLS_PATH is already set, then we can return right now # if [ -n "$EDK_TOOLS_PATH" ] then return 0 fi
# # Try $CONF_PATH/EdkTools # if [ -e $CONF_PATH/EdkTools ] then export EDK_TOOLS_PATH=$CONF_PATH/EdkTools return 0 fi
# # Try $CONF_PATH/BaseToolsSource # if [ -e $CONF_PATH/BaseToolsSource ] then export EDK_TOOLS_PATH=$CONF_PATH/BaseToolsSource return 0 fi
# # Try $WORKSPACE/BaseTools # if [ -e $WORKSPACE/BaseTools ] then export EDK_TOOLS_PATH=$WORKSPACE/BaseTools return 0 fi
# # Try $PACKAGES_PATH # if [ -n "$PACKAGES_PATH"] then PATH_LIST=${PACKAGES_PATH//:/ } for DIR in $PATH_LIST do if [ -d $DIR/BaseTools ] then export EDK_TOOLS_PATH=$DIR/BaseTools return 0 fi done fi
echo "Unable to determine EDK_TOOLS_PATH" echo echo "You may need to download the 'BaseTools' from buildtools.tianocore.org." echo "After downloading, either create a symbolic link to the source at" echo "\$WORKSPACE/Conf/BaseToolsSource, or set the EDK_TOOLS_PATH environment" echo "variable."
}
# 由系统类型,获取相关的子文件夹名称 GetBaseToolsBinSubDir() { # # Figure out a uniq directory name from the uname command # UNAME_DIRNAME=`uname -sm` UNAME_DIRNAME=${UNAME_DIRNAME// /-} UNAME_DIRNAME=${UNAME_DIRNAME//\//-} echo $UNAME_DIRNAME }
# 结合上一个函数,得到edk下二进制存放目录 GetEdkToolsPathBinDirectory() { # # Figure out a uniq directory name from the uname command # BIN_SUB_DIR=`GetBaseToolsBinSubDir`
if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ] then EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR else EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR fi
# If a python2 command is available, use it in preference to python if command -v python2 >/dev/null 2>&1; then python_exe=python2 fi
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here dir=$(dirname "$full_cmd") cmd=${full_cmd##*/}