1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Script to build a kernel module in /tmp. Useful if the module sources
|
---|
5 | # are installed in read-only directory.
|
---|
6 | #
|
---|
7 | # Copyright (C) 2007-2015 Oracle Corporation
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | # available from http://www.virtualbox.org. This file is free software;
|
---|
11 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | # General Public License (GPL) as published by the Free Software
|
---|
13 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 |
|
---|
18 | # find a unique temp directory
|
---|
19 | num=0
|
---|
20 | while true; do
|
---|
21 | tmpdir="/tmp/vbox.$num"
|
---|
22 | if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
|
---|
23 | break
|
---|
24 | fi
|
---|
25 | num=`expr $num + 1`
|
---|
26 | if [ $num -gt 200 ]; then
|
---|
27 | echo "Could not find a valid tmp directory"
|
---|
28 | exit 1
|
---|
29 | fi
|
---|
30 | done
|
---|
31 |
|
---|
32 | # Guest optimal number of make jobs.
|
---|
33 | MAKE_JOBS=`grep vendor_id /proc/cpuinfo | wc -l`
|
---|
34 | if [ "${MAKE_JOBS}" -le "0" ]; then MAKE_JOBS=1; fi
|
---|
35 |
|
---|
36 | # Parse our arguments, anything we don't grok is for make.
|
---|
37 | while true; do
|
---|
38 | if [ "$1" = "--save-module-symvers" ]; then
|
---|
39 | shift
|
---|
40 | SAVE_MOD_SYMVERS="$1"
|
---|
41 | shift
|
---|
42 | elif [ "$1" = "--use-module-symvers" ]; then
|
---|
43 | shift
|
---|
44 | USE_MOD_SYMVERS="$1"
|
---|
45 | shift
|
---|
46 | elif [ "$1" = "--module-source" ]; then
|
---|
47 | shift
|
---|
48 | MODULE_SOURCE="$1"
|
---|
49 | shift
|
---|
50 | else
|
---|
51 | break
|
---|
52 | fi
|
---|
53 | done
|
---|
54 |
|
---|
55 | # copy
|
---|
56 | if [ -n "$MODULE_SOURCE" ]; then
|
---|
57 | cp -a "$MODULE_SOURCE"/* $tmpdir/
|
---|
58 | else
|
---|
59 | cp -a ${0%/*}/* $tmpdir/
|
---|
60 | fi
|
---|
61 | if [ -n "$USE_MOD_SYMVERS" ]; then
|
---|
62 | cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
|
---|
63 | fi
|
---|
64 |
|
---|
65 | # make, cleanup if success
|
---|
66 | cd "$tmpdir"
|
---|
67 | if make "-j${MAKE_JOBS}" "$@"; then
|
---|
68 | if [ -n "$SAVE_MOD_SYMVERS" ]; then
|
---|
69 | if [ -f Module.symvers ]; then
|
---|
70 | cp -f Module.symvers $SAVE_MOD_SYMVERS
|
---|
71 | else
|
---|
72 | cat /dev/null > $SAVE_MOD_SYMVERS
|
---|
73 | fi
|
---|
74 | fi
|
---|
75 | rm -rf $tmpdir
|
---|
76 | exit 0
|
---|
77 | fi
|
---|
78 |
|
---|
79 | # failure
|
---|
80 | rm -rf $tmpdir
|
---|
81 | exit 1
|
---|