3 # Prepares to build kernel modules. This script figures out and munges
4 # version strings. The goal is:
6 # * Set the package name to openafs-modules-$(KVERS) where $(KVERS) is the
7 # major kernel revision plus the debian subrevision and whatever
8 # architecture string is appropriate if building against the stock Debian
9 # kernels. $(KVERS) should be identical to the version component contained
10 # in the Debian kernel package names.
12 # * Make the package recommend either kernel-image-$(KVERS) or
13 # linux-image-$(KVERS) as appropriate for the kernel version that we're
14 # building against. Use recommend rather than depends since the user may
15 # have built their own kernel outside of the Debian package infrastructure.
17 # * Save the version number of the binary package in debian/VERSION for later
18 # use by dh_gencontrol. This will be the version number of the source
19 # package followed by a + and the version number of the kernel package that
20 # we're building against. If the kernel package version contains an epoch,
21 # try to hack our way into doing the right thing by using that epoch number
22 # as our own. This isn't quite the right thing, but seems reasonably good.
24 # This script generates debian/control from debian/control.module using sed.
25 # Unfortunately, substvars cannot be used since the name of the package is
26 # modified and substvars happens too late. It also outputs debian/VERSION,
27 # containing the version of the binary package.
31 if [ "$#" -ne 1 ]; then
32 echo Usage: $0 kernelsource-location
36 # We can get the kernel version from one of three places. If KVERS and KDREV
37 # are both already set in the environment (which will be the case when invoked
38 # by make-kpkg or module-assistant), use them. Otherwise, if we have a kernel
39 # source directory that contains debian/changelog (generated by make-kpkg),
40 # parse that file to find the version information. Finally, if neither works,
41 # extract the kernel version from the kernel headers, append INT_SUBARCH to
42 # that version if it's available, and assume a kernel package revision of -0
43 # if none is provided.
45 # Set the variables $afs_kvers, which will hold the revision of the kernel,
46 # and $afs_kdrev, which will hold the version of the kernel package that we're
49 changelog="$1/debian/changelog"
50 if [ -n "$KVERS" ] && [ -n "$KDREV" ]; then
51 afs_kvers="${KVERS}${INT_SUBARCH}"
53 elif [ ! -f "$changelog" ] ; then
54 if [ -n "$KVERS" ] ; then
57 afs_kvers=`perl debian/kernel-version "$1"`
59 if [ -z "$KDREV" ] ; then
60 afs_kdrev="${afs_kvers}-0"
62 afs_kvers="${afs_kvers}${INT_SUBARCH}"
66 if [ -n "$KVERS" ] ; then
69 afs_kvers=`head -1 "$changelog" \
70 | sed -e 's/.*source-\([^ ]*\) (\([^)]*\)).*/\1/'`
72 afs_kdrev=`head -1 "$changelog" \
73 | sed -e 's/.*source-\([^ ]*\) (\([^)]*\)).*/\2/'`
76 # Determine the kernel package name. For right now, assume linux-image for
77 # 2.6.12 and later, and kernel-image for anything earlier. If this doesn't
78 # work for someone, please submit a bug with the details.
80 if dpkg --compare-versions "$afs_kvers" ge "2.6.12" ; then
83 afs_image=kernel-image
86 # Generate the control file from the template.
88 sed -e "s/=KVERS/${afs_kvers}/g" -e "s/=IMG/${afs_image}/g" \
89 debian/control.module > debian/control
91 # Now, calcuate the binary package version. Extract the epoch from the kernel
92 # package revision and add it to the beginning of the binary package version
93 # if present. Then, concatenate the source version, '+', and the kernel
94 # package revision without the epoch.
96 afs_version=`head -1 debian/changelog | sed -e 's/.*(\([^)]*\)).*/\1/'`
97 afs_epoch=`echo ${afs_kdrev} | sed -n -e 's/^\([0-9]*\):.*/\1/p'`
98 afs_version="${afs_version}+`echo ${afs_kdrev} | sed -e 's/^[0-9]*://'`"
99 if [ -n "$afs_epoch" ] ; then
100 afs_version="${afs_epoch}:${afs_version}"
103 echo "$afs_version" > debian/VERSION