CloverBootloader/xbuildme
Сергей Исаков de3e1aa606 fixex xbuildme by matxpa
Signed-off-by: Сергей Исаков <sergey@iMac-Sergej.local>
2025-09-17 22:36:33 +03:00

368 lines
9.0 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# created by vector sigma on July 15 2019
# github version
# Linux users should be able to use this wrapper, although the following are needed:
# gcc (check for ./build_gcc8.sh or newer)
# python (sudo apt-get install python)
# uuid-dev (sudo apt-get install uuid-dev)
# git (sudo apt-get install git)
export TERM=xterm-256color
export LC_ALL=C.UTF-8
BASE_DIR="$(dirname "$0")"
# $1 argument override MYTOOLCHAIN variable, in case you want GCC53 for example
cd "$(dirname $0)"
# ====== COLORS ======
# Основные цвета
COL_RED=$(tput setaf 1) # Red
COL_GREEN=$(tput setaf 2) # Green
COL_YELLOW=$(tput setaf 3) # Yellow
COL_BLUE=$(tput setaf 4) # Blue
COL_PURPLE=$(tput setaf 5) # Purple
COL_CYAN=$(tput setaf 6) # Cyan
COL_WHITE=$(tput setaf 7) # White
# Light shades
COL_LIGHT_RED=$(tput setaf 9) # Light Red
COL_LIGHT_GREEN=$(tput setaf 10) # Light Green
COL_LIGHT_YELLOW=$(tput setaf 229) # Light Yellow (замена для setaf 11)
COL_LIGHT_BLUE=$(tput setaf 153) # Light Blue (замена для setaf 12)
COL_LIGHT_PURPLE=$(tput setaf 183) # Light Purple (замена для setaf 13)
COL_LIGHT_CYAN=$(tput setaf 14) # Light Cyan
# Dark shades
COL_DARK_RED=$(tput setaf 124) # Dark Red
COL_DARK_GREEN=$(tput setaf 22) # Dark Green
COL_DARK_YELLOW=$(tput setaf 94) # Dark Yellow
COL_DARK_BLUE=$(tput setaf 18) # Dark Blue
COL_DARK_PURPLE=$(tput setaf 54) # Dark Purple
COL_DARK_CYAN=$(tput setaf 30) # Dark Cyan
# Bold options
COL_RED_BOLD=$(tput bold; tput setaf 1) # Bold Red
COL_GREEN_BOLD=$(tput bold; tput setaf 2) # Bold Green
COL_YELLOW_BOLD=$(tput bold; tput setaf 3) # Bold Yellow
COL_BLUE_BOLD=$(tput bold; tput setaf 4) # Bold Blue
COL_PURPLE_BOLD=$(tput bold; tput setaf 5) # Bold Purple
COL_CYAN_BOLD=$(tput bold; tput setaf 6) # Bold Cyan
COL_WHITE_BOLD=$(tput bold; tput setaf 7) # Bold White
# Italic variants
COL_RED_ITALIC=$(tput sitm; tput setaf 1) # Italic Red
COL_GREEN_ITALIC=$(tput sitm; tput setaf 2) # Italic Green
COL_YELLOW_ITALIC=$(tput sitm; tput setaf 3) # Italic Yellow
COL_BLUE_ITALIC=$(tput sitm; tput setaf 4) # Italic Blue
COL_PURPLE_ITALIC=$(tput sitm; tput setaf 5) # Italic Purple
COL_CYAN_ITALIC=$(tput sitm; tput setaf 6) # Italic Cyan
COL_WHITE_ITALIC=$(tput sitm; tput setaf 7) # Italic White
COL_RESET="\x1b[39;49;00m" 
revision=$(git describe --tags $(git rev-list --tags --max-count=1))
# ====== Main Window SetUp ======
if [[ "$2" != "ci" ]]; then
osascript <<EOF
tell application "System Events"
tell application "Terminal"
try
activate
set bounds of front window to {0, 23, 615, 420}
on error errMsg
display dialog "Error setting Terminal window: " & errMsg buttons {"OK"} default button "OK" with icon caution
end try
end tell
end tell
EOF
fi
# ====== Display Menu ======
echo -e "${COL_GREEN} ---------------------------------------------------------------------------------"
echo -e "${COL_GREEN} 🍀 Clover r${revision} ${COL_WHITE}(SHA: 64d434947)"
echo -e "${COL_WHITE} Default TOOLCHAIN: ${COL_CYAN}GCC151${COL_WHITE}"
echo -e "${COL_WHITE} Switch to ${COL_CYAN}XCODE${COL_WHITE} select: ${COL_CYAN}build (with XCode)"
echo -e "${COL_WHITE} Depending on your ${COL_CYAN}XCODE version${COL_WHITE} the Toolset will be ${COL_CYAN}automatically chosen"
echo -e "${COL_GREEN} ---------------------- ${COL_CYAN}Current Python version: ${COL_WHITE}Python 3.13.7${COL_GREEN} --------------------${COL_RESET}"
declare -r CLOVERROOT="$PWD"
declare -r MYTOOLCHAIN=${1:-GCC151}
TOOLCHAIN_DIR=${TOOLCHAIN_DIR:-"$CLOVERROOT/toolchain"}
# Functions
pathmunge() {
if [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
if [[ "${2:-}" = "after" ]]; then
export PATH=$PATH:$1
else
export PATH=$1:$PATH
fi
fi
}
checkXCODE() {
echo "[CHECK XCODE]"
if [[ ! -x /usr/bin/xcodebuild ]]; then
echo "ERROR: Install Xcode Tools from Apple before using this script."
exit 1
fi
if [[ ! -d "$(xcode-select --print-path)" ]]; then
echo "ERROR: Xcode Command Line Tools not selected:"
echo " open Xcode.app and go in Preferences->Locations,"
echo " and select the Command Line Tools"
exit 1
fi
}
checkGETTEXT() {
if [[ ! -x $(which gettext) ]]; then
"${CLOVERROOT}"/buildgettext.sh
fi
}
exportPaths() {
if [[ "$(uname)" == Darwin ]]; then
pathmunge "$(xcode-select --print-path)"/usr/bin
fi
pathmunge "$TOOLCHAIN_DIR"/bin
export TOOLCHAIN_DIR=$TOOLCHAIN_DIR
export DIR_MAIN=${DIR_MAIN:-"$CLOVERROOT/toolchain"}
export DIR_TOOLS=${DIR_TOOLS:-"$DIR_MAIN/tools"}
export DIR_DOWNLOADS=${DIR_DOWNLOADS:-"$DIR_TOOLS/download"}
export DIR_LOGS=${DIR_LOGS:-"$DIR_TOOLS/logs"}
export PREFIX=${TOOLCHAIN_DIR}
}
checkTools() {
if [[ "$(uname)" == Darwin && $MYTOOLCHAIN != GCC* ]]; then
checkXCODE
fi
exportPaths
if [[ "$(uname)" == Darwin ]]; then
checkGETTEXT
fi
}
updateClover() {
echo "[UPDATE CLOVER]"
cd "${CLOVERROOT}"
if [[ -d .git ]]; then
git fetch --all
git pull origin master
else
echo "Error: this is not a git repository, can't update!"
fi
}
updateResetClover() {
echo "[UPDATE RESET CLOVER]"
cd "${CLOVERROOT}"
if [[ -d .git ]]; then
git fetch --all
git reset --hard origin/master
git pull origin master
else
echo "Error: this is not a git repository, can't update!"
fi
}
buildClover() {
checkTools
cd "${CLOVERROOT}"
if [[ -z "$WORKSPACE" ]]; then
rm -rf "$CLOVERROOT/Conf"
mkdir "$CLOVERROOT/Conf"
cd "${CLOVERROOT}"
export EDK_TOOLS_PATH="${PWD}"/BaseTools
set +u
source ./edksetup.sh BaseTools
set -u
cd "$CLOVERROOT"
WORKSPACE="${PWD}"
fi
echo "[BUILD CLOVER]"
# Run a custom build script if exist (~/src/tools/Scripts/build.sh)
# This allow the user to run ebuild.sh with own parameters
if [[ -x "${DIR_TOOLS}"/Scripts/build.sh ]]; then
echo "Running custom build script"
"${DIR_TOOLS}"/Scripts/build.sh "${CLOVERROOT}" $MYTOOLCHAIN
else
./ebuild.sh -fr -t $MYTOOLCHAIN
./ebuild.sh -fr -mc --no-usb -D NO_GRUB_DRIVERS_EMBEDDED -t $MYTOOLCHAIN
fi
# Run a post build script if exist (~/src/tools/Scripts/postbuild.sh)
if [[ -x "${DIR_TOOLS}"/Scripts/postbuild.sh ]]; then
echo "Running postbuild script"
"${DIR_TOOLS}"/Scripts/postbuild.sh "${CLOVERROOT}" $MYTOOLCHAIN
fi
}
buildCloverTest() {
checkTools
cd "${CLOVERROOT}"
if [[ -z "$WORKSPACE" ]]; then
export EDK_TOOLS_PATH="${PWD}"/BaseTools
set +u
source ./edksetup.sh BaseTools
set -u
cd "$CLOVERROOT"
WORKSPACE="${PWD}"
fi
echo "[BUILD CLOVER TEST]"
./ebuild.sh -t $MYTOOLCHAIN
}
buildPkg() {
cd "${CLOVERROOT}/CloverPackage"
echo "[BUILD PKG]"
echo "The log will be created in the CloverPackage folder."
rm -f mpkg.log
make pkg | tee mpkg.log
}
buildIso() {
cd "${CLOVERROOT}"/CloverPackage
echo "[BUILD ISO]"
make iso
}
checkStatus() {
cd "${CLOVERROOT}"
if [[ -d .git ]]; then
git fetch origin
git status
else
echo "Error: this is not a git repository, can't get info!"
fi
}
showdiff() {
cd "${CLOVERROOT}"
if [[ -d .git ]]; then
git fetch origin
git diff
else
echo "Error: this is not a git repository, can't get info!"
fi
}
cleanBaseTools() {
cd "${CLOVERROOT}"/BaseTools
make clean
}
menu() {
echo
echo '------------------------------------------------------------------------'
cd "${CLOVERROOT}"
local lsha1="not a git repo"
if [[ -d .git ]]; then
lsha1=$(git rev-parse --short HEAD)
fi
echo "buildme, Clover v5 r${revision} (SHA: $lsha1)"
echo "TOOLCHAIN: $MYTOOLCHAIN (override example: './buildme GCC53')"
echo
PS3='Please enter your choice: '
options=( 'build Clover'
'make pkg'
'make iso'
'build all'
'test build (no autogen, no boot files)'
'status'
'update Clover'
'update Clover (reset changes)'
'show diff'
'open drivers directory'
'clean BaseTools'
'quit')
select opt in "${options[@]}"
do
case $opt in
"build Clover")
buildClover
break
;;
"make pkg")
buildPkg
break
;;
"make iso")
buildIso
break
;;
"build all")
buildClover
buildPkg
buildIso
break
;;
"test build (no autogen, no boot files)")
buildCloverTest
break
;;
"update Clover")
updateClover
break
;;
"update Clover (reset changes)")
updateResetClover
break
;;
"status")
checkStatus
break
;;
"show diff")
showdiff
break
;;
"open drivers directory")
if [[ -d "${CLOVERROOT}"/CloverPackage/CloverV2/EFI/CLOVER/drivers ]]; then
open "${CLOVERROOT}"/CloverPackage/CloverV2/EFI/CLOVER/drivers
else
echo && echo "Directory not found. Compile Clover first!!"
sleep 2
fi
break
;;
"clean BaseTools")
cleanBaseTools
break
;;
"quit")
exit 0
;;
*)
echo "invalid option $REPLY"
break
;;
esac
done
menu
}
# Main
set -e
menu