Update librte-pmd-bond1.symbols with new symbol.
[deb_dpdk.git] / debian / prep-modules
1 #! /bin/sh
2 #
3 # Copyright (c)  2009-2016 Andreas Beckmann <anbe@debian.org>
4 #                2010-2016 Russ Allbery <rra@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this script.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # This script originally comes from:
20 # https://anonscm.debian.org/viewvc/pkg-nvidia/packages/nvidia-graphics-drivers/trunk/debian/module/debian/prep-modules?view=markup
21 # The original copyright and license (GPL2+) can be found at:
22 # https://anonscm.debian.org/viewvc/pkg-nvidia/packages/nvidia-graphics-drivers/trunk/debian/copyright?view=markup
23 #
24 # Prepares to build kernel modules.  This script figures out and munges
25 # version strings.  The goal is:
26 #
27 #  * Set the package name to dpdk-modules-$(KVERS) where $(KVERS) is the
28 #    major kernel revision plus the debian subrevision and whatever
29 #    architecture string is appropriate if building against the stock Debian
30 #    kernels.  $(KVERS) should be identical to the version component contained
31 #    in the Debian kernel package names (in other words, the ABI version, not
32 #    the package version).
33 #
34 #  * Make the package depend on linux-image-$(KVERS) (= version) as appropriate
35 #    for the kernel version that we're building against.  Use depend as the
36 #    kernel ABI is not stable and it's not guaranteed that a module built
37 #    against a version of the headers will work under a different kernel.
38 #
39 #  * Save the version number of the binary package in debian/VERSION for later
40 #    use by dh_gencontrol.  This will be the version number of the source
41 #    package followed by a + and the version number of the kernel package that
42 #    we're building against.  If the kernel package version contains an epoch,
43 #    try to hack our way into doing the right thing by using that epoch number
44 #    as our own.  This isn't quite the right thing, but seems reasonably good.
45 #
46 # This script generates debian/control from debian/control.template using sed.
47 # Unfortunately, substvars cannot be used since the name of the package is
48 # modified and substvars happens too late.  It also outputs debian/VERSION,
49 # containing the version of the binary package.
50
51 set -e
52
53 if [ "$#" -ne 1 ]; then
54     echo "Usage: $0 <kernel-source-location>"
55     exit 1
56 fi
57
58 # We can get the kernel version from one of three places.  If KVERS and KDREV
59 # are both already set in the environment (which will be the case when invoked
60 # by make-kpkg or module-assistant), use them.  Otherwise, if we have a kernel
61 # source directory that contains debian/changelog (generated by make-kpkg),
62 # parse that file to find the version information.  Finally, if neither works,
63 # extract the kernel version from the kernel headers, append INT_SUBARCH to
64 # that version if it's available, and assume a kernel package revision of -1
65 # if none is provided.
66 #
67 # Set the variables $dpdk_kvers, which will hold the revision of the kernel,
68 # and $dpdk_kdrev, which will hold the version of the kernel package that
69 # we're building against.
70
71 changelog="$1/debian/changelog"
72 if [ -n "$KVERS" ] && [ -n "$KDREV" ]; then
73     dpdk_kvers="${KVERS}${INT_SUBARCH}"
74     dpdk_kdrev="${KDREV}"
75 elif [ ! -f "$changelog" ] ; then
76     if [ -n "$KVERS" ] ; then
77         dpdk_kvers="$KVERS"
78     else
79         dpdk_kvers=`perl debian/kernel-version "$1"`
80     fi
81     if [ -z "$KDREV" ] ; then
82         set +e
83         dpdk_kdrev=`dpkg-query -W -f='${Version}\n' linux-headers-${dpdk_kvers} 2> /dev/null`
84         if [ $? -ne 0 ] ; then
85             dpdk_kdrev="${dpdk_kvers}-1"
86         fi
87         set -e
88     else
89         dpdk_kvers="${dpdk_kvers}${INT_SUBARCH}"
90         dpdk_kdrev="${KDREV}"
91     fi
92 else
93     if [ -n "$KVERS" ] ; then
94         dpdk_kvers="$KVERS"
95     else
96         dpdk_kvers=`head -1 "$changelog" \
97             | sed -e 's/.*source-\([^ ]*\) (\([^)]*\)).*/\1/'`
98     fi
99     dpdk_kdrev=`head -1 "$changelog" \
100         | sed -e 's/.*source-\([^ ]*\) (\([^)]*\)).*/\2/'`
101 fi
102
103 # Sanitize.
104 dpdk_kvers="$(echo "$dpdk_kvers" | tr _ -)"
105 dpdk_kdrev="$(echo "$dpdk_kdrev" | tr _ -)"
106
107 # Generate the control file from the template.
108
109 sed -e "s/#KVERS#/${dpdk_kvers}/g" -e "s/#KDREV#/(= ${dpdk_kdrev})/g" debian/control.modules.in > debian/control.modules
110
111 # Now, calcuate the binary package version.  Extract the epoch from the kernel
112 # package revision and add it to the beginning of the binary package version
113 # if present.  Then, concatenate the source version, '+', and the kernel
114 # package revision without the epoch.
115
116 dpdk_version=`head -1 debian/changelog | sed -e 's/.*(\([^)]*\)).*/\1/'`
117 dpdk_epoch=`echo ${dpdk_kdrev} | sed -n -e 's/^\([0-9]*\):.*/\1/p'`
118 dpdk_version="${dpdk_version}+`echo ${dpdk_kdrev} | sed 's/^[0-9]*://'`"
119 if [ -n "$dpdk_epoch" ] ; then
120     dpdk_version="${dpdk_epoch}:${dpdk_version}"
121 fi
122
123 echo "$dpdk_version" > debian/VERSION