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

Last change on this file since 719 was 719, checked in by ehem, 4 years ago

Rename kernel package everything to include "debwrt"

Make use of make-kpkg's --stem option. This is so other DebWRT packages
can depend upon linux-debwrt-* to insist upon installation of DebWRT's
builds.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.9 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.*"
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
109rm -f "${DEBIAN_BUILD_DIR}/linux-"*"-${linuxver}"*"-${device}_"*"${linuxver}"*"_${arch}.deb"
110
111linuxdir="${DEBIAN_BUILD_DIR}/linux-source-${linuxver}"
112
113
114# unpack the kernel if not already present
115if [ \! -d "${linuxdir}" -o \( -d "${linuxdir}/patches" -a \! -f "${linuxdir}/patches/.last" \) ]
116then
117        rm -rf "${linuxdir}"
118        case "${kernsrc}" in
119        *.xz)
120                unpack="unxz -c"
121        ;;
122        *.bz2)
123                unpack="bunzip2 -c"
124        ;;
125        *.gz)
126                unpack="gunzip -c"
127        ;;
128        esac
129        echo ${unpack} \| tar -C \""${DEBIAN_BUILD_DIR}"\" -xf \""${kernsrc}"\"
130        ${unpack} | tar -C "${DEBIAN_BUILD_DIR}" -xf "${kernsrc}"
131fi
132
133
134# remove unneeded left-behind patches, apply additional ones we need
135index=0
136for patch in ${patches}
137do
138        remove=$(echo "${linuxdir}/patches/${index}"-*.remove)
139        if [ "${remove}" \!= "${linuxdir}/patches/${index}-${patch}.remove" ]
140        then
141                if [ -x "${remove}" ]
142                then
143                        echo \""${remove}"\"
144                        "${remove}"
145                fi
146                echo \""/usr/src/${patch}/apply"\" \""${linuxdir}"\"
147                if ! "/usr/src/${patch}/apply" "${linuxdir}"
148                then
149                        echo Application of patch \"${patch}\" failed, aborting\! 1>&2
150                        rm "${linuxdir}/patches/.last"
151                        exit 1
152                fi
153        fi
154        index=$(($index + 1))
155done
156
157#
158#find "${linuxdir}" -name \*.rej -print -quit
159#
160
161
162# unpack modules used by this device
163cd "${linuxdir}"
164
165# remove modules we're not supposed to build for this kernel
166for mod in ${linuxdir}/modules/*
167do
168        if [ "${modules}" = "${modules#*${mod##*/}}" ]
169        then    echo rm -rf \""${linuxdir}/modules/${mod}"\"
170                rm -rf "${linuxdir}/modules/${mod}"
171        fi
172done
173
174# unpack the modules that weren't already present
175for mod in ${modules}
176do
177        if [ ! -e "${linuxdir}/modules/${mod}" ]
178        then
179                case "/usr/src/${mod}.tar.*" in
180                *.xz)
181                        unpack="unxz -c"
182                ;;
183                *.bz2)
184                        unpack="bunzip2 -c"
185                ;;
186                *.gz)
187                        unpack="gunzip -c"
188                ;;
189                esac
190                echo ${unpack} \""/usr/src/${mod}.tar.*"\" \| tar -C \""${linuxdir}"\" -xf -
191                ${unpack} "/usr/src/${mod}.tar.*" | tar -C "${linuxdir}" -xf -
192        fi
193done
194
195
196# setup
197rm -f "${linuxdir}/.version"
198
199echo cp \""${basedir}/configs/${device}.linux-${linuxver}.config"\" \""${linuxdir}/.config"\"
200cp "${basedir}/configs/${device}.linux-${linuxver}.config" "${linuxdir}/.config"
201
202
203# the key command
204echo MODULE_LOC=\""${linuxdir}/modules"\" make-kpkg --config config --arch \""${arch}"\" --stem linux-debwrt --initrd --append_to_version \""-${device}${EXTRAEXTRAVERSION}"\" --revision \""${revision}"\" --cross-compile \""${archfull}-"\" kernel_image modules_image kernel_headers
205if ! yes "" 2>/dev/null | MODULE_LOC="${linuxdir}/modules" make-kpkg --config config --arch "${arch}" --stem linux-debwrt --initrd --append_to_version "-${device}${EXTRAEXTRAVERSION}" --revision "${revision}" --cross-compile "${archfull}-" kernel_image modules_image kernel_headers
206then
207        echo ; echo Kernel build failed\!
208        exit 1
209fi
210
211
212# move the packages to the bin directory
213packages="${DEBIAN_BUILD_DIR}/linux-debwrt-image-${revision}${EXTRAEXTRAVERSION}-${device}_${revision}_${arch}.deb"\ "${DEBIAN_BUILD_DIR}/linux-debwrt-headers-${revision}${EXTRAEXTRAVERSION}-${device}_${revision}_${arch}.deb"
214
215if [ -n "${modules}" ]
216then    packages="${packages} ""${DEBIAN_BUILD_DIR}/linux-debwrt-module-"*"-${revision}-${device}${EXTRAEXTRAVERSION}_"*"+${revision}_${arch}.deb"
217fi
218
219if ! mv -t "${INSTALL_DIR_DEBIAN_PACKAGES}" ${packages} > /dev/null 2>&1
220then
221        echo ; echo Output files missing, did kernel build fail\?
222        exit 1
223fi
224
225echo ; echo Successfully built kernel.
226
227exit 0
228
Note: See TracBrowser for help on using the repository browser.