-
-
Save justinmk/1a06be60062852d7861e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if test -t 1; then | |
COLOR_FAIL="\e[31;1m" | |
COLOR_SUCCESS="\e[32;1m" | |
COLOR_BUILD_HEADING="\e[34;1m" | |
COLOR_OTHER_HEADING="\e[35m" | |
COLOR_RESET="\e[0m" | |
fi | |
say_fail() { | |
printf "${COLOR_FAIL}$1${COLOR_RESET}\n" | |
} | |
say_success() { | |
printf "${COLOR_SUCCESS}$1${COLOR_RESET}\n" | |
} | |
say_build_heading() { | |
printf "${COLOR_BUILD_HEADING}$1\n$(echo -n "$1" | tr 'a-zA-Z_' '=')${COLOR_RESET}\n" | |
} | |
say_other_heading() { | |
printf "${COLOR_OTHER_HEADING}$1\n$(echo -n "$1" | tr 'a-zA-Z_' '=')${COLOR_RESET}\n" | |
} | |
CN=cninja | |
EXTRA_TARGETS=all | |
TIME_CMD= | |
while [[ $# > 0 ]] | |
do | |
key="$1" | |
shift | |
case $key in | |
debug) | |
BUILD_TYPES="${BUILD_TYPES} Debug" | |
;; | |
rdebug) | |
BUILD_TYPES="${BUILD_TYPES} RelWithDebInfo" | |
;; | |
release) | |
BUILD_TYPES="${BUILD_TYPES} Release" | |
;; | |
-c|--clean) | |
CLEAN="true" | |
;; | |
-v|--verbose) | |
VERBOSE=true | |
CN="$CN -v" | |
;; | |
-u|--unittest) | |
EXTRA_TARGETS="$EXTRA_TARGETS unittest" | |
;; | |
-t|--time) | |
TIME_CMD=time | |
;; | |
--no-ccache) | |
export CCACHE_DISABLE=1 | |
;; | |
*) | |
if [[ "$key" == -* ]] | |
then | |
# unknown option | |
echo 1>&2 "Unknown option '$key'" | |
exit 1 | |
else | |
EXTRA_TARGETS="$EXTRA_TARGETS $key" | |
fi | |
;; | |
esac | |
done | |
BUILD_TYPES="${BUILD_TYPES:-Debug RelWithDebInfo Release}" | |
# Ensure deps is built | |
say_other_heading "Deps" | |
if [ -n "${VERBOSE}" ]; then | |
make deps || exit 1 | |
else | |
make deps > /dev/null || exit 1 | |
fi | |
echo | |
failed= | |
for build in ${BUILD_TYPES} | |
do | |
say_build_heading "${build}" | |
build_dir="build/$(echo "${build}" | perl -pe 's/([A-Z])/-\l\1/g' | cut -c 2-)" | |
if [ -n "${CLEAN}" ]; then | |
rm -rf "${build_dir}" | |
fi | |
mkdir -p "${build_dir}" | |
pushd "${build_dir}" > /dev/null 2>&1 | |
generate="cmake -G Ninja '-DCMAKE_BUILD_TYPE=${build}' ../.." | |
if [ -z "${VERBOSE}" ]; then | |
generate="${generate} > /dev/null" | |
fi | |
test -e CMakeCache.txt || { | |
eval "${generate}" || failed=true | |
} | |
test -e CMakeCache.txt && ${TIME_CMD} ${CN} ${EXTRA_TARGETS} || failed=true | |
popd > /dev/null 2>&1 | |
echo | |
done | |
if [ -n "${failed}" ]; then | |
say_fail "BUILD_FAILED" | |
exit 1 | |
else | |
say_success "Build succeeded" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment