summaryrefslogtreecommitdiff
path: root/ci/install-dependencies.sh
blob: 75cbaf6d34616221db07d284b00e0693a45994ee (plain)
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
#!/bin/sh -ex

type sudo >/dev/null 2>&1 && sudo=sudo || sudo=
common_packages='autoconf automake faketime file gawk gcc-multilib git gzip libdw-dev make pkg-config xz-utils'

updated=
apt_get_install()
{
	[ -n "$updated" ] || {
		$sudo apt-get -qq update
		updated=1
	}
	$sudo apt-get -qq --no-install-suggests --no-install-recommends \
		install -y "$@"
}

git_installed=
clone_repo()
{
	local src dst
	src="$1"; shift
	dst="$1"; shift

	[ -n "$git_installed" ] || {
		apt_get_install git ca-certificates
		git_installed=1
	}

	case "$src" in
		*://*)	;;
		*)	local url path
			url="$(git config remote.origin.url)"
			path="${url#*://*/}"
			src="${url%$path}$src"
			;;
	esac

	git clone --depth=1 "$src" "$dst"
}

case "$KHEADERS" in
	*/*)
		clone_repo https://github.com/"$KHEADERS" kernel
		apt_get_install $common_packages
		$sudo make -C kernel headers_install INSTALL_HDR_PATH=/opt/kernel
		$sudo rm -rf kernel
		KHEADERS_INC=/opt/kernel/include
		;;
	*)
		KHEADERS_INC=/usr/include
		;;
esac

case "$CC" in
	gcc)
		apt_get_install $common_packages
		;;
	gcc-*)
		$sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
		apt_get_install $common_packages "$CC"-multilib
		;;
	clang*)
		apt_get_install $common_packages "$CC"
		;;
	musl-gcc)
		clone_repo strace/musl musl
		apt_get_install $common_packages
		cd musl
			CC=gcc
			build=
			case "${TARGET-}" in
				x32)
					CC="$CC -mx32"
					;;
				x86)
					CC="$CC -m32"
					build='--build=i686-pc-linux-gnu --target=i686-pc-linux-gnu'
					;;
			esac
			./configure --prefix=/opt/musl --exec-prefix=/usr ${build}
			make
			$sudo make install
		cd -
		rm -rf musl
		$sudo ln -s \
			$KHEADERS_INC/asm* \
			$KHEADERS_INC/linux \
			$KHEADERS_INC/mtd \
			/opt/musl/include/
		;;
esac

case "${CHECK-}" in
	coverage)
		apt_get_install lcov
		pip install --user codecov
		;;
	valgrind)
		apt_get_install valgrind
		;;
esac