build_in_tmp revision de8e40551b020624bc0683e5905f06b51f3ceebe
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence#!/bin/sh
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews#
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# Script to build a kernel module in /tmp. Useful if the module sources
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence# are installed in read-only directory.
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence#
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence# Copyright (C) 2007 innotek GmbH
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# This file is part of VirtualBox Open Source Edition (OSE), as
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# available from http://www.virtualbox.org. This file is free software;
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# you can redistribute it and/or modify it under the terms of the GNU
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# General Public License as published by the Free Software Foundation,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# distribution. VirtualBox OSE is distributed in the hope that it will
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# be useful, but WITHOUT ANY WARRANTY of any kind.
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence#
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence# If you received this file as part of a commercial VirtualBox
69f08f8ae4980678911fa2d81323a0930708db4aMark Andrews# distribution, then only the terms of your commercial VirtualBox
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence# license agreement apply instead of the previous paragraph.
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley#
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley# find a unique temp directory
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleynum=0
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleywhile true; do
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley tmpdir="/tmp/vbox.$num"
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley if mkdir -m 0755 "$tmpdir" 2> /dev/null; then
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley break
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley fi
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley num=`expr $num + 1`
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley if [ $num -gt 200 ]; then
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley echo "Could not find a valid tmp directory"
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley exit 1
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley fi
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleydone
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleyif [ "$1" = "--save-module-symvers" ]; then
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley shift
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley SAVE_MOD_SYMVERS="$1"
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley shift
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleyfi
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleyif [ "$1" = "--use-module-symvers" ]; then
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley shift
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley USE_MOD_SYMVERS="$1"
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley shift
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleyfi
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence# copy
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrencecp -a ${0%/*}/* $tmpdir/
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrencecp $USE_MOD_SYMVERS $tmpdir/Module.symvers
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence# make, cleanup if success
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrencecd "$tmpdir"
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrenceif make "$@"; then
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence if [ -n "$SAVE_MOD_SYMVERS" ]; then
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence if [ -f Module.symvers ]; then
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence cp -f Module.symvers $SAVE_MOD_SYMVERS
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence else
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence cat /dev/null > $SAVE_MOD_SYMVERS
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence fi
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence fi
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence rm -rf $tmpdir
69f08f8ae4980678911fa2d81323a0930708db4aMark Andrews exit 0
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrencefi
e1747e09e7cc6771dca1a1702e42e6401dbeebedDavid Lawrence
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley# failure
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halleyexit 1
767d29c43d98bae8ea95f0ccd2b9653cbcd43310Bob Halley