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 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 | # Attempt to build using DKMS first
|
---|
22 | DKMS=`which dkms 2>/dev/null`
|
---|
23 | if [ "$1" = "--no-dkms" ]; then
|
---|
24 | shift
|
---|
25 | DKMS=""
|
---|
26 | fi
|
---|
27 | if [ -n "$DKMS" ]
|
---|
28 | then
|
---|
29 | echo "Attempting to install using DKMS"
|
---|
30 | $DKMS status -m _MODULE_ | while read line
|
---|
31 | # first, remove _any_ old module
|
---|
32 | do
|
---|
33 | if echo "$line" | grep -q added > /dev/null ||
|
---|
34 | echo "$line" | grep -q built > /dev/null ||
|
---|
35 | echo "$line" | grep -q installed > /dev/null; then
|
---|
36 | # either 'vboxvideo, <version>: added' or 'vboxvideo, <version>, ...: installed'
|
---|
37 | version=`echo "$line" | sed "s/_MODULE_,\([^,]*\)[,:].*/\1/;t;d"`
|
---|
38 | echo " removing old DKMS module _MODULE_ version $version"
|
---|
39 | $DKMS remove -m _MODULE_ -v $version --all
|
---|
40 | fi
|
---|
41 | done
|
---|
42 | # there should not be any more matches
|
---|
43 | status=`$DKMS status -m _MODULE_ -v _VERSION_`
|
---|
44 | if echo $status | grep added > /dev/null ||
|
---|
45 | echo $status | grep built > /dev/null ||
|
---|
46 | echo $status | grep installed > /dev/null
|
---|
47 | then
|
---|
48 | $DKMS remove -m _MODULE_ -v _VERSION_ --all
|
---|
49 | fi
|
---|
50 | # finally install the module
|
---|
51 | if $DKMS add -m _MODULE_ -v _VERSION_ &&
|
---|
52 | $DKMS build -m _MODULE_ -v _VERSION_ &&
|
---|
53 | $DKMS install -m _MODULE_ -v _VERSION_ --force
|
---|
54 | then
|
---|
55 | exit 0
|
---|
56 | fi
|
---|
57 | echo "Failed to install using DKMS, attempting to install without"
|
---|
58 | fi
|
---|
59 |
|
---|
60 | # find a unique temp directory
|
---|
61 | num=0
|
---|
62 | while true; do
|
---|
63 | tmpdir="/tmp/vbox.$num"
|
---|
64 | if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
|
---|
65 | break
|
---|
66 | fi
|
---|
67 | num=`expr $num + 1`
|
---|
68 | if [ $num -gt 200 ]; then
|
---|
69 | echo "Could not find a valid tmp directory"
|
---|
70 | exit 1
|
---|
71 | fi
|
---|
72 | done
|
---|
73 |
|
---|
74 | if [ "$1" = "--save-module-symvers" ]; then
|
---|
75 | shift
|
---|
76 | SAVE_MOD_SYMVERS="$1"
|
---|
77 | shift
|
---|
78 | fi
|
---|
79 |
|
---|
80 | if [ "$1" = "--use-module-symvers" ]; then
|
---|
81 | shift
|
---|
82 | USE_MOD_SYMVERS="$1"
|
---|
83 | shift
|
---|
84 | fi
|
---|
85 |
|
---|
86 | # copy
|
---|
87 | cp -a ${0%/*}/* $tmpdir/
|
---|
88 | if [ -n "$USE_MOD_SYMVERS" ]; then
|
---|
89 | cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
|
---|
90 | fi
|
---|
91 |
|
---|
92 | # make, cleanup if success
|
---|
93 | cd "$tmpdir"
|
---|
94 | if make "$@"; then
|
---|
95 | if [ -n "$SAVE_MOD_SYMVERS" ]; then
|
---|
96 | if [ -f Module.symvers ]; then
|
---|
97 | cp -f Module.symvers $SAVE_MOD_SYMVERS
|
---|
98 | else
|
---|
99 | cat /dev/null > $SAVE_MOD_SYMVERS
|
---|
100 | fi
|
---|
101 | fi
|
---|
102 | rm -rf $tmpdir
|
---|
103 | exit 0
|
---|
104 | fi
|
---|
105 |
|
---|
106 | # failure
|
---|
107 | rm -rf $tmpdir
|
---|
108 | exit 1
|
---|