source: branches/contrib/debian/linux-image/build.sh @ 672

Last change on this file since 672 was 672, checked in by ehem, 5 years ago

Cover another error condition that people may run into. Some later
kernels require a later version of kernel-package to build.

Add the feature of adding ${EXTRAEXTRAVERSION} from the environment to
the kernel version. Should anyone want to add onto the version string,
this is the way to do it.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/bin/sh
2#########################################################################
3# DebWRT Linux kernel build script                                      #
4#########################################################################
5
6
7
8basedir=`pwd`/`dirname $0`
9
10case $# in
110)
12        echo Configuration is available for the devices\:
13        ( cd ${basedir} ; ls -1 configs/*.vars ) | cut -c9- | cut -d. -f1
14        exit 0
15;;
161)
17        device=$1
18;;
19*)
20        echo $0\: error\: bad argument count\: $# 1>&2
21        exit 1
22esac
23
24# check for presence of device settings
25if ! [ -f "${basedir}/configs/${device}.vars" ]
26then
27        echo $0\: error\: device \"${device}\" is unsupported
28        exit 1
29fi
30
31# check for kernel-package being installed
32if ! which make-kpkg > /dev/null
33then
34        echo $0\: kernel-package is absent, please install the package \"kernel-package\"
35        exit 1
36fi
37# retrieve kernel-package version
38kpkg_rev=`make-kpkg --help | grep -e^Version\:`
39kpkg_rev=${kpkg_rev#Version\:\ }
40
41. "${basedir}/configs/${device}.vars"
42
43# check compatibility between kernel-package and kernel
44case "${linuxver}" in
45[12].*|3.[0-9])
46        min_kpkg="12.036+nmu3"
47;;
48# I'm unsure where the version breakdown is, but 3.2 can use v12, 3.16 needs v13
493.[0-9][0-9]*|[4-9].*|*.*|*)
50        min_kpkg="13.014+nmu1"
51;;
52esac
53if dpkg --compare-versions "${kpkg_rev}" lt "${min_kpkg}"
54then
55        echo $0\: installed version of kernel-package \("${kpkg_rev}"\) is too old, need at least version "${min_kpkg}" to build
56        exit 1
57fi
58
59kernsrc="/usr/src/linux-source-${linuxver}.tar.bz2"
60
61archfull=`dpkg-architecture "-a${arch}" -qDEB_HOST_MULTIARCH`
62
63#CC=${archfull}-cc
64CC=${archfull}-gcc
65export CC
66
67if ! which ${CC} > /dev/null
68then
69        echo $0\: GCC for architecture \"${arch}\" not found, please install package c-compiler\:${arch} or c-compiler-${archfull}
70        fail=64
71fi
72
73if ! [ -f "${kernsrc}" ]
74then
75        echo $0\: Linux kernel source for version ${linuxver} is absent, please install package linux-source-${linuxver}
76        fail=64
77fi
78
79for patch in ${patches}
80do
81        if ! [ -d /usr/src/${patch} ]
82        then
83                echo $0\: Linux patch \"${patch}\" for kernel version ${linuxver} is absent, please install ${patch}
84                fail=64
85        elif ! [ -d /usr/src/${patch}/patches-${linuxver} ]
86        then
87                echo $0\: Linux patch \"${patch}\" for kernel version ${linuxvar} is absent, please install a version of ${patch}, which includes Linux ${linuxvar} support
88                fail=64
89        fi
90done
91
92for mod in ${modules}
93do
94        if ! [ -f /usr/src/${mod}.tar.bz2 ]
95        then
96                echo $0\: Linux module \"${mod}\" is absent, please install package
97                fail=64
98        fi
99done
100
101if [ -n "${fail}" ]
102then exit ${fail}
103fi
104
105# retrieve the full package/kernel version
106revision=`dpkg -s linux-source-${linuxver} | grep -e^Version\:`
107revision=${revision#Version\:\ }
108# retrieve the extra version
109revextra="${revision#${linuxver}.}"
110while [ "${revextra}" != "${revextra#[0-9]}" ]
111do revextra="${revextra#[0-9]}"
112done
113
114rm -f "${DEBIAN_BUILD_DIR}/linux-"*"-${linuxver}"*"-${device}_"*"${linuxver}"*"_${arch}.deb"
115
116linuxdir="${DEBIAN_BUILD_DIR}/linux-source-${linuxver}"
117
118
119# unpack the kernel if not already present
120if [ \! -d "${linuxdir}" -o \( -d "${linuxdir}/patches" -a \! -f "${linuxdir}/patches/.last" \) ]
121then
122        rm -rf "${linuxdir}"
123        echo tar -C \""${DEBIAN_BUILD_DIR}"\" -jxf \""${kernsrc}"\"
124        tar -C "${DEBIAN_BUILD_DIR}" -jxf "${kernsrc}"
125fi
126
127
128# remove unneeded left-behind patches, apply additional ones we need
129index=0
130for patch in ${patches}
131do
132        remove=$(echo "${linuxdir}/patches/${index}"-*.remove)
133        if [ "${remove}" \!= "${linuxdir}/patches/${index}-${patch}.remove" ]
134        then
135                if [ -x "${remove}" ]
136                then
137                        echo \""${remove}"\"
138                        "${remove}"
139                fi
140                echo \""/usr/src/${patch}/apply"\" \""${linuxdir}"\"
141                if ! "/usr/src/${patch}/apply" "${linuxdir}"
142                then
143                        echo Application of patch \"${patch}\" failed, aborting\! 1>&2
144                        rm "${linuxdir}/patches/.last"
145                        exit 1
146                fi
147        fi
148        index=$(($index + 1))
149done
150
151#
152#find "${linuxdir}" -name \*.rej -print -quit
153#
154
155
156# unpack modules used by this device
157cd "${linuxdir}"
158
159rm -rf modules
160
161for mod in ${modules}
162do
163        echo tar -C \""${linuxdir}"\" -jxf \""/usr/src/${mod}.tar.bz2"\"
164        tar -C "${linuxdir}" -jxf "/usr/src/${mod}.tar.bz2"
165done
166
167
168# setup
169rm -f "${linuxdir}/.version"
170
171echo cp \""${basedir}/configs/${device}.linux-${linuxver}.config"\" \""${linuxdir}/.config"\"
172cp "${basedir}/configs/${device}.linux-${linuxver}.config" "${linuxdir}/.config"
173
174
175# the key command
176echo MODULE_LOC=\""${linuxdir}/modules"\" make-kpkg --config config --arch \""${arch}"\" --initrd --append_to_version \""${revextra}${EXTRAEXTRAVERSION}-${device}"\" --revision \""${revision}"\" --cross-compile \""${archfull}-"\" kernel_image modules_image kernel_headers
177if ! yes "" 2>/dev/null | MODULE_LOC="${linuxdir}/modules" make-kpkg --config config --arch "${arch}" --initrd --append_to_version "${revextra}${EXTRAEXTRAVERSION}-${device}" --revision "${revision}" --cross-compile "${archfull}-" kernel_image modules_image kernel_headers
178then
179        echo ; echo Kernel build failed\!
180        exit 1
181fi
182
183
184# move the packages to the bin directory
185packages="${DEBIAN_BUILD_DIR}/linux-image-${revision}${EXTRAEXTRAVERSION}-${device}_${revision}_${arch}.deb"\ "${DEBIAN_BUILD_DIR}/linux-headers-${revision}${EXTRAEXTRAVERSION}-${device}_${revision}_${arch}.deb"
186
187if [ -n "${modules}" ]
188then    packages="${packages} ""${DEBIAN_BUILD_DIR}/linux-module-"*"-${revision}${EXTRAEXTRAVERSION}-${device}_"*"+${revision}_${arch}.deb"
189fi
190
191if ! mv -t "${INSTALL_DIR_DEBIAN_PACKAGES}" ${packages} > /dev/null 2>&1
192then
193        echo ; echo Output files missing, did kernel build fail\?
194        exit 1
195fi
196
197echo ; echo Successfully built kernel.
198
199exit 0
200
Note: See TracBrowser for help on using the repository browser.