aboutsummaryrefslogtreecommitdiffstats
path: root/debian/rules.real
blob: 273df72b6e9808fd4cd4e9210f93cb89982badae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#
# This Makefile executes the unpack/build/binary targets for a single
# subarch, which is passed in the subarch variable. Empty subarch
# variable means that we are building for an arch without the subarch.
# Additionally, variables version, abiname and ltver are
# expected to be available (need to be exported from the parent process).
#
SHELL  := bash -e
DEB_HOST_ARCH     := $(shell dpkg-architecture -a'$(ARCH)' -qDEB_HOST_ARCH)
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -a'$(ARCH)' -qDEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH:= $(shell dpkg-architecture -a'$(ARCH)' -qDEB_HOST_MULTIARCH)
DEB_BUILD_ARCH    := $(shell dpkg-architecture -a'$(ARCH)' -qDEB_BUILD_ARCH)
MAINTAINER := $(shell sed -ne 's,^Maintainer: .[^<]*<\([^>]*\)>,\1,p' debian/control)
DISTRIBUTION := $(shell dpkg-parsechangelog | sed -ne 's,^Distribution: ,,p')

DISTRIBUTOR := $(shell lsb_release -is 2>/dev/null)
ifeq ($(DISTRIBUTOR),)
DISTRIBUTOR := Debian
endif

export PYTHONPATH = $(CURDIR)/debian/lib/python
export DH_OPTIONS
export DEB_HOST_ARCH DEB_HOST_GNU_TYPE DEB_BUILD_ARCH

ifneq (,$(filter experimental UNRELEASED,$(DISTRIBUTION)))
  export KW_CHECK_NONFATAL = y
endif

# Set Multi-Arch fields only when built in a suite that supports it
ifneq (,$(DEB_HOST_MULTIARCH))
DEFINE_MULTIARCH = -Vlinux:Multi-Arch=$(1)
else
DEFINE_MULTIARCH = -Vlinux:Multi-Arch=
endif

include debian/rules.defs

stamp = [ -d $(dir $@) ] || mkdir $(dir $@); touch $@

setup_env := env -u ABINAME -u ABINAME_PART -u ARCH -u FEATURESET -u FLAVOUR -u VERSION -u LOCALVERSION
setup_env += DISTRIBUTION_OFFICIAL_BUILD=1 DISTRIBUTOR="$(DISTRIBUTOR)" DISTRIBUTION_VERSION="$(SOURCEVERSION)" KBUILD_BUILD_TIMESTAMP="$(DISTRIBUTOR) $(SOURCEVERSION)" KBUILD_BUILD_USER="$(word 1,$(subst @, ,$(MAINTAINER)))" KBUILD_BUILD_HOST="$(word 2,$(subst @, ,$(MAINTAINER)))"

MAKE_CLEAN = $(setup_env) $(MAKE)
MAKE_SELF := $(MAKE) -f debian/rules.real $(MAKEOVERRIDES)
MAKEOVERRIDES =

#
# Targets
#
ifneq ($(FOREIGN_KERNEL),True)
  binary-arch-arch: install-headers_$(ARCH)
endif
binary-arch-arch: install-libc-dev_$(ARCH)
binary-arch-featureset: install-headers_$(ARCH)_$(FEATURESET)
binary-arch-flavour: install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE)
ifeq ($(DEBUG),True)
  binary-arch-flavour: install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
endif
ifeq ($(MODULES),True)
  binary-arch-flavour: install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
endif

binary-indep: install-doc
binary-indep: install-manual
binary-indep: install-source
binary-indep: install-support

build-arch: $(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE)
build-indep: $(STAMPS_DIR)/build-doc

setup-flavour: $(STAMPS_DIR)/setup_$(ARCH)_$(FEATURESET)_$(FLAVOUR)

source-featureset: $(STAMPS_DIR)/source_$(FEATURESET)

$(BUILD_DIR)/config.$(ARCH)_$(FEATURESET)_$(FLAVOUR): $(KCONFIG)
	mkdir -p '$(dir $@)'
	python debian/bin/kconfig.py '$@' $(KCONFIG) $(KCONFIG_OPTIONS)

define copy_source
mkdir -p '$(1)'
cp -al $(filter-out debian .pc .svk .svn .git, $(wildcard * .[^.]*)) '$(1)'
endef

$(BUILD_DIR)/linux-source-$(UPSTREAMVERSION).tar.bz2: DIR = $(BUILD_DIR)/linux-source-$(UPSTREAMVERSION)
$(BUILD_DIR)/linux-source-$(UPSTREAMVERSION).tar.bz2: $(STAMPS_DIR)/source
	rm -rf '$@' '$(DIR)'
	$(call copy_source,$(DIR))
	chmod -R u+rw,go=rX '$(DIR)'
	cd '$(BUILD_DIR)'; tar -cjf 'linux-source-$(UPSTREAMVERSION).tar.bz2' 'linux-source-$(UPSTREAMVERSION)'
	rm -rf '$(DIR)'

$(BUILD_DIR)/linux-patch-$(UPSTREAMVERSION)-%.patch.bz2: $(STAMPS_DIR)/source_none $(STAMPS_DIR)/source_%
	set -o pipefail;						\
	(cd '$(BUILD_DIR)';						\
	 set +e;							\
         diff -urN -p -x debian -x .pc -x .svk -x .svn -x .git source_none source_$*; \
	 test $$? -eq 1) |						\
	filterdiff --remove-timestamps --strip=1 --addoldprefix=a/ --addnewprefix=b/ | \
	bzip2 -c >$@ ||							\
	(rm -f $@; exit 1)

define patch_cmd
cd '$(DIR)' && QUILT_PATCHES='$(CURDIR)/debian/patches' QUILT_SERIES=series-$(1) QUILT_PC=.pc quilt push --quiltrc - -a -q --fuzz=0
endef

$(STAMPS_DIR)/source:
	test -d .pc
	set +e; QUILT_PC=.pc quilt unapplied --quiltrc - >/dev/null && echo 'Patch series not fully applied'; test $$? -eq 1
	@$(stamp)

$(STAMPS_DIR)/source_%: SOURCE_DIR=$(BUILD_DIR)/source
$(STAMPS_DIR)/source_%: DIR=$(BUILD_DIR)/source_$*
$(STAMPS_DIR)/source_%: $(STAMPS_DIR)/source
	mkdir -p '$(BUILD_DIR)'
	rm -rf '$(DIR)'
	$(call copy_source,$(DIR))
	$(call patch_cmd,$*)
	@$(stamp)
.PRECIOUS: $(STAMPS_DIR)/source_%

$(STAMPS_DIR)/source_none: DIR=$(BUILD_DIR)/source_none
$(STAMPS_DIR)/source_none: $(STAMPS_DIR)/source
	mkdir -p '$(BUILD_DIR)'
	rm -f '$(DIR)'
	ln -s '$(CURDIR)' '$(DIR)'
	@$(stamp)

$(STAMPS_DIR)/setup_$(ARCH)_$(FEATURESET)_$(FLAVOUR): CONFIG=$(BUILD_DIR)/config.$(ARCH)_$(FEATURESET)_$(FLAVOUR)
$(STAMPS_DIR)/setup_$(ARCH)_$(FEATURESET)_$(FLAVOUR): SOURCE_DIR=$(BUILD_DIR)/source_$(FEATURESET)
$(STAMPS_DIR)/setup_$(ARCH)_$(FEATURESET)_$(FLAVOUR): DIR=$(BUILD_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
$(STAMPS_DIR)/setup_$(ARCH)_$(FEATURESET)_$(FLAVOUR): $(STAMPS_DIR)/source_$(FEATURESET) $(BUILD_DIR)/config.$(ARCH)_$(FEATURESET)_$(FLAVOUR)
	rm -rf '$(DIR)'
	mkdir '$(DIR)'
	cp '$(CONFIG)' '$(DIR)/.config'
	echo 'override ARCH = $(KERNEL_ARCH)' >> '$(DIR)/.kernelvariables'
	echo 'override KERNELRELEASE = $(ABINAME)$(LOCALVERSION_IMAGE)' >> '$(DIR)/.kernelvariables'
	echo 'CCACHE = ccache' >> '$(DIR)/.kernelvariables'
	echo 'CC = $$(if $$(DEBIAN_KERNEL_USE_CCACHE),$$(CCACHE)) $$(CROSS_COMPILE)$(COMPILER)' >> '$(DIR)/.kernelvariables'
# TODO: Should we set CROSS_COMPILE always?
ifdef OVERRIDE_HOST_TYPE
	echo 'override CROSS_COMPILE = $(OVERRIDE_HOST_TYPE)-' >> '$(DIR)/.kernelvariables'
else
	echo 'ifneq ($$(DEB_BUILD_ARCH),$$(DEB_HOST_ARCH))' >> '$(DIR)/.kernelvariables'
	echo 'override CROSS_COMPILE = $$(DEB_HOST_GNU_TYPE)-' >> '$(DIR)/.kernelvariables'
	echo 'endif' >> '$(DIR)/.kernelvariables'
endif
ifdef CFLAGS_KERNEL
	echo 'CFLAGS_KERNEL += $(CFLAGS_KERNEL)' >> '$(DIR)/.kernelvariables'
	echo 'CFLAGS_MODULE += $(CFLAGS_KERNEL)' >> '$(DIR)/.kernelvariables'
endif
	+$(MAKE_CLEAN) -C '$(SOURCE_DIR)' O='$(CURDIR)/$(DIR)' V=1 listnewconfig
	+yes "" | $(MAKE_CLEAN) -C '$(SOURCE_DIR)' O='$(CURDIR)/$(DIR)' oldconfig >/dev/null
	+$(MAKE_CLEAN) -C '$(SOURCE_DIR)' O='$(CURDIR)/$(DIR)' prepare
	@$(stamp)

$(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): DIR=$(BUILD_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
$(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): $(STAMPS_DIR)/setup_$(ARCH)_$(FEATURESET)_$(FLAVOUR)

$(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain:
	+$(MAKE_CLEAN) -C '$(DIR)' $(BUILD_TARGET)
	python debian/bin/buildcheck.py $(DIR) $(ARCH) $(FEATURESET) $(FLAVOUR)
	@$(stamp)

$(STAMPS_DIR)/build-doc: DIR=$(BUILD_DIR)/build-doc
$(STAMPS_DIR)/build-doc: $(STAMPS_DIR)/source
	rm -rf $(DIR)
	mkdir -p $(DIR)
	+$(MAKE_CLEAN) O='$(CURDIR)/$(DIR)' xmldocs
	+$(MAKE_CLEAN) O='$(CURDIR)/$(DIR)' htmldocs mandocs
	@$(stamp)

install-base:
	dh_installchangelogs
	dh_installdocs
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol -- $(GENCONTROL_ARGS)
	dh_md5sums
	dh_builddeb -- -Zxz $(BUILDDEB_ARGS)

install-dummy:
	dh_testdir
	dh_testroot
	dh_prep
	+$(MAKE_SELF) install-base

install-doc: PACKAGE_NAME = linux-doc-$(VERSION)
install-doc: DIR = $(BUILD_DIR)/build-doc
install-doc: PACKAGE_DIR = debian/$(PACKAGE_NAME)
install-doc: OUT_DIR = $(PACKAGE_DIR)/usr/share/doc/$(PACKAGE_NAME)
install-doc: DH_OPTIONS = -p$(PACKAGE_NAME)
install-doc: $(STAMPS_DIR)/build-doc
	dh_prep
	mkdir -p $(OUT_DIR)
	cp -a CREDITS MAINTAINERS README REPORTING-BUGS Documentation $(OUT_DIR)
	rm -rf $(OUT_DIR)/Documentation/DocBook
	cd $(DIR)/Documentation/DocBook; \
	find * -name '*.html' -print \
	| \
	cpio -pd --preserve-modification-time '$(CURDIR)/$(OUT_DIR)/html'
	gzip -9qfr $(OUT_DIR)/Documentation
	+$(MAKE_SELF) install-base GENCONTROL_ARGS='$(call DEFINE_MULTIARCH,foreign)'

install-manual: PACKAGE_NAME = linux-manual-$(VERSION)
install-manual: DIR=$(BUILD_DIR)/build-doc
install-manual: DH_OPTIONS = -p$(PACKAGE_NAME)
install-manual: $(STAMPS_DIR)/build-doc
	dh_prep
	find $(DIR)/Documentation/DocBook/man/ -name '*.9' | xargs dh_installman
	+$(MAKE_SELF) install-base GENCONTROL_ARGS='$(call DEFINE_MULTIARCH,foreign)'

install-headers_$(ARCH): PACKAGE_NAMES = linux-headers-$(ABINAME)-all linux-headers-$(ABINAME)-all-$(ARCH)
install-headers_$(ARCH): DH_OPTIONS = $(foreach p, $(PACKAGE_NAMES), -p$(p))
install-headers_$(ARCH):
	dh_testdir
	dh_testroot
	+$(MAKE_SELF) install-base GENCONTROL_ARGS='-Vkernel:Arch=$(ARCH)'

install-headers_$(ARCH)_$(FEATURESET): PACKAGE_NAME = linux-headers-$(ABINAME)-common$(LOCALVERSION_HEADERS)
install-headers_$(ARCH)_$(FEATURESET): PACKAGE_NAME_KBUILD = linux-kbuild-$(VERSION)
install-headers_$(ARCH)_$(FEATURESET): DH_OPTIONS = -p$(PACKAGE_NAME)
install-headers_$(ARCH)_$(FEATURESET): BASE_DIR = /usr/src/$(PACKAGE_NAME)
install-headers_$(ARCH)_$(FEATURESET): SOURCE_DIR = $(BUILD_DIR)/source_$(FEATURESET)
install-headers_$(ARCH)_$(FEATURESET): DIR = debian/$(PACKAGE_NAME)/$(BASE_DIR)
install-headers_$(ARCH)_$(FEATURESET): $(STAMPS_DIR)/source_$(FEATURESET)
	dh_testdir
	dh_testroot
	dh_prep

	cd $(SOURCE_DIR); \
	( \
	  echo Makefile; \
	  find arch/$(KERNEL_ARCH) -maxdepth 1 -name 'Makefile*' -print; \
	  find arch/$(KERNEL_ARCH) -name 'module.lds' -print; \
	  find $$(find arch/$(KERNEL_ARCH) \( -name include -o -name scripts \) -type d -print) -print; \
	  find include -print; \
	) \
	| \
	cpio -pd --preserve-modification-time '$(CURDIR)/$(DIR)'

	dh_link /usr/lib/$(PACKAGE_NAME_KBUILD)/scripts $(BASE_DIR)/scripts

	+$(MAKE_SELF) install-base

install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): REAL_VERSION = $(ABINAME)$(LOCALVERSION)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): PACKAGE_NAME = linux-headers-$(REAL_VERSION)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): PACKAGE_NAME_COMMON = linux-headers-$(ABINAME)-common$(LOCALVERSION_HEADERS)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): PACKAGE_NAME_KBUILD = linux-kbuild-$(VERSION)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): DH_OPTIONS = -p$(PACKAGE_NAME)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): BASE_DIR = /usr/src/$(PACKAGE_NAME)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): BASE_DIR_COMMON = /usr/src/$(PACKAGE_NAME_COMMON)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): SOURCE_DIR = $(BUILD_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): REF_DIR = $(BUILD_DIR)/source_$(FEATURESET)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): PACKAGE_DIR = debian/$(PACKAGE_NAME)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): DIR = $(PACKAGE_DIR)/$(BASE_DIR)
install-headers_$(ARCH)_$(FEATURESET)_$(FLAVOUR): $(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE)
	dh_testdir
	dh_testroot
	dh_prep

	mkdir -p $(DIR)/arch/$(KERNEL_ARCH)/kernel
	cp -a $(SOURCE_DIR)/{.config,.kernel*,Module.symvers,include} $(DIR)
	cp -a $(SOURCE_DIR)/arch/$(KERNEL_ARCH)/include $(DIR)/arch/$(KERNEL_ARCH)
	cp -a $(SOURCE_DIR)/arch/$(KERNEL_ARCH)/kernel/asm-offsets.s $(DIR)/arch/$(KERNEL_ARCH)/kernel

	if [ -f $(SOURCE_DIR)/arch/$(KERNEL_ARCH)/lib/crtsavres.o ]; then \
		mkdir $(DIR)/arch/$(KERNEL_ARCH)/lib; \
		cp -a $(SOURCE_DIR)/arch/$(KERNEL_ARCH)/lib/crtsavres.o $(DIR)/arch/$(KERNEL_ARCH)/lib; \
	fi

	@echo 'VERSION = 2' > $(DIR)/Makefile
	@echo 'PATCHLEVEL = 6' >> $(DIR)/Makefile

	@echo 'MAKEARGS := -C $(BASE_DIR_COMMON) O=$(BASE_DIR)' >> $(DIR)/Makefile
	@echo 'MAKEFLAGS += --no-print-directory' >> $(DIR)/Makefile

	@echo '.PHONY: all $$(MAKECMDGOALS)' >> $(DIR)/Makefile
	@echo 'cmd := $$(filter-out all Makefile,$$(MAKECMDGOALS))' >> $(DIR)/Makefile
	@echo 'all:' >> $(DIR)/Makefile
	@echo '	@$$(MAKE) $$(MAKEARGS) $$(cmd)' >> $(DIR)/Makefile
	@echo 'Makefile:;' >> $(DIR)/Makefile
	@echo '$$(cmd) %/: all' >> $(DIR)/Makefile
	@echo '	@:' >> $(DIR)/Makefile

	dh_link /usr/lib/$(PACKAGE_NAME_KBUILD)/scripts $(BASE_DIR)/scripts

	mkdir -p $(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)
	ln -s /usr/src/$(PACKAGE_NAME) $(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)/build
	ln -s /usr/src/$(PACKAGE_NAME_COMMON) $(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)/source

	install -d $(PACKAGE_DIR)/DEBIAN
	sed -e 's/=V/$(REAL_VERSION)/g' \
	  debian/templates/temp.headers.plain/postinst \
	  > $(PACKAGE_DIR)/DEBIAN/postinst
	chmod 755 $(PACKAGE_DIR)/DEBIAN/postinst

	+$(MAKE_SELF) install-base

install-libc-dev_$(ARCH): PACKAGE_NAME = linux-libc-dev
install-libc-dev_$(ARCH): DH_OPTIONS = -p$(PACKAGE_NAME)
install-libc-dev_$(ARCH): DIR = $(BUILD_DIR)/build-libc-dev
install-libc-dev_$(ARCH): OUT_DIR = debian/$(PACKAGE_NAME)/usr
install-libc-dev_$(ARCH):
	dh_testdir
	dh_testroot
	dh_prep
	rm -rf '$(DIR)'
	mkdir -p $(DIR)
	+$(MAKE_CLEAN) O='$(CURDIR)/$(DIR)' headers_check ARCH=$(KERNEL_ARCH)
	+$(MAKE_CLEAN) O='$(CURDIR)/$(DIR)' headers_install ARCH=$(KERNEL_ARCH) INSTALL_HDR_PATH='$(CURDIR)'/$(OUT_DIR)

	rm -rf $(OUT_DIR)/include/drm $(OUT_DIR)/include/scsi
	find $(OUT_DIR)/include \( -name .install -o -name ..install.cmd \) -execdir rm {} +

ifneq (,$(DEB_HOST_MULTIARCH))
	# Move include/asm to arch-specific directory
	mkdir -p $(OUT_DIR)/include/$(DEB_HOST_MULTIARCH)
	mv $(OUT_DIR)/include/asm $(OUT_DIR)/include/$(DEB_HOST_MULTIARCH)/
endif
	
	+$(MAKE_SELF) install-base GENCONTROL_ARGS='$(call DEFINE_MULTIARCH,same)'

install-support: PACKAGE_NAME = linux-support-$(ABINAME)
install-support: DH_OPTIONS = -p$(PACKAGE_NAME)
install-support: PACKAGE_DIR = debian/$(PACKAGE_NAME)
install-support: PACKAGE_ROOT = /usr/share/$(PACKAGE_NAME)
install-support:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs $(PACKAGE_ROOT)/lib/python/debian_linux $(PACKAGE_ROOT)/modules
	cp debian/config.defines.dump $(PACKAGE_DIR)$(PACKAGE_ROOT)
	cp debian/lib/python/debian_linux/*.py $(PACKAGE_DIR)$(PACKAGE_ROOT)/lib/python/debian_linux
	dh_python2
	dh_link $(PACKAGE_ROOT) /usr/src/$(PACKAGE_NAME)
	+$(MAKE_SELF) install-base GENCONTROL_ARGS='$(call DEFINE_MULTIARCH,foreign)'

install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): REAL_VERSION = $(ABINAME)$(LOCALVERSION)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): PACKAGE_NAME = linux-image-$(REAL_VERSION)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): PACKAGE_DIR = debian/$(PACKAGE_NAME)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): INSTALL_DIR = $(PACKAGE_DIR)/boot
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): DIR = $(BUILD_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): DH_OPTIONS = -p$(PACKAGE_NAME)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE): $(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE)

install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs 'boot'
	+$(MAKE_SELF) \
	  install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_image \
	  DIR='$(DIR)' PACKAGE_DIR='$(PACKAGE_DIR)' INSTALL_DIR='$(INSTALL_DIR)' REAL_VERSION='$(REAL_VERSION)'
ifeq ($(MODULES),True)
	+$(MAKE_CLEAN) -C $(DIR) modules_install DEPMOD='$(CURDIR)/debian/bin/no-depmod' INSTALL_MOD_PATH='$(CURDIR)'/$(PACKAGE_DIR) INSTALL_MOD_STRIP=1
ifeq ($(DEBUG),True)
	find $(PACKAGE_DIR) -name '*.ko' | sed 's|$(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)/kernel/||' | while read module ; do \
	  objcopy --add-gnu-debuglink=$(DIR)/$$module $(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)/kernel/$$module || exit; \
	done
endif
	cp $(DIR)/.config $(PACKAGE_DIR)/boot/config-$(REAL_VERSION)
	cp $(DIR)/System.map $(PACKAGE_DIR)/boot/System.map-$(REAL_VERSION)
	rm -f $(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)/build
	rm -f $(PACKAGE_DIR)/lib/modules/$(REAL_VERSION)/source
	rm $(PACKAGE_DIR)/lib/firmware -rf
endif
	+$(MAKE_SELF) \
	  install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_templates \
	  PACKAGE_NAME='$(PACKAGE_NAME)' PACKAGE_DIR='$(PACKAGE_DIR)' REAL_VERSION='$(REAL_VERSION)'
	+$(MAKE_SELF) \
	  install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_bug \
	  PACKAGE_DIR='$(PACKAGE_DIR)' PACKAGE_NAME='$(PACKAGE_NAME)' REAL_VERSION='$(REAL_VERSION)'
	+$(MAKE_SELF) install-base

install-image_sparc_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_sparc64_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_sh4_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/arch/$(KERNEL_ARCH)/boot/zImage' $(INSTALL_DIR)/vmlinuz-$(REAL_VERSION)

ifneq ($(filter armel armhf,$(ARCH)),)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_image: DTB_INSTALL_DIR = /usr/lib/linux-image-$(REAL_VERSION)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/arch/$(KERNEL_ARCH)/boot/zImage' $(INSTALL_DIR)/vmlinuz-$(REAL_VERSION)
	+$(MAKE_CLEAN) -C $(DIR) dtbs
	shopt -s nullglob ; for i in $(DIR)/arch/arm/boot/*.dtb ; do \
		install -D -m644 $$i '$(PACKAGE_DIR)'/'$(DTB_INSTALL_DIR)'/$$(basename $$i) ; \
	done
endif

install-image_amd64_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_i386_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/arch/$(KERNEL_ARCH)/boot/bzImage' $(INSTALL_DIR)/vmlinuz-$(REAL_VERSION)

install-image_alpha_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/arch/$(KERNEL_ARCH)/boot/vmlinux.gz' $(INSTALL_DIR)/vmlinuz-$(REAL_VERSION)

install-image_ia64_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_m68k_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/vmlinux.gz' $(INSTALL_DIR)/vmlinuz-$(REAL_VERSION)

install-image_hppa_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_mips_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_mipsel_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/vmlinux' $(INSTALL_DIR)/vmlinux-$(REAL_VERSION)

install-image_powerpc_$(FEATURESET)_$(FLAVOUR)_plain_image: WRAPPER_INSTALL_DIR = '$(CURDIR)'/$(PACKAGE_DIR)/usr/lib/linux-image-$(REAL_VERSION)
install-image_ppc64_$(FEATURESET)_$(FLAVOUR)_plain_image: WRAPPER_INSTALL_DIR = '$(CURDIR)'/$(PACKAGE_DIR)/usr/lib/linux-image-$(REAL_VERSION)
install-image_powerpc_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_ppc64_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/vmlinux' $(INSTALL_DIR)/vmlinux-$(REAL_VERSION)
	+$(MAKE_CLEAN) -C '$(DIR)' bootwrapper_install \
	  WRAPPER_OBJDIR='$(WRAPPER_INSTALL_DIR)' \
	  WRAPPER_DTSDIR='$(WRAPPER_INSTALL_DIR)'/dts \
	  WRAPPER_BINDIR='$(WRAPPER_INSTALL_DIR)'

install-image_s390_$(FEATURESET)_$(FLAVOUR)_plain_image \
install-image_s390x_$(FEATURESET)_$(FLAVOUR)_plain_image:
	install -m644 '$(DIR)/arch/s390/boot/image' $(INSTALL_DIR)/vmlinuz-$(REAL_VERSION)

ifneq ($(INITRAMFS),False)
install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_templates: ARG_INITRD = YES
endif

ARG_KIMAGE = vmlinuz
install-image_hppa_$(FEATURESET)_$(FLAVOUR)_plain_templates \
install-image_mips_$(FEATURESET)_$(FLAVOUR)_plain_templates \
install-image_mipsel_$(FEATURESET)_$(FLAVOUR)_plain_templates \
install-image_powerpc_$(FEATURESET)_$(FLAVOUR)_plain_templates \
install-image_ppc64_$(FEATURESET)_$(FLAVOUR)_plain_templates: ARG_KIMAGE = vmlinux

install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_templates:
	for i in $(wildcard debian/templates/temp.image.plain/*); do \
	  sed \
	    -e 's@=B@$(KERNEL_ARCH)@g' \
	    -e 's/=I/$(ARG_INITRD)/g' \
	    -e 's/=K/$(ARG_KIMAGE)/g' \
	    -e 's/=V/$(REAL_VERSION)/g' \
	    $$i > debian/$(PACKAGE_NAME).$$(basename $$i) || exit; \
	done
	mkdir -p debian/$(PACKAGE_NAME).po
	for i in $(wildcard debian/po/*.po); do \
	  sed \
	    -e 's/=V/$(REAL_VERSION)/g' \
	    $$i > debian/$(PACKAGE_NAME).po/$$(basename $$i) || exit; \
	done
	mkdir -p debian/$(PACKAGE_NAME)/DEBIAN
	po2debconf --podir debian/$(PACKAGE_NAME).po \
	  -o debian/$(PACKAGE_NAME)/DEBIAN/templates \
	  debian/$(PACKAGE_NAME).templates

install-image_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_plain_bug:
	dh_installdirs usr/share/bug/$(PACKAGE_NAME)
	dh_install debian/templates/image.plain.bug/* usr/share/bug/$(PACKAGE_NAME)
	chmod 755 $(PACKAGE_DIR)/usr/share/bug/$(PACKAGE_NAME)/script
	echo "RELEASE='$(REAL_VERSION)'" > $(PACKAGE_DIR)/usr/share/bug/$(PACKAGE_NAME)/info

install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): REAL_VERSION = $(ABINAME)$(LOCALVERSION)
install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): PACKAGE_NAME = linux-image-$(REAL_VERSION)-dbg
install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): PACKAGE_DIR = debian/$(PACKAGE_NAME)
install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): DEBUG_DIR = $(PACKAGE_DIR)/usr/lib/debug
install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): DIR = $(BUILD_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)
install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): DH_OPTIONS = -p$(PACKAGE_NAME)
install-image-dbg_$(ARCH)_$(FEATURESET)_$(FLAVOUR): $(STAMPS_DIR)/build_$(ARCH)_$(FEATURESET)_$(FLAVOUR)_$(TYPE)
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs usr/lib/debug usr/lib/debug/boot usr/share/lintian/overrides/
	sed -e 's/=V/$(REAL_VERSION)/g' \
	  debian/templates/image-dbg.lintian-override.in \
	  > $(PACKAGE_DIR)/usr/share/lintian/overrides/$(PACKAGE_NAME)
	install -m644 $(DIR)/vmlinux $(DEBUG_DIR)/boot/vmlinux-$(REAL_VERSION)
ifeq ($(MODULES),True)
	+$(MAKE_CLEAN) -C $(DIR) modules_install DEPMOD='$(CURDIR)/debian/bin/no-depmod' INSTALL_MOD_PATH='$(CURDIR)'/$(DEBUG_DIR)
	find $(DEBUG_DIR)/lib/modules/$(REAL_VERSION)/ -mindepth 1 -maxdepth 1 \! -name kernel -exec rm {} \+
	rm $(DEBUG_DIR)/lib/firmware -rf
endif
	+$(MAKE_SELF) install-base

install-udeb_$(ARCH): export KW_DEFCONFIG_DIR=debian/installer
install-udeb_$(ARCH): export KW_CONFIG_DIR=debian/installer/$(ARCH)
install-udeb_$(ARCH): DH_OPTIONS=$(PACKAGE_NAMES:%=-p%)
install-udeb_$(ARCH):
	dh_testdir
	dh_prep
	kernel-wedge install-files $(ABINAME)
	kernel-wedge check $(PACKAGE_NAMES)
	dh_fixperms
	dh_gencontrol
	dh_builddeb

install-source: DH_OPTIONS = -plinux-source-$(VERSION)
install-source: $(BUILD_DIR)/linux-source-$(UPSTREAMVERSION).tar.bz2 $(foreach FEATURESET,$(filter-out none,$(ALL_FEATURESETS)),$(BUILD_DIR)/linux-patch-$(UPSTREAMVERSION)-$(FEATURESET).patch.bz2)
	dh_testdir
	dh_testroot
	dh_install '$^' /usr/src
	+$(MAKE_SELF) install-base GENCONTROL_ARGS='$(call DEFINE_MULTIARCH,foreign)'

# vim: filetype=make