-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabuild
executable file
·71 lines (59 loc) · 1.53 KB
/
abuild
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
#!/bin/bash
die() {
echo "$@"
exit 1
}
has_word() {
keyword="$1"
shift
grep -qw -- "$keyword" <(echo "$@")
}
glob_exists() {
compgen -G "$1" &>/dev/null
}
if has_word "-h" "$@"; then
cat <<EOL
Usage: $0 [debug|release]
Try to detect build method and automatically build the files.
Currently only supports Qt .pro and CMakeList.txt with make
Options:
debug If provided, will force debug build type.
release If provided, will force release build type.
EOL
exit 1
fi
if ! echo "$PATH" | grep -q ccache; then
ccache_path=/usr/lib/ccache
[ -d "$ccache_path/bin" ] &&
ccache_path=/usr/lib/ccache/bin
PATH="$ccache_path:$PATH"
fi
build_dir=".build"
source_dir="$(realpath --relative-to "$build_dir" ".")"
if [ -f CMakeLists.txt ]; then
PREBUILD_DEBUG_FLAG="-DCMAKE_BUILD_TYPE=Debug"
PREBUILD_RELEASE_FLAG="-DCMAKE_BUILD_TYPE=Release"
PREBUILD_COMMAND=( "cmake" "$source_dir" )
BUILD_COMMAND="make"
elif glob_exists "*.pro"; then
PREBUILD_DEBUG_FLAG="CONFIG+=debug"
PREBUILD_RELEASE_FLAG="CONFIG+=release"
PREBUILD_COMMAND=("qmake" "$source_dir")
BUILD_COMMAND="make"
fi
if has_word "debug" "$@" && has_word "release" "$@"; then
die "Only one build type allowed, but multiple provided"
fi
if has_word "debug" "$@"; then
PREBUILD_COMMAND+=("$PREBUILD_DEBUG_FLAG")
elif has_word "release" "$@"; then
PREBUILD_COMMAND+=("$PREBUILD_RELEASE_FLAG")
fi
mkdir -p "$build_dir"
(
if ! cd "$build_dir"; then
die "Failed to enter build directory."
fi
"${PREBUILD_COMMAND[@]}"
$BUILD_COMMAND
)