1 | #!/bin/sh
|
---|
2 | # $Id: build_in_tmp 93115 2022-01-01 11:31:46Z 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-2022 Oracle Corporation
|
---|
11 | #
|
---|
12 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | # available from http://www.virtualbox.org. This file is free software;
|
---|
14 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | # General Public License (GPL) as published by the Free Software
|
---|
16 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 | #
|
---|
20 | # The contents of this file may alternatively be used under the terms
|
---|
21 | # of the Common Development and Distribution License Version 1.0
|
---|
22 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | # CDDL are applicable instead of those of the GPL.
|
---|
25 | #
|
---|
26 | # You may elect to license modified versions of this file under the
|
---|
27 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | #
|
---|
29 |
|
---|
30 | # find a unique temp directory
|
---|
31 | num=0
|
---|
32 | while true; do
|
---|
33 | tmpdir="/tmp/vbox.$num"
|
---|
34 | if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
|
---|
35 | break
|
---|
36 | fi
|
---|
37 | num=`expr $num + 1`
|
---|
38 | if [ $num -gt 200 ]; then
|
---|
39 | echo "Could not find a valid tmp directory"
|
---|
40 | exit 1
|
---|
41 | fi
|
---|
42 | done
|
---|
43 |
|
---|
44 | # Guest optimal number of make jobs.
|
---|
45 | MAKE_JOBS=`grep vendor_id /proc/cpuinfo | wc -l`
|
---|
46 | if [ "${MAKE_JOBS}" -le "0" ]; then MAKE_JOBS=1; fi
|
---|
47 |
|
---|
48 | # Parse our arguments, anything we don't grok is for make.
|
---|
49 | while true; do
|
---|
50 | if [ "$1" = "--save-module-symvers" ]; then
|
---|
51 | shift
|
---|
52 | SAVE_MOD_SYMVERS="$1"
|
---|
53 | shift
|
---|
54 | elif [ "$1" = "--use-module-symvers" ]; then
|
---|
55 | shift
|
---|
56 | USE_MOD_SYMVERS="$1"
|
---|
57 | shift
|
---|
58 | elif [ "$1" = "--module-source" ]; then
|
---|
59 | shift
|
---|
60 | MODULE_SOURCE="$1"
|
---|
61 | shift
|
---|
62 | else
|
---|
63 | break
|
---|
64 | fi
|
---|
65 | done
|
---|
66 |
|
---|
67 | # copy
|
---|
68 | if [ -n "$MODULE_SOURCE" ]; then
|
---|
69 | cp -a "$MODULE_SOURCE"/* $tmpdir/
|
---|
70 | else
|
---|
71 | cp -a ${0%/*}/* $tmpdir/
|
---|
72 | fi
|
---|
73 | if [ -n "$USE_MOD_SYMVERS" ]; then
|
---|
74 | cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
|
---|
75 | MAKE_EXTRAOPTS="KBUILD_EXTRA_SYMBOLS=$tmpdir/Module.symvers"
|
---|
76 | fi
|
---|
77 |
|
---|
78 | # make, cleanup if success
|
---|
79 | cd "$tmpdir"
|
---|
80 | if make "-j`echo ${MAKE_JOBS}`" "$@" ${MAKE_EXTRAOPTS}; then # strip leading space from "MAKE_JOBS"
|
---|
81 | if [ -n "$SAVE_MOD_SYMVERS" ]; then
|
---|
82 | if [ -f Module.symvers ]; then
|
---|
83 | cp -f Module.symvers $SAVE_MOD_SYMVERS
|
---|
84 | else
|
---|
85 | cat /dev/null > $SAVE_MOD_SYMVERS
|
---|
86 | fi
|
---|
87 | fi
|
---|
88 | rm -rf $tmpdir
|
---|
89 | exit 0
|
---|
90 | fi
|
---|
91 |
|
---|
92 | # failure
|
---|
93 | rm -rf $tmpdir
|
---|
94 | exit 1
|
---|