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 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | # in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | # distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | # be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | #
|
---|
17 | # If you received this file as part of a commercial VirtualBox
|
---|
18 | # distribution, then only the terms of your commercial VirtualBox
|
---|
19 | # license agreement apply instead of the previous paragraph.
|
---|
20 | #
|
---|
21 |
|
---|
22 | # find a unique temp directory
|
---|
23 | num=0
|
---|
24 | while true; do
|
---|
25 | tmpdir="/tmp/vbox.$num"
|
---|
26 | if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
|
---|
27 | break
|
---|
28 | fi
|
---|
29 | num=`expr $num + 1`
|
---|
30 | if [ $num -gt 200 ]; then
|
---|
31 | echo "Could not find a valid tmp directory"
|
---|
32 | exit 1
|
---|
33 | fi
|
---|
34 | done
|
---|
35 |
|
---|
36 | if [ "$1" = "--save-module-symvers" ]; then
|
---|
37 | shift
|
---|
38 | SAVE_MOD_SYMVERS="$1"
|
---|
39 | shift
|
---|
40 | fi
|
---|
41 |
|
---|
42 | if [ "$1" = "--use-module-symvers" ]; then
|
---|
43 | shift
|
---|
44 | USE_MOD_SYMVERS="$1"
|
---|
45 | shift
|
---|
46 | fi
|
---|
47 |
|
---|
48 | # copy
|
---|
49 | cp -a ${0%/*}/* $tmpdir/
|
---|
50 | if [ -n "$USE_MOD_SYMVERS" ]; then
|
---|
51 | cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
|
---|
52 | fi
|
---|
53 |
|
---|
54 | # make, cleanup if success
|
---|
55 | cd "$tmpdir"
|
---|
56 | if make "$@"; then
|
---|
57 | if [ -n "$SAVE_MOD_SYMVERS" ]; then
|
---|
58 | if [ -f Module.symvers ]; then
|
---|
59 | cp -f Module.symvers $SAVE_MOD_SYMVERS
|
---|
60 | else
|
---|
61 | cat /dev/null > $SAVE_MOD_SYMVERS
|
---|
62 | fi
|
---|
63 | fi
|
---|
64 | rm -rf $tmpdir
|
---|
65 | exit 0
|
---|
66 | fi
|
---|
67 |
|
---|
68 | # failure
|
---|
69 | exit 1
|
---|