summaryrefslogtreecommitdiff
path: root/debian/rules
blob: afdd2783ad2ef39a5368e7ffd5c654087df94695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
#!/usr/bin/make -f
#------------------------------------------------------------------------------
# vim: syntax=make
#
# $Sendmail: rules,v 8.12.10 2003-07-13 21:46:03 cowboy Exp $
#
# Copyright (c) 1998-2003 Richard Nelson.  All Rights Reserved.
#
# ./rules.	Generated from rules.in by configure.
#
# Rules file for Sendmail 8.12.10-6(527370)
#			 on  Debian testing/unstable
#			 via Debhelper V4.1
#
# Note: the .in file supports Sendmail 8.7.6 - 8.12.10
#		on Debian slink, potato, woody, testing, sid, ...
#		but the generated file is customized to the version noted above.
#
# The only thing to watch for is to make sure the changelog correctly
# reflects the appropriate version and distribution!
#
# To support private builds:
#	1) use the environment variables (defaults shown first):
#			CC=gcc|gcc-3.0..........-- choose compiler
#			CFLAGS='-O2 -Wall [-g]'.-- choose compile options
#			DEFINES=''..............-- additional -Dxxx
#			SM_CONF=''..............-- Site local customization
#			SM_CONF_OPT=''..........-- additional configure options
#			SM_BUILD_OPT=''.........-- additional build options
#	2) Build the package using your normal setup:
#		A) [fakeroot] debian/rules binary
#		B) debuild -rfakeroot
#		C) dpkg-buildpackage -rfakeroot -uc -us
#
# DEB_BUILD_OPTIONS (global Debian package build options)
#	Debian specific, and common across package options
#		noopt	- Do *NOT* compile with optimization (force -O0)
#		nostrip - Do *NOT* strip binaries (for debugging)
#
# SM_CONF
#	A quick means to customize the Debian Sendmail package according
#	to your sites guidelines !
#		 1) Choose a configuration name (ie FooBar)
#		 2) cp debian/configure.options debian/FooBar.options
#		 3) $(EDIT) debian/FooBar.options to taste
#		 4) mkdir debian/FooBar.patches
#		 5) add any local patches in that directory - following
#			the style in debian/patches style (ie, 8.13/8.13.3 subdirectory)
#		 6) cp debian/changelog debian/FooBar.changelog
#		 7) $(EDIT) debian/FooBar.changelog, delete everything after the
#			1st null line (but leave that null!!!)
#		 8) Update debian/FooBar.changelog to show your updates
#		 9) SM_CONF="FooBar" debian/rules configure ** IMPORTANT ***
#		10) build the package (SM_CONF="FooBar" dpkg-buildpackage or debuild)
#
#
# SM_CONF_OPT
#	Additional configure options and/or overrides may be specified thusly:
#		1) export SM_CONF_OPT='--enable-shm=no'
#		   dpkg-buildpackage -rfakeroot -uc -us
#		2) SM_CONF_OPT='--enable-shm=no' dpkg-buildpackage
#		3) debuild -e SM_CONF_OPT='--enable-shm=no'
#		etc...
#
# SM_BUILD_OPT
#	1) export SM_BUILD_OPT='nodoc'
#	   dpkg-buildpackage -rfakeroot -uc -us
#	2) SM_BUILD_OPT='nodoc' dpkg-buildpackage -rfakeroot -uc -us
#	3) debuild -e SM_BUILD_OPT='nodoc' -e CLFAGS='-O3 Wall'
#	etc...
#
#	Supported options values for SM_BUILD_OPT:
#		nodev		Disable generation of libmilter-dev package
#		nodoc		Disable generation of sendmail-doc package
#
# This make file uses scripts from the DBS (0.8) package!
#
# Richard Nelson <cowboy@debian.org> 2004-11-16 16:17:00 (-0800)
#------------------------------------------------------------------------------
#SHELL := /bin/sh -x

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

# This is the debhelper compatibility version to use. (we'll set it later)
#export DH_COMPAT=4

# This has to be exported to make some magic below work.
export DH_OPTIONS

# Support separate debian directory
ifeq (yes, $(shell test -d debian && echo 'yes'))
	debian_dir := ./debian
	pwd_dir := $(shell pwd)
else
	debian_dir := .
	pwd_dir := $(shell pwd)/..
	SM_CONF_OPT += --enable-maintainer-mode
	endif

# Determine build,host architectures (via dpkg-architecture)
ifeq (, ${DEB_BUILD_ARCH})
	ifeq (yes, $(shell test -x /usr/bin/dpkg-architecture && echo 'yes'))
		include ${debian_dir}/scripts/dpkg-arch.mk
		endif
	endif

# Check for cross-compilation
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	ifneq (, $(DEB_BUILD_GNU_TYPE))
		endif
	endif

# will want path info for some things... Like patches/changelogs...
pwd_string := $(shell expr "${pwd_dir}" : '.*-\([X?0-9.].*\)')
ifeq (, $(findstring +,${pwd_string}))
	pwd_version := ${pwd_string}
else
	pwd_version := $(shell expr "${pwd_string}" : '.*+\([0-9.].*\)')
	endif
ifneq (, $(findstring Final,${pwd_version}))
	pwd_version := $(shell expr "${pwd_version}" : '\(.*\)\.Final')
	endif
pwd_major  := $(shell expr "${pwd_version}" : '\([0-9]*\.[0-9]*\)')

# get package/version information from the changelog
package		   := $(shell (cd ${debian_dir}/.. >/dev/null && \
		dpkg-parsechangelog 2>/dev/null) | awk '/^Source:/ {print $$2}')
version_string := $(shell (cd ${debian_dir}/.. >/dev/null && \
		dpkg-parsechangelog 2>/dev/null) | awk '/^Version:/ {print $$2}')
# Remove local site name from version string
ifneq (, ${SM_CONF})
ifneq (, $(findstring ${SM_CONF}.,${version_string}))
	version_string := $(shell expr "${version_string}" : "${SM_CONF}.\(.*\)")
endif
endif
version_full   := $(shell expr "${version_string}" : '\([^-]*\)')
version_debian := $(shell expr "${version_string}" : '[^-]*\(-.*\)')
version		   := ${version_full}
version_major  := $(shell expr "${version_full}" : '\([0-9]*\.[0-9]*\)')
version_minor  := $(shell expr "${version_full}" : '[0-9]*\.[0-9]*\.\(.*\)')
ifneq (, $(findstring +,${version_minor}))
	beta_version := $(shell expr "${version_full}" : '.*+\([0-9.].*\)')
	beta_major := $(shell expr "${beta_version}" : '\([0-9]*\.[0-9]*\)')
	beta_minor := $(shell expr "${beta_version}" : '[0-9]*\.[0-9]*\.\(.*\)')
	ifneq (, $(beta_version))
		version		   := ${beta_version}
		version_major  := ${beta_major}
		version_minor  := ${beta_minor}
		endif
	endif

# Many things depend upon which release (slink, potato, woody, etc.)
PKG_DIR  := ${debian_dir}/${package}-bin
DATA_DIR := /usr/share
ifeq (v4, $(shell (cd ${debian_dir}/.. >/dev/null && dh_testversion 4.0.0 2>/dev/null && echo 'v4')))
	DH_COMPAT := 4
else
	ifeq (v3, $(shell (cd ${debian_dir}/.. >/dev/null && dh_testversion 3.0.0 2>/dev/null && echo 'v3')))
		DH_COMPAT := 3
	else
		ifeq (v2, $(shell (cd ${debian_dir}/.. >/dev/null && dh_testversion 2.0.40 2>/dev/null && echo 'v2')))
			DH_COMPAT := 2
		else
			DH_COMPAT := 1
			PKG_DIR   := ${debian_dir}/tmp
			DATA_DIR  := /usr
			endif
		endif
	endif
export DH_COMPAT

# the dbs rules
TAR_DIR := ${package}-${version}
# Handle the case where the changelog is newer that what we're building
ifneq (yes, $(shell test -e ${debian_dir}/../${TAR_DIR}.tar.gz && echo 'yes'))
	TAR_DIR := ${package}-${pwd_version}
	endif
SOURCE_DIR := build-tree
BUILD_TREE := ${SOURCE_DIR}/${TAR_DIR}
PATCH_DIR  := ${debian_dir}/patches/${version_major}/${version}
SCRIPT_DIR := ${debian_dir}/scripts
STAMP_DIR  := ${debian_dir}/build/stampdir

# Include Debian Autoconf settings
ifeq (yes, $(shell test -e ${debian_dir}/build/autoconf.mk && echo 'yes'))
	include ${debian_dir}/build/autoconf.mk
else
	include ${debian_dir}/build/autoconf.mk.in
	endif

# these are strictly for my own consuption
PKG_DOC		 := ${debian_dir}/${package}-doc${docdir}/${package}-doc
PACKAGES	 := sendmail sendmail-base sendmail-cf sendmail-doc \
		libmilter-dev rmail sensible-mda
SM_SUBDIRS	 := editmap libmilter mail.local mailstats \
		makemap praliases rmail sendmail smrsh vacation
#
# We want delayed interpretation of the options !
ifeq (yes, $(shell test -x /usr/bin/debuild && echo 'yes'))
	DEB_BUILD = \
		SM_BUILD_OPT="${SM_BUILD_OPT}" \
		SM_CONF="${SM_CONF}" \
		SM_CONF_OPT="${SM_CONF_OPT}" \
		DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS}" \
		debuild -e SM_CONF -e SM_CONF_OPT -e SM_BUILD_OPT
else
	DEB_BUILD = \
		SM_BUILD_OPT="${SM_BUILD_OPT}" \
		SM_CONF="${SM_CONF}" \
		SM_CONF_OPT="${SM_CONF_OPT}" \
		DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS}" \
		dpkg-buildpackage
	endif

# Process build-time options:
#	1) options from SM_BUILD_OPT (Prior to configure)
#	2) defaults (Prior to configure)
ENABLE_INDEP := yes
ENABLE_ARCH  := yes
ENABLE_LIB	 := yes
ENABLE_BIN	 := yes
ifneq (, $(findstring nodev,${SM_BUILD_OPT}))
	ENABLE_DEV := no
else
	ENABLE_DEV := yes
	endif
ifneq (, $(findstring nodoc,${SM_BUILD_OPT}))
	ENABLE_DOC := no
else
	ENABLE_DOC := yes
	endif
#
# Summarize above options into -INDEP and -ARCH for this Makefile
ENABLE_INDEP := ${ENABLE_DOC}
ifeq (no, ${ENABLE_BIN})
	ifeq (no, ${ENABLE_LIB})
		ifeq (no, ${ENABLE_DEV})
			ENABLE_ARCH := no
			endif
		endif
	endif

# Now that all that is out of the way, read the desired configuration
# settings
ifeq (, ${SM_CONF})
	CONF_NAME = ${debian_dir}/configure.options
else
	ifneq (y, $(shell test -e debian/${SM_CONF}.options && echo 'y'))
		CONF_NAME := $(error Create ${SM_CONF}.options from configure.options)
		endif
	ifneq (y, $(shell test -e debian/${SM_CONF}.changelog && echo 'y'))
		CONF_NAME := $(error Create ${SM_CONF}.changelog from changelog)
		endif
	CONF_NAME = ${debian_dir}/${SM_CONF}.options
	SM_CONF_OPT += --with-custom=${SM_CONF}
endif
$(eval CONFIG_OPTS := $(shell grep -v "^\#" ${CONF_NAME}))

all:
	@echo 'Please specify a real target in the future...';
	$(MAKE) -f ${debian_dir}/rules \
		version_string=${pwd_string} \
		SM_BUILD_OPT="${SM_BUILD_OPT}" \
		SM_CONF="${SM_CONF}" \
		SM_CONF_OPT="${SM_CONF_OPT}" \
		DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS}" \
		binary-all;
	

#------------------------------------------------------------------------------
#	Rules to maintain the external Debian directory
#------------------------------------------------------------------------------
#-------------
.PHONY: refresh-dbs
refresh-dbs:
	@echo 'updating debian/scripts directory...';
	cp -af /usr/share/dbs/* ${SCRIPT_DIR}/;
	chmod a-w ${SCRIPT_DIR}/*;

#-------------
.PHONY: refresh-debian
refresh-debian:
	@dh_testdir;
	@echo 'updating debian directory ...';
	sudo $(RM) -r debian;
	sudo cp -a ../debian ./;
	sudo $(RM) -rf ${SOURCE_DIR} ${STAMP_DIR};
	# Remove some local configuration
	$(RM) -r debian/CaveIn.changelog \
		debian/CaveIn.options \
		debian/CaveIn.patches;
	# Make sure directories are writeable by the owner (mine aren't)
	chmod -R ug+w debian;
	-(cd ${debian_dir} && aclocal);
	-(cd ${debian_dir} && autoconf);
	-(cd ${debian_dir} && automake);
	# Force a configure here, using $${PWD} so the changelog, etc.
	# wind up with the right version numbers
	$(MAKE) -f ${debian_dir}/rules \
		version_string="${pwd_string}" \
		SM_BUILD_OPT="${SM_BUILD_OPT}" \
		SM_CONF="" \
		SM_CONF_OPT="${SM_CONF_OPT}" \
		DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS}" \
		configure;
	-(cd ${debian_dir} && $(MAKE) distclean;)
	$(RM) -r ${debian_dir}/autom4te.cache;
	# Remove pieces not needed for further building
	find ${debian_dir}/patches -type d -a ! -name 'patches' \
		-a ! -name 'contrib' \
		-a ! -name "${pwd_major}" \
		-a ! -name "${pwd_version}" \
		| xargs -r $(RM) -r;
	$(RM) -r ${debian_dir}/bugs ${debian_dir}/private;
	find ${debian_dir} -type f -name '*.am' | xargs -r $(RM);
	$(RM) \
		${debian_dir}/aclocal.m4 \
		${debian_dir}/build/*.m4;
	$(MAKE) -f ${debian_dir}/rules clean-debian;


#-------------
.PHONY: clean-debian
clean-debian:
	@echo 'cleaning debian directory...';
	#-(cd ${debian_dir} && $(MAKE) -f Makefile maintainer-clean;)
	#-(cd ${debian_dir} && $(MAKE) -f Makefile distclean;)
	find ${debian_dir} -name '*~' -o -name '\.*\.swp' \
			| xargs -r rm;
	$(RM) ${debian_dir}/*.sav ${debian_dir}/build/*.sav;
	$(RM) ${STAMP_DIR}/autotools ${STAMP_DIR}/configure;

#-------------
.PHONY: refresh-faq
refresh-faq:
	@echo 'Refreshing FAQ'
	@chmod u+w ${debian_dir}/faq.txt;
	(cd ${debian_dir} && wget --passive-ftp --timestamping \
		--cache=off http://www.sendmail.org/faq/faq.txt;);
	@chmod a-w ${debian_dir}/faq.txt;
	@echo 'Refreshing Misc'
	@chmod u+w ${debian_dir}/cf/feature/rhsbl.m4;
	(cd ${debian_dir}/cf/feature && wget --passive-ftp --timestamping \
		--cache=off http://www.megacity.org/software_downloads/rhsbl.m4;);
	@chmod u-w ${debian_dir}/cf/feature/rhsbl.m4;


#-------------
.PHONY: world
world:
	# Debian build daemons don't (for the nonce) support build-indep,
	# so this rule allows *me* to build both arch and indep portions
	# of sendmail in one go (so I don't forget).
	@dh_testdir;
	#time $(MAKE) -f ${debian_dir}/rules parts;
	time ${DEB_BUILD};
.PHONY: parts
parts:
	$(MAKE) -f ${debian_dir}/rules info;
	fakeroot $(MAKE) -f ${debian_dir}/rules clean;
	$(MAKE) -f ${debian_dir}/rules configure;
	fakeroot $(MAKE) -f ${debian_dir}/rules binary-all;

.PHONY: test
test:
	@dh_testdir;
	$(MAKE) -f ${debian_dir}/rules clean-debian;
	fakeroot $(MAKE) -f ${debian_dir}/rules clean;
	$(MAKE) -f ${debian_dir}/rules \
		ENABLE_DEV=no ENABLE_DOC=no \
		CFLAGS='-O2 -Wall' DEB_BUILD_OPTIONS='nostrip' configure;
	#time ${DEB_BUILD} -rfakeroot -d -us -uc;
	time $(MAKE) -f ${debian_dir}/rules build-arch;

.PHONY: print
print:
	@dh_testdir;
	-(cd ${BUILD_TREE}/.. && \
		for file in `find . -name 'README'`; do \
			lpr $$file; \
			done; );
	-(cd ${BUILD_TREE}/.. && \
		lpr */KNOWNBUGS; \
		lpr */RELEASE_NOTES; \
		lpr */sendmail/SECURITY; \
		lpr */sendmail/TUNING; \
		lpr */sendmail/TRACEFLAGS; \
		lpr */doc/op/op.ps; \
		lpr */cf/feature/nullclient.m4; \
		lpr */cf/feature/msp.m4; \
		);
	-(cd ${debian_dir} && \
		lpr ../../${debian_dir}/configure.ac; \
		lpr ../../${debian_dir}/build/rules.in; \
		lpr build/site.config.m4.in; \
		lpr cf/hack/msp_nullclient.m4; \
		);


#------------------------------------------------------------------------------
# Misc rules
#------------------------------------------------------------------------------
#-------------
${STAMP_DIR}:
	mkdir -p ${STAMP_DIR};


#------------------------------------------------------------------------------
# Autoconf rules
#------------------------------------------------------------------------------
#-------------
${debian_dir}/config.status: ${debian_dir}/configure
	# *** *** *** configure changed ?!? *** *** ***
	if [ -e ${debian_dir}/config.status ]; then \
		chmod ug+x ${debian_dir}/config.status; \
		(cd ${debian_dir} && ./config.status --recheck;) \
		fi;

#-------------
${debian_dir}/configure: ${debian_dir}/configure.ac
	# *** *** *** configure.ac changed ?!? *** *** ***
	cp -af ${debian_dir}/configure.ac \
		${debian_dir}/configure.in;
	(cd ${debian_dir} && autoconf;);
	$(RM) ${debian_dir}/configure.in;
	chmod ug+x ${debian_dir}/configure;

#-------------
.PHONY: autotools
autotools: ${STAMP_DIR} ${STAMP_DIR}/autotools
${STAMP_DIR}/autotools:

	#Add here commands to setup the autotools environment

	# Make sure we have the latest available config.{guess,sub}
	# Allow the package to override either by faking the date...
	if [ -e /usr/share/misc/config.guess ] \
	&& [ -e ${debian_dir}/build/config.guess ]; then \
		chmod ug+x ${debian_dir}/build/config.guess; \
		OLDDATEGUESS=`${debian_dir}/build/config.guess -t | tr -d - `; \
		NEWDATEGUESS=`/usr/share/misc/config.guess -t | tr -d - `; \
		if [ "$$OLDDATEGUESS" -lt "$$NEWDATEGUESS" ]; then \
			if [ ! -e ${debian_dir}/build/config.guess.sav ]; then \
				cp -pf ${debian_dir}/build/config.guess \
					${debian_dir}/build/config.guess.sav;\
				fi; \
			if [ -e ${debian_dir}/build/config.guess.sav ]; then \
				cp -pf /usr/share/misc/config.guess \
					${debian_dir}/build/config.guess; \
				fi; \
			fi; \
		fi;
	if [ -e /usr/share/misc/config.sub ] \
	&& [ -e ${debian_dir}/build/config.sub ]; then \
		chmod ug+x ${debian_dir}/build/config.sub; \
		OLDDATESUB=`${debian_dir}/build/config.sub -t | tr -d - `; \
		NEWDATESUB=`/usr/share/misc/config.sub -t | tr -d - `; \
		if [ "$$OLDDATESUB" -lt "$$NEWDATESUB" ]; then \
			if [ ! -e ${debian_dir}/build/config.sub.sav ]; then \
				cp -pf ${debian_dir}/build/config.sub \
					${debian_dir}/build/config.sub.sav; \
				fi; \
			if [ -e ${debian_dir}/build/config.sub.sav ]; then \
				cp -pf /usr/share/misc/config.sub \
					${debian_dir}/build/config.sub; \
				fi; \
			fi; \
		fi;

	# Make sure that some autotools stuff is executable.
	chmod ug+x \
		${debian_dir}/build/config.guess \
		${debian_dir}/build/config.sub \
		${debian_dir}/build/depcomp \
		${debian_dir}/build/install-sh \
		${debian_dir}/build/missing \
		${debian_dir}/build/mkinstalldirs \
		;

	touch ${STAMP_DIR}/autotools;



#------------------------------------------------------------------------------
# Build/Package check rules
#------------------------------------------------------------------------------
#-------------
.PHONY: info
info:

	#--------------------------------------------------------------------
	# The following information will be used for this run:
	#	SM_CONF    = ${SM_CONF} 
	#	Source	   = ${package} ${pwd_string}
	#	Package    = ${package} ${version_string}
	#	Version    = ${version_major}.${version_minor}${version_debian}
	#	BuildTree  = ${BUILD_TREE}
	#	PatchDir   = ${PATCH_DIR}
	#	Arch	   = ${DEB_BUILD_ARCH} on ${DEB_HOST_ARCH}
	#	Options
	#	  configure   = ${CONFIG_OPTS}
	#	  config opt  = ${SM_CONF_OPT}
	#	  build opt   = ${SM_BUILD_OPT}
	#	  ENABLE_INDEP= ${ENABLE_INDEP}
	#	  ENABLE_ARCH = ${ENABLE_ARCH}
	#	  ENABLE_DEV  = ${ENABLE_DEV}
	#	  ENABLE_DOC  = ${ENABLE_DOC}
	#	  compile opt = ${CC} ${CFLAGS} ${DEFINES}
	#	DEB_BUILD_OPTIONS = ${DEB_BUILD_OPTIONS}
	#	DH_VERBOSE = ${DH_VERBOSE}
	#	DH_OPTIONS = ${DH_OPTIONS}
	#	DH_COMPAT  = ${DH_COMPAT}
	#--------------------------------------------------------------------

#-------------
.PHONY: buildinfo
buildinfo:
	@echo '';
	@dpkg -l \
		debhelper \
		dpkg-dev \
		gcc \
		'libc6*' \
		binutils \
		ldso \
		make \
		m4 \
		libdb4			libdb4-dev \
		libdb3			libdb3-dev \
		libdb2			libdb2-dev \
		libwrap0		libwrap0-dev \
		libldap2		libldap2-dev \
		libopenldap1	libopenldap-dev \
		umich-libldap	umich-libldap-dev \
		libsasl2		libsasl2-dev \
		libsasl7		libsasl-dev \
		openssl			libssl-dev		   'libssl0*' \
		${BUILD_INFO} \
		2> /dev/null \
		| awk '$$1 == "ii" { printf("%s-%s\n", $$2, $$3) }' \
		| tee ${debian_dir}/buildinfo;
	@echo '';
	@chmod 644 ${debian_dir}/buildinfo;

#-------------
.PHONY: pristine
pristine:
	@dh_testdir;
	#$(MAKE) -f ${debian_dir}/rules info;
	#
	# Fail if there are any modifications to the original
	# tarball, other than the debian directory
	if [ -f ../${package}_${version_string}.diff.gz ]; then \
		zgrep -e "^\+\+\+ " ../${package}_${version_string}.diff.gz \
		| sed -e "/^\+\+\+ ${package}-${version}\/debian\/.*$$/d" - \
		| [ ! -z - ]; \
		fi;

	# Check for presence of TLS (crypto) enablement and bitch if found
	@if (grep -qEe '^#TLS:[[:space:]]*yes' \
		${debian_dir}/build/site.config.m4); then \
		echo '** ** --------------------------------------------------- ** **';\
		echo '** ** This package contains crypto support ! Be careful ! ** **';\
		echo '** ** --------------------------------------------------- ** **';\
		fi;

#-------------
.PHONY: verify
verify:
	@dh_testdir;
	# Verifying the md5 summs and signed files
	@for file in $$(find . -maxdepth 1 -name '*.md5'); do \
		echo "Checking MD5 source: $$file."; \
		cat $$file; \
		md5sum -c $$file; \
		done;
	@for file in $$(find . -maxdepth 1 -name '*.sig'); do \
		echo "Checking signature file $$file."; \
		part=$$(echo "$$file" | sed -e 's/\.sig$$//'); \
		if [ -f $$part ]; then \
			gpg --verify $$part.sig $$part || true; \
		elif [ -f $$part.gz ]; then \
			gunzip -c $$part.gz > $$part; \
			gpg --verify $$part.sig $$part || true; \
			rm $$part; \
			fi; \
		done;


#------------------------------------------------------------------------------
# User callable rules
#------------------------------------------------------------------------------
#-------------
.PHONY: clean
clean:
	@dh_testdir;
	@dh_testroot;

	# Add here commands to clean up after the build process.
	#-$(MAKE) clean;
	#-$(MAKE) distclean;

	# First, remove any patches, and source directories
	#$(MAKE) -f ${debian_dir}/sys-build.mk source.clean;

	# Local stuff
	-if [ -f ${debian_dir}/Makefile ]; then \
		(cd ${debian_dir} && $(MAKE) -f Makefile clean;) \
		fi;

	# Debian stuff
	$(RM) -r ${SOURCE_DIR} ${STAMP_DIR};
	$(RM) \
		${debian_dir}/config.log \
		${debian_dir}/config.status \
		${debian_dir}/*.buildinfo.Debian \
		${debian_dir}/*.debhelper \
		${debian_dir}/build/debian/changelog.in \
		${debian_dir}/build/debian/control \
		;
	for file in tmp ${PACKAGES};do \
		$(RM) -r ${debian_dir}/$$file; \
		done;

ifeq (3, $(shell test ${DH_COMPAT} -ge 3 && echo '3'))
	# Debhelper V3 conffile handling - prevent duplicates
	for file in $$(find ${debian_dir} -maxdepth 1 -type f \
		-name '*\.conffiles\.sav'); do \
		mv $$file $$(echo "$$file" | sed -e 's?\.sav$$??'); \
		done;
endif
	# Restore pre-existing config.{guess,sub}
	-if [ -e ${debian_dir}/build/config.sub.sav ]; then \
		cp -pf ${debian_dir}/build/config.sub.sav \
			${debian_dir}/build/config.sub \
		&& $(RM) ${debian_dir}/build/config.sub.sav; \
		fi;
	-if [ -e ${debian_dir}/build/config.guess.sav ]; then \
		cp -pf ${debian_dir}/build/config.guess.sav \
			${debian_dir}/build/config.guess \
		&& $(RM) ${debian_dir}/build/config.guess.sav; \
		fi;

	# Cleanup after build (for pristine source, smaller diffs)
	#find .. -name ${package}*.asc -size 0 -maxdepth 1 -exec rm {} ';';
	dh_clean;


#-------------
.PHONY: setup
setup: ${STAMP_DIR}/setup
${STAMP_DIR}/setup: ${STAMP_DIR}/patch
	$(MAKE) -f ${debian_dir}/rules info
# Support separate debian directory
ifeq (yes, $(shell test -d debian && echo 'yes'))
	touch ${STAMP_DIR}/setup;
endif

.PHONY: patch
patch: ${STAMP_DIR}/patch
${STAMP_DIR}/patch: unpack
# patch source
ifeq (yes, $(shell test -d debian && echo 'yes'))
	@dh_testdir;
ifeq (yes, $(shell test -d debian/${SM_CONF}.patches && echo 'yes'))
	cp -af debian/${SM_CONF}.patches/* debian/patches/;
endif
	$(MAKE) -f ${SCRIPT_DIR}/dbs-build.mk \
		BUILD_TREE="${BUILD_TREE}" \
		TAR_DIR="${TAR_DIR}" \
		STAMP_DIR="${STAMP_DIR}" \
		PATCH_DIR="${PATCH_DIR}" \
		SCRIPT_DIR="${SCRIPT_DIR}" \
		${STAMP_DIR}/patch;
	#touch ${STAMP_DIR}/patch;
endif

.PHONY: unpack
unpack: ${STAMP_DIR}/unpack
${STAMP_DIR}/unpack:
	$(MAKE) -f ${debian_dir}/rules info;
# unpack source
ifeq (yes, $(shell test -d debian && echo 'yes'))
	@dh_testdir;
	$(MAKE) -f ${SCRIPT_DIR}/dbs-build.mk \
		BUILD_TREE="${BUILD_TREE}" \
		TAR_DIR="${TAR_DIR}" \
		STAMP_DIR="${STAMP_DIR}" \
		PATCH_DIR="${PATCH_DIR}" \
		SCRIPT_DIR="${SCRIPT_DIR}" \
		${STAMP_DIR}/unpack;
	#touch ${STAMP_DIR}/unpack;
endif


#-------------
.PHONY: configure
configure: ${STAMP_DIR}/configure
${STAMP_DIR}/configure: ${STAMP_DIR}/setup ${STAMP_DIR}/autotools
	$(MAKE) -f ${debian_dir}/rules info;
	#Add here commands to configure the package.
	#./configure --prefix=/usr
	# Use autoconf to handle varying degrees of library support
	# NOTE: options values are Yes/No/Auto, but auto isn't always
	# used herein, as it can cause problems to be ignored
	# so it is only used on items of lesser importance
	chmod ug+x ${debian_dir}/configure;
	(cd ${debian_dir} && \
	./configure \
		${CONFIG_OPTS} \
		${SM_CONF_OPT} \
		;);
		# CC="${CC}" CFLAGS="${CFLAGS}
# Force a re-read of the rules file (to pull configure settings)
ifeq (yes, $(shell test -d debian && echo 'yes'))
	touch debian/rules;
endif
ifeq (3, $(shell test ${DH_COMPAT} -ge 3 && echo '3'))
	# Debhelper V3 conffile handling - prevent duplicates
	for file in $$(find ${debian_dir} -maxdepth 1 -type f \
		-name '*.conffiles'); do \
		mv $$file $$file.sav; \
		done;
endif
ifeq (smX, ${package})
	(cd ${BUILD_TREE} && \
		CFLAGS="-DSM_USE_TLS -DSM_USE_SASL ${CFLAGS}" \
		./configure \
			--libexecdir=/usr/lib/sm.bin \
			--datarootdir= \
			--datadir=${DATA_DIR} \
			--sysconfdir=/etc \
			--localstatedir=/var \
			--infodir=${DATA_DIR}/info \
			--mandir=${DATA_DIR}/man \
			--enable-TLS \
			--enable-SASL \
			--enable-pmilter \
	)
endif
	touch ${STAMP_DIR}/configure;


#-------------
.PHONY: build-indep
build-indep: ${STAMP_DIR}/build-indep
${STAMP_DIR}/build-indep: ${STAMP_DIR}/configure
# Skip work if nothing to do...
ifeq (yes, ${ENABLE_INDEP})
	@dh_testdir;
ifeq (smX,${package})
else
	# Add here commands to build/compile the documentation/package.
	#$(MAKE) doc;
	# Only valid on newer (8.11+) Sendmails
	#(cd ${BUILD_TREE}/doc/op/ && make op.txt);
	# So we'll do it by hand...
	$(RM) ${BUILD_TREE}/doc/op/op.txt;
	pic -C ${BUILD_TREE}/doc/op/op.me | eqn -C -Tascii \
		| GROFF_NO_SGR=1 groff -Tascii -me | ul -t dumb > ${BUILD_TREE}/doc/op/op.txt;
	# Debian stuff
	(cd ${debian_dir} && $(MAKE) -f Makefile build-indep;)
endif
endif
	touch ${STAMP_DIR}/build-indep;


#-------------
.PHONY: build-arch
build-arch: ${STAMP_DIR}/build-arch
${STAMP_DIR}/build-arch: ${STAMP_DIR}/configure
# Skip work if nothing to do...
ifeq (yes, ${ENABLE_ARCH})
	@dh_testdir;
	# Add here commands to compile the package.
	# $(MAKE);
	#
ifeq (smX,${package})
	(cd ${BUILD_TREE} && make)
	#(cd ${BUILD_TREE} && make -i check >check.log 2>&1)
else
	# Place our m4 configuration files for the sendmail build to use
	if [ -d ${BUILD_TREE}/devtools/Site ]; then \
		cp -f ${debian_dir}/build/site.config.m4 \
			${BUILD_TREE}/devtools/Site/; \
		fi;
	# Finally, build the whole enchilada (we'll let sendmail figure
	# which, if any of the dependant libraries each component needs)
	for subdir in ${SM_SUBDIRS}; do \
		if [ -d  ${BUILD_TREE}/$${subdir} ]; then \
			(cd ${BUILD_TREE}/$${subdir} && ./Build -S;); \
			fi; \
		if [ -d ${BUILD_TREE}/libmilter ]; then \
			(cd ${BUILD_TREE}/obj*/libmilter && \
				gcc -shared -pthread -o libmilter.so.0 \
					-Wl,-soname,libmilter.so.0 \
					main.o engine.o listener.o handler.o comm.o \
					smfi.o signal.o sm_gethost.o errstring.o strl.o;); \
			fi; \
		done;
	# Debian stuff
	(cd ${debian_dir} && $(MAKE) -f Makefile build-arch;)
	# Remove our config m4 files
	$(RM) ${BUILD_TREE}/devtools/Site/site.config.m4;
endif
endif
	touch ${STAMP_DIR}/build-arch;


#-------------
.PHONY: check-arch
check-arch: ${STAMP_DIR}/check-arch
${STAMP_DIR}/check-arch: ${STAMP_DIR}/build-arch
# Skip work if nothing to do...
ifeq (yes, ${ENABLE_ARCH})
	@dh_testdir;
	# Add here commands to compile the package.
	# $(MAKE);
	#
ifeq (smX,${package})
	(cd ${BUILD_TREE} && make -i check >check.log 2>&1)
else
endif
endif
	touch ${STAMP_DIR}/check-arch;


#-------------
.PHONY: install-indep
install-indep: ${STAMP_DIR}/install-indep
${STAMP_DIR}/install-indep: DH_OPTIONS=-i
${STAMP_DIR}/install-indep: ${STAMP_DIR}/build-indep
# Skip work if nothing to do...
ifeq (yes, ${ENABLE_INDEP})
	@dh_testdir;
	@dh_testroot;
	#dh_clean -k;
	dh_installdirs;
	if [ -x /usr/bin/dh_link ]; then dh_link; fi;
ifeq (smX,${package})
else
	# Add here commands to install the documentation/package.
	#$(MAKE) prefix=`pwd`/${PKG_DIR}/usr install;
	# sendmail operations guide and other documentation
	$(INSTALL_DATA) ${BUILD_TREE}/doc/op/op.ps	${PKG_DOC}/op;
	$(INSTALL_DATA) ${BUILD_TREE}/doc/op/op.txt ${PKG_DOC}/op;
	$(INSTALL_DATA) ${BUILD_TREE}/README		${PKG_DOC}/;
	$(INSTALL_DATA) ${BUILD_TREE}/KNOWNBUGS	${PKG_DOC}/;
	$(INSTALL_DATA) ${BUILD_TREE}/cf/README	${PKG_DOC}/cf.README;
	$(INSTALL_DATA) debian/README.Debian.sendmail \
		${PKG_DOC}/sendmail/README.Debian;
	$(INSTALL_DATA) ${BUILD_TREE}/sendmail/README \
		${PKG_DOC}/sendmail/;
	if [ -f ${BUILD_TREE}/sendmail/SECURITY ]; then \
		$(INSTALL_DATA) ${BUILD_TREE}/sendmail/SECURITY \
			${PKG_DOC}/sendmail/SECURITY; \
		fi;
	$(INSTALL_DATA) ${BUILD_TREE}/sendmail/TRACEFLAGS \
		${PKG_DOC}/sendmail/TRACEFLAGS;
	if [ -f ${BUILD_TREE}/sendmail/TUNING ]; then \
		$(INSTALL_DATA) ${BUILD_TREE}/sendmail/TUNING \
			${PKG_DOC}/sendmail/TUNING; \
		fi;
	sed -e "s?/usr/libexec?${libexecdir}?g" \
		-e "s?/usr/ucb/vacation?${libexecdir}/vacation.sendmail?g" \
		-e "s?/usr/adm/sm.bin?/etc/mail/smrsh?g" \
		${BUILD_TREE}/smrsh/README \
		> ${PKG_DOC}/smrsh.README;
	$(INSTALL_DATA) debian/faq.txt	${PKG_DOC}/;
ifeq (yes, ${ENABLE_DEV})
	# libmilter-dev package
	if [ -d ${BUILD_TREE}/libmilter ]; then \
		$(INSTALL_DATA) debian/README.Debian.libmilter-dev \
			${PKG_DOC}/libmilter/README.Debian; \
		$(INSTALL_DATA) ${BUILD_TREE}/libmilter/README \
			${PKG_DOC}/libmilter/README; \
		if [ -d  ${BUILD_TREE}/libmilter/docs ]; then \
			cp -a ${BUILD_TREE}/libmilter/docs/* \
				${PKG_DOC}/libmilter/html; \
			fi; \
		fi;
endif
	# Debian stuff
	(cd ${debian_dir}/cf && \
		$(MAKE) -f Makefile install-indep \
			DESTDIR="${top_srcdir}/sendmail-cf";);	
	(cd ${debian_dir}/examples && \
		$(MAKE) -f Makefile install-indep \
			DESTDIR="${top_srcdir}/sendmail-base";);
	(cd ${debian_dir}/local && \
		$(MAKE) -f Makefile install-indep \
			DESTDIR="${top_srcdir}/sendmail-base";);
	# Multiple package fixup
	#dh_movefiles -i --sourcedir debian/${package};
	# Actions from binary-common
	#
	dh_fixperms;
	#
	# Cleanup misc permissions, etc... (fakeroot, dh_fixperms, etc.)
	# Install Lintian overrides
	$(INSTALL_DATA) -g root -m 644 \
		debian/build/debian/sendmail-base.lintian-overrides \
		debian/sendmail-base/usr/share/lintian/overrides/sendmail-base;
endif
endif
	touch ${STAMP_DIR}/install-indep;


#-------------
.PHONY: install-arch
install-arch: ${STAMP_DIR}/install-arch
${STAMP_DIR}/install-arch: DH_OPTIONS=-a
${STAMP_DIR}/install-arch: ${STAMP_DIR}/build-arch
# Skip work if nothing to do...
ifeq (yes, ${ENABLE_ARCH})
	@dh_testdir;
	@dh_testroot;
	#dh_clean -k;
	dh_installdirs;
	if [ -x /usr/bin/dh_link ]; then dh_link; fi;
	# Add here commands to install the package into ${PKG_DIR}.
	#$(MAKE) prefix=`pwd`/${PKG_DIR}/usr install;
	# sendmail install proper... with a little help ;-}
	#$(MAKE) install DESTDIR="$${pwd}/${PKG_DIR}";
	# Finally, install the whole enchilada
ifeq (smX,${package})
else
	for subdir in ${SM_SUBDIRS}; do \
		if [ -d  ${BUILD_TREE}/$${subdir} ]; then \
			if [ "$${subdir}" = 'libmilter' ]; then \
				(cd ${BUILD_TREE}/obj*/$${subdir} && \
					$(INSTALL) libmilter.so.0 \
						../../../../debian/libmilter0/usr/lib/; \
				); \
			elif [ "$${subdir}" = 'mail.local' ]  \
			||	 [ "$${subdir}" = 'rmail' ]; then \
				(cd ${BUILD_TREE}/obj*/$${subdir} && \
					$(MAKE) force-install \
					DESTDIR="../../../../${PKG_DIR}";); \
			else \
				(cd ${BUILD_TREE}/obj*/$${subdir} && \
					$(MAKE) install \
					DESTDIR="../../../../${PKG_DIR}";); \
				fi; \
			fi; \
		done;
	# Support older Sendmail (below 8.10.0)
	if [ -f ${PKG_DIR}${sysconfdir}/mail/sendmail.hf ]; then \
		mv -f ${PKG_DIR}${sysconfdir}/mail/sendmail.hf \
			${PKG_DIR}${sysconfdir}/mail/helpfile; \
		$(RM) ${PKG_DIR}${localstatedir}/lib/sendmail/sendmail.st; \
		fi;
	# FHS says that rmail belongs in ${sbindir} - and we now put
	# it there, but in the rmail package !
	mv ${PKG_DIR}${libexecdir}/rmail ${debian_dir}/rmail/${sbindir}/;
	mv ${PKG_DIR}${mandir}/man8/rmail.8 ${debian_dir}/rmail/${mandir}/man8/;
	# Sendmail alias handling...
	# NOTE: whilst smptd is a valid alias for sendmail, we don't create
	# one so that we can co-exists with smtpd (a firewall frontend)
	# NOTE: newscache package also contains ${sbindir}/hoststat
	# NOTE: newalias, purgestat, etc. aren't for the general user..
	#		yeah, yeah, I know... these can be done with -b<flag>!
	(cd ${PKG_DIR}${bindir} && \
		$(RM) hoststat mailq newaliases purgestat smtpd;)
	(cd ${PKG_DIR}${sbindir} && for file in \
		newaliases hoststat purgestat \
		; do \
			ln -sf sendmail-mta $$file; \
			done;);
	# Handle man pages for these aliases
	mv ${PKG_DIR}${mandir}/man5/aliases.5 \
		${PKG_DIR}${mandir}/man5/aliases.sendmail.5;
	mv ${PKG_DIR}${mandir}/man1/mailq.1 \
		${PKG_DIR}${mandir}/man1/mailq.sendmail.1;
	mv ${PKG_DIR}${mandir}/man1/newaliases.1 \
		${PKG_DIR}${mandir}/man8/newaliases.sendmail.8;
	(cd ${PKG_DIR}${mandir}/man8 && for file in \
		hoststat.8.gz purgestat.8.gz \
		; do \
			ln -sf sendmail-mta.8.gz $$file; \
			done;);
	# Place those removed aliases in ${libexecdir} (mostly for me)
	(cd ${PKG_DIR}${libexecdir} && for file in \
		hoststat mailq newaliases purgestat smtpd; do \
		ln -sf sendmail $$file; \
		done;);
	# NOTE: with the MSP/MTA split, we'll provide our own mailstats (keep orig)
	ln -s ../share/sendmail/mailstats ${PKG_DIR}${sbindir}/mailstats;
	ln -s ../share/sendmail/mailq ${PKG_DIR}${bindir}/mailq;
	ln -s ../lib/sm.bin/editmap ${PKG_DIR}${sbindir}/editmap;
	ln -s ../lib/sm.bin/makemap ${PKG_DIR}${sbindir}/makemap;
	ln -s ../lib/sm.bin/praliases ${PKG_DIR}${sbindir}/praliases;
	# Special handling of vacation - Debian has a seperate package
	# with a different version (sigh) keep our copy just in case...
	if [ -d ${BUILD_TREE}/vacation ]; then \
		mv ${PKG_DIR}${libexecdir}/vacation \
			${PKG_DIR}${libexecdir}/vacation.sendmail; \
		mv ${PKG_DIR}${mandir}/man1/vacation.1 \
			${PKG_DIR}${mandir}/man1/vacation.sendmail.1; \
		fi;
	# Correct some paths in upstream man pages
	sed -e "s?/usr/adm/sm.bin?${sysconfdir}/mail/smrsh?g" \
		-e "s?sm.bin?${sysconfdir}/mail/smrsh?g" \
		${BUILD_TREE}/smrsh/smrsh.8 \
		> ${BUILD_TREE}/smrsh/smrsh.8.new;
	mv ${BUILD_TREE}/smrsh/smrsh.8.new ${BUILD_TREE}/smrsh/smrsh.8;
	sed -e "s?/etc/mail/statistics?${localstatedir}/lib/sendmail/sendmail.st?g"\
		${BUILD_TREE}/sendmail/sendmail.8 \
		> ${BUILD_TREE}/sendmail/sendmail.8.new;
	mv ${BUILD_TREE}/sendmail/sendmail.8.new \
		${PKG_DIR}${mandir}/man8/sendmail.sendmail.8;
	rm ${BUILD_TREE}/sendmail/sendmail.8;
	# Debian stuff
	(cd ${debian_dir}/sensible_mda && \
		$(MAKE) -f Makefile install-arch \
			DESTDIR="${top_srcdir}/sensible-mda";);
	# libmilter-dev package
ifeq (yes, ${ENABLE_DEV})
	if [ -d ${BUILD_TREE}/libmilter ]; then \
		(cd ${BUILD_TREE}/obj*/libmilter && \
			$(MAKE) install \
			DESTDIR="../../../../debian/libmilter-dev";); \
		$(INSTALL_PROGRAM) ${BUILD_TREE}/obj.*/libmilter/libmilter.a \
			debian/libmilter-dev${libdir}/libmilter/; \
		$(INSTALL_DATA) ${BUILD_TREE}/include/libmilter/mfapi.h \
			debian/libmilter-dev${includedir}/libmilter/; \
		if [ -f ${BUILD_TREE}/include/libmilter/mfdef.h ]; then \
			$(INSTALL_DATA) ${BUILD_TREE}/include/libmilter/mfdef.h \
				debian/libmilter-dev${includedir}/libmilter/; \
			fi; \
		$(INSTALL_PROGRAM) ${BUILD_TREE}/obj.*/libsmutil/libsmutil.a \
			debian/libmilter-dev${libdir}/libmilter/; \
		if [ -d ${BUILD_TREE}/libsm ]; then \
			$(INSTALL_PROGRAM) ${BUILD_TREE}/obj.*/libsm/libsm.a \
				debian/libmilter-dev${libdir}/libmilter/; \
			fi; \
		fi;
endif
	# Multiple package fixup
	#dh_movefiles -a --sourcedir debian/${package};
	#
	dh_fixperms;
	#
	# Cleanup misc permissions, etc... (fakeroot, dh_fixperms, etc.)
	#
	# You may want to make some executables suid here.
	chown root:mail	${PKG_DIR}${libexecdir}/sendmail;
	chmod 02755 ${PKG_DIR}${libexecdir}/sendmail;
	chown root:mail	${PKG_DIR}${libexecdir}/mailstats;
	chmod 02755 ${PKG_DIR}${libexecdir}/mailstats;
	chmod 04755 debian/sensible-mda/usr/sbin/sensible-mda;
	# Special case Perl for Debian Slink (2.1), debhelper v1
	if [ ! -x /usr/bin/dh_perl ]; then \
		echo 'perl:Depends=perl5|perl' >> debian/substvars; fi;
	# Install Lintian overrides
	$(INSTALL_DATA) -g root -m 644 \
		debian/build/debian/libmilter0.lintian-overrides \
		debian/libmilter0/usr/share/lintian/overrides/libmilter0;
ifeq (yes, ${ENABLE_DEV})
	$(INSTALL_DATA) -g root -m 644 \
		debian/build/debian/libmilter-dev.lintian-overrides \
		debian/libmilter-dev/usr/share/lintian/overrides/libmilter-dev;
endif
	$(INSTALL_DATA) -g root -m 644 \
		debian/build/debian/rmail.lintian-overrides \
		debian/rmail/usr/share/lintian/overrides/rmail;
	$(INSTALL_DATA) -g root -m 644 \
		debian/build/debian/sensible-mda.lintian-overrides \
		debian/sensible-mda/usr/share/lintian/overrides/sensible-mda;
	$(INSTALL_DATA) -g root -m 644 \
		debian/build/debian/sendmail-bin.lintian-overrides \
		debian/sendmail-bin/usr/share/lintian/overrides/sendmail-bin;
ifeq (, $(findstring nostrip,${DEB_BUILD_OPTIONS}))
	dh_strip --keep-debug;
endif
	# Remove unneeded debugging information
	rm -rf debian/sendmail-bin/usr/lib/debug;
	rm -rf debian/sensible-mda/usr/lib/debug;
	rm -rf debian/rmail/usr/lib/debug;
endif
	dh_makeshlibs; # -V "libmilter0 (>= ${version_major}.${version_minor})";
	dh_shlibdeps;
endif
	touch ${STAMP_DIR}/install-arch;


#-------------
# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
#
# Must not depend on anything. This is to be called by
# binary-arch/binary-indep in another 'make' thread.
.PHONY: binary-common
binary-common:
	@dh_testdir;
	@dh_testroot;
	# Document what we're building against
	if [ -x /usr/bin/dh_buildinfo ]; then \
		dh_buildinfo; \
		dh_installdocs; \
	else \
		$(MAKE) -f ${debian_dir}/rules buildinfo; \
		dh_installdocs -A ${debian_dir}/buildinfo; \
		fi;
	# Done in install-xxx, but still need to get rid of *.debhelper !!!
	#dh_clean -k;
	dh_installchangelogs -k ${BUILD_TREE}/RELEASE_NOTES;
	dh_installcron --name=${package};
	if [ -x /usr/bin/dh_installdebconf ]; then dh_installdebconf; fi;
	#dh_installemacsen;
	#dh_installexamples;
	#if [ -x /usr/bin/dh_installinfo ]; then dh_installinfo; fi;
	dh_installinit --name=${package} --update-rcd-params="defaults 21 19";
	if [ -x /usr/bin/dh_installlogrotate ]; then \
		dh_installlogrotate --name=${package}; fi;
	if [ -x /usr/bin/dh_installman ]; then dh_installman; fi;
	#dh_installmenu;
	#dh_installmime;
	#dh_undocumented;
	if [ -x /usr/bin/dh_installpam ]; then dh_installpam; fi;
	#dh_strip; #-- done in install-arch
	dh_compress;
	#dh_fixperms; #-- done in install-xxx
	# Need to special case this now that we're using dynamic uid/gid
	#if [ -x /usr/sbin/suidregister -a -s /etc/suid.conf ]; then
	#	dh_suidregister; fi;
	#
	# Cleanup misc permissions, etc... (fakeroot, dh_fixperms, etc.)
	# Done in install-xxx
	#
	# You may want to make some executables suid here.
	# Done in install-xxx
	#
	#dh_makeshlibs -V; #-- done in install-arch
	#dh_shlibdeps; #-- done in install-arch
	dh_installdeb;
	if [ -x /usr/bin/dh_perl ]; then dh_perl; fi
	dh_gencontrol;
	dh_md5sums;
	dh_builddeb;
	$(MAKE) -f ${debian_dir}/rules pristine;


#-------------
# Build architecture independant packages using the common target.
# (Uncomment this next line if you have such packages.)
.PHONY: binary-indep
binary-indep: ${STAMP_DIR}/build-indep ${STAMP_DIR}/install-indep

# Skip work if nothing to do...
ifeq (yes, ${ENABLE_INDEP})
	$(MAKE) -f ${debian_dir}/rules DH_OPTIONS=-i binary-common;
endif


#-------------
# Build architecture dependant packages using the common target.
.PHONY: binary-arch
binary-arch: ${STAMP_DIR}/build-arch ${STAMP_DIR}/install-arch

# Skip work if nothing to do...
ifeq (yes, ${ENABLE_ARCH})
	$(MAKE) -f ${debian_dir}/rules DH_OPTIONS=-a binary-common;
endif


#-------------
# Any other binary targets build just one binary package at a time.
.PHONY: binary-%
binary-%:
	$(MAKE) -f ${debian_dir}/rules binary-common DH_OPTIONS=-p$*;


#-------------
# Below here is fairly generic really

.PHONY: FORCE
FORCE: ;

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

# Due to buildd not (for the nonce) supporting build-arch, kluge next rules
# so that buildd ONLY build/install *-arch packages
.PHONY: build
build: build-arch
.PHONY: build-all
build-all: build-indep build-arch
.PHONY: check check-all
check: check-arch
check-all: check-arch
.PHONY: install
install: install-arch
.PHONY: binary
binary: binary-all
.PHONY: binary-all
binary-all: binary-indep binary-arch
.SUFFIXES:
.PRECIOUS: ${debian_dir}/rule