forked from ARM-software/LLVM-embedded-toolchain-for-Arm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-common.sh
executable file
·103 lines (88 loc) · 2.34 KB
/
build-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
97
98
99
100
101
102
103
#!/bin/bash
#
# Copyright (c) 2020, Arm Limited and affiliates.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file contains common routines, shared amongst components build scripts.
error () {
set +u
echo "$0: error: $@" >&2
set -u
exit 1
}
warning () {
set +u
echo "$0: warning: $@" >&2
set -u
}
checkPrograms () {
for p in $@; do
local prog=`which $p`
if [ -z $prog ]; then
error "'$p' is required to build the toolchain."
fi
done
}
moveMerge () {
local SRC_DIR="$1"
local DEST_DIR="$2"
(cd "$SRC_DIR" && \
find . -type d -exec mkdir -p "$DEST_DIR"/\{} \; && \
find . -type f -exec mv \{} "$DEST_DIR"/\{} \; && \
find . -type d -empty -delete)
}
# Clean DIR if it exists, or create an empty one, and pushd to it.
pushToCleanDir () {
local DIR="$1"
[ -d $DIR ] && rm -Rf $DIR
mkdir -p $DIR
pushd $DIR
}
# Build using either ninja or make
build () {
if [ $USE_NINJA -ne 0 ]; then
ninja "$@"
else
make -j$NPROC "$@"
fi
}
# Install using either ninja or make
install () {
if [ $USE_NINJA -ne 0 ]; then
ninja install
else
make install
fi
}
# Get the CMake generator to use
cmakeUseGenerator () {
if [ $USE_NINJA -ne 0 ]; then
echo "-G Ninja"
fi
}
# Tell CMake to use ccache
cmakeUseCCache () {
if [ $USE_CCACHE -ne 0 ]; then
echo "-DCMAKE_C_COMPILER_LAUNCHER:STRING=ccache -DCMAKE_CXX_COMPILER_LAUNCHER:STRING=ccache"
fi
}
# Return whether the first version is less than the second one. Comparison uses
# natural sort of version numbers. For instance, calling
# `versionLessThan 3.10.1 3.5.2` yields 0.
versionLessThan () {
[ "$1" != "$2" ] && [ "$1" = "$(printf "$1\n$2\n" | sort -V | head -n1)" ]
}
export -f error warning checkPrograms moveMerge pushToCleanDir build install \
cmakeUseGenerator cmakeUseCCache versionLessThan