summaryrefslogtreecommitdiffstats
path: root/core/modules/vbox-src/module.build
blob: 36417f9e92c1c8af0ad4f9a374c65f6e898d4f40 (plain) (blame)
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
#!/bin/bash
fetch_source() {
	[ -d "${MODULE_WORK_DIR}/src" ] && rm -rf "${MODULE_WORK_DIR}/src"
	[ -z "${REQUIRED_VBOX_VERSION}" ] && perror "REQUIRED_VBOX_VERSION is not set!"

	local BASE_URL="https://download.virtualbox.org/virtualbox"
	local DOWNLOAD_URL="${BASE_URL}/${REQUIRED_VBOX_VERSION}/VirtualBox-${REQUIRED_VBOX_VERSION}.tar.bz2"
	download_untar "$DOWNLOAD_URL" "${MODULE_WORK_DIR}/src" || \
		perror "Could not download_untar '$DOWNLOAD_URL' to '${MODULE_WORK_DIR}/src'."

	# oracle's extension pack
	DOWNLOAD_URL="${DOWNLOAD_URL%/*}/Oracle_VM_VirtualBox_Extension_Pack-${REQUIRED_VBOX_VERSION}-${REQUIRED_VBOX_EXTPACK_REVISION}.vbox-extpack"
	download_untar "$DOWNLOAD_URL" "${MODULE_WORK_DIR}/extpack" || \
		perror "Could not download_untar '$DOWNLOAD_URL' to '${MODULE_WORK_DIR}/extpack'."
}

build() {
	[ -n "${KERNEL_HEADERS_DIR}" ] || perror "KERNEL_HEADERS_DIR not set, kernel module present?"
	cd "${MODULE_WORK_DIR}/src/VirtualBox-${REQUIRED_VBOX_VERSION}" || \
		perror "Could not cd to '${MODULE_WORK_DIR}/src/VirtualBox-${REQUIRED_VBOX_VERSION}'."
	local VBOX_BUILD_DIR="${MODULE_WORK_DIR}/src/VirtualBox-${REQUIRED_VBOX_VERSION}/build"
	mkdir -p "$VBOX_BUILD_DIR" || perror "Failed to mkdir '$VBOX_BUILD_DIR'."
	./configure \
		--disable-docs				\
		--disable-java				\
		--disable-python			\
		--disable-libvpx			\
		--with-linux="${KERNEL_HEADERS_DIR}"	\
		--out-path="${VBOX_BUILD_DIR}"	\
			|| perror "'configure' failed."

	# the configure script should have created a file called 'env.sh'
	source "${VBOX_BUILD_DIR}/env.sh" || perror "Failed to source '${VBOX_BUILD_DIR}/env.sh'."
	# copy the LocalConfig.kmk to the build dir to be more LSB-compliant
	cp "${MODULE_DIR}/LocalConfig.kmk" "${VBOX_BUILD_DIR}" || \
		perror "Failed to cp LocalConfig.kmk to build dir"
	kmk all || perror "Failed to execute 'kmk'."

	# check the generated build directory, use BUILD_PLATFORM_ARCH defined in env.sh
	local VBOX_RELEASE_BUILD_DIR="${VBOX_BUILD_DIR}/linux.${BUILD_PLATFORM_ARCH}/release"
	[ -d "${VBOX_RELEASE_BUILD_DIR}" ] || \
		perror "No release build dir found under '${VBOX_RELEASE_BUILD_DIR}'. Build failed?"

	# the resulting linux.<arch>/release/bin folder contains the whole build,
	# copy it over to usr/lib/virtualbox
	mkdir -p "${MODULE_BUILD_DIR}/usr/lib/virtualbox" || \
		perror "Failed to mkdir '${MODULE_BUILD_DIR}/usr/lib/virtualbox'."
	cp -r "${VBOX_RELEASE_BUILD_DIR}/bin/"* "${MODULE_BUILD_DIR}/usr/lib/virtualbox" || \
		perror "Failed to cp -r '${VBOX_RELEASE_BUILD_DIR}/bin' to '${MODULE_BUILD_DIR}/usr/lib/virtualbox'."

	# set suid bits
	for BIN in VBoxHeadless VBoxNetAdpCtl VBoxNetDHCP VBoxSDL VBoxVolInfo VirtualBox VBoxNetAdpCtl; do
		if ! [ -e "${MODULE_BUILD_DIR}/usr/lib/virtualbox/$BIN" ]; then
			pwarning "No such file: '${MODULE_BUILD_DIR}/usr/lib/virtualbox/$BIN', cannot add suid bit."
			continue
		fi
		chmod u+s "${MODULE_BUILD_DIR}/usr/lib/virtualbox/${BIN}" || perror "Failed to set suid bit on '${BIN}'."
	done

	## Kernel modules
	# build kernel modules from the release dir
	cd "${VBOX_RELEASE_BUILD_DIR}/bin/src" || \
		perror "Failed to cd to '${VBOX_RELEASE_BUILD_DIR}/bin/src'."
	make \
		KERN_DIR="${KERNEL_HEADERS_DIR}" \
		KERN_VER="${TARGET_KERNEL_LONG}" \
			|| perror "Build kernel modules failed."
	# check they were, in fact, built and copy them to build dir
	mkdir -p "${MODULE_BUILD_DIR}/lib/modules/vbox" || \
		perror "Failed to mkdir '${MODULE_BUILD_DIR}/lib/modules/vbox'."
	for MOD in $(find * -maxdepth 0 -type d); do
		[ -e "$MOD.ko" ] || perror "Module '$MOD' was not built!"
		cp "$MOD.ko" "${MODULE_BUILD_DIR}/lib/modules/vbox/" || \
			perror "Failed to cp $MOD.ko to '${MODULE_BUILD_DIR}/lib/modules/vbox/'."
	done

	# finally copy the extension pack files, everthing is needed as the subfolders
	# target the guest architectures and not that of the host!
	local VBOX_EXTPACK_DIR="${MODULE_BUILD_DIR}/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack"
	cp -ar "${MODULE_WORK_DIR}/extpack" "${VBOX_EXTPACK_DIR}" || \
		perror "Failed to cp '${MODULE_WORK_DIR}/extpack' to '${VBOX_EXTPACK_DIR}'."
	chown -R root:root "${VBOX_EXTPACK_DIR}" || \
		perror "Failed to chown '${VBOX_EXTPACK_DIR}' to root:root."

	# od binary
	local OD_BIN="$(which od 2>/dev/null)"
	if [ -n "$OD_BIN" -a -e "$OD_BIN" ]; then
		tarcopy "$OD_BIN" "$MODULE_BUILD_DIR"
	fi
}

post_copy() {
	:
}