Blame view

scripts/package/builddeb 7.14 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  #!/bin/sh
  #
4964451a3   Frans Pop   kbuild, deb-pkg: ...
3
  # builddeb 1.3
1da177e4c   Linus Torvalds   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   Frans Pop   kbuild, deb-pkg: ...
7
  # complexity of what to do with a kernel after it is installed or removed
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
  # is left to other scripts and packages: they can install scripts in the
fe233cb6b   Frans Pop   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   Linus Torvalds   Linux-2.6.12-rc2
12
13
  
  set -e
515f4c633   Masahiro Yamada   kbuild: deb-pkg: ...
14
  is_enabled() {
6fb7ef5a3   Masahiro Yamada   kbuild: pkg: grep...
15
  	grep -q "^$1=y" include/config/auto.conf
515f4c633   Masahiro Yamada   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   Frans Pop   kbuild, deb-pkg: ...
25
26
  create_package() {
  	local pname="$1" pdir="$2"
3e8541803   Guillem Jover   builddeb: Enable ...
27
  	local dpkg_deb_opts
3e2ab2563   Frans Pop   kbuild, deb-pkg: ...
28

bf7b00557   Riku Voipio   deb-pkg: simplify...
29
30
  	mkdir -m 755 -p "$pdir/DEBIAN"
  	mkdir -p "$pdir/usr/share/doc/$pname"
9461f666e   Frans Pop   kbuild, deb-pkg: ...
31
  	cp debian/copyright "$pdir/usr/share/doc/$pname/"
1ab18486e   maximilian attems   kbuild: deb-pkg s...
32
  	cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
51ccdbfbe   Guillem Jover   builddeb: Pass -n...
33
  	gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
b59a12258   FEJES Jozsef   kbuild: deb-pkg m...
34
35
  	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
  		| xargs -r0 md5sum > DEBIAN/md5sums"
9461f666e   Frans Pop   kbuild, deb-pkg: ...
36

3e2ab2563   Frans Pop   kbuild, deb-pkg: ...
37
  	# Fix ownership and permissions
3e8541803   Guillem Jover   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   Frans Pop   kbuild, deb-pkg: ...
43
  	chmod -R go-w "$pdir"
ca617dc68   Henning Schild   builddeb: fix fil...
44
45
  	# in case we are in a restrictive umask environment like 0077
  	chmod -R a+rX "$pdir"
d1889589a   Sven Joachim   builddeb: Fix roo...
46
47
  	# in case we build in a setuid/setgid directory
  	chmod -R ug-s "$pdir"
3e2ab2563   Frans Pop   kbuild, deb-pkg: ...
48

dca0c0246   Riku Voipio   deb-pkg: move set...
49
  	# Create the package
b41d920ac   Riku Voipio   kbuild: deb-pkg: ...
50
  	dpkg-gencontrol -p$pname -P"$pdir"
3e8541803   Guillem Jover   builddeb: Enable ...
51
  	dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
dca0c0246   Riku Voipio   deb-pkg: move set...
52
  }
3126c17d2   Masahiro Yamada   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   Masahiro Yamada   kbuild: preproces...
62
  		find arch/$SRCARCH -name Kbuild.platforms -o -name Platform
3126c17d2   Masahiro Yamada   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   Masahiro Yamada   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   Linus Torvalds   Linux-2.6.12-rc2
104
  version=$KERNELRELEASE
f9a4711eb   Masahiro Yamada   builddeb: remove ...
105
  tmpdir=debian/linux-image
f9a4711eb   Masahiro Yamada   builddeb: remove ...
106
  dbg_dir=debian/linux-image-dbg
f7a2c31f1   maximilian attems   kbuild, deb-pkg: ...
107
  packagename=linux-image-$version
810e84374   Anisse Astier   deb-pkg: split de...
108
  dbg_packagename=$packagename-dbg
687c3dac5   Sam Ravnborg   uml: Make deb-pkg...
109

4f66199b4   Frans Pop   kbuild, deb-pkg: ...
110
  if [ "$ARCH" = "um" ] ; then
687c3dac5   Sam Ravnborg   uml: Make deb-pkg...
111
112
  	packagename=user-mode-linux-$version
  fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113

9de701764   Anisse Astier   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   Masahiro Yamada   kbuild: deb-pkg: ...
127
  BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
810e84374   Anisse Astier   deb-pkg: split de...
128

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
  # Setup the directory structure
451dff37f   Masahiro Yamada   builddeb: split l...
130
  rm -rf "$tmpdir" "$dbg_dir" debian/files
e86c2412c   maximilian attems   kbuild, deb-pkg: ...
131
  mkdir -m 755 -p "$tmpdir/DEBIAN"
bf7b00557   Riku Voipio   deb-pkg: simplify...
132
  mkdir -p "$tmpdir/lib" "$tmpdir/boot"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133

aae6a6712   Masahiro Yamada   builddeb: remove ...
134
  # Install the kernel
4f66199b4   Frans Pop   kbuild, deb-pkg: ...
135
  if [ "$ARCH" = "um" ] ; then
bf7b00557   Riku Voipio   deb-pkg: simplify...
136
  	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
687c3dac5   Sam Ravnborg   uml: Make deb-pkg...
137
  	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
d20917670   Anisse Astier   deb-pkg: use KCON...
138
  	cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
687c3dac5   Sam Ravnborg   uml: Make deb-pkg...
139
  	gzip "$tmpdir/usr/share/doc/$packagename/config"
38385f8f0   Masahiro Yamada   kbuild: trivial -...
140
  else
687c3dac5   Sam Ravnborg   uml: Make deb-pkg...
141
  	cp System.map "$tmpdir/boot/System.map-$version"
d20917670   Anisse Astier   deb-pkg: use KCON...
142
  	cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
9de701764   Anisse Astier   deb-pkg: fix inst...
143
  fi
02826a6ba   Masahiro Yamada   kbuild: deb-pkg: ...
144
  cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145

515f4c633   Masahiro Yamada   kbuild: deb-pkg: ...
146
  if is_enabled CONFIG_OF_EARLY_FLATTREE; then
ca2a9d2cf   Arnaud Patard   deb-pkg: Add devi...
147
  	# Only some architectures with OF support have this target
d5615e472   Rob Herring   builddeb: Fix inc...
148
  	if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
175209cce   Masahiro Yamada   kbuild: pkg: use ...
149
  		$MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
ca2a9d2cf   Arnaud Patard   deb-pkg: Add devi...
150
151
  	fi
  fi
515f4c633   Masahiro Yamada   kbuild: deb-pkg: ...
152
  if is_enabled CONFIG_MODULES; then
175209cce   Masahiro Yamada   kbuild: pkg: use ...
153
  	INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install
a47b6c61f   Joerg Roedel   kbuild: Fix link ...
154
155
  	rm -f "$tmpdir/lib/modules/$version/build"
  	rm -f "$tmpdir/lib/modules/$version/source"
4f66199b4   Frans Pop   kbuild, deb-pkg: ...
156
  	if [ "$ARCH" = "um" ] ; then
687c3dac5   Sam Ravnborg   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   Anisse Astier   deb-pkg: split de...
160
  	if [ -n "$BUILD_DEBUG" ] ; then
2d0871396   Michal Marek   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   Andrey Skvortsov   builddeb: fix str...
172
173
  
  		# resign stripped modules
515f4c633   Masahiro Yamada   kbuild: deb-pkg: ...
174
  		if is_enabled CONFIG_MODULE_SIG_ALL; then
175209cce   Masahiro Yamada   kbuild: pkg: use ...
175
  			INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign
64178cb62   Andrey Skvortsov   builddeb: fix str...
176
  		fi
810e84374   Anisse Astier   deb-pkg: split de...
177
  	fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
179
180
  fi
  
  # Install the maintainer scripts
fe233cb6b   Frans Pop   kbuild, deb-pkg: ...
181
  # Note: hook scripts under /etc/kernel are also executed by official Debian
1c8ddae09   Ben Hutchings   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   Frans Pop   kbuild, deb-pkg: ...
185
  debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
  for script in postinst postrm preinst prerm ; do
fe233cb6b   Frans Pop   kbuild, deb-pkg: ...
187
  	mkdir -p "$tmpdir$debhookdir/$script.d"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
188
189
190
191
  	cat <<EOF > "$tmpdir/DEBIAN/$script"
  #!/bin/sh
  
  set -e
4964451a3   Frans Pop   kbuild, deb-pkg: ...
192
  # Pass maintainer script parameters to hook scripts
241ad11f2   maximilian attems   kbuild, deb-pkg: ...
193
  export DEB_MAINT_PARAMS="\$*"
4964451a3   Frans Pop   kbuild, deb-pkg: ...
194

1c8ddae09   Ben Hutchings   deb-pkg: Inhibit ...
195
  # Tell initramfs builder whether it's wanted
515f4c633   Masahiro Yamada   kbuild: deb-pkg: ...
196
  export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
1c8ddae09   Ben Hutchings   deb-pkg: Inhibit ...
197

c95182bf9   Anisse Astier   deb-pkg: add a ho...
198
  test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
201
202
  exit 0
  EOF
  	chmod 755 "$tmpdir/DEBIAN/$script"
  done
d7d357bc2   Joerg Roedel   kbuild: Only buil...
203
  if [ "$ARCH" != "um" ]; then
bac977cbc   Masahiro Yamada   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   Masahiro Yamada   builddeb: split k...
208

451dff37f   Masahiro Yamada   builddeb: split l...
209
210
  	deploy_libc_headers debian/linux-libc-dev
  	create_package linux-libc-dev debian/linux-libc-dev
d7d357bc2   Joerg Roedel   kbuild: Only buil...
211
  fi
3e2ab2563   Frans Pop   kbuild, deb-pkg: ...
212
  create_package "$packagename" "$tmpdir"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213

810e84374   Anisse Astier   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   Anisse Astier   deb-pkg: split de...
225
226
  	create_package "$dbg_packagename" "$dbg_dir"
  fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
  exit 0