1
0

compile: some portability-related tweaks

echo -n are not POSIX-sh-portable, so use printf.
Neither are parentheses inside [ ]. Some of the usage are
clearly better covered by `case`, so let's use it.
This commit is contained in:
Mingye Wang (Arthur2e5) 2016-03-15 21:48:34 -04:00
parent bd2fc7716c
commit d2d7310909

View File

@ -6,9 +6,9 @@ set -e
#TODO command line parameter handling for non-interactive mode. #TODO command line parameter handling for non-interactive mode.
# Do we already have a repo? # Do we already have a repo?
if [ \( -d .git \) -a \( -f easyinstall.sh \) -a \( -f src/BlockArea.cpp \) ]; then # A good enough indicator that we're in the Cuberite git repo. if [ -d .git ] && [ -f easyinstall.sh ] && [ -f src/BlockArea.cpp ]; then # A good enough indicator that we're in the Cuberite git repo.
cd ../ cd ../
echo "Cuberite repository detected. This should make the process faster, especially if you compiled before." echo "Cuberite repository detected. This should make the process faster, especially if you compiled before."
fi fi
# Error functions. # Error functions.
@ -69,7 +69,7 @@ GCC_EXISTS=0
CLANG_EXISTS=0 CLANG_EXISTS=0
$GCC_EXE_NAME --help > /dev/null 2> /dev/null && GCC_EXISTS=1 $GCC_EXE_NAME --help > /dev/null 2> /dev/null && GCC_EXISTS=1
$CLANG_EXE_NAME --help > /dev/null 2> /dev/null && CLANG_EXISTS=1 $CLANG_EXE_NAME --help > /dev/null 2> /dev/null && CLANG_EXISTS=1
if [ $GCC_EXISTS -eq 0 -a $CLANG_EXISTS -eq 0 ]; then if [ "$GCC_EXISTS" -eq 0 ] && [ "$CLANG_EXISTS" -eq 0 ]; then
MISSING_PACKAGES=" $COMPILER_PACKAGE_NAME" MISSING_PACKAGES=" $COMPILER_PACKAGE_NAME"
fi fi
@ -79,7 +79,7 @@ checkPackages ()
echo "$PROGRAMS" | while read line; do echo "$PROGRAMS" | while read line; do
EXE_NAME=`echo "$line" | cut -f 1` EXE_NAME=`echo "$line" | cut -f 1`
PACKAGE_NAME=`echo "$line" | cut -f 2` PACKAGE_NAME=`echo "$line" | cut -f 2`
command -v $EXE_NAME > /dev/null 2> /dev/null || echo -n " $PACKAGE_NAME" command -v $EXE_NAME > /dev/null 2> /dev/null || printf %s " $PACKAGE_NAME"
done done
} }
MISSING_PACKAGES="$MISSING_PACKAGES`checkPackages`" MISSING_PACKAGES="$MISSING_PACKAGES`checkPackages`"
@ -138,18 +138,22 @@ You can choose between 3 branches:
# Input: Branch choice. # Input: Branch choice.
echo -n "Choose the branch (s/t/d): " printf %s "Choose the branch (s/t/d): "
read BRANCH read BRANCH
if [ \( "$BRANCH" = "s" \) -o \( "$BRANCH" = "S" \) ]; then case $BRANCH in
#BRANCH="stable" s|S)
error "We don't have a stable branch yet, please use testing, sorry." error "We don't have a stable branch yet, please use testing, sorry."
elif [ \( $BRANCH = "t" \) -o \( $BRANCH = "T" \) ]; then ;;
BRANCH="testing" t|T)
elif [ \( $BRANCH = "d" \) -o \( $BRANCH = "D" \) ]; then BRANCH="testing"
BRANCH="master" ;;
else d|D)
error "Unrecognized user input." BRANCH="master"
fi ;;
*)
error "Unrecognized user input."
;;
esac
} }
### Inactive code end. ### ### Inactive code end. ###
@ -171,16 +175,19 @@ code after this step. It will then compile your program.
" "
# Input: Compile mode choice. # Input: Compile mode choice.
echo -n "Choose compile mode: (n/d): " printf %s "Choose compile mode: (n/d): "
read BUILDTYPE read BUILDTYPE
if [ \( "$BUILDTYPE" = "d" \) -o \( "$BUILDTYPE" = "D" \) ]; then case $BUILDTYPE in
BUILDTYPE="Debug" d|D)
elif [ \( "$BUILDTYPE" = "n" \) -o \( "$BUILDTYPE" = "N" \) ]; then BUILDTYPE="Debug"
BUILDTYPE="Release" ;;
else n|N)
error "Unrecognized user input." BUILDTYPE="Release"
fi ;;
*)
error "Unrecognized user input."
;;
esac
# Echo: Downloading began. # Echo: Downloading began.
echo echo