File: rules

package info (click to toggle)
emacs23 23.4%2B1-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 104,780 kB
  • sloc: lisp: 996,499; ansic: 249,051; objc: 10,008; makefile: 4,213; sh: 2,210; perl: 1,365; cs: 772; cpp: 490; awk: 465; python: 331; xml: 44; java: 27; csh: 8; sed: 4
file content (743 lines) | stat: -rwxr-xr-x 26,891 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
#!/usr/bin/make -f
# -*- makefile -*-

# This file is licensed under the terms of the Gnu Public License.
# With the one additional provision that Ian Jackson's name may not be
# removed from the file.

# Copyright 1994,1995 Ian Jackson
# Copyright 2004-2005 Jrme Marant <jerome@debian.org>
# Copyright 1998-2010 Rob Browning <rlb@defaultvalue.org>

# Originally copied from the GNU Hello Debian rules file (1.3).
# Modified for emacs by Mark Eichin <eichin@kitten.gen.ma.us>.
# Debhelper support added via one of Joey Hess' example files.
# See the debian/changelog for further historical information.

# TODO:
#
#   Figure out what happened to fns-*.elc
#   Should we set defaults for things like xsupport at the top here?
#   Deal with build_binary_pkg and continue integration.

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

SHELL := /bin/bash

quilt := QUILT_PATCHES=debian/patches quilt

pf := set -o pipefail

# This package uses debian/source/format 3.0 (quilt).

# For now we assume that emacs' versioning scheme is always
# MAJOR.MINORtinyrev where MAJOR and MINOR are integers and tinyrev is
# an optional lowercase letter (or letters).  We also assume that
# upstream uses a numbering scheme that sorts in a "Debian friendly"
# way.  So far that's always been true.  If it becomes false, some of
# the values below will have to be set manually.

# As you might expect, a "debian/rules clean" should always get you
# back to the state you were in before "debian/rules build".  In order
# to accomplish that, this rules file actually performs three
# independent builds to produce the emacsXY, emacsXY-nox, and
# emacsXY-lucid packages.  The source is actually copied into separate
# debian/build-* directories and built there.  Certain aspects of the
# upstream build process have led to this approach.

# For example, the original upstream source ships the .elc files, but
# we need to re-build them when we patch the corresponding .el files.
# The situation is further complicated by the fact that any of these
# .el files may have macros, and if those are changed, then any other
# .el files that use those macros must also be recompiled.  Over the
# years, we've tried various ways to handle this issue, originally by
# trying to keep track of which files need to be recompiled and only
# recompiling those, then later by just re-building all the .elc files
# with "make bootstrap".  In either case, if you don't want to have
# diff bloat, you have to do something to keep track of the original
# .elc files so you can restore them during make clean.

# All of this was a lot of work, and was using quite a bit of
# unnecessary storage both in the .orig.tar.gz.  To avoid that, and to
# simplify the process, we now just remove the .elc files from the
# upstream distribution whenever we create the debian .orig.tar.gz
# file for a given upstream release.  Since we were always clobbering
# the .elc files during the package build, that was no great loss.

# (You might imagine that a VPATH build would allow us to avoid having
#  to copy the entire source tree for each of the three builds, but it
#  turns out that without additional complexity, VPATH builds will
#  cause diff bloat.  That's because the emacs build process doesn't
#  completely respect the .elc files; some are modified in srcdir, not
#  builddir.)

# Copying the source to a separate build directory and building there
# is much simpler than previous approaches, it makes cleaning trivial,
# and it avoids any diff bloat.

# If the source tree ever ends up in an untenable "can't go forward,
# can't go back" state with respect to patching, you can always start
# over by just moving the current debian directory to a newly unpacked
# orig.tar.gz tree.  Note that if you were in the process of editing a
# patch, you will lose those edits, but you shouldn't lose anything
# else.  This process just reverts all of the upstream files and
# abandons the volatile "what's been done to the current tree" state
# that quilt maintains in ./.pc.  All of the actual patches are stored
# in debian/patches and should be unharmed.

######################################################################
# Important top-level targets:
#
# check-vars - displays how the version number has been parsed.
# buildpackage - build binary packages via dpkg-buildpackage w/suitable args
# prepare-release - prepare and check debs for upload.
#
######################################################################

# The name of the Debian source package
src_name := $(shell $(pf); dpkg-parsechangelog | egrep '^Source:')
src_name := $(shell $(pf); echo $(src_name) | perl -pe 's/Source:\s+//o')

# The version from the changelog (i.e. 20.5-1)
debian_ver := $(shell $(pf); dpkg-parsechangelog | egrep '^Version:')
debian_ver := $(shell $(pf); echo $(debian_ver) | perl -pe 's/Version:\s+//o')
# The Debian revision (i.e. the 1 from 20.5-1)
# Always everything after the last '-'
debian_rev := $(shell $(pf); echo $(debian_ver) | perl -pe 's/.*-//o')

# The official upstream version defined by emacs-version in lisp/version.el.
# The extraction method matches the code in the upstream configure.in.
nominal_ver := \
  $(shell $(pf); grep 'defconst[	 ]*emacs-version' lisp/version.el \
    | sed -e 's/^[^"]*"\([^"]*\)".*$$/\1/')

# This must be the version that's actually used at runtime for things
# like load-path.  It may not be the same as the upstream version
# (i.e. when you have upstream 20.5a, the functional version may still
# be 20.5), so sometimes we may have to do this by hand.
runtime_ver := $(shell $(pf); echo $(nominal_ver) | perl -pe 's/[a-z]+$$//o')

major_ver := $(shell $(pf); echo $(runtime_ver) | perl -pe 's/\..*$$//o')
minor_ver := $(shell $(pf); echo $(runtime_ver) | perl -pe 's/^[^.]*\.//o')

# version for the debian source, i.e. if the upstream is 21.3, this
# might be 21.3, or it might be 21.3+1 if we've had to have more than
# one re-release of the upstream source.  Rare, but it happens...
# Always everything before the last '-'
debsrc_ver := $(shell $(pf); echo $(debian_ver) | perl -pe 's/-[^-]+$$//o')

# upstream version - the actual upstream version, i.e. 21.4a, minus any +foo
upstream_ver := $(shell $(pf); echo $(debsrc_ver) | perl -pe 's/\+[^+]+$$//o')

deb_orig_tgz := $(src_name)_$(debsrc_ver).orig.tar.gz
# name of the orig_tgz unpack directory
deb_orig_tgz_dir := emacs-$(runtime_ver)

######################################################################
# Customizable variables

# The flavor (i.e. emacs21) currently matches the source package name.
flavor := $(src_name)

bin_priority := 26

# This might also be something like 2006-09-09 for snapshots.
menu_ver := $(major_ver)

info_subdir := emacs-$(major_ver)

######################################################################

# Should these be exported like this (as autotools-dev recommends for
# the two vars below) or not?
export DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
export DEB_HOST_GNU_CPU ?= $(shell dpkg-architecture -qDEB_HOST_GNU_CPU)

# As recommended by /usr/share/doc/autotools-dev/README.Debian.gz.
# Handle cross-compiling and don't make ./configure guess.
export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# FOR AUTOCONF 2.52 AND NEWER ONLY
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

deb_host_multiarch := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

CFLAGS = `dpkg-buildflags --get CFLAGS`
CFLAGS += -Wall
LDFLAGS = `dpkg-buildflags --get LDFLAGS`
CPPFLAGS = `dpkg-buildflags --get CPPFLAGS`

LDFLAGS   += -g
CFLAGS    += -DDEBIAN

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  ifneq (,$(filter $(DEB_HOST_ARCH),m68k ia64))
    # Fix a problem with newer versions of gcc on m68k and ia64.
    # There -O2 causes a build failure (broken byte compiler) - see
    # bugs #207580 and #582439.
    CFLAGS += -O1
  else # neq (m68k or ia64)
    CFLAGS += -O2
  endif # neq (m68k or ia64)
endif # not noopt

joblimit := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
ifeq (,$(joblimit))
  joblimit := 1
endif

# Force joblimit to 1 until an upstream race condition is fixed:
#   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=592992
joblimit := 1

target := $(DEB_HOST_GNU_TYPE)
movemail_bin := usr/lib/emacs/$(runtime_ver)/$(target)/movemail

# Info files that are going to show up in the main dir.
main_dir_info_files := \
  efaq

# Files that the build stage depends on (may also be listed in other vars).
persistent_autogen_build_files := debian/control debian/copyright
nonpersistent_autogen_build_files :=

# These files must always exist, i.e. can't ever be cleaned.
persistent_autogen_install_files :=

nonpersistent_autogen_install_files := \
  debian/$(flavor)-bin-common.lintian-overrides \
  debian/$(flavor)-bin-common.postinst \
  debian/$(flavor)-bin-common.prerm \
  debian/$(flavor)-common.README.Debian \
  debian/$(flavor)-common.docs \
  debian/$(flavor)-common.lintian-overrides \
  debian/$(flavor)-common.postinst \
  debian/$(flavor)-common.prerm \
  debian/$(flavor)-nox.README.Debian \
  debian/$(flavor)-nox.lintian-overrides \
  debian/$(flavor)-nox.menu \
  debian/$(flavor)-nox.postinst \
  debian/$(flavor)-nox.prerm \
  debian/$(flavor)-lucid.README.Debian \
  debian/$(flavor)-lucid.desktop \
  debian/$(flavor)-lucid.lintian-overrides \
  debian/$(flavor)-lucid.menu \
  debian/$(flavor)-lucid.postinst \
  debian/$(flavor)-lucid.prerm \
  debian/$(flavor).README.Debian \
  debian/$(flavor).desktop \
  debian/$(flavor).menu \
  debian/$(flavor).lintian-overrides \
  debian/$(flavor).postinst \
  debian/$(flavor).prerm

autogen_build_files := \
  $(nonpersistent_autogen_build_files) $(persistent_autogen_build_files)

autogen_install_files := \
  $(nonpersistent_autogen_install_files) $(persistent_autogen_install_files)

persistent_autogen_files := \
  $(persistent_autogen_build_files) $(persistent_autogen_install_files)

nonpersistent_autogen_files := \
  $(nonpersistent_autogen_build_files) $(nonpersistent_autogen_install_files)


# Build directories
pkgdir_common := $(CURDIR)/debian/$(flavor)-common
pkgdir_bin_common := $(CURDIR)/debian/$(flavor)-bin-common
pkgdir_x := $(CURDIR)/debian/$(flavor)
pkgdir_nox := $(CURDIR)/debian/$(flavor)-nox
pkgdir_lucid := $(CURDIR)/debian/$(flavor)-lucid
pkgdir_el := $(CURDIR)/debian/$(flavor)-el

install_dir_x := $(CURDIR)/debian/install-x
install_dir_nox := $(CURDIR)/debian/install-nox
install_dir_lucid := $(CURDIR)/debian/install-lucid

local_lpath := /etc/$(flavor):/etc/emacs
local_lpath := $(local_lpath):/usr/local/share/emacs/$(runtime_ver)/site-lisp
local_lpath := $(local_lpath):/usr/local/share/emacs/site-lisp
local_lpath := $(local_lpath):/usr/share/emacs/$(runtime_ver)/site-lisp
local_lpath := $(local_lpath):/usr/share/emacs/site-lisp

# Installation local_lpath
local_lpath_install \
  := $(pkgdir_common)/$(subst :,:$(pkgdir_common)/,$(local_lpath))

define testdir
  dh_testdir debian/emacsVER.postinst
endef

# If we ever need to do the stripping outside of dh_strip, just add an
# INSTALL_STRIP="-s" to the make vars below.

define emacs_inst
  $(MAKE) -C debian/$(1) install DESTDIR=$(2) \
    infodir=/usr/share/info/emacs-$(major_ver) \
    localstatedir=/var
endef

# If we ever need it, we can create a copy that doesn't assume ./debian/
define deb_sub
  perl -p \
    -e "s|\@PKG_NAME\@|$(pkg_name)|go;" \
    -e "s|\@MAJOR_VERSION\@|$(major_ver)|go;" \
    -e "s|\@MINOR_VERSION\@|$(minor_ver)|go;" \
    -e "s|\@FULL_VERSION\@|$(runtime_ver)|go;" \
    -e "s|\@PACKAGE_VERSION\@|$(debian_ver)|go;" \
    -e "s|\@DEBIAN_REV\@|$(deb_rev)|go;" \
    -e "s|\@NOMINAL_VERSION\@|$(nominal_ver)|go;" \
    -e "s|\@UPSTREAM_VERSION\@|$(upstream_ver)|go;" \
    -e "s|\@DEBSRC_VERSION\@|$(debsrc_ver)|go;" \
    -e "s|\@DEB_FLAVOR\@|$(flavor)|go;" \
    -e "s|\@MENU_VERSION\@|$(menu_ver)|go;" \
    -e "s|\@INFO_FILES\@|$(main_dir_info_files)|go;" \
    -e "s|\@INFO_SUBDIR\@|$(info_subdir)|go;" \
    -e "s|\@X_SUPPORT\@|$(xsupport)|go;" \
    -e "s|\@BIN_PRIORITY\@|$(bin_priority)|go;" \
    -e "s|\@MOVEMAIL_BIN\@|$(movemail_bin)|go;" \
      < $(1) > $(2)
endef

%:
	dh $@ --parallel

check-vars:
	@echo "src_name: $(src_name)"
	@echo "upstream_ver: $(upstream_ver)"
	@echo "debian_ver: $(debian_ver)"
	@echo "debsrc_ver: $(debsrc_ver)"
	@echo "debian_rev: $(debian_rev)"
	@echo "nominal_ver: $(nominal_ver)"
	@echo "runtime_ver: $(runtime_ver)"
	@echo "major_ver: $(major_ver)"
	@echo "minor_ver: $(minor_ver)"
	@echo "movemail_bin: $(movemail_bin)"

define check_diff
  @if $(quilt) series | grep -E '^debian-changes-'; \
  then \
    echo "Diffs found outside ./debian:"; \
    ls debian/patches/debian-changes-*; \
    false; \
  else \
    echo "../$(src_name)_$(debsrc_ver).diff.gz looks OK."; \
  fi
endef

check-diff: clean
	$(testdir)
	cd .. && dpkg-source -b -i "$(basename $(CURDIR))"
	$(check_diff)

buildpackage:
	$(testdir)
	dpkg-buildpackage -D -us -uc -rfakeroot -i
	$(check_diff)

prepare-release:
	$(testdir)
        # don't want to be root -- using fakeroot below.
        # also, stacking fakeroots seems to cause trouble generating diff.
	@test "`whoami`" != root || \
	  (echo "please run prepare-release as a normal user (not root)"; \
	   false)
        # check for any uncommitted changes
	@cd debian; \
	if ! git diff-files --quiet; \
	then \
	  git status; \
	  echo; \
	  read -p "Uncommitted changes.  Continue? [y/n] "; \
          if test "$${REPLY}" != y; \
	  then \
	    false; \
	  fi; \
	fi
        # TODO: make sure we actually installed the binary.
        # TODO: run tests (use a check target?)
	$(MAKE) -f debian/rules buildpackage
	@echo "Everything looks OK.  Ready for release."

debian-sync: $(persistent_autogen_files)
        # so dh pattern rule doesn't try to handle this target
	true

debian/$(flavor).%: xsupport := "x"
debian/$(flavor).%: pkg_name := $(flavor)

debian/$(flavor)-nox.%: xsupport := "nox"
debian/$(flavor)-nox.%: pkg_name := $(flavor)-nox

debian/$(flavor)-lucid.%: xsupport := "lucid"
debian/$(flavor)-lucid.%: pkg_name := $(flavor)-lucid

debian/$(flavor)-common.%: pkg_name := $(flavor)-common
debian/$(flavor)-bin-common.%: pkg_name := $(flavor)-bin-common

debian/%: debian/%.in debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor)-bin-common.%: debian/emacsVER-bin-common.% debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor)-common.%: debian/emacsVER-common.% debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor)-el.%: debian/emacsVER-el.% debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor).%: debian/emacsVER.% debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor)-nox.%: debian/emacsVER.% debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor)-lucid.%: debian/emacsVER.% debian/changelog
	$(call deb_sub,$<,$@)

debian/$(flavor)-common.README.Debian: \
  debian/emacsVER-common.README debian/patches/*.patch debian/patches/series \
  debian/rules debian/patch-to-news
	cd debian && \
	  csplit -s -f emacsVER-common.README. \
	  emacsVER-common.README '/@@PATCH_LIST_HERE@@/'
	cp debian/emacsVER-common.README.00 debian/emacsVER-common.README.tmp
	for p in $$($(quilt) series); do \
	  debian/patch-to-news debian/patches/$$p \
	    >> debian/emacsVER-common.README.tmp; \
	  echo >> debian/emacsVER-common.README.tmp; \
	done
	tail -n +2 \
	  < debian/emacsVER-common.README.01 \
	  >> debian/emacsVER-common.README.tmp
	mv debian/emacsVER-common.README.tmp $@

debian/setup-stamp:
	$(testdir)
	aclocal
	autoconf
	autoheader
	mkdir -p $(dir $@) && touch $@

# common configure flags
confflags += --prefix=/usr
confflags += --sharedstatedir=/var/lib
confflags += --libexecdir=/usr/lib
confflags += --localstatedir=/var/lib
confflags += --infodir=/usr/share/info
confflags += --mandir=/usr/share/man
confflags += --with-pop=yes
confflags += --enable-locallisppath=$(local_lpath)

# multiarch compatibility
confflags += --with-crt-dir=/usr/lib/$(deb_host_multiarch)

# x configure flags
confflags_x := $(confflags) 
confflags_x += --with-x=yes
confflags_x += --with-x-toolkit=gtk
# For those who prefer the old-style non-toolkit scrollbars, just
# change the assignment below to --without-toolkit-scroll-bars.  The
# resulting emacsXY package will have the old scrollbars.
confflags_x += --with-toolkit-scroll-bars

# nox configure flags
confflags_nox := $(confflags) 
confflags_nox += --with-x=no
confflags_nox += --without-gconf

# lucid configure flags
confflags_lucid := $(confflags)
confflags_lucid += --with-x=yes
confflags_lucid += --with-x-toolkit=lucid
confflags_lucid += --with-toolkit-scroll-bars
confflags_lucid += --without-gconf

define cfg_tree
  rm -rf $(1)
  mkdir $(1)
  cp -a $$(ls -A | grep -v '^debian$$' | grep -v '^.pc$$') "$(1)"
  cd $(1) && CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" ./configure $(confflags) $(2)
endef

define build_cmd
  $(MAKE) -C $(1) -j $(joblimit) CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
  # If we don't use bootstrap, we need to explicitly build info.
  $(MAKE) -C $(1) -j $(joblimit) CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" info
endef

override_dh_auto_configure: debian/setup-stamp
        # Can't use dh --with autotools_dev because it only works if
        # you haven't removed the config.sub and config.guess files
        # from the source tree.
	cp -a /usr/share/misc/config.guess .
	cp -a /usr/share/misc/config.sub .
	$(call cfg_tree,debian/build-x,$(confflags_x))
	$(call cfg_tree,debian/build-nox,$(confflags_nox))
	$(call cfg_tree,debian/build-lucid,$(confflags_lucid))

override_dh_auto_build: $(autogen_build_files)
	$(call build_cmd,debian/build-x)
	$(call build_cmd,debian/build-nox)
	$(call build_cmd,debian/build-lucid)

define install_common_binpkg_bits
  # args: (1) srcdir (2) pkgdir (3) pkgname (4) bin-suffix

  install -d $(2)/usr/bin/
  test -f $(1)/usr/bin/emacs-*
  cp -a $(1)/usr/bin/emacs-* $(2)/usr/bin/$(flavor)-$(4)
  dh_link -p$(3) usr/bin/$(flavor)-$(4) usr/bin/$(flavor)

  install -d $(2)/usr/share/emacs/$(runtime_ver)/etc
  cp -a $(1)/usr/share/emacs/$(runtime_ver)/etc/DOC-$(runtime_ver).1 \
	$(2)/usr/share/emacs/$(runtime_ver)/etc/

  install -d $(2)/usr/share/man/man1
  dh_link -p$(3) \
    usr/share/man/man1/emacs.$(flavor).1.gz \
    usr/share/man/man1/$(flavor).1.gz
  dh_link -p$(3) \
    usr/share/man/man1/emacs.$(flavor).1.gz \
    usr/share/man/man1/$(flavor)-$(4).1.gz
endef

override_dh_auto_install: $(autogen_install_files)
	rm -rf \
	  $(install_dir_x) $(install_dir_nox) $(install_dir_lucid) \
	  $(pkgdir_common)/* \
	  $(pkgdir_bin_common)/* \
	  $(pkgdir_x)/* \
	  $(pkgdir_nox)/* \
	  $(pkgdir_lucid)/* \
	  $(pkgdir_el)/*

	$(call emacs_inst,build-x,$(install_dir_x))

        ##################################################
        # emacsXY-common
        ifneq (,$(findstring $(flavor)-common, $(shell dh_listpackages)))
	  install -d $(pkgdir_common)
	  cp -a $(install_dir_x)/* $(pkgdir_common)

	  rm -r $(pkgdir_common)/usr/bin
	  rm -r $(pkgdir_common)/usr/lib

	  cd $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc \
	    && test -f DOC-$(runtime_ver).*
	  cd $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc \
	    && rm DOC-$(runtime_ver).*

	  # lisp path directories
	  install -d $(pkgdir_common)/etc/$(flavor)/site-start.d
	  install -d $(pkgdir_common)/usr/share/$(flavor)

	  # The version-specific site-lisp dir, say emacs/21.1/site-lisp, needs
	  # to be in share/FLAVOR so that as we upgrade from 21.1 to 21.2,
	  # etc., add-on package bits don't get left behind.
	  mv $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/site-lisp \
		  $(pkgdir_common)/usr/share/$(flavor)
	  dh_link -p$(flavor)-common usr/share/$(flavor)/site-lisp \
			  usr/share/emacs/$(runtime_ver)/site-lisp

	  # This is a duplicate of the file in FLAVOR/site-lisp
	  rm $(pkgdir_common)/usr/share/emacs/site-lisp/subdirs.el

	  cd $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc/images/icons \
	    && convert hicolor/16x16/apps/emacs.{png,xpm}
	  cd $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc/images/icons \
	    && convert hicolor/32x32/apps/emacs.{png,xpm}

	  # Fixup image files in unversioned directories (remove old
	  # images, version unversioned images) and prepare for
	  # update-alternatives.
	  rm $(pkgdir_common)/usr/share/icons/hicolor/16x16/apps/emacs22.png
	  rm $(pkgdir_common)/usr/share/icons/hicolor/24x24/apps/emacs22.png
	  rm $(pkgdir_common)/usr/share/icons/hicolor/48x48/apps/emacs22.png

	  cd $(pkgdir_common)/usr/share/icons/hicolor \
	    && mv scalable/apps/emacs.svg scalable/apps/${flavor}.svg \
	    && mv 16x16/apps/emacs.png 16x16/apps/${flavor}.png \
	    && mv 24x24/apps/emacs.png 24x24/apps/${flavor}.png \
	    && mv 32x32/apps/emacs.png 32x32/apps/${flavor}.png \
	    && mv 48x48/apps/emacs.png 48x48/apps/${flavor}.png \
	    && mv 128x128/apps/emacs.png 128x128/apps/${flavor}.png

	  cd $(pkgdir_common)/usr/share/icons/hicolor/scalable/mimetypes \
	    && mv emacs-document.svg ${flavor}-document.svg

	  # Remove redundant emacs.desktop file.
	  rm $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc/emacs.desktop
	  rm $(pkgdir_common)/usr/share/applications/emacs.desktop

	  # Mangle info files.
	  chmod 755 debian/mangle-info
	  for f in $(main_dir_info_files); \
	  do \
	    DEBIAN_INFO_PREFIX=$(info_subdir) \
	      debian/mangle-info \
		$(pkgdir_common)/usr/share/info/$(info_subdir)/$$f; \
	  done

	  perl -pi -e "s|man1/etags\\.1|man1/etags\\.$(flavor)\\.1|" \
	    $(pkgdir_common)/usr/share/man/man1/ctags.1

	  cd $(pkgdir_common)/usr/share/man/man1/ && \
	    for f in *.1; do mv $$f $$(basename $${f} .1).$(flavor).1; done

	  # At least etc/COPYING is needed by M-x describe-copying.
	  rm $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc/COPYING
	  rm $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/lisp/COPYING
	  dh_link -p$(flavor)-common /usr/share/common-licenses/GPL-3 \
	    usr/share/emacs/$(runtime_ver)/etc/COPYING
	  dh_link -p$(flavor)-common /usr/share/common-licenses/GPL-3 \
	    usr/share/emacs/$(runtime_ver)/lisp/COPYING

	  # Install replacements for non-free files that can be reached
	  # through C-h
	  for f in THE-GNU-PROJECT; \
	  do \
	    sed \
	      -e "s/@FILE@/$$f/g" \
	      -e "s/@MAJOR_VERSION@/$(major_ver)/g" \
	      $(CURDIR)/debian/missing-file.dfsg > \
	      $(pkgdir_common)/usr/share/emacs/$(runtime_ver)/etc/$$f.dfsg ; \
	  done

	  $(pf); cd $(pkgdir_common) && \
	    find -name "*.elc" | perl -pe 's/\.elc$$/\.el/o' | xargs rm -f

	  $(pf); cd $(pkgdir_common) && \
	    find -name "*.elc" | perl -pe 's/\.elc$$/\.el\.gz/o' | xargs rm -f

	  # Remove extraneous info dir files.  These may not exist if dpkg
	  # is 1.5.4 or newer.
	  rm -f $(pkgdir_common)/usr/share/info/emacs-$(major_ver)/dir
	  rm -f $(pkgdir_common)/usr/share/info/emacs-$(major_ver)/dir.old

	  # Remove the shared game score directory as a simple way to
	  # avoid a conflict with other flavors of Emacs.  Since
	  # Debian's update-game-score binary isn't setuid, that
	  # directory is never used.
	  rm $(pkgdir_common)/var/games/emacs/tetris-scores
	  rm $(pkgdir_common)/var/games/emacs/snake-scores
	  rmdir $(pkgdir_common)/var/games/emacs/
	  rmdir $(pkgdir_common)/var/games/
	  rmdir $(pkgdir_common)/var/

	  # Make sure /usr/local dir doesn't exist.
	  rm -r $(pkgdir_common)/usr/local
        endif

        ##################################################
        # emacsXY-bin-common
        ifneq (,$(findstring $(flavor)-bin-common, $(shell dh_listpackages)))
	  # Move common binaries to emacs-bin-common.
	  install -d $(pkgdir_bin_common)/usr
	  cp -a $(install_dir_x)/usr/bin $(pkgdir_bin_common)/usr
	  cp -a $(install_dir_x)/usr/lib $(pkgdir_bin_common)/usr

	  # Make sure there's just one.
	  test -f $(pkgdir_bin_common)/usr/bin/emacs-*
	  rm $(pkgdir_bin_common)/usr/bin/{emacs,emacs-*}

	  # Set up movemail.
	  chown root.mail $(pkgdir_bin_common)/$(movemail_bin)
	  chmod g+s $(pkgdir_bin_common)/$(movemail_bin)

	  # Set up alternatives.
	  alternatives=`ls $(pkgdir_bin_common)/usr/bin | xargs` && \
	    set -x && \
	    for f in debian/$(flavor)-bin-common.*; \
	    do \
	      perl -pwi -e "s|\@ALTERNATIVES\@|$${alternatives}|go" $$f ; \
	    done

	  for f in `ls $(pkgdir_bin_common)/usr/bin`; \
	  do \
	    mv $(pkgdir_bin_common)/usr/bin/$$f \
	       $(pkgdir_bin_common)/usr/bin/$$f.$(flavor) ; \
	  done
        endif

        ##################################################
        # emacsXY
        ifneq (,$(findstring $(flavor), $(shell dh_listpackages)))
	  $(call install_common_binpkg_bits,\
	    $(install_dir_x),$(pkgdir_x),$(flavor),x)

          # install desktop entry
	  install -d $(pkgdir_x)/usr/share/applications
	  install -m 0644 \
	    debian/$(flavor).desktop $(pkgdir_x)/usr/share/applications/
        endif

        ##################################################
        # emacsXY-nox
        ifneq (,$(findstring $(flavor)-nox, $(shell dh_listpackages)))
	  $(call emacs_inst,build-nox,$(install_dir_nox))
	  $(call install_common_binpkg_bits,\
	    $(install_dir_nox),$(pkgdir_nox),$(flavor)-nox,nox)
	  rm -rf $(install_dir_nox)
        endif

        ##################################################
        # emacsXY-lucid
        ifneq (,$(findstring $(flavor)-lucid, $(shell dh_listpackages)))
	  $(call emacs_inst,build-lucid,$(install_dir_lucid))
	  $(call install_common_binpkg_bits,\
	    $(install_dir_lucid),$(pkgdir_lucid),$(flavor)-lucid,lucid)

          # install desktop entry
	  install -d $(pkgdir_lucid)/usr/share/applications
	  install -m 0644 \
	    debian/$(flavor)-lucid.desktop \
	    $(pkgdir_lucid)/usr/share/applications/
	  rm -rf $(install_dir_lucid)
        endif

        ##################################################
        # emacsXY-el
        ifneq (,$(findstring $(flavor)-el, $(shell dh_listpackages)))
	  $(pf); \
	  (cd $(install_dir_x) && find -name "*.el" -o -name "*.el.gz" -print0 \
	   | tar cpf - --null --files-from -) \
	     | (cd $(pkgdir_el) && tar xpf -)
        endif

        ##################################################
        # final cleanup
	rm -rf $(install_dir_x)
	rm -rf $(install_dir_nox)
	rm -rf $(install_dir_lucid)

override_dh_testdir:
	$(testdir)

override_dh_fixperms:
	dh_fixperms -X$(movemail_bin)

override_dh_clean: $(persistent_autogen_files)
	rm -rf \
	  debian/build-x \
	  debian/install-x \
	  debian/build-nox \
	  debian/install-nox \
	  debian/build-lucid \
	  debian/install-lucid \
	  debian/*-stamp \
	  config.guess \
	  config.sub \
	  configure \
	  src/config.in
	rm -f $(nonpersistent_autogen_files)
	dh_clean