2004-06-07 14:16:45

by Wichert Akkerman

[permalink] [raw]
Subject: kbuild make deb patch

I originally posted this before 2.6.0 was out and was told to wait until
things have stabilized a bit. At least from my point of view that has
happened by now so I'm bringing this one up again.

kbuild has had a rpm make target for some time now. Since the concept of
kernel packages is quite convenient I added a deb target as well, using
the patch below.

Since I'm (still) not familiar with kbuild Makefile bits are quite
rough, but they Work For Me(Tm).

Wichert.

--- linux-2.6.6/scripts/builddeb 1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6/scripts/builddeb 2004-05-21 12:23:31.000000000 +0200
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# builddeb 1.2
+# Copyright 2003,2004 Wichert Akkerman <[email protected]>
+#
+# Simple script to generate a deb package for a Linux kernel. All the
+# complexity of what to do with a kernel after it is installer or removed
+# is left to other scripts and packages: they can install scripts in the
+# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
+# package install and removal.
+
+set -e
+
+# Some variables and settings used throughout the script
+version="$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
+tmpdir="$(pwd)/debian/tmp"
+
+# Setup the directory structure
+rm -rf "$tmpdir"
+mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
+
+# Build and install the kernel
+cp System.map "$tmpdir/boot/System.map-$version"
+cp .config "$tmpdir/boot/config-$version"
+if $(arch | grep -q i.86) ; then
+ cp arch/i386/boot/bzImage "$tmpdir/boot/vmlinuz-$version"
+else
+ cp vmlinux "$tmpdir/boot/vmlinuz-$version"
+fi
+if grep -q '^CONFIG_MODULES=y' .config ; then
+ INSTALL_MOD_PATH="$tmpdir" make modules_install
+fi
+
+# Install the maintainer scripts
+for script in postinst postrm preinst prerm ; do
+ mkdir -p "$tmpdir/etc/kernel/$script.d"
+ cat <<EOF > "$tmpdir/DEBIAN/$script"
+#!/bin/sh
+
+set -e
+
+test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
+exit 0
+EOF
+ chmod 755 "$tmpdir/DEBIAN/$script"
+done
+
+name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
+# Generate a simple changelog template
+cat <<EOF > debian/changelog
+linux ($version) unstable; urgency=low
+
+ * A standard release
+
+ -- $name $(date -R)
+EOF
+
+# Generate a control file
+cat <<EOF > debian/control
+Source: linux
+Section: base
+Priority: optional
+Maintainer: $name
+Standards-Version: 3.6.1
+
+Package: linux-$version
+Architecture: any
+Description: Linux kernel, version $version
+ This package contains the Linux kernel, modules and corresponding other
+ files version $version.
+EOF
+
+# Fix some ownership and permissions
+chown -R root:root "$tmpdir"
+chmod -R go-w "$tmpdir"
+
+# Perform the final magic
+dpkg-gencontrol -isp
+dpkg --build "$tmpdir" ..
+
+exit 0
+
--- linux-2.6.6/Makefile 2004-05-10 04:32:53.000000000 +0200
+++ linux-2.6/Makefile 2004-05-10 10:37:44.000000000 +0200
@@ -788,33 +788,40 @@

###
# Cleaning is done on three levels.
-# make clean Delete most generated files
-# Leave enough to build external modules
-# make mrproper Delete the current configuration, and all generated files
+# make clean Delete all automatically generated files, including
+# tools and firmware.
+# make mrproper Delete the current configuration, and related files
+# Any core files spread around are deleted as well
# make distclean Remove editor backup files, patch leftover files and the like

# Directories & files removed with 'make clean'
-CLEAN_DIRS += $(MODVERDIR)
-CLEAN_FILES += vmlinux System.map kernel.spec \
- .tmp_kallsyms* .tmp_version .tmp_vmlinux*
-
-# Directories & files removed with 'make mrproper'
-MRPROPER_DIRS += include/config include2
-MRPROPER_FILES += .config .config.old include/asm .version \
+CLEAN_DIRS += $(MODVERDIR) include/config include2
+CLEAN_FILES += vmlinux System.map \
include/linux/autoconf.h include/linux/version.h \
- Module.symvers tags TAGS cscope*
+ include/asm include/linux/modversions.h \
+ kernel.spec .tmp*

-# clean - Delete most, but leave enough to build external modules
-#
-clean: rm-dirs := $(CLEAN_DIRS)
-clean: rm-files := $(CLEAN_FILES)
-clean-dirs := $(addprefix _clean_,$(vmlinux-alldirs))
+# Files removed with 'make mrproper'
+MRPROPER_FILES += .version .config .config.old tags TAGS cscope*

-.PHONY: $(clean-dirs) clean archclean
+# clean - Delete all intermediate files
+#
+clean-dirs += $(addprefix _clean_,$(ALL_SUBDIRS) Documentation/DocBook scripts)
+.PHONY: $(clean-dirs) clean archclean mrproper archmrproper distclean
$(clean-dirs):
$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)

-clean: archclean $(clean-dirs)
+clean: rm-dirs := $(wildcard $(CLEAN_DIRS))
+mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
+quiet_cmd_rmdirs = $(if $(rm-dirs),CLEAN $(rm-dirs))
+ cmd_rmdirs = rm -rf $(rm-dirs)
+
+clean: rm-files := $(wildcard $(CLEAN_FILES))
+mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
+quiet_cmd_rmfiles = $(if $(rm-files),CLEAN $(rm-files))
+ cmd_rmfiles = rm -rf $(rm-files)
+
+clean: archclean debclean $(clean-dirs)
$(call cmd,rmdirs)
$(call cmd,rmfiles)
@find . $(RCS_FIND_IGNORE) \
@@ -848,6 +855,66 @@
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
-type f -print | xargs rm -f

+# Generate tags for editors
+# ---------------------------------------------------------------------------
+
+define all-sources
+ ( find . $(RCS_FIND_IGNORE) \
+ \( -name include -o -name arch \) -prune -o \
+ -name '*.[chS]' -print; \
+ find arch/$(ARCH) $(RCS_FIND_IGNORE) \
+ -name '*.[chS]' -print; \
+ find include $(RCS_FIND_IGNORE) \
+ \( -name config -o -name 'asm-*' \) -prune \
+ -o -name '*.[chS]' -print; \
+ find include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
+ -name '*.[chS]' -print; \
+ find include/asm-generic $(RCS_FIND_IGNORE) \
+ -name '*.[chS]' -print )
+endef
+
+quiet_cmd_cscope-file = FILELST cscope.files
+ cmd_cscope-file = $(all-sources) > cscope.files
+
+quiet_cmd_cscope = MAKE cscope.out
+ cmd_cscope = cscope -k -b -q
+
+cscope: FORCE
+ $(call cmd,cscope-file)
+ $(call cmd,cscope)
+
+quiet_cmd_TAGS = MAKE $@
+cmd_TAGS = $(all-sources) | etags -
+
+# Exuberant ctags works better with -I
+
+quiet_cmd_tags = MAKE $@
+define cmd_tags
+ rm -f $@; \
+ CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \
+ $(all-sources) | xargs ctags $$CTAGSF -a
+endef
+
+TAGS: FORCE
+ $(call cmd,TAGS)
+
+tags: FORCE
+ $(call cmd,tags)
+
+# DEB target
+# ---------------------------------------------------------------------------
+
+.PHONY: deb debclean
+
+debclean:
+ rm -rf debian/tmp
+ rm -f debian/changelog debian/control debian/files
+ -rmdir debian
+
+deb: all
+ @echo ' Creating kernel deb package'
+ @$(srctree)/scripts/builddeb
+
# RPM target
# ---------------------------------------------------------------------------

--
Wichert Akkerman <[email protected]> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.


2004-06-07 14:36:44

by David Vrabel

[permalink] [raw]
Subject: Re: kbuild make deb patch

Wichert Akkerman wrote:
>
> kbuild has had a rpm make target for some time now. Since the concept of
> kernel packages is quite convenient I added a deb target as well,

Why this and not the make-kpkg utility in Debian's kernel-package package?

David Vrabel
--
David Vrabel, Design Engineer

Arcom, Clifton Road Tel: +44 (0)1223 411200 ext. 3233
Cambridge CB1 7EA, UK Web: http://www.arcom.com/

2004-06-07 14:39:20

by Wichert Akkerman

[permalink] [raw]
Subject: Re: kbuild make deb patch

Previously David Vrabel wrote:
> Why this and not the make-kpkg utility in Debian's kernel-package package?

Several reasons:

a) it works on non-Debian systems which use dpkg
b) it is a *lot* simpler and faster than make-kpkg

Wichert.

--
Wichert Akkerman <[email protected]> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.

2004-06-07 15:18:01

by Flavio Stanchina

[permalink] [raw]
Subject: Re: kbuild make deb patch

Wichert Akkerman wrote:
> kbuild has had a rpm make target for some time now. Since the concept of
> kernel packages is quite convenient I added a deb target as well, using
> the patch below.

I like the idea a lot, but your patch to the makefile touches quite a
few things in the clean target that AFAICT are not related to the deb
target in any way. Perhaps you are diffing from an older tree?

--
Ciao, Flavio

2004-06-07 15:22:53

by Wichert Akkerman

[permalink] [raw]
Subject: Re: kbuild make deb patch

Previously Flavio Stanchina wrote:
> I like the idea a lot, but your patch to the makefile touches quite a
> few things in the clean target that AFAICT are not related to the deb
> target in any way. Perhaps you are diffing from an older tree?

Ah, hmm, good catch. Looks like I dropped a bit of a patch at some point
due to a reject and forgot to clean that up. So lets try that again:

--- linux-2.6.6/scripts/builddeb 1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6/scripts/builddeb 2004-05-21 12:23:31.000000000 +0200
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# builddeb 1.2
+# Copyright 2003,2004 Wichert Akkerman <[email protected]>
+#
+# Simple script to generate a deb package for a Linux kernel. All the
+# complexity of what to do with a kernel after it is installer or removed
+# is left to other scripts and packages: they can install scripts in the
+# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
+# package install and removal.
+
+set -e
+
+# Some variables and settings used throughout the script
+version="$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
+tmpdir="$(pwd)/debian/tmp"
+
+# Setup the directory structure
+rm -rf "$tmpdir"
+mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
+
+# Build and install the kernel
+cp System.map "$tmpdir/boot/System.map-$version"
+cp .config "$tmpdir/boot/config-$version"
+if $(arch | grep -q i.86) ; then
+ cp arch/i386/boot/bzImage "$tmpdir/boot/vmlinuz-$version"
+else
+ cp vmlinux "$tmpdir/boot/vmlinuz-$version"
+fi
+if grep -q '^CONFIG_MODULES=y' .config ; then
+ INSTALL_MOD_PATH="$tmpdir" make modules_install
+fi
+
+# Install the maintainer scripts
+for script in postinst postrm preinst prerm ; do
+ mkdir -p "$tmpdir/etc/kernel/$script.d"
+ cat <<EOF > "$tmpdir/DEBIAN/$script"
+#!/bin/sh
+
+set -e
+
+test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
+exit 0
+EOF
+ chmod 755 "$tmpdir/DEBIAN/$script"
+done
+
+name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
+# Generate a simple changelog template
+cat <<EOF > debian/changelog
+linux ($version) unstable; urgency=low
+
+ * A standard release
+
+ -- $name $(date -R)
+EOF
+
+# Generate a control file
+cat <<EOF > debian/control
+Source: linux
+Section: base
+Priority: optional
+Maintainer: $name
+Standards-Version: 3.6.1
+
+Package: linux-$version
+Architecture: any
+Description: Linux kernel, version $version
+ This package contains the Linux kernel, modules and corresponding other
+ files version $version.
+EOF
+
+# Fix some ownership and permissions
+chown -R root:root "$tmpdir"
+chmod -R go-w "$tmpdir"
+
+# Perform the final magic
+dpkg-gencontrol -isp
+dpkg --build "$tmpdir" ..
+
+exit 0
+
--- linux-2.6.6/Makefile 2004-05-10 04:32:53.000000000 +0200
+++ linux-2.6/Makefile 2004-05-10 10:37:44.000000000 +0200
@@ -814,7 +814,7 @@
$(clean-dirs):
$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)

-clean: archclean $(clean-dirs)
+clean: archclean debclean $(clean-dirs)
$(call cmd,rmdirs)
$(call cmd,rmfiles)
@find . $(RCS_FIND_IGNORE) \
@@ -848,6 +848,20 @@
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
-type f -print | xargs rm -f

+# DEB target
+# ---------------------------------------------------------------------------
+
+.PHONY: deb debclean
+
+debclean:
+ rm -rf debian/tmp
+ rm -f debian/changelog debian/control debian/files
+ -rmdir debian
+
+deb: all
+ @echo ' Creating kernel deb package'
+ @$(srctree)/scripts/builddeb
+
# RPM target
# ---------------------------------------------------------------------------


--
Wichert Akkerman <[email protected]> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.

2004-06-08 21:02:41

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild make deb patch

On Mon, Jun 07, 2004 at 04:13:53PM +0200, Wichert Akkerman wrote:
> I originally posted this before 2.6.0 was out and was told to wait until
> things have stabilized a bit. At least from my point of view that has
> happened by now so I'm bringing this one up again.
>
> kbuild has had a rpm make target for some time now. Since the concept of
> kernel packages is quite convenient I added a deb target as well, using
> the patch below.
>
> Since I'm (still) not familiar with kbuild Makefile bits are quite
> rough, but they Work For Me(Tm).

I'm in progress of doing some infrastructure work to better support building
different packages. I have requests for .tar.gz, tar.gz2 as well
as deb.

I hope to post a few patches later this week.
I will include your script in the patch-set then.

Sam

2004-06-09 14:21:54

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: kbuild make deb patch

On Tue, 2004-06-08 23:08:46 +0200, Sam Ravnborg <[email protected]>
wrote in message <[email protected]>:
> On Mon, Jun 07, 2004 at 04:13:53PM +0200, Wichert Akkerman wrote:
> I'm in progress of doing some infrastructure work to better support building
> different packages. I have requests for .tar.gz, tar.gz2 as well
> as deb.

(Being a Debian user...) I really *love* to see a .tar.{gz,bz2} target.
For my in-house use (as well in in the company I work for) we do have a
script to basically install modules (+ vmlinuz + vmlinux + .config +
System.map), adding some identifier to the filenames (of the last four
files mentioned) and preparing a .tar.gz from that.

For my private use, my version of the script also handles some non-ia32
archs :)

MfG, JBG

--
Jan-Benedict Glaw [email protected] . +49-172-7608481
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg
fuer einen Freien Staat voll Freier B?rger" | im Internet! | im Irak!
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));


Attachments:
(No filename) (1.06 kB)
signature.asc (189.00 B)
Digital signature
Download all attachments

2004-06-13 06:11:57

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild make deb patch

On Wed, Jun 09, 2004 at 04:21:41PM +0200, Jan-Benedict Glaw wrote:
> On Tue, 2004-06-08 23:08:46 +0200, Sam Ravnborg <[email protected]>
> wrote in message <[email protected]>:
> > On Mon, Jun 07, 2004 at 04:13:53PM +0200, Wichert Akkerman wrote:
> > I'm in progress of doing some infrastructure work to better support building
> > different packages. I have requests for .tar.gz, tar.gz2 as well
> > as deb.
>
> (Being a Debian user...) I really *love* to see a .tar.{gz,bz2} target.
> For my in-house use (as well in in the company I work for) we do have a
> script to basically install modules (+ vmlinuz + vmlinux + .config +
> System.map), adding some identifier to the filenames (of the last four
> files mentioned) and preparing a .tar.gz from that.

Could you try to be more specific in what you expect to see in a .tar.gz'ed kernel.
A script that creates a .tar.gz from current kernel would be fine :-)


I expect something like:
All files stored in a directory named: kernel-2.6.6-rc4/
Includes all source files
Includes .config

Do you expect to see a fully build kernel?
- With all .o files
- With the output file (bzImage or whatever used by selected architecture)

Anything else?

Sam

2004-06-14 08:34:25

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: kbuild make deb patch

On Sun, 2004-06-13 08:19:57 +0200, Sam Ravnborg <[email protected]>
wrote in message <[email protected]>:
> On Wed, Jun 09, 2004 at 04:21:41PM +0200, Jan-Benedict Glaw wrote:
> > On Tue, 2004-06-08 23:08:46 +0200, Sam Ravnborg <[email protected]>
> > wrote in message <[email protected]>:
> > > On Mon, Jun 07, 2004 at 04:13:53PM +0200, Wichert Akkerman wrote:
> > > I'm in progress of doing some infrastructure work to better support building
> > > different packages. I have requests for .tar.gz, tar.gz2 as well
> > > as deb.
> >
> > (Being a Debian user...) I really *love* to see a .tar.{gz,bz2} target.
> > For my in-house use (as well in in the company I work for) we do have a
> > script to basically install modules (+ vmlinuz + vmlinux + .config +
> > System.map), adding some identifier to the filenames (of the last four
> > files mentioned) and preparing a .tar.gz from that.
>
> Could you try to be more specific in what you expect to see in a .tar.gz'ed kernel.
> A script that creates a .tar.gz from current kernel would be fine :-)

I'd expect something that you can extract with:

~# cd /
/# tar xzf /path/to/kernel.tar.gz --no-same-owner

That tar file should contain:

./boot/vmlinux-<version> # unstripped vmlinux file for debugging
./boot/vmlinuz-<version> # bootable file - non-i386 archs obviously
# need different files
./boot/System.map-<version> # Map file for 'ps' and for me
./boot/config-<version> # To recreate the kernel
./boot/patch-<version> # Only if it was requested at .tar.gz
# build time, containing a -Nurp style
# diff to a clean source tree (which
# needs to be specified then)
./lib/modules/<kversion>/* # Modules

The tricky part is the <version> and/or <kversion> part. For my personal
use, version is like kversion, but extended with whatever the user
specified. kversion is Makefile's $(KERNELRELEASE).

As I stated, it's clumsy at ./lib/modules/<kversion>/*, because you'll
probably overwrite other modules of the same kernel version with a
different(ly compiled) .tar.gz . The tarball's name should exactly
contain <version> in it's name so that a script that extracts is can
place a proper symlink within ./boot easily.

MfG, JBG

--
Jan-Benedict Glaw [email protected] . +49-172-7608481
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg
fuer einen Freien Staat voll Freier B?rger" | im Internet! | im Irak!
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));


Attachments:
(No filename) (2.49 kB)
signature.asc (189.00 B)
Digital signature
Download all attachments