File: rules

package info (click to toggle)
imagemagick 8:6.9.10.23+dfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 62,332 kB
  • sloc: ansic: 344,643; cpp: 21,804; xml: 9,842; perl: 6,403; sh: 5,895; makefile: 3,020; tcl: 459
file content (851 lines) | stat: -rwxr-xr-x 39,482 bytes parent folder | download
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1


# quantum depth is channel depth
export QUANTUMDEPTH ?= q16 q16hdri
# lib version, run make -f debian/rules update_pkg in order to upgrade
export CORESOVERSION ?= 6
export WANDSOVERSION ?= 6
export PPSOVERSION ?= 8

# minimal version ABI compatible of common
export COMMONMINVERSION ?= 8:6.9.6.2+dfsg-3

# default im version used for adding default file
export DEFAULTIMVERSION ?= 6


# poc arch for test empty means no test
POC_ARCH ?= any-i386 any-amd64
VALGRIND_POC_ARCH ?=

# for hardening
# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/architecture.mk

# version extracted from changelog
#DEB_VERSION_UPSTREAM
DEB_UPSTREAM_VERSION_DROPREVISION := $(shell set -e;echo $(DEB_VERSION_UPSTREAM) |  sed -r "s/(^.+)\..+$$/\1/g")
DEB_UPSTREAM_VERSION_MAJOR := $(shell set -e;echo $(DEB_VERSION_UPSTREAM) | sed -r "s/(^[[:digit:]]+)\..+$$/\1/g")
export IMVERSION := $(DEB_UPSTREAM_VERSION_MAJOR)

# where to put documentation (relative)
export DOC_PKG_PATH := usr/share/doc/imagemagick-$(DEB_UPSTREAM_VERSION_MAJOR)-common/html

# quantum depth used by default and by quantum independant package (first one of QUANTUMDEPTH)
export DEFAULTQUANTUMDEPTH := $(shell echo $(QUANTUMDEPTH) | cut -f 1 -d ' ')
export NOQUANTUMDEPTH := $(shell echo $(QUANTUMDEPTH) | cut -f 1 -d ' ')

# convert used for icons
export CONVERT ?= ./magick.sh convert
VALGRIND_CONVERT ?= ./libtool --mode=execute valgrind $(CONVERT)
CONVERT_FLAGS ?= -background none -define filter:blur=0.75 -filter Gaussian

# perl path
export DEB_PERL_ARCHLIB := $(shell perl -MConfig -e 'print $$Config{vendorarch}')


# configure cache for acceleration
STATIC_CONFIGURE_CACHEFILE := config.cache
CONFIGURE_CACHEFILE ?= $(STATIC_CONFIGURE_CACHEFILE)

STATIC_CONFIGURE_OPTIONS_CACHE := \
       --cache-file=../../$(CONFIGURE_CACHEFILE)
CONFIGURE_OPTIONS_CACHE ?= $(STATIC_CONFIGURE_OPTIONS_CACHE)

# disable arch optimization see #757996 and AX_GCC_ARCHFLAG m4 macro
STATIC_CONFIGURE_ARCH_FLAGS := --without-gcc-arch
CONFIGURE_ARCH_FLAGS ?= $(STATIC_CONFIGURE_ARCH_FLAGS)

# NOTICE: remove EPL delegate lib gvc (license problem)
# should be last variable
STATIC_CONFIGURE_OPTIONS := \
	--enable-reproducible-build \
	--prefix=/usr \
	--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
	--docdir=/$(DOC_PKG_PATH) \
	--with-extra-doc-dir=' (on debian system you may install the imagemagick-$(IMVERSION) package)' \
	--sysconfdir=/etc \
	--with-includearch-dir=/usr/include/$(DEB_HOST_MULTIARCH)/ \
	--mandir=/usr/share/man \
	--infodir=/usr/share/info \
	--with-modules \
	--with-gs-font-dir=/usr/share/fonts/type1/gsfonts \
	--with-magick-plus-plus \
	--with-djvu \
        --with-heic \
	--with-openjp2 \
        --with-webp \
	--with-wmf \
	--without-gvc \
	--enable-shared \
	--without-dps \
	--without-fpx \
	--with-perl \
	--with-perl-options='INSTALLDIRS=vendor' \
	--x-includes=/usr/include/X11 \
	--x-libraries=/usr/lib/X11 \
	--without-rsvg
CONFIGURE_OPTIONS ?= $(STATIC_CONFIGURE_OPTIONS) \
			    $(CONFIGURE_OPTIONS_CACHE) \
			    $(CONFIGURE_ARCH_FLAGS)

# export for alternatives
export MAGICK_PROGRAMS := compare animate convert composite conjure import identify stream display montage mogrify

MAGICK_ANY_QUANTUM_PACKAGES :=  imagemagick-$(IMVERSION).$$QUANTUM \
				libmagickcore-${IMVERSION}.$$QUANTUM-${CORESOVERSION} \
				libmagickcore-${IMVERSION}.$$QUANTUM-${CORESOVERSION}-extra \
				libmagickwand-${IMVERSION}.$$QUANTUM-${WANDSOVERSION} \
				libmagick++-${IMVERSION}.$$QUANTUM-${PPSOVERSION} \
				libmagick++-${IMVERSION}.$$QUANTUM-dev \
				libmagickcore-${IMVERSION}.$$QUANTUM-dev \
				libmagickwand-${IMVERSION}.$$QUANTUM-dev \
				libimage-magick-$$QUANTUM-perl

MAGICK_ANY_PACKAGES :=  libmagickcore-$(IMVERSION)-arch-config
MAGICK_ANY_COMPAT_PACKAGES := imagemagick

MAGICK_ALL_PACKAGES :=  imagemagick-$(IMVERSION)-common \
			imagemagick-$(IMVERSION)-doc \
			libmagickcore-$(IMVERSION)-headers \
			libmagickwand-$(IMVERSION)-headers \
			libmagick++-$(IMVERSION)-headers \
			libimage-magick-perl

MAGICK_ALL_COMPAT_PACKAGES := imagemagick-common \
			      imagemagick-doc \
			      perlmagick \
			      libmagickcore-dev \
			      libmagickwand-dev \
			      libmagick++-dev

# run POC
TEST_POC_CMD:= \
	     POCFOUND='no'; \
	     set -e; for POC in $(POC_ARCH); do \
		if dpkg-architecture -i$$POC; then \
			POCFOUND='yes'; break;\
		fi; \
	     done; \
	     echo $$POCFOUND
TEST_POC := $(shell $(TEST_POC_CMD))

VALGRIND_TEST_POC_CMD:= \
	     POCFOUND='no'; \
	     set -e; for POC in $(VALGRIND_POC_ARCH); do \
		if dpkg-architecture -i$$POC; then \
			POCFOUND='yes'; break;\
		fi; \
	     done; \
	     echo $$POCFOUND

VALGRIND_TEST_POC := $(shell $(VALGRIND_TEST_POC_CMD))
# check if FPU
HAVE_FPU_CMD := \
		set -e; \
		case $(DEB_HOST_MULTIARCH) in \
		mips*-*) \
			if grep " FPU" /proc/cpuinfo > /dev/null; then \
				echo -n "yes"; \
			else \
				echo -n "no"; \
			fi; \
		;;\
		*) \
			echo -n "yes"; \
		;; \
	       esac;

STATIC_HAVE_FPU := $(shell $(HAVE_FPU_CMD))
export HAVE_FPU ?= $(STATIC_HAVE_FPU)

# upper/lower case function
LC = ${shell set -e; echo '$1' | sed -e 's/\(.*\)/\L\1/'}
UC = ${shell set -e; echo '$1' | sed -e 's/\(.*\)/\U\1/'}
REPLACE_QUANTUM = ${shell set -e;echo '$1' |  sed -e 's/$$QUANTUM/$2/g'}
MAGICK_ANY_Q_PACKAGES = ${shell set -e;echo '$(MAGICK_ANY_QUANTUM_PACKAGES)' |  sed -e 's/$$QUANTUM/$1/g'}

# extract quantum
QUANTUM_PART = ${shell set -e;echo -n '$1' | sed -r 's/q?([[:digit:]]*)(HDRI)?/\1/gi'}
HDRI_PART = ${shell set -e;case $$(set -e; echo -n '$1' | sed -e 's/\(.*\)/\L\1/') in *hdri) echo 'yes';; *) echo 'no' ;; esac }
HDRI_STR_PART = ${shell set -e;case $$(set -e;echo -n '$1' | sed -e 's/\(.*\)/\L\1/') in *hdri) echo ' with high dynamic range';; *) echo '' ;; esac }
PRIO_COMPUTATION =${shell $(CURDIR)/debian/scripts/quantumpriority.sh '$1'}

# bug #840682
DH_EXEC_SUBST = /usr/lib/dh-exec/dh-exec-subst
DH_EXEC_SUBST_ENV = debian/scripts/dh-exec-subst-env

# js dir
JS_DIR=www/assets

dummy:

test_fpu:
	echo $(HAVE_FPU)

PROVIDES_COMPAT_VERSION=$(DEB_VERSION)
PROVIDES_PKG_LIBMAGICKCORE_DEV_DEFAULTQ=libmagickcore-${IMVERSION}.defaultquantum-dev, libmagickcore-dev (=$${binary:Version}),
PROVIDES_LIBMAGICKCORE_DEV_DEFAULTQ=Provides: ${PROVIDES_PKG_LIBMAGICKCORE_DEV_DEFAULTQ}
PROVIDES_PKG_LIBMAGICKWAND_DEV_DEFAULTQ=libmagickwand-${IMVERSION}.defaultquantum-dev, libmagickwand-dev (=$${binary:Version}),
PROVIDES_LIBMAGICKWAND_DEV_DEFAULTQ=Provides: ${PROVIDES_PKG_LIBMAGICKWAND_DEV_DEFAULTQ}
PROVIDES_PKG_LIBMAGICKPP_DEV_DEFAULTQ=libmagick++-${IMVERSION}.defaultquantum-dev, libmagick++-dev (=$${binary:Version})
PROVIDES_LIBMAGICKPP_DEV_DEFAULTQ=Provides: ${PROVIDES_PKG_LIBMAGICKPP_DEV_DEFAULTQ}
PROVIDES_PKG_MAGICK_PERL_DEFAULTQ=libimage-magick-defaultquantum-perl, perlmagick (=$${binary:Version})
PROVIDES_MAGICK_PERL_DEFAULTQ=Provides: ${PROVIDES_PKG_MAGICK_PERL_DEFAULTQ}
DELPLACEHOLDER=XXXXX_DELETE_XXXXX

# update package files
update_pkg.%:
	# control
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	HDRI_STR="$(call HDRI_STR_PART,$*)" \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	DESC_QUANTUM="$$QUANTUM bits$$HDRI_STR" \
	PROVIDES_LIBMAGICKCORE_DEV='$(if $(subst $(DEFAULTQUANTUMDEPTH),,$*),$(DELPLACEHOLDER),${PROVIDES_LIBMAGICKCORE_DEV_DEFAULTQ})' \
	PROVIDES_LIBMAGICKWAND_DEV='$(if $(subst $(DEFAULTQUANTUMDEPTH),,$*),$(DELPLACEHOLDER),${PROVIDES_LIBMAGICKWAND_DEV_DEFAULTQ})' \
	PROVIDES_LIBMAGICKPP_DEV='$(if $(subst $(DEFAULTQUANTUMDEPTH),,$*),$(DELPLACEHOLDER),${PROVIDES_LIBMAGICKPP_DEV_DEFAULTQ})' \
	PROVIDES_MAGICK_PERL='$(if $(subst $(DEFAULTQUANTUMDEPTH),,$*),$(DELPLACEHOLDER),${PROVIDES_MAGICK_PERL_DEFAULTQ})' \
	$(DH_EXEC_SUBST_ENV) $(CURDIR)/debian/control.d/quantum.in > $(CURDIR)/debian/control.d/quantum.$*;
	if test x$* = x$(DEFAULTQUANTUMDEPTH); then \
		cat $(CURDIR)/debian/control.d/quantum.$* | sed -e '/$(DELPLACEHOLDER)/d' >> $(CURDIR)/debian/control.d/quantum; \
	else \
		cat $(CURDIR)/debian/control.d/quantum.$* | sed -e '/defaultquantum/d' -e '/$(DELPLACEHOLDER)/d'  >> $(CURDIR)/debian/control.d/quantum; \
	fi;
	# test
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	$(DH_EXEC_SUBST_ENV) $(CURDIR)/debian/tests.d/control.quantum.in >>  $(CURDIR)/debian/tests.d/control.quantum
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/tests.d/rose-IMVERSION.QUANTUMDEPTH.in > $(CURDIR)/debian/tests/rose-$(IMVERSION).$*
	chmod +x $(CURDIR)/debian/tests/rose-$(IMVERSION).$*
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/tests.d/perlmagick-IMVERSION.QUANTUMDEPTH.in > $(CURDIR)/debian/tests/perlmagick-$(IMVERSION).$*
	chmod +x $(CURDIR)/debian/tests/perlmagick-$(IMVERSION).$*
	# clean up
	rm -f $(CURDIR)/debian/control.d/quantum.$*

update_pkg: $(foreach Q,$(QUANTUMDEPTH),update_pkg.$Q)
	$(DH_EXEC_SUBST_ENV) $(CURDIR)/debian/control.d/noquantum.in >> $(CURDIR)/debian/control.d/noquantum
	$(DH_EXEC_SUBST_ENV) $(CURDIR)/debian/control.d/compat.in > $(CURDIR)/debian/control.d/compat
	printf "# Autogenerated %s from make -f debian/rules $@\n" "`LC_ALL=C date`" > $(CURDIR)/debian/control
	cat $(CURDIR)/debian/control.d/noquantum >> $(CURDIR)/debian/control
	cat $(CURDIR)/debian/control.d/quantum >> $(CURDIR)/debian/control
	cat $(CURDIR)/debian/control.d/compat >> $(CURDIR)/debian/control
	cat $(CURDIR)/debian/tests.d/control.quantum > $(CURDIR)/debian/tests/control
	rm -f $(CURDIR)/debian/control.d/compat
	rm -f $(CURDIR)/debian/control.d/quantum
	rm -f $(CURDIR)/debian/control.d/noquantum
	rm -f $(CURDIR)/debian/tests.d/control.quantum

%:
	if test "BUG#704225" = "SOLVED"; then \
		dh $@ --parallel --with pkgkde_symbolshelper; \
	else \
		dh $@  --no-parallel --with pkgkde_symbolshelper; \
	fi;


override_dh_autoreconf:
	@echo "CPU has FPU...$(HAVE_FPU)"
	dh_autoreconf --as-needed



# make autogenerated file
override_dh_auto_configure-arch_generatefile_quantum.%:
	# imagemagick-IMVERSION.QUANTUMDEPTH
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/imagemagick-IMVERSION.QUANTUMDEPTH.manpages.in > $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.manpages
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/imagemagick-IMVERSION.QUANTUMDEPTH.mime.in > $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.mime
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/imagemagick-IMVERSION.QUANTUMDEPTH.desktop.in > $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.desktop
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/imagemagick-IMVERSION.QUANTUMDEPTH.install.in > $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	QUANTUM_PRIO=$(call PRIO_COMPUTATION,$*) \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/imagemagick-IMVERSION.QUANTUMDEPTH.postinst.in > $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.postinst
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/imagemagick-IMVERSION.QUANTUMDEPTH.prerm.in > $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.prerm

	# libimage-magick-QUANTUM-perl
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libimage-magick-QUANTUMDEPTH-perl.install.in > $(CURDIR)/debian/libimage-magick-$*-perl.install

	# libmagick++-IMVERSION.QUANTUMDEPTH-PPSOVERSION.install.in
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagick++-IMVERSION.QUANTUMDEPTH-PPSOVERSION.install.in > $(CURDIR)/debian/libmagick++-$(IMVERSION).$*-$(PPSOVERSION).install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagick++-IMVERSION.QUANTUMDEPTH-dev.install.in > $(CURDIR)/debian/libmagick++-$(IMVERSION).$*-dev.install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/libmagick++-IMVERSION.QUANTUMDEPTH-PPSOVERSION.symbols.in > $(CURDIR)/debian/libmagick++-$(IMVERSION).$*-$(PPSOVERSION).symbols.notyet

	# libmagickcore
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagickcore-IMVERSION.QUANTUMDEPTH-CORESOVERSION.install.in > $(CURDIR)/debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION).install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagickcore-IMVERSION.QUANTUMDEPTH-CORESOVERSION-extra.install.in > $(CURDIR)/debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION)-extra.install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagickcore-IMVERSION.QUANTUMDEPTH-dev.install.in > $(CURDIR)/debian/libmagickcore-$(IMVERSION).$*-dev.install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/libmagickcore-IMVERSION.QUANTUMDEPTH-CORESOVERSION.symbols.in > $(CURDIR)/debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION).symbols

	# wand
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagickwand-IMVERSION.QUANTUMDEPTH-WANDSOVERSION.install.in > $(CURDIR)/debian/libmagickwand-$(IMVERSION).$*-$(WANDSOVERSION).install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	dh-exec $(CURDIR)/debian/libmagickwand-IMVERSION.QUANTUMDEPTH-dev.install.in > $(CURDIR)/debian/libmagickwand-$(IMVERSION).$*-dev.install
	QUANTUM=$(call QUANTUM_PART,$*) \
	HDRI=$(call HDRI_PART,$*) \
	QUANTUMDEPTH=$* \
	UCQUANTUMDEPTH=$(call UC,$*) \
	$(DH_EXEC_SUBST) $(CURDIR)/debian/libmagickwand-IMVERSION.QUANTUMDEPTH-WANDSOVERSION.symbols.in > $(CURDIR)/debian/libmagickwand-$(IMVERSION).$*-$(WANDSOVERSION).symbols

	touch $@

# configure in build directory
override_dh_auto_configure-arch_quantum.%: override_dh_auto_configure-arch_generatefile_quantum.%
	@echo "configure for $* : quantum=$(call QUANTUM_PART,$*) HDRI=$(call HDRI_PART,$*)"
	dh_auto_configure --builddirectory="debian/build-quantum-$*" -- \
		 ${CONFIGURE_OPTIONS} \
		--disable-silent-rules \
		--with-quantum-depth=$(call QUANTUM_PART,$*) \
		--enable-hdri=$(call HDRI_PART,$*)
	touch $@

override_dh_auto_configure-arch: $(foreach Q,$(QUANTUMDEPTH),override_dh_auto_configure-arch_quantum.$Q)

override_dh_auto_configure-indep:
	@echo "configure indep for $* : quantum=$(call QUANTUM_PART,$*) HDRI=$(call HDRI_PART,$*)"
	dh_auto_configure --builddirectory="debian/build-quantum-indep" -- \
		 ${CONFIGURE_OPTIONS} \
		--with-quantum-depth=$(call QUANTUM_PART,$(NOQUANTUMDEPTH)) \
		--enable-hdri=$(call HDRI_PART,$(NOQUANTUMDEPTH))
	# HACK: create default quantum package Makefile
	cd debian/build-quantum-indep/PerlMagick/default/ && perl Makefile.PL INSTALLDIRS=vendor

# dh_auto_build in build directory
# build icons cache build for each arch in order to get more testing
override_dh_auto_build-arch_quantum.%:
	dh_auto_build --builddirectory="debian/build-quantum-$*" -- all perl-build
	touch $@

override_dh_auto_build-arch: $(foreach Q,$(QUANTUMDEPTH),override_dh_auto_build-arch_quantum.$Q)

override_dh_auto_build-indep:
	# generate html doc
	dh_auto_build --builddirectory="debian/build-quantum-indep" -- html
	cd debian/build-quantum-indep/PerlMagick/default/ && make

# valgrind poc
ifeq ($(VALGRINDTEST_POC),yes)
override_dh_auto_test-arch_native_has_fpu_valgrindpoc_quantum.%: override_dh_auto_test-arch_native_has_fpu_poc_quantum.%:
	@echo "*******************************************************************************"
	@echo " valgrind test of security problems                                            "
	@echo "*******************************************************************************"
	set -e; for POC in $(CURDIR)/debian/poc/SEGV/*; do \
		echo "Test POC $$POC"; \
		(cd $(CURDIR)/debian/build-quantum-$*; $(VALGRIND_CONVERT) $$POC png:/dev/null) || true; \
	done;
else
override_dh_auto_test-arch_native_has_fpu_valgrindpoc_quantum.%:
endif
	touch $@

# poc
ifeq ($(TEST_POC),yes)
override_dh_auto_test-arch_native_has_fpu_poc_quantum.%: override_dh_auto_test-arch_native_has_fpu_testsuite_quantum.%
	@echo "*******************************************************************************" ;
	@echo " Basic test of security problems                                               " ;
	@echo "*******************************************************************************" ;
	set -e; for POC in $(CURDIR)/debian/poc/SEGV/*; do \
		echo "Test POC $$POC"; \
		(cd $(CURDIR)/debian/build-quantum-$*; $(CONVERT) $$POC png:/dev/null) || true; \
	done;
else
override_dh_auto_test-arch_native_has_fpu_poc_quantum.%:
endif
	touch $@

# test suite
override_dh_auto_test-arch_native_has_fpu_testsuite_quantum.%:
	unset DISPLAY; \
	if ! dh_auto_test --builddirectory="debian/build-quantum-$*"; then \
		find "debian/build-quantum-$*/tests" -name *.log -exec cat {} ; false ;\
	fi;
	touch $@

#only run if FPU
override_dh_auto_test-arch_native_has_fpu_quantum.%: override_dh_auto_test-arch_native_has_fpu_testsuite_quantum.% override_dh_auto_test-arch_native_has_fpu_poc_quantum.% override_dh_auto_test-arch_native_has_fpu_valgrindpoc_quantum.%
	touch $@

# only run if native build
ifeq ($(HAVE_FPU),yes)
override_dh_auto_test-arch_native_quantum.%: override_dh_auto_test-arch_native_has_fpu_quantum.%
else
override_dh_auto_test-arch_native_quantum.%:
	@echo "*******************************************************************************"
	@echo " skipped test suite NO FPU. Test suite too slow                                "
	@echo "*******************************************************************************"
endif
	touch $@

# dh_auto_test in build directory
# display log in case of failure
ifeq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
override_dh_auto_test-arch_quantum.%: override_dh_auto_test-arch_native_quantum.%
else
override_dh_auto_test-arch_quantum.%:
	@echo "****************************************************************************************"
	@echo " skipped test suite cross build host=$(DEB_HOST_GNU_TYPE) != build=$(DEB_BUILD_GNU_TYPE)"
	@echo "****************************************************************************************"
endif
	touch $@

override_dh_auto_test-arch: $(foreach Q,$(QUANTUMDEPTH),override_dh_auto_test-arch_quantum.$Q)

override_dh_auto_test-indep:


# build icons cache for quantum
override_dh_auto_install-arch_iconcache_quantum.%:
	# build icons cache (build for each arch in order to get more testing)
	set -e; while read SIZE; do \
		mkdir -p $(CURDIR)/debian/tmp-$*/usr/share/icons/hicolor/$$SIZE/apps/ ;\
		cd $(CURDIR)/debian/build-quantum-$*; \
		echo "Make icons for size $$SIZE..."; \
		$(CONVERT) $(CURDIR)/debian/display-im$(IMVERSION).svg \
			   $(CONVERT_FLAGS) -resize $$SIZE \
			   -gravity center -extent $$SIZE  \
			   +set date:create +set date:modify -define png:exclude-chunk=time  \
			   $(CURDIR)/debian/tmp-$*/usr/share/icons/hicolor/$$SIZE/apps/display-im$(IMVERSION).$*.png; \
		echo "Done"; \
	done < $(CURDIR)/debian/display-im$(IMVERSION).iconssize
	# make xpm
	mkdir -p $(CURDIR)/debian/tmp-$*/usr/share/pixmaps/
	cd $(CURDIR)/debian/build-quantum-$*; \
	echo "Make xpm size 32x32..." ; \
	$(CONVERT) $(CURDIR)/debian/display-im$(IMVERSION).svg $(CONVERT_FLAGS) -resize 32x32 \
		-gravity center -extent 32x32  \
		$(CURDIR)/debian/tmp-$*/usr/share/pixmaps/display-im$(IMVERSION).$*.xpm ;\
	echo "Done"
	# do not forget svgz
	mkdir -p $(CURDIR)/debian/tmp-$*/usr/share/icons/hicolor/scalable/apps/
	gzip -c -n -9 $(CURDIR)/debian/display-im$(IMVERSION).svg \
		> $(CURDIR)/debian/tmp-$*/usr/share/icons/hicolor/scalable/apps/display-im$(IMVERSION).$*.svgz
	touch $@

# dh_auto_install in build directory
override_dh_auto_install-arch_quantum.%: override_dh_auto_install-arch_iconcache_quantum.%
	dh_auto_install --builddirectory="debian/build-quantum-$*" \
			--destdir="debian/tmp-$*" \
			-- install pkgdocdir=/$(DOC_PKG_PATH) V=1

	# empties dependency_libs from .la files
	# http://lists.debian.org/debian-devel/2009/08/msg00783.html
	find $(CURDIR)/debian/tmp-$*/usr/lib -name '*.la' -exec \
		sed -i "s,^dependency_libs=.*,dependency_libs=''," {} \;
	# Remove RPATH from *.so
	find $(CURDIR)/debian/tmp-$* -name '*.so*' -exec \
		chrpath -d {} \;

	# move binaries to /usr/bin/*quantum
	set -e; for basename in $(MAGICK_PROGRAMS); do \
		mv "$(CURDIR)/debian/tmp-$*/usr/bin/$$basename" \
		   "$(CURDIR)/debian/tmp-$*/usr/bin/$$basename-im$(IMVERSION).$*"; \
		mv "$(CURDIR)/debian/tmp-$*/usr/share/man/man1/$$basename.1" \
		   "$(CURDIR)/debian/tmp-$*/usr/share/man/man1/$$basename-im$(IMVERSION).$*.1" ;\
	done
	# move generic man page
	mv "$(CURDIR)/debian/tmp-$*/usr/share/man/man1/ImageMagick.1" \
	   "$(CURDIR)/debian/tmp-$*/usr/share/man/man1/ImageMagick-im$(IMVERSION).$*.1"

	# move config script to arch directory
	# TODO: remove after jessie +1
	mkdir -p "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/ImageMagick-$(DEB_UPSTREAM_VERSION_DROPREVISION)/bin-$*/"; \
	set -e; for SCRIPT in Magick-config MagickCore-config MagickWand-config Wand-config Magick++-config; do \
		cp -f "debian/tmp-$*/usr/bin/$$SCRIPT" \
		      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/ImageMagick-$(DEB_UPSTREAM_VERSION_DROPREVISION)/bin-$*/"; \
	done;

	# add desktop for default
	mkdir -p debian/tmp-$*/usr/share/applications/
	cp $(CURDIR)/debian/imagemagick-$(IMVERSION).$*.desktop \
	   $(CURDIR)/debian/tmp-$*/usr/share/applications/display-im$(IMVERSION).$*.desktop

	# move pc file to quantum one c++
	mv "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++.pc" \
	   "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++-im$(IMVERSION).$*.pc"

	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++-$(IMVERSION).$(call UC,$*).pc"
	ln -s "ImageMagick++-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++-$(IMVERSION).$(call UC,$*).pc"
	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++-$(IMVERSION).$(call UC,$*).pc"

	ln -s "ImageMagick++-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++-im$(IMVERSION).$(call UC,$*).pc"
	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++.pc"
	ln -s "ImageMagick++-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++-im$(IMVERSION).$*.pc"
	# move pc file to quantum one core
	mv "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick.pc" \
	   "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick-im$(IMVERSION).$*.pc"

	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick-$(IMVERSION).$(call UC,$*).pc"
	ln -s "ImageMagick-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick-$(IMVERSION).$(call UC,$*).pc"

	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore-$(IMVERSION).$(call UC,$*).pc"
	ln -s "ImageMagick-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore-$(IMVERSION).$(call UC,$*).pc"
	# move pc file to quantum one wand
	mv "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand.pc" \
	   "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand-im$(IMVERSION).$*.pc"

	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand-$(IMVERSION).$(call UC,$*).pc"
	ln -s "MagickWand-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand-$(IMVERSION).$(call UC,$*).pc"

	-rm -f "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand-$(IMVERSION).$(call UC,$*).pc"
	ln -s "MagickWand-im$(IMVERSION).$*.pc" \
	      "debian/tmp-$*/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand-$(IMVERSION).$(call UC,$*).pc"

	# Remove empty directories in debian/tmp
	-find $(CURDIR)/debian/tmp-$* -type d -empty -print0 | xargs -0 -r rmdir -p --ignore-fail-on-non-empty
	touch $@

override_dh_auto_install-arch: $(foreach Q,$(QUANTUMDEPTH),override_dh_auto_install-arch_quantum.$Q)
	# default quantum pc file for c++
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++-im$(IMVERSION).pc"
	ln -s "ImageMagick++-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++-im$(IMVERSION).pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++-im$(IMVERSION).pc"
	ln -s "ImageMagick++-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++-im$(IMVERSION).pc"
	# default quantum for core
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick-im$(IMVERSION).pc"
	ln -s "ImageMagick-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick-im$(IMVERSION).pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore-im$(IMVERSION).pc"
	ln -s "ImageMagick-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore-im$(IMVERSION).pc"
	# wand
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand-im$(IMVERSION).pc"
	ln -s "MagickWand-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand-im$(IMVERSION).pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand-im$(IMVERSION).pc"
	ln -s "MagickWand-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand-im$(IMVERSION).pc"
	# delete default version
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++.pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++.pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick.pc"
	-rm -f  "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore.pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand.pc"
	-rm -f "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand.pc"
ifeq ($(DEFAULTIMVERSION),$(IMVERSION))
	# for c++
	ln -s "ImageMagick++-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++.pc"

	ln -s "ImageMagick++-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++.pc"
	# for core
	ln -s "ImageMagick-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick.pc"
	ln -s "ImageMagick-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore.pc"
	# for wand
	ln -s "MagickWand-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand.pc"
	ln -s "MagickWand-im$(IMVERSION).${DEFAULTQUANTUMDEPTH}.pc" \
	      "debian/tmp-${DEFAULTQUANTUMDEPTH}/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand.pc"
endif

override_dh_auto_install-indep:
	# install headers
	if test "BUG#703261" = "SOLVED"; then \
	dh_auto_install --builddirectory="$(CURDIR)/debian/build-quantum-indep" \
			--destdir="$(CURDIR)/debian/tmp-indep" \
			--  install-configlibDATA install-configshareDATA \
			    install-data-html \
			    install-magickincHEADERS  install-wandincHEADERS install-magickppincHEADERS install-magickpptopincHEADERS \
			    install-man1 \
			    V=1;\
	else \
	cd "$(CURDIR)/debian/build-quantum-indep" && \
		make  DESTDIR=$(CURDIR)/debian/tmp-indep \
			    install-configlibDATA install-configshareDATA \
			    install-data-html \
			    install-magickincHEADERS  install-wandincHEADERS install-magickppincHEADERS install-magickpptopincHEADERS \
			    install-man1 \
			    V=1 ;\
	fi;

	# Use x-terminal emulator for editing (Bug #132947) TODO: proper patch please
	sed -i 's/xterm/\/etc\/alternatives\/x-terminal-emulator/' \
		$(CURDIR)/debian/tmp-indep/etc/ImageMagick-$(IMVERSION)/delegates.xml

	# install default perl
	cd debian/build-quantum-indep/PerlMagick/default/ && make install DESTDIR=$(CURDIR)/debian/tmp-indep

	# Remove empty directories in debian/tmp
	-find $(CURDIR)/debian/tmp-indep -type d -empty -print0 | xargs -r -0 rmdir -p --ignore-fail-on-non-empty

	# remove boostrap copy
	if test -d "$(CURDIR)/debian/tmp-indep/$(DOC_PKG_PATH)/$(JS_DIR)/"; then \
	     rm -rf "$(CURDIR)/debian/tmp-indep/$(DOC_PKG_PATH)/$(JS_DIR)/"*; \
	else \
	    mkdir -p "$(CURDIR)/debian/tmp-indep/$(DOC_PKG_PATH)/$(JS_DIR)/"; \
	fi
	ln -s /usr/share/javascript/bootstrap/js/bootstrap.min.js \
	     "$(CURDIR)/debian/tmp-indep/$(DOC_PKG_PATH)/$(JS_DIR)/magick.js"
	ln -s /usr/share/javascript/bootstrap/css/bootstrap.min.css \
	     "$(CURDIR)/debian/tmp-indep/$(DOC_PKG_PATH)/$(JS_DIR)/magick.css"

	# now apply privacy cleanning rules
	cd "$(CURDIR)/debian/tmp-indep/$(DOC_PKG_PATH)" && \
	find  . \
	     -path './www/api/MagickCore' -prune -o \
	     -path './www/api/MagickWand' -prune -o \
	     -type f -and -name '*.html' -and -not -empty -print0 \
	     | xargs -r -0 -n 1 "$(CURDIR)/debian/scripts/removeprivacybreach" "$(CURDIR)/debian/scripts/removeprivacybreach.xslt"

# install quantum package
override_dh_install-arch_quantum.%:
	set -e; for PKG in $(call REPLACE_QUANTUM, $(MAGICK_ANY_QUANTUM_PACKAGES),$*); do \
		dh_install --package=$$PKG \
			--sourcedir=debian/tmp-$* --autodest; \
	done;

	# Remove extra coders from libmagickcore
	set -e; while read FILE; do \
		rm -f debian/libmagickcore-${IMVERSION}.$*-${CORESOVERSION}/$$FILE; \
	done < debian/libmagickcore-${IMVERSION}.$*-${CORESOVERSION}-extra.install

# install arch package
override_dh_install-arch: $(foreach Q,$(QUANTUMDEPTH),override_dh_install-arch_quantum.$Q)
	# take arch include in default quantum
	set -e; for PKG in $(MAGICK_ANY_PACKAGES); do \
		dh_install --package=$$PKG \
			--sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest; \
	done;

	# install default pc file
ifeq ($(DEFAULTIMVERSION),$(IMVERSION))
	# for c++
	dh_install --package=libmagick++-${IMVERSION}.${DEFAULTQUANTUMDEPTH}-dev \
		   --sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest \
		   "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Magick++.pc"
	dh_install --package=libmagick++-${IMVERSION}.${DEFAULTQUANTUMDEPTH}-dev \
		   --sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest \
		   "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick++.pc"
	# for core
	dh_install --package=libmagickcore-${IMVERSION}.${DEFAULTQUANTUMDEPTH}-dev \
		   --sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest \
		   "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/ImageMagick.pc"
	dh_install --package=libmagickcore-${IMVERSION}.${DEFAULTQUANTUMDEPTH}-dev \
		   --sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest \
		   "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickCore.pc"
	# for wand
	dh_install --package=libmagickwand-${IMVERSION}.${DEFAULTQUANTUMDEPTH}-dev \
		   --sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest \
		   "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/MagickWand.pc"
	dh_install --package=libmagickwand-${IMVERSION}.${DEFAULTQUANTUMDEPTH}-dev \
		   --sourcedir=debian/tmp-${DEFAULTQUANTUMDEPTH} --autodest \
		   "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Wand.pc"
endif

override_dh_install-indep:
	# special source imagemagick-*-common
	dh_install --package=imagemagick-$(IMVERSION)-common
	# remaining package
	dh_install --indep --remaining-packages --sourcedir=debian/tmp-indep --autodest
	# fix doxygen problem
	./debian/scripts/dh_doxygen --indep --package=imagemagick-$(IMVERSION)-doc
	# remove spurious php file
	find debian/imagemagick-$(IMVERSION)-doc/usr/share/doc/imagemagick-$(IMVERSION)-common/html -name '*.php' -delete
	# fix duplicate files
	jdupes -rl debian/imagemagick-$(IMVERSION)-doc/usr/share/doc/imagemagick-$(IMVERSION)-common/html

override_dh_compress:
	# fix #611125
	dh_compress -X$(DOC_PKG_PATH)

override_dh_makeshlibs:
	# avoid plugins' dir
	FAIL=0; \
	for PKG in $$(dh_listpackages -a); do \
	  echo dh_makeshlibs -p$$PKG -v -Xcoders/ -Xfilters/ ; \
	  dh_makeshlibs -p$$PKG -v -Xcoders/ -Xfilters/; \
	  FAIL=$$?; \
	done; \
	exit $$fail

# remove after jessie+2
override_dh_strip:
	dh_strip --ddeb-migration='imagemagick-dbg (<< 8:6.9.2.10-1~)'

# link bug file
override_dh_bugfiles-arch_quantum.%:
	set -e; for PKG in ${call REPLACE_QUANTUM, $(MAGICK_ANY_QUANTUM_PACKAGES),$*}; do \
		mkdir -p $(CURDIR)/debian/$$PKG/usr/share/bug/ ; \
		ln -s imagemagick-$(IMVERSION)-common \
		      $(CURDIR)/debian/$$PKG/usr/share/bug/$$PKG ; \
	done
	touch $@

override_dh_bugfiles-arch: $(foreach Q,$(QUANTUMDEPTH),override_dh_bugfiles-arch_quantum.$Q)
	set -e; for PKG in $(MAGICK_ANY_PACKAGES); do \
		mkdir -p $(CURDIR)/debian/$$PKG/usr/share/bug/ ; \
		ln -s imagemagick-$(IMVERSION)-common \
		      $(CURDIR)/debian/$$PKG/usr/share/bug/$$PKG ; \
	done
	set -e; for PKG in $(MAGICK_ANY_COMPAT_PACKAGES); do \
		mkdir -p $(CURDIR)/debian/$$PKG/usr/share/bug/ ; \
		ln -s imagemagick-$(IMVERSION)-common \
		      $(CURDIR)/debian/$$PKG/usr/share/bug/$$PKG ; \
	done

override_dh_bugfiles-indep:
	dh_bugfiles --package=imagemagick-$(IMVERSION)-common
	# link normal package
	set -e; for PKG in $(MAGICK_ALL_PACKAGES); do \
		if test "X$$PKG" != Ximagemagick-$(IMVERSION)-common; then \
			mkdir -p $(CURDIR)/debian/$$PKG/usr/share/bug/ ; \
			ln -s imagemagick-$(IMVERSION)-common \
			      $(CURDIR)/debian/$$PKG/usr/share/bug/$$PKG ; \
		fi; \
	done

	# link compat package
	set -e; for PKG in $(MAGICK_ALL_COMPAT_PACKAGES); do \
		mkdir -p $(CURDIR)/debian/$$PKG/usr/share/bug/ ; \
		ln -s imagemagick-$(IMVERSION)-common \
		      $(CURDIR)/debian/$$PKG/usr/share/bug/$$PKG ; \
	done

override_dh_installdocs-indep:
	dh_installdocs --indep --link-doc=imagemagick-$(IMVERSION)-common

override_dh_installdocs-arch:
	dh_installdocs --arch

# prep rules
override_dh_prep_quantum.%:
	[ ! -d debian/tmp-$* ] || rm -rf debian/tmp-$*

override_dh_prep: $(foreach Q,$(QUANTUMDEPTH),override_dh_prep_quantum.$Q) override_dh_prep_quantum.indep
	dh_prep


# clean rules
override_dh_clean_quantum.%:
	[ ! -d debian/build-quantum-$* ] || rm -rf debian/build-quantum-$*
	[ ! -d debian/tmp-$* ] || rm -rf debian/tmp-$*
	# generated file
	[ ! -f debian/imagemagick-$(IMVERSION).$*.manpages ] || rm debian/imagemagick-$(IMVERSION).$*.manpages
	[ ! -f debian/imagemagick-$(IMVERSION).$*.mime ] || rm debian/imagemagick-$(IMVERSION).$*.mime
	[ ! -f debian/imagemagick-$(IMVERSION).$*.desktop ] || rm debian/imagemagick-$(IMVERSION).$*.desktop
	[ ! -f debian/imagemagick-$(IMVERSION).$*.postinst ] || rm debian/imagemagick-$(IMVERSION).$*.postinst
	[ ! -f debian/imagemagick-$(IMVERSION).$*.prerm ] || rm debian/imagemagick-$(IMVERSION).$*.prerm
	[ ! -f debian/imagemagick-$(IMVERSION).$*.install ] || rm debian/imagemagick-$(IMVERSION).$*.install

	[ ! -f debian/libimage-magick-$*-perl.install ] || rm debian/libimage-magick-$*-perl.install

	[ ! -f debian/libmagick++-$(IMVERSION).$*-$(PPSOVERSION).install ] || rm debian/libmagick++-$(IMVERSION).$*-$(PPSOVERSION).install
	[ ! -f debian/libmagick++-$(IMVERSION).$*-dev.install ] || rm debian/libmagick++-$(IMVERSION).$*-dev.install
	[ ! -f debian/libmagick++-$(IMVERSION).$*-$(PPSOVERSION).symbols ] || rm debian/libmagick++-$(IMVERSION).$*-$(PPSOVERSION).symbols

	[ ! -f debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION).install ] || rm -f debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION).install
	[ ! -f debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION)-extra.install ] || rm -f debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION)-extra.install
	[ ! -f debian/libmagickcore-$(IMVERSION).$*-dev.install ] || rm -f debian/libmagickcore-$(IMVERSION).$*-dev.install
	[ ! -f debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION).symbols ] || rm -f debian/libmagickcore-$(IMVERSION).$*-$(CORESOVERSION).symbols

	[ ! -f debian/libmagickwand-$(IMVERSION).$*-$(WANDSOVERSION).install ] || rm -f debian/libmagickwand-$(IMVERSION).$*-$(WANDSOVERSION).install
	[ ! -f debian/libmagickwand-$(IMVERSION).$*-dev.install ] || rm -f debian/libmagickwand-$(IMVERSION).$*-dev.install
	[ ! -f debian/libmagickwand-$(IMVERSION).$*-$(WANDSOVERSION).symbols ] || rm -f debian/libmagickwand-$(IMVERSION).$*-$(WANDSOVERSION).symbols
	# autoreconf
	[ ! -f override_dh_auto_configure-arch_quantum.$* ] || rm override_dh_auto_configure-arch_quantum.$*
	[ ! -f override_dh_auto_configure-arch_generatefile_quantum.$* ] || rm override_dh_auto_configure-arch_generatefile_quantum.$*
	# auto_build
	[ ! -f override_dh_auto_build-arch_quantum.$* ] || rm override_dh_auto_build-arch_quantum.$*
	# auto install
	[ ! -f override_dh_auto_install-arch_quantum.$* ] || rm override_dh_auto_install-arch_quantum.$*
	[ ! -f override_dh_auto_install-arch_iconcache_quantum.$* ] || rm override_dh_auto_install-arch_iconcache_quantum.$*
	# dh_bugfile
	[ ! -f override_dh_bugfiles-arch_quantum.$* ] || rm override_dh_bugfiles-arch_quantum.$*
	# test suite target
	[ ! -f override_dh_auto_test-arch_quantum.$* ] || rm override_dh_auto_test-arch_quantum.$*
	[ ! -f override_dh_auto_test-arch_native_quantum.$* ] || rm override_dh_auto_test-arch_native_quantum.$*
	[ ! -f override_dh_auto_test-arch_native_has_fpu_quantum.$* ] || rm override_dh_auto_test-arch_native_has_fpu_quantum.$*
	[ ! -f override_dh_auto_test-arch_native_has_fpu_testsuite_quantum.$* ] || rm override_dh_auto_test-arch_native_has_fpu_testsuite_quantum.$*
	[ ! -f override_dh_auto_test-arch_native_has_fpu_poc_quantum.$* ] || rm override_dh_auto_test-arch_native_has_fpu_poc_quantum.$*
	[ ! -f override_dh_auto_test-arch_native_has_fpu_valgrindpoc_quantum.$* ] || rm override_dh_auto_test-arch_native_has_fpu_valgrindpoc_quantum.$*


override_dh_clean: $(foreach Q,$(QUANTUMDEPTH),override_dh_clean_quantum.$Q) override_dh_clean_quantum.indep
	[ ! -f $(CONFIGURE_CACHEFILE) ] || rm -f $(CONFIGURE_CACHEFILE)
	dh_clean


# maint rules
#########################

maint-html-is-sane:
	find $(CURDIR) \
		-maxdepth 3 -type f -and -name '*.html' -and -not -empty -print0 \
		| xargs -r -0 -t xmllint --noout --nonet