-
Notifications
You must be signed in to change notification settings - Fork 653
/
build-util.sh
executable file
·97 lines (84 loc) · 2.64 KB
/
build-util.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
# Derived from
# https://github.com/riscv/riscv-tools/blob/master/build.common
[ -n "${SRCDIR}" ] || exit 1
# Scale number of parallel make jobs by hardware thread count
ncpu="${NPROC:-$(getconf _NPROCESSORS_ONLN || # GNU
getconf NPROCESSORS_ONLN || # *BSD, Solaris
nproc --all || # Linux
sysctl -n hw.ncpu || # *BSD, OS X
:)}" 2>/dev/null
case ${ncpu} in
''|*[!0-9]*) ;; # Ignore non-integer values
*) export MAKEFLAGS="-j ${ncpu} ${MAKEFLAGS}" ;;
esac
# Allow user to override MAKE
[ -n "${MAKE:+x}" ] || MAKE=$(command -v gnumake || command -v gmake || command -v make)
readonly MAKE
module_prepare() ( # <submodule> [ignored-submodule..]
set -e
name=$1
shift
dir="${SRCDIR}/${name}"
echo "=> Starting ${name} build"
echo "==> Initializing ${name} submodule"
if [ $# -gt 0 ] ; then
(set -x; git submodule update --init "${dir}")
while [ -n "$1" ] ; do
(set -x; git -C "${dir}" config submodule."${1}".update none)
shift
done
fi
(set -x; git submodule update --init --recursive "${dir}")
)
module_run() ( # <submodule> <command..>
set -e
echo "=> cd ${SRCDIR}/${1}"
cd "${SRCDIR}/${1}"
shift
(set -x; "$@")
)
module_make() ( # <submodule> <target..>
set -e -o pipefail
build_dir="${SRCDIR}/${1}/build"
shift
(set -x; "${MAKE}" -C "$build_dir" "$@") | tee "build-${1:-make}.log"
if [ -n "$CLEANAFTERINSTALL" ] ; then
(set -x; "${MAKE}" -C "$build_dir" clean) # get rid of intermediate files
fi
)
module_build() ( # <submodule> [configure-arg..]
set -e -o pipefail
name=$1
shift
echo "==> cd ${SRCDIR}/${name}"
cd "${SRCDIR}/${name}"
if [ -e build ] ; then
echo "==> Removing existing ${name}/build directory"
(set -x; rm -rf build)
fi
if ! [ -e configure ] ; then
echo "==> Updating autoconf files for ${name}"
find . -iname configure.ac -type f -print0 |
while read -r -d '' file ; do
(set -x; mkdir -p -- "${file%/*}/m4")
done
(set -x; autoreconf -i)
fi
(set -x; mkdir -p build)
{
export PATH="${RISCV:+${RISCV}/bin:}${PATH}"
echo "==> Configuring ${name}"
(set -x; cd build && ../configure "$@")
echo "==> Building ${name}"
(set -x; "${MAKE}" -C build)
echo "==> Installing ${name}"
(set -x; "${MAKE}" -C build install)
if [ -n "$CLEANAFTERINSTALL" ] ; then
(set -x; "${MAKE}" -C build clean) # get rid of intermediate files
fi
} 2>&1 | tee build.log
)
module_all() { # <submodule> [configure-arg..]
module_prepare "$1"
module_build "$@"
}