VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/linux/export_modules.sh@ 92126

Last change on this file since 92126 was 89370, checked in by vboxsync, 4 years ago

Host drivers: SUPDrv-linux: print revision number and optional extra version string on module load, bugref:9958.

Also, export_modules.sh was extended with --override-svn-rev
and --extra-version-string optional command line parameters in
order to get more flexibility when creating src tar for kmod SRPM
package.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 9.9 KB
Line 
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.
29TARGET=`readlink -e -- "${0}"` || exit 1
30MY_DIR="${TARGET%/[!/]*}"
31
32# What this script does:
33usage_msg="\
34Usage: `basename ${0}` --file <path>|--folder <path> \
35 [--override-svn-rev <rev>] [--extra-version-string <string>] [--without-hardening]
36
37Exports the VirtualBox host kernel modules to the tar.gz archive or folder in \
38<path>, optionally adjusting the Make files to build them without hardening.
39
40Examples:
41 `basename ${0}` --file /tmp/vboxhost.tar.gz
42 `basename ${0}` --folder /tmp/tmpdir --without-hardening"
43
44usage()
45{
46 case "${1}" in
47 0)
48 echo "${usage_msg}" | fold -s -w80 ;;
49 *)
50 echo "${usage_msg}" | fold -s -w80 >&2 ;;
51 esac
52 exit "${1}"
53}
54
55fail()
56{
57 echo "${1}" | fold -s -w80 >&2
58 exit 1
59}
60
61unset FILE FOLDER
62VBOX_WITH_HARDENING=1
63while test -n "${1}"; do
64 case "${1}" in
65 --file)
66 FILE="${2}"
67 shift 2 ;;
68 --folder)
69 FOLDER="${2}"
70 shift 2 ;;
71 --override-svn-rev)
72 OVERRIDE_SVN_REV="${2}"
73 shift 2 ;;
74 --extra-version-string)
75 EXTRA_VERSION_STRING="${2}"
76 shift 2 ;;
77 --without-hardening)
78 unset VBOX_WITH_HARDENING
79 shift ;;
80 -h|--help)
81 usage 0 ;;
82 *)
83 echo "Unknown parameter ${1}" >&2
84 usage 1 ;;
85 esac
86done
87test -z "$FILE" || test -z "$FOLDER" ||
88 fail "Only one of --file and --folder may be used"
89test -n "$FILE" || test -n "$FOLDER" || usage 1
90
91if test -n "$FOLDER"; then
92 PATH_TMP="$FOLDER"
93else
94 PATH_TMP="`cd \`dirname $FILE\`; pwd`/.vbox_modules"
95 FILE_OUT="`cd \`dirname $FILE\`; pwd`/`basename $FILE`"
96fi
97PATH_OUT=$PATH_TMP
98PATH_ROOT="`cd ${MY_DIR}/../../../..; pwd`"
99PATH_LOG=/tmp/vbox-export-host.log
100PATH_LINUX="$PATH_ROOT/src/VBox/HostDrivers/linux"
101PATH_VBOXDRV="$PATH_ROOT/src/VBox/HostDrivers/Support"
102PATH_VBOXNET="$PATH_ROOT/src/VBox/HostDrivers/VBoxNetFlt"
103PATH_VBOXADP="$PATH_ROOT/src/VBox/HostDrivers/VBoxNetAdp"
104PATH_VBOXPCI="$PATH_ROOT/src/VBox/HostDrivers/VBoxPci"
105
106VBOX_VERSION_MAJOR=`sed -e "s/^ *VBOX_VERSION_MAJOR *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
107VBOX_VERSION_MINOR=`sed -e "s/^ *VBOX_VERSION_MINOR *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
108VBOX_VERSION_BUILD=`sed -e "s/^ *VBOX_VERSION_BUILD *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
109VBOX_VERSION_STRING=$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD
110VBOX_VERSION_BUILD=`sed -e "s/^ *VBOX_VERSION_BUILD *= \+\([0-9]\+\)/\1/;t;d" $PATH_ROOT/Version.kmk`
111VBOX_SVN_CONFIG_REV=`sed -e 's/^ *VBOX_SVN_REV_CONFIG_FALLBACK *:= \+\$(patsubst *%:,, *\$Rev: *\([0-9]\+\) *\$ *) */\1/;t;d' $PATH_ROOT/Config.kmk`
112VBOX_SVN_VERSION_REV=`sed -e 's/^ *VBOX_SVN_REV_VERSION_FALLBACK *:= \+\$(patsubst *%:,, *\$Rev: *\([0-9]\+\) *\$ *) */\1/;t;d' $PATH_ROOT/Version.kmk`
113
114if [ -n "$OVERRIDE_SVN_REV" ]; then
115 VBOX_SVN_REV=$OVERRIDE_SVN_REV
116elif [ "$VBOX_SVN_CONFIG_REV" -gt "$VBOX_SVN_VERSION_REV" ]; then
117 VBOX_SVN_REV=$VBOX_SVN_CONFIG_REV
118else
119 VBOX_SVN_REV=$VBOX_SVN_VERSION_REV
120fi
121VBOX_VENDOR=`sed -e 's/^ *VBOX_VENDOR *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`
122VBOX_VENDOR_SHORT=`sed -e 's/^ *VBOX_VENDOR_SHORT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`
123VBOX_PRODUCT=`sed -e 's/^ *VBOX_PRODUCT *= \+\(.\+\)/\1/;t;d' $PATH_ROOT/Config.kmk`
124VBOX_C_YEAR=`date +%Y`
125VBOX_WITH_PCI_PASSTHROUGH=`sed -e '/^ *VBOX_WITH_PCI_PASSTHROUGH *[:]\?= */!d' -e 's/ *#.*$//' -e 's/^.*= *//' $PATH_ROOT/Config.kmk`
126
127. $PATH_VBOXDRV/linux/files_vboxdrv
128. $PATH_VBOXNET/linux/files_vboxnetflt
129. $PATH_VBOXADP/linux/files_vboxnetadp
130if [ "${VBOX_WITH_PCI_PASSTHROUGH}" = "1" ]; then
131 . $PATH_VBOXPCI/linux/files_vboxpci
132fi
133
134# Temporary path for creating the modules, will be removed later
135rm -rf "$PATH_TMP"
136mkdir $PATH_TMP || exit 1
137
138# Create auto-generated version file, needed by all modules
139echo "#ifndef ___version_generated_h___" > $PATH_TMP/version-generated.h
140echo "#define ___version_generated_h___" >> $PATH_TMP/version-generated.h
141echo "" >> $PATH_TMP/version-generated.h
142echo "#define VBOX_VERSION_MAJOR $VBOX_VERSION_MAJOR" >> $PATH_TMP/version-generated.h
143echo "#define VBOX_VERSION_MINOR $VBOX_VERSION_MINOR" >> $PATH_TMP/version-generated.h
144echo "#define VBOX_VERSION_BUILD $VBOX_VERSION_BUILD" >> $PATH_TMP/version-generated.h
145echo "#define VBOX_VERSION_STRING_RAW \"$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD\"" >> $PATH_TMP/version-generated.h
146echo "#define VBOX_VERSION_STRING \"$VBOX_VERSION_STRING\"" >> $PATH_TMP/version-generated.h
147echo "#define VBOX_API_VERSION_STRING \"${VBOX_VERSION_MAJOR}_${VBOX_VERSION_MINOR}\"" >> $PATH_TMP/version-generated.h
148[ -n "$EXTRA_VERSION_STRING" ] && echo "#define VBOX_EXTRA_VERSION_STRING \" ${EXTRA_VERSION_STRING}\"" >> $PATH_TMP/version-generated.h
149echo "#define VBOX_PRIVATE_BUILD_DESC \"Private build with export_modules\"" >> $PATH_TMP/version-generated.h
150echo "" >> $PATH_TMP/version-generated.h
151echo "#endif" >> $PATH_TMP/version-generated.h
152
153# Create auto-generated revision file, needed by all modules
154echo "#ifndef __revision_generated_h__" > $PATH_TMP/revision-generated.h
155echo "#define __revision_generated_h__" >> $PATH_TMP/revision-generated.h
156echo "" >> $PATH_TMP/revision-generated.h
157echo "#define VBOX_SVN_REV $VBOX_SVN_REV" >> $PATH_TMP/revision-generated.h
158echo "" >> $PATH_TMP/revision-generated.h
159echo "#endif" >> $PATH_TMP/revision-generated.h
160
161# Create auto-generated product file, needed by all modules
162echo "#ifndef ___product_generated_h___" > $PATH_TMP/product-generated.h
163echo "#define ___product_generated_h___" >> $PATH_TMP/product-generated.h
164echo "" >> $PATH_TMP/product-generated.h
165echo "#define VBOX_VENDOR \"$VBOX_VENDOR\"" >> $PATH_TMP/product-generated.h
166echo "#define VBOX_VENDOR_SHORT \"$VBOX_VENDOR_SHORT\"" >> $PATH_TMP/product-generated.h
167echo "" >> $PATH_TMP/product-generated.h
168echo "#define VBOX_PRODUCT \"$VBOX_PRODUCT\"" >> $PATH_TMP/product-generated.h
169echo "#define VBOX_C_YEAR \"$VBOX_C_YEAR\"" >> $PATH_TMP/product-generated.h
170echo "" >> $PATH_TMP/product-generated.h
171echo "#endif" >> $PATH_TMP/product-generated.h
172
173# vboxdrv (VirtualBox host kernel module)
174mkdir $PATH_TMP/vboxdrv || exit 1
175for f in $FILES_VBOXDRV_NOBIN; do
176 install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxdrv/`echo $f|cut -d'>' -f2`"
177done
178for f in $FILES_VBOXDRV_BIN; do
179 install -D -m 0755 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxdrv/`echo $f|cut -d'>' -f2`"
180done
181if [ -n "$VBOX_WITH_HARDENING" ]; then
182 sed -e "s;VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV;;g" \
183 -e "s;IPRT_WITH_EFLAGS_AC_PRESERVING;;g" \
184 < $PATH_VBOXDRV/linux/Makefile > $PATH_TMP/vboxdrv/Makefile
185else
186 sed -e "s;VBOX_WITH_HARDENING;;g" \
187 -e "s;VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV;;g" \
188 -e "s;IPRT_WITH_EFLAGS_AC_PRESERVING;;g" \
189 < $PATH_VBOXDRV/linux/Makefile > $PATH_TMP/vboxdrv/Makefile
190fi
191
192# vboxnetflt (VirtualBox netfilter kernel module)
193mkdir $PATH_TMP/vboxnetflt || exit 1
194for f in $VBOX_VBOXNETFLT_SOURCES; do
195 install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxnetflt/`echo $f|cut -d'>' -f2`"
196done
197if [ -n "$VBOX_WITH_HARDENING" ]; then
198 cat $PATH_VBOXNET/linux/Makefile > $PATH_TMP/vboxnetflt/Makefile
199else
200 sed -e "s;VBOX_WITH_HARDENING;;g" < $PATH_VBOXNET/linux/Makefile > $PATH_TMP/vboxnetflt/Makefile
201fi
202
203# vboxnetadp (VirtualBox network adapter kernel module)
204mkdir $PATH_TMP/vboxnetadp || exit 1
205for f in $VBOX_VBOXNETADP_SOURCES; do
206 install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxnetadp/`echo $f|cut -d'>' -f2`"
207done
208if [ -n "$VBOX_WITH_HARDENING" ]; then
209 cat $PATH_VBOXADP/linux/Makefile > $PATH_TMP/vboxnetadp/Makefile
210else
211 sed -e "s;VBOX_WITH_HARDENING;;g" < $PATH_VBOXADP/linux/Makefile > $PATH_TMP/vboxnetadp/Makefile
212fi
213
214# vboxpci (VirtualBox host PCI access kernel module)
215if [ "${VBOX_WITH_PCI_PASSTHROUGH}" = "1" ]; then
216 mkdir $PATH_TMP/vboxpci || exit 1
217 for f in $VBOX_VBOXPCI_SOURCES; do
218 install -D -m 0644 `echo $f|cut -d'=' -f1` "$PATH_TMP/vboxpci/`echo $f|cut -d'>' -f2`"
219 done
220 if [ -n "$VBOX_WITH_HARDENING" ]; then
221 cat $PATH_VBOXPCI/linux/Makefile > $PATH_TMP/vboxpci/Makefile
222 else
223 sed -e "s;VBOX_WITH_HARDENING;;g" < $PATH_VBOXPCI/linux/Makefile > $PATH_TMP/vboxpci/Makefile
224 fi
225fi
226
227install -D -m 0644 $PATH_LINUX/Makefile $PATH_TMP/Makefile
228install -D -m 0755 $PATH_LINUX/build_in_tmp $PATH_TMP/build_in_tmp
229
230# Only temporary, omit from archive
231rm $PATH_TMP/version-generated.h
232rm $PATH_TMP/revision-generated.h
233rm $PATH_TMP/product-generated.h
234
235# If we are exporting to a folder then stop now.
236test -z "$FOLDER" || exit 0
237
238# Do a test build
239echo Doing a test build, this may take a while.
240make -C $PATH_TMP > $PATH_LOG 2>&1 &&
241 make -C $PATH_TMP clean >> $PATH_LOG 2>&1 ||
242 echo "Warning: test build failed. Please check $PATH_LOG"
243
244# Create the archive
245tar -czf $FILE_OUT -C $PATH_TMP . || exit 1
246
247# Remove the temporary directory
248rm -r $PATH_TMP
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette