builddeb 7.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2
#!/bin/sh
#
3
# builddeb 1.3
L
Linus Torvalds 已提交
4 5 6
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
#
# Simple script to generate a deb package for a Linux kernel. All the
7
# complexity of what to do with a kernel after it is installed or removed
L
Linus Torvalds 已提交
8
# is left to other scripts and packages: they can install scripts in the
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.
L
Linus Torvalds 已提交
12 13 14

set -e

15
is_enabled() {
16
	grep -q "^$1=y" include/config/auto.conf
17 18 19 20 21 22 23 24 25 26
}

if_enabled_echo() {
	if is_enabled "$1"; then
		echo -n "$2"
	elif [ $# -ge 3 ]; then
		echo -n "$3"
	fi
}

27 28 29
create_package() {
	local pname="$1" pdir="$2"

30 31
	mkdir -m 755 -p "$pdir/DEBIAN"
	mkdir -p "$pdir/usr/share/doc/$pname"
32
	cp debian/copyright "$pdir/usr/share/doc/$pname/"
33 34
	cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
	gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
F
FEJES Jozsef 已提交
35 36
	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
		| xargs -r0 md5sum > DEBIAN/md5sums"
37

38 39 40
	# Fix ownership and permissions
	chown -R root:root "$pdir"
	chmod -R go-w "$pdir"
41 42
	# in case we are in a restrictive umask environment like 0077
	chmod -R a+rX "$pdir"
43

44
	# Create the package
45
	dpkg-gencontrol -p$pname -P"$pdir"
46 47 48
	dpkg --build "$pdir" ..
}

L
Linus Torvalds 已提交
49 50
version=$KERNELRELEASE
tmpdir="$objtree/debian/tmp"
51 52
kernel_headers_dir="$objtree/debian/hdrtmp"
libc_headers_dir="$objtree/debian/headertmp"
53
dbg_dir="$objtree/debian/dbgtmp"
54
packagename=linux-image-$version
55 56
kernel_headers_packagename=linux-headers-$version
libc_headers_packagename=linux-libc-dev
57
dbg_packagename=$packagename-dbg
58

59
if [ "$ARCH" = "um" ] ; then
60 61
	packagename=user-mode-linux-$version
fi
L
Linus Torvalds 已提交
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76
# 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

77
BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
78

L
Linus Torvalds 已提交
79
# Setup the directory structure
80
rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files
81
mkdir -m 755 -p "$tmpdir/DEBIAN"
82
mkdir -p "$tmpdir/lib" "$tmpdir/boot"
83
mkdir -p "$kernel_headers_dir/lib/modules/$version/"
L
Linus Torvalds 已提交
84 85

# Build and install the kernel
86
if [ "$ARCH" = "um" ] ; then
87
	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
88 89
	$MAKE linux
	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
90
	cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
91
	gzip "$tmpdir/usr/share/doc/$packagename/config"
92
else
93
	cp System.map "$tmpdir/boot/System.map-$version"
94
	cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
95
fi
96
cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
L
Linus Torvalds 已提交
97

98
if is_enabled CONFIG_OF_EARLY_FLATTREE; then
99
	# Only some architectures with OF support have this target
100
	if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
101
		$MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
102 103 104
	fi
fi

105
if is_enabled CONFIG_MODULES; then
106
	INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install
107 108
	rm -f "$tmpdir/lib/modules/$version/build"
	rm -f "$tmpdir/lib/modules/$version/source"
109
	if [ "$ARCH" = "um" ] ; then
110 111 112
		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
		rmdir "$tmpdir/lib/modules/$version"
	fi
113
	if [ -n "$BUILD_DEBUG" ] ; then
114 115 116 117 118 119 120 121 122 123
		for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); 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
124 125

		# resign stripped modules
126
		if is_enabled CONFIG_MODULE_SIG_ALL; then
127
			INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign
128
		fi
129
	fi
L
Linus Torvalds 已提交
130 131
fi

132
if [ "$ARCH" != "um" ]; then
133
	$MAKE -f $srctree/Makefile headers
134
	$MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH="$libc_headers_dir/usr"
135
fi
136

L
Linus Torvalds 已提交
137
# Install the maintainer scripts
138
# Note: hook scripts under /etc/kernel are also executed by official Debian
139 140 141
# 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.
142
debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
L
Linus Torvalds 已提交
143
for script in postinst postrm preinst prerm ; do
144
	mkdir -p "$tmpdir$debhookdir/$script.d"
L
Linus Torvalds 已提交
145 146 147 148 149
	cat <<EOF > "$tmpdir/DEBIAN/$script"
#!/bin/sh

set -e

150
# Pass maintainer script parameters to hook scripts
151
export DEB_MAINT_PARAMS="\$*"
152

153
# Tell initramfs builder whether it's wanted
154
export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
155

156
test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
L
Linus Torvalds 已提交
157 158 159 160 161
exit 0
EOF
	chmod 755 "$tmpdir/DEBIAN/$script"
done

162
# Build kernel header package
M
Michal Marek 已提交
163
(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles"
164
(cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles"
165 166
(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
167
if is_enabled CONFIG_STACK_VALIDATION; then
168 169
	(cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles"
fi
M
Michal Marek 已提交
170
(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
171
if is_enabled CONFIG_GCC_PLUGINS; then
172 173
	(cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
fi
174 175
destdir=$kernel_headers_dir/usr/src/linux-headers-$version
mkdir -p "$destdir"
M
Michal Marek 已提交
176 177
(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
(cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -)
178
(cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be
179
ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build"
180
rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles"
181

182 183 184 185 186
if [ "$ARCH" != "um" ]; then
	create_package "$kernel_headers_packagename" "$kernel_headers_dir"
	create_package "$libc_headers_packagename" "$libc_headers_dir"
fi

187
create_package "$packagename" "$tmpdir"
L
Linus Torvalds 已提交
188

189 190 191 192 193 194 195 196 197 198 199 200 201 202
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
	create_package "$dbg_packagename" "$dbg_dir"
fi

L
Linus Torvalds 已提交
203
exit 0