This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
common.sh
executable file
·96 lines (83 loc) · 1.81 KB
/
common.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
SOURCE_DIR=${PWD}/source
BUILD_DIR=${PWD}/build
OUTPUT_DIR=${PWD}/output
MAKE_JOBS=$(nproc)
COLOR_STATUS=$'\033[1m\033[32m'
COLOR_RESET=$'\033[0m'
show_status() {
echo "$COLOR_STATUS=> $1$COLOR_RESET"
}
check_run() {
"$@"
local STATUS=$?
if (( $STATUS != 0 )); then
exit $STATUS
fi
}
shopt -s nullglob
load_quirks() {
if [ ! -z "$1" ]; then
show_status "Loading quirks file: $1"
source "$1"
fi
}
call_quirk() {
local QUIRK_NAME="quirk_$1"
QUIRK_NAME=`declare -f -F "$QUIRK_NAME"`
if (( $? == 0 )); then
show_status "Executing $QUIRK_NAME"
$QUIRK_NAME
fi
}
create_build_directories() {
mkdir -p $SOURCE_DIR
mkdir -p $BUILD_DIR
mkdir -p $OUTPUT_DIR
}
download_repo() {
if [ -d $SOURCE_DIR/$1 ]; then
show_status "Updating $2"
pushd $SOURCE_DIR/$1
check_run git fetch origin $3
check_run git reset --hard FETCH_HEAD
check_run git submodule update --init --recursive
popd
else
show_status "Downloading $2"
mkdir -p $SOURCE_DIR/$1
pushd $SOURCE_DIR/$1
check_run git init
check_run git remote add origin $2
check_run git fetch origin $3
check_run git reset --hard FETCH_HEAD
check_run git submodule update --init --recursive
popd
fi
}
reset_cmake_options() {
CMAKE_OPTIONS=()
}
add_cmake_options() {
CMAKE_OPTIONS=("${CMAKE_OPTIONS[@]}" "$@")
}
build_component() {
show_status "Building $1"
mkdir -p $BUILD_DIR/$1
pushd $BUILD_DIR/$1
echo "cmake" $CMAKE_OPTIONS "$SOURCE_DIR/$1"
check_run cmake "${CMAKE_OPTIONS[@]}" "$SOURCE_DIR/$1"
check_run make -j${MAKE_JOBS}
popd
}
install_component_cpack() {
pushd $OUTPUT_DIR
for cf in $BUILD_DIR/$1/**/CPackConfig.cmake; do
echo "CPack config: $cf"
check_run cpack --config $cf
done
popd
}
cleanup_build() {
rm -rf $OUTPUT_DIR/_CPack_Packages
}