1 | #!/bin/sh
|
---|
2 | # $Id: build_in_tmp 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Script to build a kernel module in /tmp.
|
---|
5 | #
|
---|
6 | # Useful if the module sources are installed in read-only directory.
|
---|
7 | #
|
---|
8 |
|
---|
9 | #
|
---|
10 | # Copyright (C) 2007-2024 Oracle and/or its affiliates.
|
---|
11 | #
|
---|
12 | # This file is part of VirtualBox base platform packages, as
|
---|
13 | # available from https://www.virtualbox.org.
|
---|
14 | #
|
---|
15 | # This program is free software; you can redistribute it and/or
|
---|
16 | # modify it under the terms of the GNU General Public License
|
---|
17 | # as published by the Free Software Foundation, in version 3 of the
|
---|
18 | # License.
|
---|
19 | #
|
---|
20 | # This program is distributed in the hope that it will be useful, but
|
---|
21 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
23 | # General Public License for more details.
|
---|
24 | #
|
---|
25 | # You should have received a copy of the GNU General Public License
|
---|
26 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
27 | #
|
---|
28 | # The contents of this file may alternatively be used under the terms
|
---|
29 | # of the Common Development and Distribution License Version 1.0
|
---|
30 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
31 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
32 | # CDDL are applicable instead of those of the GPL.
|
---|
33 | #
|
---|
34 | # You may elect to license modified versions of this file under the
|
---|
35 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
36 | #
|
---|
37 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
38 | #
|
---|
39 |
|
---|
40 | # find a unique temp directory
|
---|
41 | num=0
|
---|
42 | while true; do
|
---|
43 | tmpdir="/tmp/vbox.$num"
|
---|
44 | if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
|
---|
45 | break
|
---|
46 | fi
|
---|
47 | num=`expr $num + 1`
|
---|
48 | if [ $num -gt 200 ]; then
|
---|
49 | echo "Could not find a valid tmp directory"
|
---|
50 | exit 1
|
---|
51 | fi
|
---|
52 | done
|
---|
53 |
|
---|
54 | # Guest optimal number of make jobs.
|
---|
55 | MAKE_JOBS=`grep vendor_id /proc/cpuinfo | wc -l`
|
---|
56 | if [ "${MAKE_JOBS}" -le "0" ]; then MAKE_JOBS=1; fi
|
---|
57 |
|
---|
58 | # Parse our arguments, anything we don't grok is for make.
|
---|
59 | while true; do
|
---|
60 | if [ "$1" = "--save-module-symvers" ]; then
|
---|
61 | shift
|
---|
62 | SAVE_MOD_SYMVERS="$1"
|
---|
63 | shift
|
---|
64 | elif [ "$1" = "--use-module-symvers" ]; then
|
---|
65 | shift
|
---|
66 | USE_MOD_SYMVERS="$1"
|
---|
67 | shift
|
---|
68 | elif [ "$1" = "--module-source" ]; then
|
---|
69 | shift
|
---|
70 | MODULE_SOURCE="$1"
|
---|
71 | shift
|
---|
72 | else
|
---|
73 | break
|
---|
74 | fi
|
---|
75 | done
|
---|
76 |
|
---|
77 | # copy
|
---|
78 | if [ -n "$MODULE_SOURCE" ]; then
|
---|
79 | cp -a "$MODULE_SOURCE"/* $tmpdir/
|
---|
80 | else
|
---|
81 | cp -a ${0%/*}/* $tmpdir/
|
---|
82 | fi
|
---|
83 | if [ -n "$USE_MOD_SYMVERS" ]; then
|
---|
84 | cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
|
---|
85 | MAKE_EXTRAOPTS="KBUILD_EXTRA_SYMBOLS=$tmpdir/Module.symvers"
|
---|
86 | fi
|
---|
87 |
|
---|
88 | # make, cleanup if success
|
---|
89 | cd "$tmpdir"
|
---|
90 | if make CONFIG_MODULE_COMPRESS_GZIP= CONFIG_MODULE_COMPRESS_XZ= CONFIG_MODULE_COMPRESS_ZSTD= "-j`echo ${MAKE_JOBS}`" "$@" ${MAKE_EXTRAOPTS}; then # strip leading space from "MAKE_JOBS"
|
---|
91 | if [ -n "$SAVE_MOD_SYMVERS" ]; then
|
---|
92 | if [ -f Module.symvers ]; then
|
---|
93 | cp -f Module.symvers $SAVE_MOD_SYMVERS
|
---|
94 | else
|
---|
95 | cat /dev/null > $SAVE_MOD_SYMVERS
|
---|
96 | fi
|
---|
97 | fi
|
---|
98 | rm -rf $tmpdir
|
---|
99 | exit 0
|
---|
100 | fi
|
---|
101 |
|
---|
102 | # failure
|
---|
103 | rm -rf $tmpdir
|
---|
104 | exit 1
|
---|