VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/linux/build_in_tmp@ 18499

Last change on this file since 18499 was 17928, checked in by vboxsync, 15 years ago

build_in_tmp: small adjustment

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
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 Sun Microsystems, Inc.
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# The contents of this file may alternatively be used under the terms
18# of the Common Development and Distribution License Version 1.0
19# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20# VirtualBox OSE distribution, in which case the provisions of the
21# CDDL are applicable instead of those of the GPL.
22#
23# You may elect to license modified versions of this file under the
24# terms and conditions of either the GPL or the CDDL or both.
25#
26# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27# Clara, CA 95054 USA or visit http://www.sun.com if you need
28# additional information or have any questions.
29#
30
31# Attempt to build using DKMS first
32DKMS=`which dkms 2>/dev/null`
33if [ -n "$DKMS" ]
34then
35 echo "Attempting to install using DKMS"
36 $DKMS status -m _MODULE_ | while read line
37 # first, remove _any_ old module
38 do
39 if echo "$line" | grep -q added > /dev/null ||
40 echo "$line" | grep -q built > /dev/null ||
41 echo "$line" | grep -q installed > /dev/null; then
42 # either 'vboxvideo, <version>: added' or 'vboxvideo, <version>, ...: installed'
43 version=`echo "$line" | sed "s/_MODULE_,\([^,]*\)[,:].*/\1/;t;d"`
44 echo " removing old DKMS module _MODULE_ version $version"
45 $DKMS remove -m _MODULE_ -v $version --all
46 fi
47 done
48 # there should not be any more matches
49 status=`$DKMS status -m _MODULE_ -v _VERSION_`
50 if echo $status | grep added > /dev/null ||
51 echo $status | grep built > /dev/null ||
52 echo $status | grep installed > /dev/null
53 then
54 $DKMS remove -m _MODULE_ -v _VERSION_ --all
55 fi
56 # finally install the module
57 if $DKMS add -m _MODULE_ -v _VERSION_ &&
58 $DKMS build -m _MODULE_ -v _VERSION_ &&
59 $DKMS install -m _MODULE_ -v _VERSION_ --force
60 then
61 exit 0
62 fi
63 echo "Failed to install using DKMS, attempting to install without"
64fi
65
66# find a unique temp directory
67num=0
68while true; do
69 tmpdir="/tmp/vbox.$num"
70 if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
71 break
72 fi
73 num=`expr $num + 1`
74 if [ $num -gt 200 ]; then
75 echo "Could not find a valid tmp directory"
76 exit 1
77 fi
78done
79
80if [ "$1" = "--save-module-symvers" ]; then
81 shift
82 SAVE_MOD_SYMVERS="$1"
83 shift
84fi
85
86if [ "$1" = "--use-module-symvers" ]; then
87 shift
88 USE_MOD_SYMVERS="$1"
89 shift
90fi
91
92# copy
93cp -a ${0%/*}/* $tmpdir/
94if [ -n "$USE_MOD_SYMVERS" ]; then
95 cp $USE_MOD_SYMVERS $tmpdir/Module.symvers
96fi
97
98# make, cleanup if success
99cd "$tmpdir"
100if make "$@"; then
101 if [ -n "$SAVE_MOD_SYMVERS" ]; then
102 if [ -f Module.symvers ]; then
103 cp -f Module.symvers $SAVE_MOD_SYMVERS
104 else
105 cat /dev/null > $SAVE_MOD_SYMVERS
106 fi
107 fi
108 rm -rf $tmpdir
109 exit 0
110fi
111
112# failure
113exit 1
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use