-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·54 lines (46 loc) · 1.71 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
BUILD_DIR="bin";
BASE_DIR="$(pwd)";
# setup color variables
if [[ -t 1 ]]; then
COLOR_MODE=`tput colors`;
if [[ -n "$COLOR_MODE" ]] && [[ "$COLOR_MODE" -ge 8 ]]; then
TITLE="\x1b[36m"; # cyan
RED="\x1b[31m";
ERROR="\x1b[31;1m"; # BOLD RED
SUCCESS="\x1b[32m"; # GREEN
RESET="\x1b[0m";
fi
fi
doing() { echo -e "${TITLE}[.] $1 ...${RESET}"; }
fail() { echo -e "${ERROR}[-] fail: $1 ${RESET}"; }
fatal() { fail "$1"; exit 1; }
success() { echo -e "${SUCCESS}[~] success: $1 ${RESET}"; }
end() { [[ $1 == 0 ]] &&
echo -e "${SUCCESS}[+] exit $1${RESET}" ||
echo -e "${ERROR}[+] exit $1${RESET}"; exit $1; }
# ===================================================================
# __ __ _ _____ _
# | \/ | __ _(_)_ __ | ____|_ __ | |_ _ __ _ _
# | |\/| |/ _` | | '_ \ | _| | '_ \| __| '__| | | |
# | | | | (_| | | | | | | |___| | | | |_| | | |_| |
# |_| |_|\__,_|_|_| |_| |_____|_| |_|\__|_| \__, |
# |___/
# ===================================================================
doing "checking build target directory";
if [[ ! -e "$BUILD_DIR" ]]; then
mkdir -p "$BUILD_DIR" && success "created build target directory \"${BUILD_DIR}\"" ||
fatal "could not create build target directory \"${BUILD_DIR}\"";
else
success "build target directory \"${BUILD_DIR}\" is existed";
fi
doing "executing cmake";
pushd "$BUILD_DIR";
if [[ -e "Makefile" ]]; then
success "skip cmake (because Makefile has been generated!)";
else
cmake "${BASE_DIR}" && success "cmake success!" || fatal "cmake failed!";
fi
doing "making";
make -j4 && success "make success!" || fatal "make failed!";
exit 0;