From 826ad10ce9650bb3ad5521ee241fb0744d09b70a Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 28 Jan 2020 12:54:07 +0100 Subject: [PATCH] build.sh: switch to "getopt" command and handle "--disable-threads" and "--force-ansi" long options. --- build.sh | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index 7bdc6a9..476eaac 100755 --- a/build.sh +++ b/build.sh @@ -4,24 +4,41 @@ mkdir build 2> /dev/null pushd build > /dev/null function usage() { - echo "Usage: ${0##*/} [ -h ] [ -t Debug|Release|RelWithDebInfo|MinSizeRel ]" + echo "Usage: ${0##*/} [ -h ] [ -t Debug|Release|RelWithDebInfo|MinSizeRel ] [ --disable-threads ] [ --force-ansi ]" exit 1 } -ARGS="" -while getopts ":h?t:" opt; do +options=$(getopt -n "${0##*/}" -o ht: --long disable-threads --long force-ansi -- "$@") - case "${opt}" in - t) ARGS="${ARGS} -DCMAKE_BUILD_TYPE=${OPTARG}" ;; - h) usage ;; - :) echo "Error: -${OPTARG} requires a value" - exit 1 +[ $? -eq 0 ] || usage + +eval set -- "$options" + +ARGS="" +while true; do + + case "${1}" in + -t) + shift + [[ ! "$1" =~ ^(Debug|Release|RelWithDebInfo|MinSizeRel)$ ]] && { + echo "Incorrect type '$1' provided" + usage + } + ARGS="${ARGS} -DCMAKE_BUILD_TYPE=${1}" + ;; + --disable-threads) + ARGS="${ARGS} -DUSE_THREADS=OFF" ;; + --force-ansi) + ARGS="${ARGS} -DFORCE_ANSI=ON" ;; + -h) usage ;; + --) shift + break ;; esac + shift done -shift $((OPTIND-1)) -cmake $ARGS $@ .. +echo cmake $ARGS .. make -B popd > /dev/null