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. Not for DKMS!
|
---|
6 | #
|
---|
7 | # Copyright (C) 2007-2010 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 | # Set the build type
|
---|
19 | export BUILD_TYPE=_BUILDTYPE_
|
---|
20 |
|
---|
21 | # find a unique temp directory
|
---|
22 | num=0
|
---|
23 | while true; do
|
---|
24 | tmpdir="/tmp/vbox.$num"
|
---|
25 | if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
|
---|
26 | break
|
---|
27 | fi
|
---|
28 | num=`expr $num + 1`
|
---|
29 | if [ $num -gt 200 ]; then
|
---|
30 | echo "Could not find a valid tmp directory"
|
---|
31 | exit 1
|
---|
32 | fi
|
---|
33 | done
|
---|
34 |
|
---|
35 | if [ "$1" = "--save-module-symvers" ]; then
|
---|
36 | shift
|
---|
37 | SAVE_MOD_SYMVERS="$1"
|
---|
38 | shift
|
---|
39 | fi
|
---|
40 |
|
---|
41 | if [ "$1" = "--use-module-symvers" ]; then
|
---|
42 | shift
|
---|
43 | USE_MOD_SYMVERS="$1"
|
---|
44 | shift
|
---|
45 | fi
|
---|
46 |
|
---|
47 | # copy
|
---|
48 | cp -a ${0%/*}/* $tmpdir/
|
---|
49 | if [ -n "$USE_MOD_SYMVERS" ]; then
|
---|
50 | cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
|
---|
51 | fi
|
---|
52 |
|
---|
53 | # make, cleanup if success
|
---|
54 | cd "$tmpdir"
|
---|
55 | if make "$@"; then
|
---|
56 | if [ -n "$SAVE_MOD_SYMVERS" ]; then
|
---|
57 | if [ -f Module.symvers ]; then
|
---|
58 | cp -f Module.symvers $SAVE_MOD_SYMVERS
|
---|
59 | else
|
---|
60 | cat /dev/null > $SAVE_MOD_SYMVERS
|
---|
61 | fi
|
---|
62 | fi
|
---|
63 | rm -rf $tmpdir
|
---|
64 | exit 0
|
---|
65 | fi
|
---|
66 |
|
---|
67 | # failure
|
---|
68 | rm -rf $tmpdir
|
---|
69 | exit 1
|
---|