1
0

Updated compile.sh script (#4009)

* Gets number of cpu threads on FreeBSD
* Fixes an issue where the script would return an error when you chose no compile mode
* Improves consistency
* 'Fixes' a wording issue: cores != threads
This commit is contained in:
Bond-009 2017-09-13 09:47:48 +02:00 committed by Alexander Harkness
parent a4c07d2f98
commit e24186bb13
2 changed files with 47 additions and 48 deletions

View File

@ -29,7 +29,7 @@ This script will download the correct binary from the project site.
### Compiling ### Compiling
- You can compile automatically for Linux / *nix with the `compile.sh` script. The script is described below. - You can compile automatically for Linux, macOS and FreeBSD with the `compile.sh` script. The script is described below.
- You can also compile manually. See [COMPILING.md][4]. - You can also compile manually. See [COMPILING.md][4].
Compiling may provide better performance (1.5-3x as fast) and it supports more operating systems. Compiling may provide better performance (1.5-3x as fast) and it supports more operating systems.

View File

@ -4,7 +4,7 @@
set -e set -e
# Global variables: # Global variables:
# CHOICE_BUILDTYPE - Either "Normal" or "Debug". # CHOICE_BUILDTYPE - Either "Release" or "Debug".
# CHOICE_THREADS - A numerical value, the amount of threads to be used for the make command. # CHOICE_THREADS - A numerical value, the amount of threads to be used for the make command.
# CHOICE_BRANCH - The branch to use. Currently locked on "master". # CHOICE_BRANCH - The branch to use. Currently locked on "master".
# STATE_INTERACTIVE - 1 If we're running interactively. 0 otherwise. # STATE_INTERACTIVE - 1 If we're running interactively. 0 otherwise.
@ -13,6 +13,7 @@ set -e
# Constants: # Constants:
DEFAULT_BUILDTYPE="Release" # Other options: "Debug" DEFAULT_BUILDTYPE="Release" # Other options: "Debug"
DEFAULT_BRANCH="master" # Other options: None currently DEFAULT_BRANCH="master" # Other options: None currently
DEFAULT_THREADS=1
# Constants not modifiable through command line: # Constants not modifiable through command line:
UPSTREAM_REPO="origin" UPSTREAM_REPO="origin"
@ -54,8 +55,8 @@ errorArguments ()
echo "options:" echo "options:"
echo " -m The compilation mode. Either \"Release\" or \"Debug\". Defaults to \"$DEFAULT_BUILDTYPE\"" echo " -m The compilation mode. Either \"Release\" or \"Debug\". Defaults to \"$DEFAULT_BUILDTYPE\""
echo ' -t The number of threads to use for compiling' echo ' -t The number of threads to use for compiling'
echo " If unspecified, at most $MAX_DEFAULT_THREADS threads are used. The special value CORES attempts to set the number of" echo " If unspecified, a default of $DEFAULT_THREADS threads is used. The special value AUTO attempts to set the number of"
echo ' threads to the number of computer cores.' echo ' compilation threads equal to the number of CPU threads.'
echo ' -b The branch to compile. (Currently unused and pinned to MASTER)' echo ' -b The branch to compile. (Currently unused and pinned to MASTER)'
echo ' -n yes: Prevent interactive mode. Unnecessary in combination with other arguments.' echo ' -n yes: Prevent interactive mode. Unnecessary in combination with other arguments.'
echo ' Use without any other argument to build with the default settings.' echo ' Use without any other argument to build with the default settings.'
@ -129,10 +130,8 @@ while getopts ":m:t:b:d:n:" name; do
;; ;;
t) t)
if [ ! -z "$CHOICE_THREADS" ]; then errorArguments; fi # Argument duplication. if [ ! -z "$CHOICE_THREADS" ]; then errorArguments; fi # Argument duplication.
if [ "$value" -gt 0 ] 2>/dev/null; then # If a positive integer. if [ "$value" -gt 0 ] 2>/dev/null || [ "$value" = "AUTO" ]; then # If a positive integer or the special value "AUTO".
CHOICE_THREADS="$value" CHOICE_THREADS="$value"
elif [ "$value" = "CORES" ]; then
CHOICE_THREADS="CORES"
else else
errorArguments errorArguments
fi fi
@ -257,23 +256,23 @@ doDependencyCheck()
# apt-get guide. # apt-get guide.
apt-get --help > /dev/null 2> /dev/null && \ apt-get --help > /dev/null 2> /dev/null && \
missingDepsExit "sudo apt-get install$MISSING_PACKAGES" missingDepsExit "apt-get install$MISSING_PACKAGES"
# yum guide. # dnf guide.
yum --help > /dev/null 2> /dev/null && \ dnf --help > /dev/null 2> /dev/null && \
missingDepsExit "sudo yum install$MISSING_PACKAGES" missingDepsExit "dnf install$MISSING_PACKAGES"
# zypper guide. # zypper guide.
zypper --help > /dev/null 2> /dev/null && \ zypper --help > /dev/null 2> /dev/null && \
missingDepsExit "sudo zypper install$MISSING_PACKAGES" missingDepsExit "zypper install$MISSING_PACKAGES"
# pacman guide. # pacman guide.
pacman --help > /dev/null 2> /dev/null && \ pacman --help > /dev/null 2> /dev/null && \
missingDepsExit "sudo pacman -S$MISSING_PACKAGES" missingDepsExit "pacman -S$MISSING_PACKAGES"
# urpmi guide. # urpmi guide.
urpmi --help > /dev/null 2> /dev/null && \ urpmi --help > /dev/null 2> /dev/null && \
missingDepsExit "sudo urpmi$MISSING_PACKAGES" missingDepsExit "urpmi$MISSING_PACKAGES"
missingDepsExit "" missingDepsExit ""
fi fi
@ -351,9 +350,6 @@ if [ $STATE_INTERACTIVE -eq 1 ]; then
r|N) r|N)
CHOICE_BUILDTYPE="Release" CHOICE_BUILDTYPE="Release"
;; ;;
*)
errorInput
;;
esac esac
fi fi
@ -366,44 +362,47 @@ fi
numberOfCores() numberOfThreads()
{ {
KERNEL=$(uname -s) KERNEL=`uname -s`
if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "Darwin" ]; then if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "Darwin" ]; then
echo $(getconf _NPROCESSORS_ONLN) echo `getconf _NPROCESSORS_ONLN`
elif [ "$KERNEL" = "FreeBSD" ]; then
echo `getconf NPROCESSORS_ONLN`
else else
echo "unknown" echo "unknown"
fi fi
} }
CORE_COUNT=`numberOfCores` CPU_THREAD_COUNT=`numberOfThreads`
if [ $STATE_INTERACTIVE -eq 1 ]; then if [ $STATE_INTERACTIVE -eq 1 ]; then
echo ""
echo "Choose the number of compilation threads." echo "Choose the number of compilation threads."
if [ "$CORE_COUNT" = "unknown" ]; then if [ "$CPU_THREAD_COUNT" = "unknown" ]; then
printf %s "Could not detect the number of cores. " echo "Could not detect the number of CPU threads."
elif [ "$CORE_COUNT" -eq 1 ]; then elif [ "$CPU_THREAD_COUNT" -eq 1 ]; then
echo "You have 1 core." echo "You have 1 thread."
else else
echo "You have $CORE_COUNT cores." echo "You have $CPU_THREAD_COUNT CPU threads."
fi fi
echo "If you have enough RAM, it is wise to choose a number as high as your core count. " echo "If you have enough RAM, it is wise to choose your CPU's thread count. "
echo "Otherwise choose lower. Raspberry Pis should choose 1. If in doubt, choose 1." echo "Otherwise choose lower. Old Raspberry Pis should choose 1. If in doubt, choose 1."
printf %s "Please enter the number of compilation threads to use (Default: 1): " printf %s "Please enter the number of compilation threads to use (Default: $DEFAULT_THREADS): "
read CHOICE_THREADS read CHOICE_THREADS
fi fi
if [ -z "$CHOICE_THREADS" ] 2> /dev/null; then if [ -z "$CHOICE_THREADS" ] 2> /dev/null; then
CHOICE_THREADS=1 CHOICE_THREADS="$DEFAULT_THREADS"
elif [ "$CHOICE_THREADS" = "CORES" ] 2> /dev/null; then elif [ "$CHOICE_THREADS" = "AUTO" ] 2> /dev/null; then
if [ $CORE_COUNT = "unknown" ]; then if [ $CPU_THREAD_COUNT = "unknown" ]; then
CHOICE_THREADS=1 CHOICE_THREADS="$DEFAULT_THREADS"
echo "WARNING: could not detect number of cores. Using 1 thread." >&2 echo "WARNING: could not detect number of threads. Using the default ($DEFAULT_THREADS) ." >&2
else else
CHOICE_THREADS="$CORE_COUNT" CHOICE_THREADS="$CPU_THREAD_COUNT"
fi fi
elif [ "$CHOICE_THREADS" -lt 0 ] 2> /dev/null; then elif [ "$CHOICE_THREADS" -lt 0 ] 2> /dev/null; then
errorInput errorInput
@ -418,17 +417,17 @@ else
previousCompilation="Detected. This should make fetching and compiling faster." previousCompilation="Detected. This should make fetching and compiling faster."
fi fi
CORE_WARNING="" THREAD_WARNING=""
if [ "$CORE_COUNT" != "unknown" ] && [ "$CORE_COUNT" -lt "$CHOICE_THREADS" ]; then if [ "$CPU_THREAD_COUNT" != "unknown" ] && [ "$CPU_THREAD_COUNT" -lt "$CHOICE_THREADS" ]; then
CORE_WARNING=" - Warning: More threads than cores." THREAD_WARNING=" - Warning: More threads assigned than there are CPU threads."
fi fi
echo "" echo ""
echoInt "#### Settings Summary ####" echoInt "#### Settings Summary ####"
echo "Build Type: " "$CHOICE_BUILDTYPE" echo "Build Type: " "$CHOICE_BUILDTYPE"
echo "Branch: " "$CHOICE_BRANCH" "(Currently the only choice)" echo "Branch: " "$CHOICE_BRANCH" "(Currently the only choice)"
echo "Compilation threads: " "$CHOICE_THREADS$CORE_WARNING" echo "Compilation threads: " "$CHOICE_THREADS$THREAD_WARNING"
echo "Cores: " "$CORE_COUNT" echo "CPU Threads: " "$CPU_THREAD_COUNT"
echo "Previous compilation: " "$previousCompilation" echo "Previous compilation: " "$previousCompilation"
echo "Upstream Link: " "$UPSTREAM_LINK" echo "Upstream Link: " "$UPSTREAM_LINK"
echo "Upstream Repo: " "$UPSTREAM_REPO" echo "Upstream Repo: " "$UPSTREAM_REPO"
@ -509,7 +508,7 @@ fi
cd .. cd ..
echo " echo "
You can always update Cuberite by executing: You can always update Cuberite by executing:
`pwd`/compile.sh $PWD/compile.sh
Enjoy :)" Enjoy :)"
exit 0 exit 0