Blame view
scripts/package/builddeb
7.14 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 |
#!/bin/sh # |
4964451a3 kbuild, deb-pkg: ... |
3 |
# builddeb 1.3 |
1da177e4c Linux-2.6.12-rc2 |
4 5 6 |
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net> # # Simple script to generate a deb package for a Linux kernel. All the |
4f66199b4 kbuild, deb-pkg: ... |
7 |
# complexity of what to do with a kernel after it is installed or removed |
1da177e4c Linux-2.6.12-rc2 |
8 |
# is left to other scripts and packages: they can install scripts in the |
fe233cb6b kbuild, deb-pkg: ... |
9 10 11 |
# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location # specified in KDEB_HOOKDIR) that will be called on package install and # removal. |
1da177e4c Linux-2.6.12-rc2 |
12 13 |
set -e |
515f4c633 kbuild: deb-pkg: ... |
14 |
is_enabled() { |
6fb7ef5a3 kbuild: pkg: grep... |
15 |
grep -q "^$1=y" include/config/auto.conf |
515f4c633 kbuild: deb-pkg: ... |
16 17 18 19 20 21 22 23 24 |
} if_enabled_echo() { if is_enabled "$1"; then echo -n "$2" elif [ $# -ge 3 ]; then echo -n "$3" fi } |
3e2ab2563 kbuild, deb-pkg: ... |
25 26 |
create_package() { local pname="$1" pdir="$2" |
3e8541803 builddeb: Enable ... |
27 |
local dpkg_deb_opts |
3e2ab2563 kbuild, deb-pkg: ... |
28 |
|
bf7b00557 deb-pkg: simplify... |
29 30 |
mkdir -m 755 -p "$pdir/DEBIAN" mkdir -p "$pdir/usr/share/doc/$pname" |
9461f666e kbuild, deb-pkg: ... |
31 |
cp debian/copyright "$pdir/usr/share/doc/$pname/" |
1ab18486e kbuild: deb-pkg s... |
32 |
cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" |
51ccdbfbe builddeb: Pass -n... |
33 |
gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian" |
b59a12258 kbuild: deb-pkg m... |
34 35 |
sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ | xargs -r0 md5sum > DEBIAN/md5sums" |
9461f666e kbuild, deb-pkg: ... |
36 |
|
3e2ab2563 kbuild, deb-pkg: ... |
37 |
# Fix ownership and permissions |
3e8541803 builddeb: Enable ... |
38 39 40 41 42 |
if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then dpkg_deb_opts="--root-owner-group" else chown -R root:root "$pdir" fi |
3e2ab2563 kbuild, deb-pkg: ... |
43 |
chmod -R go-w "$pdir" |
ca617dc68 builddeb: fix fil... |
44 45 |
# in case we are in a restrictive umask environment like 0077 chmod -R a+rX "$pdir" |
d1889589a builddeb: Fix roo... |
46 47 |
# in case we build in a setuid/setgid directory chmod -R ug-s "$pdir" |
3e2ab2563 kbuild, deb-pkg: ... |
48 |
|
dca0c0246 deb-pkg: move set... |
49 |
# Create the package |
b41d920ac kbuild: deb-pkg: ... |
50 |
dpkg-gencontrol -p$pname -P"$pdir" |
3e8541803 builddeb: Enable ... |
51 |
dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" .. |
dca0c0246 deb-pkg: move set... |
52 |
} |
3126c17d2 builddeb: split k... |
53 54 55 56 57 58 59 60 61 |
deploy_kernel_headers () { pdir=$1 rm -rf $pdir ( cd $srctree find . arch/$SRCARCH -maxdepth 1 -name Makefile\* find include scripts -type f -o -type l |
596b0474d kbuild: preproces... |
62 |
find arch/$SRCARCH -name Kbuild.platforms -o -name Platform |
3126c17d2 builddeb: split k... |
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f ) > debian/hdrsrcfiles { if is_enabled CONFIG_STACK_VALIDATION; then echo tools/objtool/objtool fi find arch/$SRCARCH/include Module.symvers include scripts -type f if is_enabled CONFIG_GCC_PLUGINS; then find scripts/gcc-plugins -name \*.so fi } > debian/hdrobjfiles destdir=$pdir/usr/src/linux-headers-$version mkdir -p $destdir tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir rm -f debian/hdrsrcfiles debian/hdrobjfiles # copy .config manually to be where it's expected to be cp $KCONFIG_CONFIG $destdir/.config mkdir -p $pdir/lib/modules/$version/ ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build } |
451dff37f builddeb: split l... |
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
deploy_libc_headers () { pdir=$1 rm -rf $pdir $MAKE -f $srctree/Makefile headers $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr # move asm headers to /usr/include/<libc-machine>/asm to match the structure # used by Debian-based distros (to support multi-arch) host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH) mkdir $pdir/usr/include/$host_arch mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/ } |
1da177e4c Linux-2.6.12-rc2 |
104 |
version=$KERNELRELEASE |
f9a4711eb builddeb: remove ... |
105 |
tmpdir=debian/linux-image |
f9a4711eb builddeb: remove ... |
106 |
dbg_dir=debian/linux-image-dbg |
f7a2c31f1 kbuild, deb-pkg: ... |
107 |
packagename=linux-image-$version |
810e84374 deb-pkg: split de... |
108 |
dbg_packagename=$packagename-dbg |
687c3dac5 uml: Make deb-pkg... |
109 |
|
4f66199b4 kbuild, deb-pkg: ... |
110 |
if [ "$ARCH" = "um" ] ; then |
687c3dac5 uml: Make deb-pkg... |
111 112 |
packagename=user-mode-linux-$version fi |
1da177e4c Linux-2.6.12-rc2 |
113 |
|
9de701764 deb-pkg: fix inst... |
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# Not all arches have the same installed path in debian # XXX: have each arch Makefile export a variable of the canonical image install # path instead case $ARCH in um) installed_image_path="usr/bin/linux-$version" ;; parisc|mips|powerpc) installed_image_path="boot/vmlinux-$version" ;; *) installed_image_path="boot/vmlinuz-$version" esac |
515f4c633 kbuild: deb-pkg: ... |
127 |
BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes) |
810e84374 deb-pkg: split de... |
128 |
|
1da177e4c Linux-2.6.12-rc2 |
129 |
# Setup the directory structure |
451dff37f builddeb: split l... |
130 |
rm -rf "$tmpdir" "$dbg_dir" debian/files |
e86c2412c kbuild, deb-pkg: ... |
131 |
mkdir -m 755 -p "$tmpdir/DEBIAN" |
bf7b00557 deb-pkg: simplify... |
132 |
mkdir -p "$tmpdir/lib" "$tmpdir/boot" |
1da177e4c Linux-2.6.12-rc2 |
133 |
|
aae6a6712 builddeb: remove ... |
134 |
# Install the kernel |
4f66199b4 kbuild, deb-pkg: ... |
135 |
if [ "$ARCH" = "um" ] ; then |
bf7b00557 deb-pkg: simplify... |
136 |
mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename" |
687c3dac5 uml: Make deb-pkg... |
137 |
cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" |
d20917670 deb-pkg: use KCON... |
138 |
cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config" |
687c3dac5 uml: Make deb-pkg... |
139 |
gzip "$tmpdir/usr/share/doc/$packagename/config" |
38385f8f0 kbuild: trivial -... |
140 |
else |
687c3dac5 uml: Make deb-pkg... |
141 |
cp System.map "$tmpdir/boot/System.map-$version" |
d20917670 deb-pkg: use KCON... |
142 |
cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version" |
9de701764 deb-pkg: fix inst... |
143 |
fi |
02826a6ba kbuild: deb-pkg: ... |
144 |
cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path" |
1da177e4c Linux-2.6.12-rc2 |
145 |
|
515f4c633 kbuild: deb-pkg: ... |
146 |
if is_enabled CONFIG_OF_EARLY_FLATTREE; then |
ca2a9d2cf deb-pkg: Add devi... |
147 |
# Only some architectures with OF support have this target |
d5615e472 builddeb: Fix inc... |
148 |
if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then |
175209cce kbuild: pkg: use ... |
149 |
$MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install |
ca2a9d2cf deb-pkg: Add devi... |
150 151 |
fi fi |
515f4c633 kbuild: deb-pkg: ... |
152 |
if is_enabled CONFIG_MODULES; then |
175209cce kbuild: pkg: use ... |
153 |
INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install |
a47b6c61f kbuild: Fix link ... |
154 155 |
rm -f "$tmpdir/lib/modules/$version/build" rm -f "$tmpdir/lib/modules/$version/source" |
4f66199b4 kbuild, deb-pkg: ... |
156 |
if [ "$ARCH" = "um" ] ; then |
687c3dac5 uml: Make deb-pkg... |
157 158 159 |
mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" rmdir "$tmpdir/lib/modules/$version" fi |
810e84374 deb-pkg: split de... |
160 |
if [ -n "$BUILD_DEBUG" ] ; then |
2d0871396 builddeb: put the... |
161 162 163 164 165 166 167 168 169 170 171 |
for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P '); do module=lib/modules/$module mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module) # only keep debug symbols in the debug file $OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module # strip original module from debug symbols $OBJCOPY --strip-debug $tmpdir/$module # then add a link to those $OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module done |
64178cb62 builddeb: fix str... |
172 173 |
# resign stripped modules |
515f4c633 kbuild: deb-pkg: ... |
174 |
if is_enabled CONFIG_MODULE_SIG_ALL; then |
175209cce kbuild: pkg: use ... |
175 |
INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign |
64178cb62 builddeb: fix str... |
176 |
fi |
810e84374 deb-pkg: split de... |
177 |
fi |
1da177e4c Linux-2.6.12-rc2 |
178 179 180 |
fi # Install the maintainer scripts |
fe233cb6b kbuild, deb-pkg: ... |
181 |
# Note: hook scripts under /etc/kernel are also executed by official Debian |
1c8ddae09 deb-pkg: Inhibit ... |
182 183 184 |
# kernel packages, as well as kernel packages built using make-kpkg. # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and # so do we; recent versions of dracut and initramfs-tools will obey this. |
fe233cb6b kbuild, deb-pkg: ... |
185 |
debhookdir=${KDEB_HOOKDIR:-/etc/kernel} |
1da177e4c Linux-2.6.12-rc2 |
186 |
for script in postinst postrm preinst prerm ; do |
fe233cb6b kbuild, deb-pkg: ... |
187 |
mkdir -p "$tmpdir$debhookdir/$script.d" |
1da177e4c Linux-2.6.12-rc2 |
188 189 190 191 |
cat <<EOF > "$tmpdir/DEBIAN/$script" #!/bin/sh set -e |
4964451a3 kbuild, deb-pkg: ... |
192 |
# Pass maintainer script parameters to hook scripts |
241ad11f2 kbuild, deb-pkg: ... |
193 |
export DEB_MAINT_PARAMS="\$*" |
4964451a3 kbuild, deb-pkg: ... |
194 |
|
1c8ddae09 deb-pkg: Inhibit ... |
195 |
# Tell initramfs builder whether it's wanted |
515f4c633 kbuild: deb-pkg: ... |
196 |
export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) |
1c8ddae09 deb-pkg: Inhibit ... |
197 |
|
c95182bf9 deb-pkg: add a ho... |
198 |
test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d |
1da177e4c Linux-2.6.12-rc2 |
199 200 201 202 |
exit 0 EOF chmod 755 "$tmpdir/DEBIAN/$script" done |
d7d357bc2 kbuild: Only buil... |
203 |
if [ "$ARCH" != "um" ]; then |
bac977cbc kbuild: deb-pkg: ... |
204 205 206 207 |
if is_enabled CONFIG_MODULES; then deploy_kernel_headers debian/linux-headers create_package linux-headers-$version debian/linux-headers fi |
3126c17d2 builddeb: split k... |
208 |
|
451dff37f builddeb: split l... |
209 210 |
deploy_libc_headers debian/linux-libc-dev create_package linux-libc-dev debian/linux-libc-dev |
d7d357bc2 kbuild: Only buil... |
211 |
fi |
3e2ab2563 kbuild, deb-pkg: ... |
212 |
create_package "$packagename" "$tmpdir" |
1da177e4c Linux-2.6.12-rc2 |
213 |
|
810e84374 deb-pkg: split de... |
214 215 216 217 218 219 220 221 222 223 224 |
if [ -n "$BUILD_DEBUG" ] ; then # Build debug package # Different tools want the image in different locations # perf mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/ cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/ # systemtap mkdir -p $dbg_dir/usr/lib/debug/boot/ ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version # kdump-tools ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version |
810e84374 deb-pkg: split de... |
225 226 |
create_package "$dbg_packagename" "$dbg_dir" fi |
1da177e4c Linux-2.6.12-rc2 |
227 |
exit 0 |