- Code: Select all
#!/bin/bash
#
# build - a handy script to build the linux kernel
#
# options:
# -f full, means it compiles the whole kernel including
# the modules and installs them.
#
# -o only, means it compiles ONLY this steps you
# you specify (see expl. of modifiers below)
#
# -s skip, means it compiles the whole kernel but SKIPS
# the steps you specify (see expl. of modifiers below)
#
# -h this help ;)
#
# modifiers:
# d dependents (or 'make dep')
# c clean (or 'make clean')
# z zImage (or 'make zImage')
# b bzImage (or 'make bzImage')
# m modules (or 'make modules')
# i modules_install (or 'make modules_install')
# to be continued....
#
# examples:
# to build the kernel but not the modules nor install them:
# ./build -s mi
#
# to build just the deps and bzImage:
# ./build -m db
#
#
# for any questions, send an PM
#
SRCDIR=/usr/src/linux
PARAM=$1
OPTSTR=$@
die()
{
echo "-- sorry, failed to make $1 :(";
exit 1
}
valid()
{
for i in $OPTSTR ; do
echo "$i" | grep "$1" > /dev/null && return 0
done
return 1
}
cddir()
{
if [ -d $1 ] ; then
cd $1
else
echo "-- sorry, dir $1 not found"
exit 1;
fi
}
case "$PARAM" in "-s" )
cddir $SRCDIR
valid "d" || (echo "making dep" && make dep || die "dep")
valid "c" || (echo "making clean" && make clean || die "clean")
valid "z" || (echo "making zImage" && make zImage || die "zImage")
valid "b" || (echo "making bzImage" && make bzImage || die "bzImage")
valid "m" || (echo "making modules" && make modules || die "modules")
valid "i" || (echo "making mod_inst" && make modules_install \
|| die "modules_install")
exit 0
;;
"-o" )
cddir $SRCDIR
valid "d" && echo "making dep" && (make dep || die "dep")
valid "c" && echo "making clean" && (make clean || die "clean")
valid "z" && echo "making zImage" && (make zImage || die "zImage")
valid "b" && echo "making bzImage" && (make bzImage || die "bzImage")
valid "m" && echo "making modules" && (make modules || die "modules")
valid "i" && echo "making mod_inst" && (make modules_install \
|| die "modules_install")
exit 0
;;
"-f" ) cddir $SRCDIR
make dep && \
make clean && \
make bzImage && \
make modules && \
make modules_install && \
echo "finished.... ;)"
exit 0
;;
"-h" )
head -31 $0|tail -29
exit 0
;;
* ) echo "build - kernel building script"
echo "usage: build [-h] [-f] [-m|-s] (d|c|z|b|m|i)"
exit 0
;;
esac
exit 1


