CloverBootloader/buildme

223 lines
4.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# created by vector sigma on July 15 2019
if [[ "$(uname)" != Darwin ]]; then
echo "Sorry, works on macOS only"
exit 1
fi
cd "$(dirname $0)"
declare -r CLOVERROOT="$PWD"
declare -r TOOLCHAIN=XCODE8
TOOLCHAIN_DIR=${TOOLCHAIN_DIR:-$(dirname $CLOVERROOT)/opt/local}
# 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
}
isNASMGood() {
# nasm should be greater or equal to 2.12.02 to be good building Clover.
# There was a bad macho relocation in outmacho.c, fixed by Zenith432
# and accepted by nasm devel during 2.12.rcxx (release candidate)
result=1
local nasmver=$( "${1}" -v | grep 'NASM version' | awk '{print $3}' )
case "$nasmver" in
2.12.0[2-9]* | 2.12.[1-9]* | 2.1[3-9]* | 2.[2-9]* | [3-9]* | [1-9][1-9]*)
result=0;;
*)
printf "\n\e[1;33mUnknown or unsupported NASM version found at:\n${1}\n\n\e[0m";;
esac
return $result
}
checkNASM() {
local nasmArray=( $(which -a nasm) )
local found=0
if [ ${#nasmArray[@]} -ge "1" ]; then
for i in "${nasmArray[@]}"
do
echo "found nasm v$(${i} -v | grep 'NASM version' | awk '{print $3}') at $(dirname ${i})"
done
# we have a good nasm?
for i in "${nasmArray[@]}"
do
if isNASMGood "${i}"; then
found=1
export NASM_PREFIX="$(dirname ${i})/"
break
fi
done
fi
if [[ "$found" -eq 0 ]]; then
echo "installing nasm.."
NASM_PREFIX="$(dirname ${i})/"
"${CLOVERROOT}"/buildnasm.sh
fi
}
checkGETTEXT() {
if [[ ! -x $(which gettext) ]]; then
"${CLOVERROOT}"/buildgettext.sh
fi
}
exportPaths() {
pathmunge "$(xcode-select --print-path)"/usr/bin
pathmunge "$TOOLCHAIN_DIR"/bin
export TOOLCHAIN_DIR=$TOOLCHAIN_DIR
export DIR_MAIN=${DIR_MAIN:-$(dirname $CLOVERROOT)}
export DIR_TOOLS=${DIR_TOOLS:-$DIR_MAIN/tools}
export DIR_BUILD=${DIR_BUILD:-$RAMDISK_MNT_PT}
export DIR_DOWNLOADS=${DIR_DOWNLOADS:-$DIR_TOOLS/download}
export DIR_LOGS=${DIR_LOGS:-$DIR_TOOLS/logs}
}
checkTools() {
checkXCODE
exportPaths
checkNASM
checkGETTEXT
}
updateCloverTakeTheirs() {
echo "[UPDATE CLOVER]"
cd "${CLOVERROOT}"
git fetch --all
git reset --hard origin/master
git pull origin master
}
updateCloverTakeYours() {
echo "[UPDATE CLOVER]"
cd "${CLOVERROOT}"
git stash
git pull origin master
git stash apply
}
buildClover() {
checkTools
cd "${CLOVERROOT}"
echo "[BUILD CLOVER]"
./ebuild.sh -fr
./ebuild.sh -fr -mc --no-usb -D NO_GRUB_DRIVERS_EMBEDDED
}
buildPkg() {
cd "${CLOVERROOT}"/CloverPackage
echo "[BUILD PKG]"
make pkg
}
buildIso() {
cd "${CLOVERROOT}"/CloverPackage
echo "[BUILD ISO]"
make iso
}
checkStatus() {
cd "${CLOVERROOT}"
git fetch origin
git status
}
showdiff() {
cd "${CLOVERROOT}"
git fetch origin
git diff
}
menu() {
echo
echo '------------------------------------------------------------------------'
cd "${CLOVERROOT}"
echo "buildme Beta, Clover v2.5k r$(cat Version.h | grep REVISION_STR | awk '{print $NF}' | tr -cd '[[:digit:]]') (SHA: $(git rev-parse --short HEAD))"
echo "Remote SHA: $(git rev-parse --short origin/master)"
echo
PS3='Please enter your choice: '
options=('build Clover' 'make pkg' 'make iso' 'build all' 'update Clover (discard local changes)' 'update Clover (stash local changes)' 'status' 'show diff' '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
;;
"update Clover (discard changes)")
updateCloverTakeTheirs
break
;;
"update Clover (stash local changes)")
updateCloverTakeYours
break
;;
"status")
checkStatus
break
;;
"show diff")
showdiff
break
;;
"quit")
exit 0
;;
*)
echo "invalid option $REPLY"
break
;;
esac
done
menu
}
# Main
set -e
menu