-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·82 lines (69 loc) · 1.87 KB
/
build
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# Copyright 2023-2024 GlitchyByte
# SPDX-License-Identifier: MIT-0
# Builds project.
# [Setup]
set -u # Exit with an error if a variable is used without being set.
set -e # Exit if any command returns an error.
# Capture caller directory and script directory.
readonly calling_dir="${PWD}"
readonly script_dir="$(cd "$(dirname "$0")" && pwd)"
# Go to script directory and load utilities.
cd "${script_dir}"
. ./_gcolors
# [Main]
# Usage.
printUsage() {
echo "Usage: build [Debug|Release|MinSizeRel|RelWithDebInfo] [clean]"
cd "${calling_dir}"
exit 1
}
# Accept 1 or more parameters.
if [ $# -lt 1 ]; then
printUsage
fi
# If there is more than 1 parameter, the 2nd must be "clean".
if [ $# -gt 1 ]; then
if [ "$2" == "clean" ]; then
readonly clean="yes"
else
printUsage
fi
else
readonly clean="no"
fi
# Capture valid flavor.
readonly flavor="$1"
if [[ "${flavor}" != "Debug" && "${flavor}" != "Release" && "${flavor}" != "MinSizeRel" && "${flavor}" != "RelWithDebInfo" ]]; then
printUsage
fi
# Dir constants.
cd "${script_dir}/code"
readonly buildConfigDir="build/build.cmake"
readonly binDir="build/bin"
# Make sure build dir exists.
if [ ! -d "build" ]; then
mkdir "build"
fi
if [ "$clean" == "yes" ]; then
echo "${c_bold}${cf_black}Refreshing configuration...${c_reset}"
# Remove build dir.
if [ -d "${buildConfigDir}" ]; then
rm -dr "${buildConfigDir}"
fi
# Clean bin dir.
if [ -d "${binDir}" ]; then
rm -dr "${binDir}"
mkdir "${binDir}"
fi
fi
# Configure.
echo "${c_bold}${cf_black}Configuring: ${cf_white}${flavor}${c_reset}"
cmake -DCMAKE_BUILD_TYPE=${flavor} -B "${buildConfigDir}" -S .
# Build.
echo "${c_bold}${cf_black}Building: ${cf_white}${flavor}${c_reset}"
cmake --build "${buildConfigDir}" --config ${flavor} --parallel
# [Teardown]
cd "${calling_dir}"
# Done!
echo "${cf_green}${c_bold}Build done!${c_reset}"