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

Last change on this file since 764 was 764, checked in by ehem, 3 years ago

Fix build issue with dash update?

It was /supposed/ to do filename expansion at this one point, did it
recieve inadaquate testing before, or did a newer dash really break
pathname expansion at the one point?!

Make sure many error messages go to stderr instead of stdout.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.1 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 1>&2
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\" 1>&2
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 1>&2
56        exit 1
57fi
58
59kernsrc="/usr/src/linux-source-${linuxver}.tar."*
60# WTF! pathname expansion *isn't* happening above?!
61kernsrc=`echo ${kernsrc}`
62
63archfull=`dpkg-architecture "-a${arch}" -qDEB_HOST_MULTIARCH`
64
65#CC=${archfull}-cc
66CC=${archfull}-gcc
67export CC
68
69if ! which ${CC} > /dev/null
70then
71        echo $0\: GCC for architecture \"${arch}\" not found, please install package c-compiler\:${arch} or c-compiler-${archfull} 1>&2
72        fail=64
73fi
74
75if ! [ -f "${kernsrc}" ]
76then
77        echo $0\: Linux kernel source for version ${linuxver} is absent, please install package linux-source-${linuxver} 1>&2
78        fail=64
79fi
80
81for patch in ${patches}
82do
83        if ! [ -d /usr/src/${patch} ]
84        then
85                echo $0\: Linux patch \"${patch}\" for kernel version ${linuxver} is absent, please install ${patch} 1>&2
86                fail=64
87        elif ! [ -d /usr/src/${patch}/patches-${linuxver} ]
88        then
89                echo $0\: Linux patch \"${patch}\" for kernel version ${linuxvar} is absent, please install a version of ${patch}, which includes Linux ${linuxvar} support 1>&2
90                fail=64
91        fi
92done
93
94for mod in ${modules}
95do
96        if ! [ -f /usr/src/${mod}.tar.bz2 ]
97        then
98                echo $0\: Linux module \"${mod}\" is absent, please install package 1>&2
99                fail=64
100        fi
101done
102
103if [ -n "${fail}" ]
104then exit ${fail}
105fi
106
107# retrieve the full package/kernel version
108revision=`dpkg -s linux-source-${linuxver} | grep -e^Version\:`
109revision=${revision#Version\:\ }
110
111rm -f "${DEBIAN_BUILD_DIR}/linux-"*"-${linuxver}"*"-${device}_"*"${linuxver}"*"_${arch}.deb"
112
113linuxdir="${DEBIAN_BUILD_DIR}/linux-source-${linuxver}"
114
115
116# unpack the kernel if not already present
117if [ \! -d "${linuxdir}" -o \( -d "${linuxdir}/patches" -a \! -f "${linuxdir}/patches/.last" \) ]
118then
119        rm -rf "${linuxdir}"
120        case "${kernsrc}" in
121        (*.xz)
122                unpack="unxz -c"
123        ;;
124        (*.bz2)
125                unpack="bunzip2 -c"
126        ;;
127        (*.gz)
128                unpack="gunzip -c"
129        ;;
130        (*)
131                echo $0: Fatal, don\'t know how to unpack file \""${kernsrc}"\" 1>&2
132                exit 64
133        ;;
134        esac
135        echo ${unpack} \""${kernsrc}"\" \| tar -C \""${DEBIAN_BUILD_DIR}"\" -xf -
136        ${unpack} "${kernsrc}" | tar -C "${DEBIAN_BUILD_DIR}" -xf -
137fi
138
139
140# remove unneeded left-behind patches, apply additional ones we need
141index=0
142for patch in ${patches}
143do
144        remove=$(echo "${linuxdir}/patches/${index}"-*.remove)
145        if [ "${remove}" \!= "${linuxdir}/patches/${index}-${patch}.remove" ]
146        then
147                if [ -x "${remove}" ]
148                then
149                        echo \""${remove}"\"
150                        "${remove}"
151                fi
152                echo \""/usr/src/${patch}/apply"\" \""${linuxdir}"\"
153                if ! "/usr/src/${patch}/apply" "${linuxdir}"
154                then
155                        echo Application of patch \"${patch}\" failed, aborting\! 1>&2
156                        rm "${linuxdir}/patches/.last"
157                        exit 1
158                fi
159        fi
160        index=$(($index + 1))
161done
162
163#
164#find "${linuxdir}" -name \*.rej -print -quit
165#
166
167
168# unpack modules used by this device
169cd "${linuxdir}"
170
171# remove modules we're not supposed to build for this kernel
172for mod in ${linuxdir}/modules/*
173do
174        if [ "${modules}" = "${modules#*${mod##*/}}" ]
175        then    echo rm -rf \""${linuxdir}/modules/${mod}"\"
176                rm -rf "${linuxdir}/modules/${mod}"
177        fi
178done
179
180# unpack the modules that weren't already present
181for mod in ${modules}
182do
183        if [ ! -e "${linuxdir}/modules/${mod}" ]
184        then
185                case "/usr/src/${mod}.tar.*" in
186                *.xz)
187                        unpack="unxz -c"
188                ;;
189                *.bz2)
190                        unpack="bunzip2 -c"
191                ;;
192                *.gz)
193                        unpack="gunzip -c"
194                ;;
195                esac
196                echo ${unpack} \""/usr/src/${mod}.tar.*"\" \| tar -C \""${linuxdir}"\" -xf -
197                ${unpack} "/usr/src/${mod}.tar.*" | tar -C "${linuxdir}" -xf -
198        fi
199done
200
201
202# setup
203rm -f "${linuxdir}/.version"
204
205echo cp \""${basedir}/configs/${device}.linux-${linuxver}.config"\" \""${linuxdir}/.config"\"
206cp "${basedir}/configs/${device}.linux-${linuxver}.config" "${linuxdir}/.config"
207
208
209# the key command
210echo 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
211if ! 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
212then
213        echo ; echo Kernel build failed\! 1>&2
214        exit 1
215fi
216
217
218# move the packages to the bin directory
219packages="${DEBIAN_BUILD_DIR}/linux-debwrt-image-${revision}${EXTRAEXTRAVERSION}-${device}_${revision}_${arch}.deb"\ "${DEBIAN_BUILD_DIR}/linux-debwrt-headers-${revision}${EXTRAEXTRAVERSION}-${device}_${revision}_${arch}.deb"
220
221if [ -n "${modules}" ]
222then    packages="${packages} ""${DEBIAN_BUILD_DIR}/linux-debwrt-module-"*"-${revision}-${device}${EXTRAEXTRAVERSION}_"*"+${revision}_${arch}.deb"
223fi
224
225if ! mv -t "${INSTALL_DIR_DEBIAN_PACKAGES}" ${packages} > /dev/null 2>&1
226then
227        echo ; echo Output files missing, did kernel build fail\? 1>&2
228        exit 1
229fi
230
231echo ; echo Successfully built kernel.
232
233exit 0
234
Note: See TracBrowser for help on using the repository browser.