1 | #!/bin/sh
|
---|
2 | # $Id$
|
---|
3 | ## @file
|
---|
4 | # Create a tar archive containing the sources of the vboxdrv kernel module.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2007-2020 Oracle Corporation
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 | # The contents of this file may alternatively be used under the terms
|
---|
19 | # of the Common Development and Distribution License Version 1.0
|
---|
20 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | # CDDL are applicable instead of those of the GPL.
|
---|
23 | #
|
---|
24 | # You may elect to license modified versions of this file under the
|
---|
25 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | #
|
---|
27 |
|
---|
28 | # The below is GNU-specific. See VBox.sh for the longer Solaris/OS X version.
|
---|
29 | TARGET=`readlink -e -- "${0}"` || exit 1
|
---|
30 | MY_DIR="${TARGET%/[!/]*}"
|
---|
31 |
|
---|
32 | # What this script does:
|
---|
33 | usage_msg="\
|
---|
34 | Usage: `basename ${0}` --file <path>|--folder <path> [--without-hardening]
|
---|
35 |
|
---|
36 | Exports the VirtualBox host kernel modules to the tar.gz archive or folder in \
|
---|
37 | <path>, optionally adjusting the Make files to build them without hardening.
|
---|
38 |
|
---|
39 | Examples:
|
---|
40 | `basename ${0}` --file /tmp/vboxhost.tar.gz
|
---|
41 | `basename ${0}` --folder /tmp/tmpdir --without-hardening"
|
---|
42 |
|
---|
43 | usage()
|
---|
44 | {
|
---|
45 | case "${1}" in
|
---|
46 | 0)
|
---|
47 | echo "${usage_msg}" | fold -s -w80 ;;
|
---|
48 | *)
|
---|
49 | echo "${usage_msg}" | fold -s -w80 >&2 ;;
|
---|
50 | esac
|
---|
51 | exit "${1}"
|
---|
52 | }
|
---|
53 |
|
---|
54 | fail()
|
---|
55 | {
|
---|
56 | echo "${1}" | fold -s -w80 >&2
|
---|
57 | exit 1
|
---|
58 | }
|
---|
59 |
|
---|
60 | unset FILE FOLDER
|
---|
61 | VBOX_WITH_HARDENING=1
|
---|
62 | while test -n "${1}"; do
|
---|
63 | case "${1}" in
|
---|
64 | --file)
|
---|
65 | FILE="${2}"
|
---|
66 | shift 2 ;;
|
---|
67 | --folder)
|
---|
68 | FOLDER="${2}"
|
---|
69 | shift 2 ;;
|
---|
70 | --without-hardening)
|
---|
71 | unset VBOX_WITH_HARDENING
|
---|
72 | shift ;;
|
---|
73 | -h|--help)
|
---|
74 | usage 0 ;;
|
---|
75 | *)
|
---|
76 | echo "Unknown parameter ${1}" >&2
|
---|
77 | usage 1 ;;
|
---|
78 | esac
|
---|
79 | done
|
---|
80 | test -z "$FILE" || test -z "$FOLDER" ||
|
---|
81 | fail "Only one of --file and --folder may be used"
|
---|
82 | test -n "$FILE" || test -n "$FOLDER" || usage 1
|
---|
83 |
|
---|
84 | if test -n "$FOLDER"; then
|
---|
85 | PATH_TMP="$FOLDER"
|
---|
86 | else
|
---|
87 | PATH_TMP="`cd \`dirname $FILE\`; pwd`/.vbox_modules"
|
---|
88 | FILE_OUT="`cd \`dirname $FILE\`; pwd`/`basename $FILE`"
|
---|
89 | fi
|
---|
90 | PATH_OUT=$PATH_TMP
|
---|
91 | PATH_ROOT="`cd ${MY_DIR}/../../../..; pwd`"
|
---|
92 | PATH_LOG=/tmp/vbox-export-host.log
|
---|
93 | PATH_LINUX="$PATH_ROOT/src/VBox/HostDrivers/linux"
|
---|
94 | PATH_VBOXDRV="$PATH_ROOT/src/VBox/HostDrivers/Support"
|
---|
95 | PATH_VBOXNET="$PATH_ROOT/src/VBox/HostDrivers/VBoxNetFlt"
|
---|
96 | PATH_VBOXADP="$PATH_ROOT/src/VBox/HostDrivers/VBoxNetAdp"
|
---|
97 | PATH_VBOXPCI="$PATH_ROOT/src/VBox/HostDrivers/VBoxPci"
|
---|
98 |
|
---|
99 | VBOX_VERSION_MAJOR=`sed -e "s/^ *VBOX_VERSION_MAJOR *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
|
---|
100 | VBOX_VERSION_MINOR=`sed -e "s/^ *VBOX_VERSION_MINOR *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
|
---|
101 | VBOX_VERSION_BUILD=`sed -e "s/^ *VBOX_VERSION_BUILD *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
|
---|
102 | VBOX_VERSION_STRING=$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD
|
---|
103 | VBOX_VERSION_BUILD=`sed -e "s/^ *VBOX_VERSION_BUILD *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
|
---|
104 | VBOX_SVN_CONFIG_REV=`sed -e 's/^ *VBOX_SVN_REV_CONFIG_FALLBACK *:= \+\$(patsubst *%:,, *\$Rev: *\([0-9]\+\) *\$ *) */\1/;t;d' $PATH_ROOT/Config.kmk`
|
---|
105 | VBOX_SVN_VERSION_REV=`sed -e 's/^ *VBOX_SVN_REV_VERSION_FALLBACK *:= \+\$(patsubst *%:,, *\$Rev: *\([0-9]\+\) *\$ *) */\1/;t;d' $PATH_ROOT/Version.kmk`
|
---|
106 | if [ "$VBOX_SVN_CONFIG_REV" -gt "$VBOX_SVN_VERSION_REV" ]; then
|
---|
107 | VBOX_SVN_REV=$VBOX_SVN_CONFIG_REV
|
---|
108 | else
|
---|
109 | VBOX_SVN_REV=$VBOX_SVN_VERSION_REV
|
---|
110 | fi
|
---|
111 | VBOX_VENDOR=`sed -e 's/^ *VBOX_VENDOR *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`
|
---|
112 | VBOX_VENDOR_SHORT=`sed -e 's/^ *VBOX_VENDOR_SHORT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`
|
---|
113 | VBOX_PRODUCT=`sed -e 's/^ *VBOX_PRODUCT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`
|
---|
114 | VBOX_C_YEAR=`date +%Y`
|
---|
115 | VBOX_WITH_PCI_PASSTHROUGH=`sed -e "s/^ *VBOX_WITH_PCI_PASSTHROUGH *= *\(1\?\)/\1/;t;d" $PATH_ROOT/Config.kmk`
|
---|
116 |
|
---|
117 | . $PATH_VBOXDRV/linux/files_vboxdrv
|
---|
118 | . $PATH_VBOXNET/linux/files_vboxnetflt
|
---|
119 | . $PATH_VBOXADP/linux/files_vboxnetadp
|
---|
120 | if [ "$VBOX_WITH_PCI_PASSTHROUGH" -eq "1" ]; then
|
---|
121 | . $PATH_VBOXPCI/linux/files_vboxpci
|
---|
122 | fi
|
---|
123 |
|
---|
124 | # Temporary path for creating the modules, will be removed later
|
---|
125 | rm -rf "$PATH_TMP"
|
---|
126 | mkdir $PATH_TMP || exit 1
|
---|
127 |
|
---|
128 | # Create auto-generated version file, needed by all modules
|
---|
129 | echo "#ifndef ___version_generated_h___" > $PATH_TMP/version-generated.h
|
---|
130 | echo "#define ___version_generated_h___" >> $PATH_TMP/version-generated.h
|
---|
131 | echo "" >> $PATH_TMP/version-generated.h
|
---|
132 | echo "#define VBOX_VERSION_MAJOR $VBOX_VERSION_MAJOR" >> $PATH_TMP/version-generated.h
|
---|
133 | echo "#define VBOX_VERSION_MINOR $VBOX_VERSION_MINOR" >> $PATH_TMP/version-generated.h
|
---|
134 | echo "#define VBOX_VERSION_BUILD $VBOX_VERSION_BUILD" >> $PATH_TMP/version-generated.h
|
---|
135 | echo "#define VBOX_VERSION_STRING_RAW \"$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD\"" >> $PATH_TMP/version-generated.h
|
---|
136 | echo "#define VBOX_VERSION_STRING \"$VBOX_VERSION_STRING\"" >> $PATH_TMP/version-generated.h
|
---|
137 | echo "#define VBOX_API_VERSION_STRING \"${VBOX_VERSION_MAJOR}_${VBOX_VERSION_MINOR}\"" >> $PATH_TMP/version-generated.h
|
---|
138 | echo "#define VBOX_PRIVATE_BUILD_DESC \"Private build with export_modules\"" >> $PATH_TMP/version-generated.h
|
---|
139 | echo "" >> $PATH_TMP/version-generated.h
|
---|
140 | echo "#endif" >> $PATH_TMP/version-generated.h
|
---|
141 |
|
---|
142 | # Create auto-generated revision file, needed by all modules
|
---|
143 | echo "#ifndef __revision_generated_h__" > $PATH_TMP/revision-generated.h
|
---|
144 | echo "#define __revision_generated_h__" >> $PATH_TMP/revision-generated.h
|
---|
145 | echo "" >> $PATH_TMP/revision-generated.h
|
---|
146 | echo "#define VBOX_SVN_REV $VBOX_SVN_REV" >> $PATH_TMP/revision-generated.h
|
---|
147 | echo "" >> $PATH_TMP/revision-generated.h
|
---|
148 | echo "#endif" >> $PATH_TMP/revision-generated.h
|
---|
149 |
|
---|
150 | # Create auto-generated product file, needed by all modules
|
---|
151 | echo "#ifndef ___product_generated_h___" > $PATH_TMP/product-generated.h
|
---|
152 | echo "#define ___product_generated_h___" >> $PATH_TMP/product-generated.h
|
---|
153 | echo "" >> $PATH_TMP/product-generated.h
|
---|
154 | echo "#define VBOX_VENDOR \"$VBOX_VENDOR\"" >> $PATH_TMP/product-generated.h
|
---|
155 | echo "#define VBOX_VENDOR_SHORT \"$VBOX_VENDOR_SHORT\"" >> $PATH_TMP/product-generated.h
|
---|
156 | echo "" >> $PATH_TMP/product-generated.h
|
---|
157 | echo "#define VBOX_PRODUCT \"$VBOX_PRODUCT\"" >> $PATH_TMP/product-generated.h
|
---|
158 | echo "#define VBOX_C_YEAR \"$VBOX_C_YEAR\"" >> $PATH_TMP/product-generated.h
|
---|
159 | echo "" >> $PATH_TMP/product-generated.h
|
---|
160 | echo "#endif" >> $PATH_TMP/product-generated.h
|
---|
161 |
|
---|
162 | # vboxdrv (VirtualBox host kernel module)
|
---|
163 | mkdir $PATH_TMP/vboxdrv || exit 1
|
---|
164 | for f in $FILES_VBOXDRV_NOBIN; do
|
---|
165 | install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxdrv/`echo $f|cut -d'>' -f2`"
|
---|
166 | done
|
---|
167 | for f in $FILES_VBOXDRV_BIN; do
|
---|
168 | install -D -m 0755 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxdrv/`echo $f|cut -d'>' -f2`"
|
---|
169 | done
|
---|
170 | if [ -n "$VBOX_WITH_HARDENING" ]; then
|
---|
171 | sed -e "s;VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV;;g" \
|
---|
172 | -e "s;IPRT_WITH_EFLAGS_AC_PRESERVING;;g" \
|
---|
173 | < $PATH_VBOXDRV/linux/Makefile > $PATH_TMP/vboxdrv/Makefile
|
---|
174 | else
|
---|
175 | sed -e "s;VBOX_WITH_HARDENING;;g" \
|
---|
176 | -e "s;VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV;;g" \
|
---|
177 | -e "s;IPRT_WITH_EFLAGS_AC_PRESERVING;;g" \
|
---|
178 | < $PATH_VBOXDRV/linux/Makefile > $PATH_TMP/vboxdrv/Makefile
|
---|
179 | fi
|
---|
180 |
|
---|
181 | # vboxnetflt (VirtualBox netfilter kernel module)
|
---|
182 | mkdir $PATH_TMP/vboxnetflt || exit 1
|
---|
183 | for f in $VBOX_VBOXNETFLT_SOURCES; do
|
---|
184 | install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxnetflt/`echo $f|cut -d'>' -f2`"
|
---|
185 | done
|
---|
186 | if [ -n "$VBOX_WITH_HARDENING" ]; then
|
---|
187 | cat $PATH_VBOXNET/linux/Makefile > $PATH_TMP/vboxnetflt/Makefile
|
---|
188 | else
|
---|
189 | sed -e "s;VBOX_WITH_HARDENING;;g" < $PATH_VBOXNET/linux/Makefile > $PATH_TMP/vboxnetflt/Makefile
|
---|
190 | fi
|
---|
191 |
|
---|
192 | # vboxnetadp (VirtualBox network adapter kernel module)
|
---|
193 | mkdir $PATH_TMP/vboxnetadp || exit 1
|
---|
194 | for f in $VBOX_VBOXNETADP_SOURCES; do
|
---|
195 | install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxnetadp/`echo $f|cut -d'>' -f2`"
|
---|
196 | done
|
---|
197 | if [ -n "$VBOX_WITH_HARDENING" ]; then
|
---|
198 | cat $PATH_VBOXADP/linux/Makefile > $PATH_TMP/vboxnetadp/Makefile
|
---|
199 | else
|
---|
200 | sed -e "s;VBOX_WITH_HARDENING;;g" < $PATH_VBOXADP/linux/Makefile > $PATH_TMP/vboxnetadp/Makefile
|
---|
201 | fi
|
---|
202 |
|
---|
203 | # vboxpci (VirtualBox host PCI access kernel module)
|
---|
204 | if [ "$VBOX_WITH_PCI_PASSTHROUGH" -eq "1" ]; then
|
---|
205 | mkdir $PATH_TMP/vboxpci || exit 1
|
---|
206 | for f in $VBOX_VBOXPCI_SOURCES; do
|
---|
207 | install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxpci/`echo $f|cut -d'>' -f2`"
|
---|
208 | done
|
---|
209 | if [ -n "$VBOX_WITH_HARDENING" ]; then
|
---|
210 | cat $PATH_VBOXPCI/linux/Makefile > $PATH_TMP/vboxpci/Makefile
|
---|
211 | else
|
---|
212 | sed -e "s;VBOX_WITH_HARDENING;;g" < $PATH_VBOXPCI/linux/Makefile > $PATH_TMP/vboxpci/Makefile
|
---|
213 | fi
|
---|
214 | fi
|
---|
215 |
|
---|
216 | install -D -m 0644 $PATH_LINUX/Makefile $PATH_TMP/Makefile
|
---|
217 | install -D -m 0755 $PATH_LINUX/build_in_tmp $PATH_TMP/build_in_tmp
|
---|
218 |
|
---|
219 | # Only temporary, omit from archive
|
---|
220 | rm $PATH_TMP/version-generated.h
|
---|
221 | rm $PATH_TMP/revision-generated.h
|
---|
222 | rm $PATH_TMP/product-generated.h
|
---|
223 |
|
---|
224 | # If we are exporting to a folder then stop now.
|
---|
225 | test -z "$FOLDER" || exit 0
|
---|
226 |
|
---|
227 | # Do a test build
|
---|
228 | echo Doing a test build, this may take a while.
|
---|
229 | make -C $PATH_TMP > $PATH_LOG 2>&1 &&
|
---|
230 | make -C $PATH_TMP clean >> $PATH_LOG 2>&1 ||
|
---|
231 | echo "Warning: test build failed. Please check $PATH_LOG"
|
---|
232 |
|
---|
233 | # Create the archive
|
---|
234 | tar -czf $FILE_OUT -C $PATH_TMP . || exit 1
|
---|
235 |
|
---|
236 | # Remove the temporary directory
|
---|
237 | rm -r $PATH_TMP
|
---|