2014-08-28 15:53:34 +02:00
|
|
|
## @file
|
|
|
|
# Setup the environment for unix-like systems running a bash-like shell.
|
|
|
|
# This file must be "sourced" not merely executed. For example: ". edksetup.sh"
|
2007-10-16 22:52:46 +02:00
|
|
|
#
|
2016-11-16 09:35:56 +01:00
|
|
|
# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
2016-10-20 17:29:46 +02:00
|
|
|
# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
|
2019-04-04 01:03:11 +02:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
2007-12-11 10:03:30 +01:00
|
|
|
#
|
2007-10-16 22:52:46 +02:00
|
|
|
|
2007-12-11 10:03:30 +01:00
|
|
|
SetWorkspace() {
|
2007-10-16 22:52:46 +02:00
|
|
|
|
2007-12-11 10:03:30 +01:00
|
|
|
#
|
|
|
|
# If WORKSPACE is already set, then we can return right now
|
|
|
|
#
|
|
|
|
if [ -n "$WORKSPACE" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Set $WORKSPACE
|
|
|
|
#
|
2023-04-24 22:59:14 +02:00
|
|
|
WORKSPACE=$(pwd)
|
|
|
|
export WORKSPACE
|
2007-12-11 10:03:30 +01:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RestorePreviousConfiguration() {
|
|
|
|
#
|
|
|
|
# Restore previous configuration
|
|
|
|
#
|
2015-10-08 11:29:56 +02:00
|
|
|
if [ -z "$CONF_PATH" ]
|
|
|
|
then
|
|
|
|
export CONF_PATH=$WORKSPACE/Conf
|
|
|
|
if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ]
|
|
|
|
then
|
2023-04-24 22:59:14 +02:00
|
|
|
for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
|
2015-10-08 11:29:56 +02:00
|
|
|
do
|
|
|
|
if [ -d $DIR/Conf ]
|
|
|
|
then
|
|
|
|
export CONF_PATH=$DIR/Conf
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
2021-02-09 15:58:08 +01:00
|
|
|
|
2015-10-08 11:29:56 +02:00
|
|
|
PREVIOUS_CONF_FILE=$CONF_PATH/BuildEnv.sh
|
2007-12-11 10:03:30 +01:00
|
|
|
if [ -e $PREVIOUS_CONF_FILE ]
|
|
|
|
then
|
2015-10-08 11:29:56 +02:00
|
|
|
echo Loading previous configuration from $PREVIOUS_CONF_FILE
|
|
|
|
. $PREVIOUS_CONF_FILE
|
2007-12-11 10:03:30 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
GenerateShellCodeToSetVariable() {
|
|
|
|
VARIABLE=$1
|
|
|
|
OUTPUT_FILE=$2
|
|
|
|
VAR_VALUE="echo \${${VARIABLE}}"
|
|
|
|
VAR_VALUE=`eval $VAR_VALUE`
|
|
|
|
echo "if [ -z \"\$${VARIABLE}\" ]" >> $OUTPUT_FILE
|
|
|
|
echo "then" >> $OUTPUT_FILE
|
|
|
|
echo " export ${VARIABLE}=${VAR_VALUE}" >> $OUTPUT_FILE
|
|
|
|
echo "fi" >> $OUTPUT_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
GenerateShellCodeToUpdatePath() {
|
|
|
|
OUTPUT_FILE=$1
|
|
|
|
echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
|
|
|
|
echo "then" >> $OUTPUT_FILE
|
2023-04-24 22:59:14 +02:00
|
|
|
echo " FOUND_TOOLS_PATH_BIN=0" >> $OUTPUT_FILE
|
|
|
|
echo " for DIR in \$(echo \$PATH | tr ':' ' '); do" >> $OUTPUT_FILE
|
|
|
|
echo " if [ \"\$DIR\" = \"$EDK_TOOLS_PATH_BIN\" ]; then" >> $OUTPUT_FILE
|
|
|
|
echo " FOUND_TOOLS_PATH_BIN=1" >> $OUTPUT_FILE
|
|
|
|
echo " fi" >> $OUTPUT_FILE
|
|
|
|
echo " done" >> $OUTPUT_FILE
|
|
|
|
echo " if [ \$FOUND_TOOLS_PATH_BIN = 0 ]" >> $OUTPUT_FILE
|
2007-12-11 10:03:30 +01:00
|
|
|
echo " then" >> $OUTPUT_FILE
|
|
|
|
echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
|
|
|
|
echo " fi" >> $OUTPUT_FILE
|
|
|
|
echo "fi" >> $OUTPUT_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
StoreCurrentConfiguration() {
|
|
|
|
#
|
|
|
|
# Write configuration to a shell script to allow for configuration to be
|
|
|
|
# easily reloaded.
|
|
|
|
#
|
2015-10-08 11:29:56 +02:00
|
|
|
OUTPUT_FILE=$CONF_PATH/BuildEnv.sh
|
|
|
|
#echo Storing current configuration into $OUTPUT_FILE
|
2023-04-24 22:59:14 +02:00
|
|
|
echo "# Auto-generated by BaseTools/BuildEnv" >| $OUTPUT_FILE
|
2007-12-11 10:03:30 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
#
|
2015-10-08 11:29:56 +02:00
|
|
|
# Try $CONF_PATH/EdkTools
|
2007-12-11 10:03:30 +01:00
|
|
|
#
|
2015-10-08 11:29:56 +02:00
|
|
|
if [ -e $CONF_PATH/EdkTools ]
|
2007-12-11 10:03:30 +01:00
|
|
|
then
|
2015-10-08 11:29:56 +02:00
|
|
|
export EDK_TOOLS_PATH=$CONF_PATH/EdkTools
|
2007-12-11 10:03:30 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
2015-10-08 11:29:56 +02:00
|
|
|
# Try $CONF_PATH/BaseToolsSource
|
2007-12-11 10:03:30 +01:00
|
|
|
#
|
2015-10-08 11:29:56 +02:00
|
|
|
if [ -e $CONF_PATH/BaseToolsSource ]
|
2007-12-11 10:03:30 +01:00
|
|
|
then
|
2015-10-08 11:29:56 +02:00
|
|
|
export EDK_TOOLS_PATH=$CONF_PATH/BaseToolsSource
|
2007-12-11 10:03:30 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
2010-07-21 04:46:15 +02:00
|
|
|
# Try $WORKSPACE/BaseTools
|
2007-12-11 10:03:30 +01:00
|
|
|
#
|
2010-07-21 04:46:15 +02:00
|
|
|
if [ -e $WORKSPACE/BaseTools ]
|
2007-12-11 10:03:30 +01:00
|
|
|
then
|
|
|
|
export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2015-10-08 11:29:56 +02:00
|
|
|
#
|
|
|
|
# Try $PACKAGES_PATH
|
|
|
|
#
|
2023-04-24 22:59:14 +02:00
|
|
|
if [ -n "$PACKAGES_PATH" ]
|
2015-10-08 11:29:56 +02:00
|
|
|
then
|
2023-04-24 22:59:14 +02:00
|
|
|
for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
|
2015-10-08 11:29:56 +02:00
|
|
|
do
|
|
|
|
if [ -d $DIR/BaseTools ]
|
|
|
|
then
|
|
|
|
export EDK_TOOLS_PATH=$DIR/BaseTools
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2007-12-11 10:03:30 +01:00
|
|
|
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
|
|
|
|
#
|
2023-04-24 22:59:14 +02:00
|
|
|
echo $(uname -sm | tr ' ' '-')
|
2007-12-11 10:03:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GetEdkToolsPathBinDirectory() {
|
|
|
|
#
|
|
|
|
# Figure out a uniq directory name from the uname command
|
|
|
|
#
|
|
|
|
BIN_SUB_DIR=`GetBaseToolsBinSubDir`
|
|
|
|
|
2008-02-13 23:44:22 +01:00
|
|
|
if [ -e $EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR ]
|
2007-12-11 10:03:30 +01:00
|
|
|
then
|
2008-02-13 23:44:22 +01:00
|
|
|
EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/BinWrappers/$BIN_SUB_DIR
|
2007-12-11 10:03:30 +01:00
|
|
|
else
|
|
|
|
EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $EDK_TOOLS_PATH_BIN
|
|
|
|
}
|
|
|
|
|
2012-04-10 09:18:20 +02:00
|
|
|
AddDirToStartOfPath() {
|
|
|
|
DIRNAME=$1
|
|
|
|
PATH=$DIRNAME:$PATH
|
|
|
|
export PATH
|
|
|
|
}
|
|
|
|
|
2007-12-11 10:03:30 +01:00
|
|
|
AddEdkToolsToPath() {
|
|
|
|
|
|
|
|
#
|
|
|
|
# If EDK_TOOLS_PATH is not set, then we cannot update PATH
|
|
|
|
#
|
|
|
|
if [ -z "$EDK_TOOLS_PATH" ]
|
|
|
|
then
|
2010-07-21 04:46:15 +02:00
|
|
|
return 1
|
2007-12-11 10:03:30 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
|
|
|
|
|
2021-02-09 15:58:08 +01:00
|
|
|
# check if the edk2basetools pip package is available
|
2023-04-24 22:59:14 +02:00
|
|
|
if $PYTHON_COMMAND -c "import edk2basetools" > /dev/null 2>&1; then
|
2021-02-09 15:58:08 +01:00
|
|
|
# if it is, use the pip version of the wrappers
|
|
|
|
echo "Using Pip Basetools"
|
|
|
|
AddDirToStartOfPath $EDK_TOOLS_PATH/BinPipWrappers/PosixLike
|
|
|
|
else
|
|
|
|
echo "Using EDK2 in-source Basetools"
|
|
|
|
AddDirToStartOfPath $EDK_TOOLS_PATH/BinWrappers/PosixLike
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2012-04-10 09:18:20 +02:00
|
|
|
AddDirToStartOfPath $EDK_TOOLS_PATH_BIN
|
2007-12-11 10:03:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CopySingleTemplateFile() {
|
|
|
|
|
2009-12-29 07:16:53 +01:00
|
|
|
SRC_FILENAME=Conf/$1.template
|
2015-10-08 11:29:56 +02:00
|
|
|
DST_FILENAME=$CONF_PATH/$1.txt
|
2007-12-11 10:03:30 +01:00
|
|
|
|
2015-10-08 11:29:56 +02:00
|
|
|
if [ -e $DST_FILENAME ]
|
2007-12-11 10:03:30 +01:00
|
|
|
then
|
2016-10-20 17:29:46 +02:00
|
|
|
[ $RECONFIG != TRUE ] && return
|
2007-12-11 10:03:30 +01:00
|
|
|
fi
|
|
|
|
|
2009-12-29 07:16:53 +01:00
|
|
|
echo "Copying \$EDK_TOOLS_PATH/$SRC_FILENAME"
|
2015-10-08 11:29:56 +02:00
|
|
|
echo " to $DST_FILENAME"
|
2009-12-29 07:16:53 +01:00
|
|
|
SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME
|
2007-12-11 10:03:30 +01:00
|
|
|
cp $SRC_FILENAME $DST_FILENAME
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyTemplateFiles() {
|
|
|
|
|
|
|
|
CopySingleTemplateFile build_rule
|
|
|
|
CopySingleTemplateFile tools_def
|
|
|
|
CopySingleTemplateFile target
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptMain() {
|
|
|
|
|
|
|
|
SetWorkspace
|
|
|
|
if [ -z $WORKSPACE ]
|
|
|
|
then
|
|
|
|
echo "Failure setting WORKSPACE"
|
2010-07-21 04:46:15 +02:00
|
|
|
return 1
|
2007-12-11 10:03:30 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
RestorePreviousConfiguration
|
|
|
|
|
|
|
|
SetEdkToolsPath
|
|
|
|
if [ -z $EDK_TOOLS_PATH ]
|
|
|
|
then
|
2010-07-21 04:46:15 +02:00
|
|
|
return 1
|
2007-12-11 10:03:30 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
AddEdkToolsToPath
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "Failure adding EDK Tools into PATH!"
|
2010-07-21 04:46:15 +02:00
|
|
|
return 1
|
2007-12-11 10:03:30 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
StoreCurrentConfiguration
|
|
|
|
|
|
|
|
echo WORKSPACE: $WORKSPACE
|
|
|
|
echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
|
2015-10-08 11:29:56 +02:00
|
|
|
echo CONF_PATH: $CONF_PATH
|
2007-12-11 10:03:30 +01:00
|
|
|
|
|
|
|
CopyTemplateFiles
|
|
|
|
|
|
|
|
}
|
2007-10-16 22:52:46 +02:00
|
|
|
|
|
|
|
#
|
2007-12-11 10:03:30 +01:00
|
|
|
# Run the main function
|
2007-10-16 22:52:46 +02:00
|
|
|
#
|
2007-12-11 10:03:30 +01:00
|
|
|
ScriptMain
|
2007-10-16 22:52:46 +02:00
|
|
|
|