summaryrefslogtreecommitdiffstats
path: root/core/modules/vbox-src/module.build
blob: c5d89c652766d991e8be1e594d97040a2c0d9e6e (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/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 BASEVER="${REQUIRED_VBOX_VERSION}"
	# In case we have something like 1.2.3a, we need 1.2.3 for the directory name below
	[[ "${BASEVER: -1}" =~ ^[0-9]$ ]] || BASEVER="${BASEVER:0:-1}"
	local BASE_URL="http://download.virtualbox.org/virtualbox"
	local DOWNLOAD_URL="${BASE_URL}/${BASEVER}/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'."

	if [ -n "$REQUIRED_EXTPACK" ]; then
		# oracle's extension pack
		DOWNLOAD_URL="${DOWNLOAD_URL%/*}/Oracle_VM_VirtualBox_Extension_Pack-${BASEVER}.vbox-extpack"
		download_untar "$DOWNLOAD_URL" "${MODULE_WORK_DIR}/extpack" || \
			perror "Could not download_untar '$DOWNLOAD_URL' to '${MODULE_WORK_DIR}/extpack'."
		# Nice, Oracle - files in the tarball are world writable, but vbox refuses to use the extpack that way
		chmod -R go-w "${MODULE_WORK_DIR}/extpack"
	fi
}

build() {
	[ -n "${KERNEL_HEADERS_DIR}" ] || perror "KERNEL_HEADERS_DIR not set, kernel module present?"
	local BASEVER="${REQUIRED_VBOX_VERSION}"
	# In case we have something like 1.2.3a, we need 1.2.3 for the directory name below
	[[ "${BASEVER: -1}" =~ ^[0-9]$ ]] || BASEVER="${BASEVER:0:-1}"
	cd "${MODULE_WORK_DIR}/src/VirtualBox-${BASEVER}" || \
		perror "Could not cd to '${MODULE_WORK_DIR}/src/VirtualBox-${BASEVER}'."
	sed -i 's/VBOX_WITH_CLOUD_NET = 1/VBOX_WITH_CLOUD_NET =/g' "Config.kmk" || perror "Could not disable cloud networking."
	local VBOX_BUILD_DIR="${MODULE_WORK_DIR}/src/VirtualBox-${BASEVER}/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 VirtualBoxVM; 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

		if [ -n "$REQUIRED_EXTPACK" ]; then
			# 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."
		fi

		# od binary
		local OD_BIN="$(which od 2>/dev/null)"
		if [ -n "$OD_BIN" ] && [ -f "$OD_BIN" ]; then
			tarcopy "$OD_BIN" "$MODULE_BUILD_DIR"
		fi
		true
	) || perror "Failed"
}

post_copy() {
	:
}