File: rules

package info (click to toggle)
grub2 2.02~beta2-22
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 54,604 kB
  • ctags: 64,764
  • sloc: ansic: 370,672; asm: 16,177; sh: 12,946; cpp: 1,993; python: 1,438; makefile: 1,357; lex: 393; sed: 271; yacc: 268; lisp: 50; awk: 48; perl: 31
file content (501 lines) | stat: -rwxr-xr-x 20,644 bytes parent folder | download | duplicates (3)
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
501
#!/usr/bin/make -f
SHELL		:= bash

deb_version		:= $(shell dpkg-parsechangelog | sed -ne "s/^Version: \(.*\)/\1/p")
upstream_version	:= $(shell echo $(deb_version) | sed -e "s/-[^-]*$$//")

package		:= grub2

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null)
DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS 2>/dev/null)
DEB_HOST_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null)

HOST_CFLAGS := -g -Wall -Wno-error=unused-result

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	HOST_CFLAGS += -O0
else
	HOST_CFLAGS += -O2
endif

unexport CFLAGS
export HOST_CFLAGS
export TARGET_CPPFLAGS := -Wno-unused-but-set-variable

ifeq (,$(shell which qemu-system-i386 2>/dev/null))
with_check := no
else
with_check := yes
endif

CC := gcc-4.9

confflags = PACKAGE_VERSION="$(deb_version)" PACKAGE_STRING="GRUB $(deb_version)" CC=$(CC) TARGET_CC=$(CC) --enable-grub-mkfont
substvars =

AUTOGEN_DEB_FILES = config templates preinst postinst postrm dirs install links maintscript

BUILD_PACKAGES := $(strip $(shell dh_listpackages))
# REAL_PACKAGES build an actual grub variant (and therefore have both configure
# and build stages). EXTRA_PACKAGES do not build grub but may depend on a
# REAL_PACKAGE (and therefore only have a build stage)
REAL_PACKAGES = grub-common grub-emu grub-pc grub-coreboot grub-efi-ia32 grub-efi-amd64 grub-efi-ia64 grub-efi-arm grub-efi-arm64 grub-ieee1275 grub-firmware-qemu grub-uboot grub-xen grub-yeeloong
EXTRA_PACKAGES = grub-rescue-pc grub-xen-host

ifneq (,$(filter i386 amd64,$(DEB_HOST_ARCH_CPU)))
COMMON_PLATFORM := pc
else ifneq (,$(filter powerpc ppc64 ppc64el sparc sparc64,$(DEB_HOST_ARCH_CPU)))
COMMON_PLATFORM := ieee1275
else ifeq (mipsel,$(DEB_HOST_ARCH_CPU))
COMMON_PLATFORM := yeeloong
else ifeq (ia64,$(DEB_HOST_ARCH_CPU))
COMMON_PLATFORM := efi-ia64
else ifeq (arm,$(DEB_HOST_ARCH_CPU))
COMMON_PLATFORM := uboot
else ifeq (arm64,$(DEB_HOST_ARCH_CPU))
COMMON_PLATFORM := efi-arm64
else
COMMON_PLATFORM := none
BUILD_PACKAGES += grub-none
endif

ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
DEFAULT_CMDLINE := quiet splash
DEFAULT_TIMEOUT := 10
ifeq ($(DEB_HOST_ARCH_CPU),ppc64el)
FLICKER_FREE_BOOT := no
else
FLICKER_FREE_BOOT := yes
endif
confflags += --enable-ubuntu-recovery
else ifeq (yes,$(shell dpkg-vendor --derives-from Tanglu && echo yes))
DEFAULT_CMDLINE := quiet splash
DEFAULT_TIMEOUT := 10
FLICKER_FREE_BOOT := yes
else
DEFAULT_CMDLINE := quiet
DEFAULT_TIMEOUT := 5
FLICKER_FREE_BOOT := no
endif

ifeq ($(FLICKER_FREE_BOOT),yes)
DEFAULT_HIDDEN_TIMEOUT := 0
DEFAULT_HIDDEN_TIMEOUT_BOOL := true
confflags += \
	--enable-quiet-boot \
	--enable-quick-boot \
	--enable-gfxpayload-dynamic \
	--enable-vt-handoff
substvars += \
	-Vlsb-base-depends="lsb-base (>= 3.0-6)" \
	-Vgfxpayload-depends="grub-gfxpayload-lists [any-i386 any-amd64]"
else
DEFAULT_HIDDEN_TIMEOUT :=
DEFAULT_HIDDEN_TIMEOUT_BOOL := false
endif

SB_PACKAGE :=
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
ifeq ($(DEB_HOST_ARCH),amd64)
SB_PACKAGE := grub-efi-amd64
SB_PLATFORM := x86_64-efi
SB_EFI_NAME := x64
endif
endif

%:
	dh $@ --parallel

override_dh_auto_configure: $(patsubst %,configure/%,$(BUILD_PACKAGES))

override_dh_auto_build: $(patsubst %,build/%,$(BUILD_PACKAGES))

override_dh_auto_install: $(patsubst %,install/%,$(BUILD_PACKAGES))

$(patsubst %,configure/%,$(REAL_PACKAGES)) :: configure/% : debian/stamps/configure-%
$(patsubst %,build/%,$(REAL_PACKAGES) $(EXTRA_PACKAGES)) :: build/% : debian/stamps/build-%

debian/stamps/configure-%: package = $(subst debian/stamps/configure-,,$@)
debian/stamps/configure-%: export DH_OPTIONS = -p$(package) -Bobj/$(package)

debian/stamps/build-%: package = $(subst debian/stamps/build-,,$@)
debian/stamps/build-%: export DH_OPTIONS = -p$(package) -Bobj/$(package)

install/%: package = $(subst install/,,$@)
install/%: package_bin = $(package)-bin
install/%: package_dbg = $(package)-dbg
install/grub-emu: package_bin = grub-emu
install/grub-emu: package_dbg = grub-emu-dbg
install/%: export DH_OPTIONS = -p$(package) -Bobj/$(patsubst grub-common,grub-$(COMMON_PLATFORM),$(package))

debian/stamps/autogen: autogen.sh configure.ac Makefile.util.def grub-core/Makefile.core.def
	mkdir -p debian/stamps
	rm -rf debian/grub-extras-enabled
	mkdir debian/grub-extras-enabled
	set -e; for extra in 915resolution ntldr-img; do \
		cp -a debian/grub-extras/$$extra debian/grub-extras-enabled/; \
	done
	env -u DH_OPTIONS GRUB_CONTRIB=$(CURDIR)/debian/grub-extras-enabled \
		dh_autoreconf -- ./autogen.sh
	touch $@

debian/stamps/configure-grub-common: debian/stamps/configure-grub-$(COMMON_PLATFORM)
	touch $@

debian/stamps/build-grub-common: debian/stamps/build-grub-$(COMMON_PLATFORM)
	touch $@

debian/stamps/configure-grub-none debian/stamps/configure-grub-pc debian/stamps/configure-grub-ieee1275 debian/stamps/configure-grub-coreboot debian/stamps/configure-grub-emu debian/stamps/configure-grub-uboot debian/stamps/configure-grub-yeeloong: debian/stamps/autogen
	mkdir -p debian/stamps obj/$(package)
	dh_auto_configure -- $(confflags) --with-platform=$(subst grub-,,$(package))
	touch $@

# This name scheme leaves room for things like amd32 someday
debian/stamps/configure-grub-efi-ia32: debian/stamps/autogen
	mkdir -p debian/stamps obj/$(package)
	dh_auto_configure -- $(confflags) --with-platform=efi --target=i386-pe --program-prefix=""
	touch $@
debian/stamps/configure-grub-efi-amd64: debian/stamps/autogen
	mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)
	dh_auto_configure -- $(confflags) --with-platform=efi --target=amd64-pe --program-prefix=""
	touch $@
debian/stamps/configure-grub-efi-ia64 debian/stamps/configure-grub-efi-arm debian/stamps/configure-grub-efi-arm64: debian/stamps/autogen
	mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)
	dh_auto_configure -- $(confflags) --with-platform=efi
	touch $@

debian/stamps/configure-grub-xen-%: debian/stamps/autogen
	mkdir -p debian/stamps obj/$(package)
	dh_auto_configure -- $(confflags) --with-platform=xen --target=$(subst debian/stamps/configure-grub-xen-,,$@) --program-prefix=""
	touch $@
debian/stamps/configure-grub-xen: debian/stamps/configure-grub-xen-i386 debian/stamps/configure-grub-xen-amd64
	touch $@

debian/stamps/configure-grub-firmware-qemu: debian/stamps/autogen
	mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)
	dh_auto_configure -- $(confflags) --with-platform=qemu
	touch $@

debian/stamps/build-grub-none debian/stamps/build-grub-efi-ia32 debian/stamps/build-grub-efi-amd64 debian/stamps/build-grub-efi-ia64 debian/stamps/build-grub-efi-arm debian/stamps/build-grub-efi-arm64 debian/stamps/build-grub-coreboot debian/stamps/build-grub-emu debian/stamps/build-grub-uboot debian/stamps/build-grub-xen-i386 debian/stamps/build-grub-xen-amd64 debian/stamps/build-grub-yeeloong: debian/stamps/build-%: debian/stamps/configure-%
	dh_auto_build
	touch $@

debian/stamps/build-grub-xen-host-i386: PVBOOT_ARCH := i386
debian/stamps/build-grub-xen-host-amd64: PVBOOT_ARCH := x86_64
debian/stamps/build-grub-xen-host-%: debian/stamps/build-grub-xen-%
	target=$(subst debian/stamps/build-grub-xen-host-,,$@) ; \
	obj_dir=$(CURDIR)/obj/grub-xen-$${target} ; \
	grub_dir=`mktemp -d` ; \
	grub_memdisk=`mktemp` ; \
	trap "rm -rf $${grub_dir} $${grub_memdisk}" EXIT HUP INT QUIT TERM ; \
	mkdir -p $${grub_dir}/boot/grub ; \
	mkdir -p $(CURDIR)/obj/$(package) ; \
	sed -e "s/@@PVBOOT_ARCH@@/$(PVBOOT_ARCH)/g" \
	    <debian/grub-xen-host_grub.cfg \
	    >$${grub_dir}/grub.cfg ; \
	tar -cf - -C $${grub_dir} grub.cfg > $${grub_memdisk} ; \
	$${obj_dir}/grub-mkimage \
		-O $(PVBOOT_ARCH)-xen \
		-c $(CURDIR)/debian/grub-xen-host_grub-bootstrap.cfg \
		-d $${obj_dir}/grub-core \
		$${obj_dir}/grub-core/*.mod \
		-m $${grub_memdisk} \
		-o $(CURDIR)/obj/$(package)/grub-$(PVBOOT_ARCH)-xen.bin
	touch $@

debian/stamps/build-grub-xen-host: debian/stamps/build-grub-xen-host-i386 debian/stamps/build-grub-xen-host-amd64
	touch $@

debian/stamps/build-grub-pc: debian/stamps/configure-grub-pc
	dh_auto_build
ifeq ($(with_check), yes)
	LC_CTYPE=C.UTF-8 PATH="$$PATH:/sbin:/usr/sbin" VERBOSE=1 dh_auto_test --max-parallel=1
endif
	touch $@

debian/stamps/build-grub-ieee1275: debian/stamps/configure-grub-ieee1275
	dh_auto_build
ifeq ($(DEB_HOST_ARCH_CPU),ppc64el)
	$(CC) $(HOST_CFLAGS) debian/prep-bootdev.c -o debian/prep-bootdev -lparted
endif
	touch $@

debian/stamps/build-grub-xen: debian/stamps/build-grub-xen-i386 debian/stamps/build-grub-xen-amd64
	touch $@

debian/stamps/build-grub-firmware-qemu: debian/stamps/configure-grub-firmware-qemu
	dh_auto_build
	grub_dir=`mktemp -d` ; \
	grub_memdisk=`mktemp` ; \
	trap "rm -rf $${grub_dir} $${grub_memdisk}" EXIT HUP INT QUIT TERM ; \
	mkdir -p $${grub_dir}/boot/grub ; \
	cp debian/grub-firmware-qemu_grub.cfg $${grub_dir}/boot/grub/grub.cfg ; \
	tar -cf - -C $${grub_dir} boot > $${grub_memdisk} ; \
	obj/$(package)/grub-mkimage \
		-O i386-qemu \
		-d $(CURDIR)/obj/$(package)/grub-core \
		$(CURDIR)/obj/$(package)/grub-core/*.mod \
		-m $${grub_memdisk} \
		-o $(CURDIR)/obj/$(package)/grub.bin
	touch $@

debian/stamps/build-grub-rescue-pc: debian/stamps/build-grub-pc
	mkdir -p obj/grub-rescue-pc/rescue-disk/boot/grub
	cp docs/grub.cfg obj/grub-rescue-pc/rescue-disk/boot/grub/
	rm -rf obj/grub-rescue-pc/grub-core
	cp -a obj/grub-pc/grub-core obj/grub-rescue-pc/grub-core
	cp -a obj/grub-pc/unicode.pf2 obj/grub-rescue-pc/
	pkgdatadir=$(CURDIR)/obj/grub-rescue-pc \
		obj/grub-pc/grub-mkrescue \
		--directory=$(CURDIR)/obj/grub-rescue-pc/grub-core \
		--locale-directory=$(CURDIR)/obj/grub-rescue-pc/grub-core/po \
		--output=$(CURDIR)/obj/grub-rescue-pc/grub-rescue-cdrom.iso \
		$(CURDIR)/obj/grub-rescue-pc/rescue-disk
	# save space for floppy image
	rm -rf obj/grub-rescue-pc/grub-core/po obj/grub-rescue-pc/unicode.pf2
	pkgdatadir=$(CURDIR)/obj/grub-rescue-pc \
		obj/grub-pc/grub-mkrescue \
		--directory=$(CURDIR)/obj/grub-rescue-pc/grub-core \
		--locale-directory=$(CURDIR)/obj/grub-rescue-pc/grub-core/po \
		--output=$(CURDIR)/obj/grub-rescue-pc/grub-rescue-floppy.img \
		--compress=xz \
		-- -no-pad $(CURDIR)/obj/grub-rescue-pc/rescue-disk
	touch $@

platform_subst = \
	if [ -e debian/$(1) ]; then \
		debian/platform-subst \
			PACKAGE="$(2)" \
			DEFAULT_CMDLINE="$(DEFAULT_CMDLINE)" \
			DEFAULT_TIMEOUT="$(DEFAULT_TIMEOUT)" \
			DEFAULT_HIDDEN_TIMEOUT_BOOL="$(DEFAULT_HIDDEN_TIMEOUT_BOOL)" \
			debian/$(1) >> debian/$(2).$(3); \
	fi

install/grub-none:
	dh_auto_install --destdir=debian/tmp-$(package)

	# Avoid failures later if we're building from a tree with no .po
	# files.
	mkdir -p debian/tmp-$(package)/usr/share/locale

install/grub-pc install/grub-efi-ia32 install/grub-efi-amd64 install/grub-efi-ia64 install/grub-efi-arm install/grub-efi-arm64 install/grub-ieee1275 install/grub-coreboot install/grub-emu install/grub-uboot install/grub-xen install/grub-yeeloong:
	set -e ; \
	if [ "$@" = "install/grub-xen" ] ; then \
		dh_auto_install -Bobj/grub-xen-i386 --destdir=debian/tmp-$(package); \
		dh_auto_install -Bobj/grub-xen-amd64 --destdir=debian/tmp-$(package); \
	else \
		dh_auto_install --destdir=debian/tmp-$(package); \
	fi

	set -e ; \
	for i in $(AUTOGEN_DEB_FILES) ; do \
		> debian/$(package).$$i; \
		if [ "$@" != "install/grub-emu" ] ; then \
			$(call platform_subst,$$i.in,$(package),$$i); \
		fi ; \
		$(call platform_subst,$(package).$$i.in,$(package),$$i); \
		$(call platform_subst,$(package).$$i.$(DEB_HOST_ARCH_CPU).in,$(package),$$i); \
		$(call platform_subst,$(package).$$i.$(DEB_HOST_ARCH_OS).in,$(package),$$i); \
		$(call platform_subst,$(package).$$i.$(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH_CPU).in,$(package),$$i); \
		[ -s debian/$(package).$$i ] || rm -f debian/$(package).$$i; \
		if [ "$@" != "install/grub-emu" ] ; then \
			> debian/$(package_bin).$$i; \
			$(call platform_subst,$$i-bin.in,$(package_bin),$$i); \
			$(call platform_subst,$(package_bin).$$i.in,$(package_bin),$$i); \
			$(call platform_subst,$(package_bin).$$i.$(DEB_HOST_ARCH_CPU).in,$(package_bin),$$i); \
			$(call platform_subst,$(package_bin).$$i.$(DEB_HOST_ARCH_OS).in,$(package_bin),$$i); \
			$(call platform_subst,$(package_bin).$$i.$(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH_CPU).in,$(package_bin),$$i); \
			[ -s debian/$(package_bin).$$i ] || rm -f debian/$(package_bin).$$i; \
		fi ; \
		> debian/$(package_dbg).$$i; \
		if [ "$@" != "install/grub-emu" ] ; then \
			$(call platform_subst,$$i-dbg.in,$(package_dbg),$$i); \
		fi ; \
		$(call platform_subst,$(package_dbg).$$i.in,$(package_dbg),$$i); \
		$(call platform_subst,$(package_dbg).$$i.$(DEB_HOST_ARCH_CPU).in,$(package_dbg),$$i); \
		$(call platform_subst,$(package_dbg).$$i.$(DEB_HOST_ARCH_OS).in,$(package_dbg),$$i); \
		$(call platform_subst,$(package_dbg).$$i.$(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH_CPU).in,$(package_dbg),$$i); \
		[ -s debian/$(package_dbg).$$i ] || rm -f debian/$(package_dbg).$$i; \
	done

	find debian/tmp-$(package)/usr/lib/grub -name modinfo.sh -print0 | \
		xargs -0r chmod +x
	find debian/tmp-$(package)/usr/lib/grub -name gdb_grub -print0 | \
		xargs -0r chmod -x
	find debian/tmp-$(package)/usr/lib/grub -name gmodule.pl -print0 | \
		xargs -0r chmod -x

	mkdir -p debian/$(package_bin)/usr/share/lintian/overrides
	echo "$(package_bin): unstripped-binary-or-object *.mod" \
		>> debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin)
	cd debian/tmp-$(package) && find usr/lib/grub -name kernel.img \
		| sed -e "s%.*%$(package_bin): statically-linked-binary &%g" \
	>> $(CURDIR)/debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin)
	cd debian/tmp-$(package) && find ./usr/lib/grub -name kernel.img \
		| sed -e "s%.*%$(package_bin): statically-linked-binary &%g" \
	>> $(CURDIR)/debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin)
	cd debian/tmp-$(package) && find usr/lib/grub -name kernel.img \
		| sed -e "s%.*%$(package_bin): unstripped-binary-or-object &%g" \
	>> $(CURDIR)/debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin)
	if ([ "$@" = "install/grub-efi-amd64" ] && [ "$(DEB_HOST_ARCH_CPU)" = "i386" ]) || \
	   ([ "$@" != "install/grub-emu" ] && [ "$(DEB_HOST_ARCH_CPU):$(DEB_HOST_ARCH_BITS)" = "amd64:32" ]) || \
	   [ "$@" = "install/grub-xen" ]; then \
		echo "$(package_bin): binary-from-other-architecture *.mod" \
			>> debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin) ; \
		cd debian/tmp-$(package) && find usr/lib/grub -name kernel.img \
			| sed -e "s%.*%$(package_bin): binary-from-other-architecture &%g" \
		>> $(CURDIR)/debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin) ; \
	fi
	if ([ "$@" = "install/grub-pc" ] || \
	    [ "$@" = "install/grub-ieee1275" ] || \
	    [ "$@" = "install/grub-coreboot" ] || \
	    [ "$@" = "install/grub-xen" ] || \
	    [ "$@" = "install/grub-emu" ]) && \
	   [ "$(DEB_HOST_ARCH_OS)" = "linux" ] && \
	   [ "$(DEB_HOST_ARCH_CPU):$(DEB_HOST_ARCH_BITS)" != "amd64:64" ] ; then \
		echo "$(package_bin): binary-from-other-architecture *efiemu64.o" \
			>> debian/$(package_bin)/usr/share/lintian/overrides/$(package_bin) ; \
	fi

	mkdir -p debian/$(package_dbg)/usr/share/lintian/overrides
	echo "$(package_dbg): unstripped-binary-or-object *.module" \
		>> debian/$(package_dbg)/usr/share/lintian/overrides/$(package_dbg)
	echo "$(package_dbg): statically-linked-binary *.image" \
		>> debian/$(package_dbg)/usr/share/lintian/overrides/$(package_dbg)
	cd debian/tmp-$(package) && find usr/lib/grub -name kernel.exec \
		| sed -e "s%.*%$(package_dbg): statically-linked-binary &%g" \
	>> $(CURDIR)/debian/$(package_dbg)/usr/share/lintian/overrides/$(package_dbg)
	if ([ "$@" = "install/grub-efi-amd64" ] && [ "$(DEB_HOST_ARCH_CPU)" = "i386" ]) || \
	   ([ "$@" != "install/grub-emu" ] && [ "$(DEB_HOST_ARCH_CPU):$(DEB_HOST_ARCH_BITS)" = "amd64:32" ]) || \
	   [ "$@" = "install/grub-xen" ] ; then \
		echo "$(package_dbg): binary-from-other-architecture *.module" \
			>> debian/$(package_dbg)/usr/share/lintian/overrides/$(package_dbg) ; \
		cd debian/tmp-$(package) && find usr/lib/grub -name kernel.exec \
			| sed -e "s%.*%$(package_dbg): binary-from-other-architecture &%g" \
		>> $(CURDIR)/debian/$(package_dbg)/usr/share/lintian/overrides/$(package_dbg) ; \
	fi

	# Avoid failures later if we're building from a tree with no .po
	# files.
	mkdir -p debian/tmp-$(package)/usr/share/locale

install/grub-common:
	set -e ; for i in $(AUTOGEN_DEB_FILES) ; do \
		if [ -e debian/grub-common.$$i.in ] ; then \
			cat debian/grub-common.$$i.in \
				> debian/grub-common.$$i ; \
		fi ; \
		if [ -e debian/grub-common.$$i.$(DEB_HOST_ARCH_CPU).in ] ; then \
			cat debian/grub-common.$$i.$(DEB_HOST_ARCH_CPU).in \
				>> debian/grub-common.$$i ; \
		fi ; \
		if [ -e debian/grub-common.$$i.$(DEB_HOST_ARCH_OS).in ] ; then \
			cat debian/grub-common.$$i.$(DEB_HOST_ARCH_OS).in \
				>> debian/grub-common.$$i ; \
		fi ; \
	done
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
	install -D -m 0755 debian/grub-common.pm-sleep \
		$(CURDIR)/debian/$(package)/etc/pm/sleep.d/10_grub-common
endif

override_dh_install:
	dh_install -pgrub2 -pgrub-linuxbios -pgrub-efi -pgrub-rescue-pc -pgrub-firmware-qemu -pgrub-xen-host
	dh_install -pgrub-common -pgrub2-common -pgrub-theme-starfield -pgrub-mount-udeb --sourcedir=debian/tmp-grub-$(COMMON_PLATFORM)
	rm -f debian/grub2-common/usr/share/info/dir*
	rm -f debian/grub-theme-starfield/usr/share/grub/themes/starfield/COPYING.CC-BY-SA-3.0
	set -e; for package in grub-pc grub-efi-ia32 grub-efi-amd64 grub-efi-ia64 grub-efi-arm grub-efi-arm64 grub-ieee1275 grub-coreboot grub-uboot grub-xen grub-yeeloong; do \
		dh_install -p$$package --sourcedir=debian/tmp-$$package; \
		dh_install -p$$package-bin --sourcedir=debian/tmp-$$package; \
		dh_install -p$$package-dbg --sourcedir=debian/tmp-$$package; \
	done
	dh_install -pgrub-emu --sourcedir=debian/tmp-grub-emu
	dh_install -pgrub-emu-dbg --sourcedir=debian/tmp-grub-emu
ifneq (,$(filter grub2-common,$(BUILD_PACKAGES)))
	sed -i \
		-e "s/@DEFAULT_CMDLINE@/$(DEFAULT_CMDLINE)/g" \
		-e "s/@DEFAULT_TIMEOUT@/$(DEFAULT_TIMEOUT)/g" \
		debian/grub2-common/usr/share/grub/default/grub
endif
ifneq (,$(DEFAULT_HIDDEN_TIMEOUT))
	perl -pi -e 's/^GRUB_TIMEOUT=.*/GRUB_HIDDEN_TIMEOUT=0\nGRUB_HIDDEN_TIMEOUT_QUIET=true\n$$&/' \
		debian/grub2-common/usr/share/grub/default/grub
endif
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
ifneq (,$(filter grub-pc,$(BUILD_PACKAGES)))
	patch debian/grub-pc/usr/lib/grub-legacy/update-grub \
		< debian/legacy/update-grub.ubuntu.patch
endif
endif

override_dh_installdocs:
	dh_installdocs -pgrub-common -pgrub-rescue-pc -pgrub-firmware-qemu -pgrub-xen-host -A AUTHORS NEWS README THANKS TODO
	dh_installdocs -Ngrub-common -Ngrub-rescue-pc -Ngrub-firmware-qemu -Ngrub-xen-host --link-doc=grub-common

ifeq ($(FLICKER_FREE_BOOT),yes)
override_dh_installinit:
	dh_installinit -- start 99 2 3 4 5 .
else
override_dh_installinit:
	:
endif

override_dh_bugfiles:
	dh_bugfiles -A

override_dh_strip:
	dh_strip -X/usr/bin/grub-emu

override_dh_shlibdeps:
	dh_shlibdeps -X.module

ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
LEGACY_DOC_CONFLICTS := grub-doc (<< 0.97-29ubuntu60), grub-legacy-doc (<< 0.97-29ubuntu60)
else
LEGACY_DOC_CONFLICTS := grub-doc (<< 0.97-32), grub-legacy-doc (<< 0.97-59)
endif

override_dh_gencontrol:
	dh_gencontrol -- \
		-Vlegacy-doc-conflicts="$(LEGACY_DOC_CONFLICTS)" $(substvars)

TARNAME := grub2_$(deb_version)_$(DEB_HOST_ARCH).tar.gz

override_dh_builddeb:
	dh_builddeb -- -Zxz
ifneq (,$(SB_PACKAGE))
	debian/build-efi-images \
		obj/grub-$(COMMON_PLATFORM)/grub-mkimage \
		obj/$(SB_PACKAGE)/grub-core \
		debian/grub2-images/$(deb_version) \
		$(SB_PLATFORM) $(SB_EFI_NAME)
	echo $(deb_version) \
		> debian/grub2-images/$(deb_version)/version
	cd debian/grub2-images && tar czvf ../../../$(TARNAME) .
	dpkg-distaddfile $(TARNAME) raw-uefi -
endif

override_dh_auto_clean:
	-rm -rf debian/grub-extras-enabled debian/stamps obj
	-rm -f contrib grub-core/contrib

override_dh_clean:
	dh_autoreconf_clean
	dh_clean

	chmod +x debian/{bug-script,grub.d/*,legacy/*,kernel/*}

	for i in $(AUTOGEN_DEB_FILES) ; do \
		rm -f debian/grub-{pc,efi-*,ieee1275,coreboot,uboot,xen,yeeloong,emu}{,-bin,-dbg}.$$i ; \
	done
	rm -f debian/grub-common.maintscript
	rm -rf debian/tmp-*/
ifneq (,$(SB_PACKAGE))
	rm -rf debian/grub2-images
endif

	# make sure PO files are always up-to-date
	debconf-updatepo

.PHONY: $(patsubst %,configure/%,$(BUILD_PACKAGES)) $(patsubst %,build/%,$(BUILD_PACKAGES)) $(patsubst %,install/%,$(BUILD_PACKAGES))