#!/bin/sh # kdeb - build .debs out of already-compiled kernel trees # Copyright (C) 2005 Christian Aichinger # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # If you want to contact me write an email to Greek0@gmx.net set -e function make_clean() { rm -rf debian conf.vars stamp-* if $OOT; then rm -rf Documentation fi } function make_conf_vars() { head -n 4 "$SOURCE/Makefile" > conf.vars echo "Debian Revision = $REVISION" >> conf.vars echo "KPKG_ARCH = $ARCH" >> conf.vars } function AppendMakefile() { if ! egrep "^$1 +=" Makefile 1>/dev/null 2>&1; then cp Makefile Makefile.new; mv -f Makefile.new Makefile egrep "^$1 +=" conf.vars >> Makefile 2>/dev/null fi } function make_Makefile() { if $OOT; then AppendMakefile "VERSION" AppendMakefile "PATCHLEVEL" AppendMakefile "SUBLEVEL" AppendMakefile "EXTRAVERSION" fi } function make_Changes() { if $OOT; then mkdir -p Documentation cp "$SOURCE/Documentation/Changes" Documentation fi } function make_debian() { make-kpkg --rootcmd fakeroot debian $MKPKG_ARGS } function make_buildinfo() { COLUMNS=150 dpkg -l 'gcc*' perl dpkg 'libc6*' binutils ldso make dpkg-dev |\ awk '$$1 ~ /[hi]i/ { printf("%s-%s\n", $$2, $$3) }' > debian/buildinfo echo this was built on a machine with the kernel: >> debian/buildinfo uname -a >> debian/buildinfo echo using the compiler: >> debian/buildinfo grep LINUX_COMPILER include/linux/compile.h | \ sed -e 's/.*LINUX_COMPILER "//' -e 's/"$$//' >> debian/buildinfo } function make_stamps() { touch stamp-build stamp-configure stamp-kernel-configure } function make_package() { make-kpkg --rootcmd fakeroot kernel_image $MKPKG_ARGS } function Usage() { [ -n "$1" ] && echo "$1" echo "Usage: kdeb " echo "Build .debs out of already-compiled kernel trees" echo "" echo "Supported args:" echo " O= Path to the build tree (_only_ for out-of-tree builds)" echo " V=1 Enable verbose mode" echo " ARCH= Set the architecture for cross-compiling" echo " CROSS_COMPILE=" echo " Set cross-compile prefix (probably ignored by make-kpkg)" echo " REVISION= Set the revision of the debian package" echo "" echo "Supported targets:" echo " build Build the debian package" echo " clean Clean files created by kdeb and make-kpkg" echo " prepare Do everything but the final call to make-kpkg kernel_image" echo "" echo "Remarks:" echo " kdeb has to be called from the top-level kernel directory." echo " If no target was specified, 'build' is assumed." echo " When doing out-of-tree builds the .deb's are generated above the build dir." exit 1 } function check_tree() { if [ ! -e "$SOURCE/include/linux" ]; then Usage "E: Not in the top-level kernel tree" fi if [ ! -e "vmlinux" ]; then Usage "E: The tree doesn't seem to be built" fi } function parse_key() { echo "$1" | sed -e 's/=.*//' } function parse_value() { echo "$1" | sed -e 's/^[^=]*=//' } ############################### # Main entry point ############################## SOURCE=`pwd` OOT=false VERBOSE=false ARCH= REVISION= MKPKG_ARGS= # parse commandline arguments declare -a TARGETS for i in $@; do case "`parse_key \"$i\"`" in O) # out-of-tree build $OOT && Usage "E: An O= option mustn't be passed twice" # set out-of-tree flag and go to the new location OOT=true cd "`parse_value \"$i\"`" ;; V) # verbose mode [ "$i" != "V=1" ] && Usage "E: Unknown parameter to V=: '$i'" VERBOSE=true ;; ARCH) ARCH="`parse_value \"$i\"`" MKPKG_ARGS="$MKPKG_ARGS --arch $ARCH" ;; CROSS_COMPILE) CR="`parse_value \"$i\"`" MKPKG_ARGS="$MKPKG_ARGS --cross-compile $CR" ;; REVISION) REVISION="`parse_value \"$i\"`" MKPKG_ARGS="$MKPKG_ARGS --revision $REVISION" ;; "-h"|"--help") Usage ;; *) # Append $i to the list of targets TARGETS[${#TARGETS[@]}]="$i" esac done if [ ${#TARGETS[@]} -eq 0 ]; then # no targets passed TARGETS[0]=build fi # Check if source and build tree are ok check_tree $VERBOSE && set -x for i in ${TARGETS[@]}; do case "$i" in clean) make_clean ;; prepare) make_clean make_conf_vars make_Makefile make_Changes make_debian make_buildinfo make_stamps ;; build) make_clean make_conf_vars make_Makefile make_Changes make_debian make_buildinfo make_stamps make_package ;; *) Usage "E: unknown target: '$i'" esac done