summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: 930a22c7688f7be5d4e797f688fd62211f416538 (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
#!/usr/bin/make -f
# debian/rules for exim4
# This file is public domain software, originally written by Joey Hess.
#
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

buildname := $(shell scripts/os-type)-$(shell scripts/arch-type)
DEBIAN := $(shell pwd)/debian

export DEB_BUILD_MAINT_OPTIONS := hardening=+all
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk
# SOURCE_DATE_EPOCH is exported by pkg-info.mk since dpkg 1.18.8/July 2016
# fall back to current date otherwise.
SOURCE_DATE_EPOCH ?= $(shell date '+%s')


# The build system ignores CPPFLAGS, append them to CFLAGS
CFLAGS += $(shell getconf LFS_CFLAGS) -D_LARGEFILE_SOURCE \
	  -fno-strict-aliasing -Wall $(CPPFLAGS)
export CFLAGS
# LFLAGS is used where GNU would use LDFLAGS
export LFLAGS = $(LDFLAGS)

LC_ALL=C
export LC_ALL

# If you want to build a daemon with a configuration tailored to YOUR special
# needs, uncomment the exim4-daemon-custom package in debian/control,
# call "debian/rules unpack-configs", copy EDITME.exim4-light to
# EDITME.exim4-custom and modify it, then call "debian/rules pack-configs".
#
# Afterwards EITHER uncomment the customdaemon definition below, or set it
# to the desired value via the environment.
# e.g run:
# env customdaemon=exim4-daemon-custom dpkg-buildpackage -uc -us
#
# If you want to create multiple custom packages with different names, use
# the script debian/create-custom-package [suffix].

# customdaemon = exim4-daemon-custom
daemons = exim4-daemon-light exim4-daemon-heavy $(customdaemon)

# If you want to build with OpenSSL instead of GnuTLS, uncomment this
# OPENSSL:=1
# Please note that building exim4-daemon-heavy with OpenSSL is a GPL
# violation.

PROVIDE_DEFAULT_MTA := $(shell if dpkg-vendor --is Ubuntu || \
	dpkg-vendor --derives-from Ubuntu ; then : ; else \
	echo "default-mta" ; fi)
# for reproducible build. If set exim would use $TZ as default value for
# TIMEZONE_DEFAULT
undefine TZ
unexport TZ


unpack-configs: unpack-configs-stamp

unpack-configs-stamp: src/EDITME exim_monitor/EDITME
	patch -o EDITME.eximon exim_monitor/EDITME \
		$(DEBIAN)/EDITME.eximon.diff
	patch -o EDITME.exim4-light src/EDITME \
		$(DEBIAN)/EDITME.exim4-light.diff
ifdef OPENSSL
	patch EDITME.exim4-light $(DEBIAN)/EDITME.openssl.exim4-light.diff
endif
	for editme in $(DEBIAN)/EDITME.exim4-*.diff; do \
	  if [ "$$editme" != "$(DEBIAN)/EDITME.exim4-light.diff" ]; then \
	    TARGETNAME=`basename $$editme .diff`; \
	    echo patch -o $$TARGETNAME EDITME.exim4-light $$editme; \
	    patch -o $$TARGETNAME EDITME.exim4-light $$editme || \
	    exit $$? ;\
	  fi; \
	done
	touch unpack-configs-stamp

pack-configs:
	-diff -u src/EDITME EDITME.exim4-light \
		> $(DEBIAN)/EDITME.exim4-light.diff
	-for editme in EDITME.exim4-*; do \
	  if [ "$$editme" != "EDITME.exim4-light" ]; then \
	    echo diff -u EDITME.exim4-light $$editme; \
	    diff -u EDITME.exim4-light $$editme > $(DEBIAN)/$${editme}.diff; \
	  fi; \
	done
	-diff -u exim_monitor/EDITME EDITME.eximon \
		> $(DEBIAN)/EDITME.eximon.diff

bdir-stamp: unpack-configs-stamp
	for i in $(daemons) ; do \
		mkdir b-$$i && \
		find . -mindepth 1 -maxdepth 1 \
		-name debian -prune -o \
		-name 'b-*' -o -print0 | \
		xargs --no-run-if-empty --null \
		cp -a --target-directory=b-$$i ; \
	done
	touch $@

override_dh_auto_configure: unpack-configs-stamp bdir-stamp
	for i in $(daemons) ; do \
		mkdir -p b-$$i/Local && \
		cp EDITME.`echo $$i | sed -e s/exim4-daemon/exim4/` \
		b-$$i/Local/Makefile && \
		cp EDITME.eximon b-$$i/Local/eximon.conf ;\
		done

override_dh_auto_build:
	for i in $(daemons) ; do \
		echo building $$i; \
		cd $(CURDIR)/b-$$i && \
		$(MAKE) FULLECHO='' ; \
		done
	# Which version of Berkeley DB are we building against?
	printf '#include <db.h>\ninstdbversionis DB_VERSION_MAJOR DB_VERSION_MINOR\n' | \
		cpp -P | grep instdbversionis |\
		sed -e 's/[[:space:]]*instdbversionis[[:space:]]//' \
		-e 's/[[:space:]][[:space:]]*/./' \
		-e 's_^_s/^BDBVERSION=.*/BDBVERSION=_' \
		-e 's_$$_/_' \
		> $(DEBIAN)/berkeleydb.sed
	# Store Berkeley DB version in postinst script.
	sed -i -f $(DEBIAN)/berkeleydb.sed \
		$(DEBIAN)/exim4-base.postinst
	# symlink identical maintainerscripts
	for i in `echo $(daemons) | sed -e s/exim4-daemon-light//` ; do \
		ln -sfv exim4-daemon-light.prerm \
			"$(DEBIAN)/$$i.prerm" ; \
		ln -sfv exim4-daemon-light.postinst \
			"$(DEBIAN)/$$i.postinst" ; \
	done

override_dh_auto_install-arch: debian/README.Debian
	cd b-exim4-daemon-light && \
	  $(MAKE) install FULLECHO='' \
		INSTALL_ARG=-no_symlink \
		inst_conf=$(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf \
		inst_aliases=$(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/aliases \
		inst_dest=$(DEBIAN)/exim4-base/usr/sbin
	if [ -e "$(DEBIAN)/example.conf.md5" ] && [ "$$(< $(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf md5sum)" != "$$(cat $(DEBIAN)/example.conf.md5)" ] ; then \
	  echo "upstream example configuration has changed, new md5sum:"; \
	  < $(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf md5sum; \
	  echo "aborting build."; \
	  exit 1; \
	fi
	< $(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf md5sum > $(DEBIAN)/example.conf.md5
	sed -e 's,/[a-zA-Z/0-9.-]*exim4-base/examples/,/etc/,' \
		< $(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf \
		> $(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf.tmp
	mv $(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf.tmp \
		$(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples/example.conf
	install -m755 b-exim4-daemon-light/build-$(buildname)/convert4r4 \
		$(DEBIAN)/exim4-base/usr/sbin/exim_convert4r4
	install -m755 \
		b-exim4-daemon-light/build-$(buildname)/transport-filter.pl \
		b-exim4-daemon-light/util/ratelimit.pl \
		$(DEBIAN)/exim4-base/usr/share/doc/exim4-base/examples
	rm $(DEBIAN)/exim4-base/usr/sbin/exim
	mv $(DEBIAN)/exim4-base/usr/sbin/eximon \
		$(DEBIAN)/eximon4/usr/sbin
	mv $(DEBIAN)/exim4-base/usr/sbin/eximon.bin \
		$(DEBIAN)/eximon4/usr/lib/exim4
	pod2man --center=EXIM4 --section=8 \
		$(DEBIAN)/exim4-base/usr/sbin/exipick \
		$(DEBIAN)/exim4-base/usr/share/man/man8/exipick.8
	pod2man --center=EXIM4 --section=8 \
		$(DEBIAN)/exim4-base/usr/sbin/eximstats \
		$(DEBIAN)/exim4-base/usr/share/man/man8/eximstats.8
	install -m755 $(DEBIAN)/syslog2eximlog $(DEBIAN)/exim4-base/usr/sbin/
	pod2man --center=EXIM4 --section=8 \
		$(DEBIAN)/syslog2eximlog \
		$(DEBIAN)/exim4-base/usr/share/man/man8/syslog2eximlog.8
	for i in b-exim4-daemon-*/build-$(buildname)/exim ; do \
		install -m4755 -oroot -groot $$i \
		$(DEBIAN)/`echo $$i | sed -e 's/^b-//' -e 's_/.*__'`/usr/sbin/exim4 ; \
		done

override_dh_auto_install-indep: debian/README.Debian
	# if you change anything here, you will have to change
	# config-custom/debian/rules as well
	sed -e \
	"s/^UPEX4C_version=\"\"/UPEX4C_version=\"$(DEB_VERSION)\"/" \
	< $(DEBIAN)/debconf/update-exim4.conf \
	> $(DEBIAN)/exim4-config/usr/sbin/update-exim4.conf
	chmod 755 $(DEBIAN)/exim4-config/usr/sbin/update-exim4.conf
	install -m 755 $(DEBIAN)/update-exim4defaults \
		$(DEBIAN)/exim4-config/usr/sbin

	cd $(DEBIAN)/debconf/conf.d && \
		tar cf - `find \( -path '*/.svn/*' -prune \) -or \
		\( -type f -print \)` | \
		{ cd $(DEBIAN)/exim4-config/etc/exim4/conf.d/ && \
		tar xf - ; }

	install -m644 $(DEBIAN)/email-addresses $(DEBIAN)/exim4-config/etc/
	install -m640 -oroot -groot $(DEBIAN)/passwd.client \
		$(DEBIAN)/exim4-config/etc/exim4/
	chmod 755 $(DEBIAN)/debconf/update-exim4.conf.template
	env CONFDIR=$(DEBIAN)/debconf \
		$(DEBIAN)/debconf/update-exim4.conf.template --nobackup --run

# only called manually by maintainer before upload.
update-mtaconflicts:
	which grep-aptavail > /dev/null && \
		grep-aptavail --show-field=Package --field=Provides \
		mail-transport-agent --no-field-names \
		| grep -v exim | sort -u | \
		tr '\n' ',' | sed -e 's/,/, /g;s/, $$//' > $(DEBIAN)/mtalist

# Generate README.Debian as text/html ...
debian/README.Debian.html: debian/README.Debian.xml
	xsltproc --nonet --stringparam section.autolabel 1 \
		-o $@ \
		/usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl \
		$<
# ... and text/plain
debian/README.Debian: debian/README.Debian.html
	chmod 755 $(DEBIAN)/lynx-dump-postprocess
	lynx -force_html -dump $< | $(DEBIAN)/lynx-dump-postprocess > $@.tmp
	mv $@.tmp $@

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# it is not possible to run exim unless the compile-time specified
	# user exists.
	if id -u Debian-exim ; then \
		echo Debian-exim user found, running minimal testsuite ; \
		chmod +x debian/minimaltest ; \
		rm -rf $(CURDIR)/test ; \
		for i in b-exim4-daemon*/build-$(buildname)/exim ;\
			do mkdir $(CURDIR)/test && \
			debian/minimaltest $(CURDIR)/test $$i || \
			{ echo testsuite error  ; exit 1 ; } ; \
			rm -rf $(CURDIR)/test ; \
		done \
	fi
endif

override_dh_auto_clean:
	debconf-updatepo

	-rm -rf build-* doc/tmp test/ b-exim*
	-rm -f EDITME.* unpack-configs-stamp bdir-stamp
	-rm -f $(DEBIAN)/debconf/exim4.conf.template $(DEBIAN)/files \
		$(DEBIAN)/README.Debian $(DEBIAN)/README.Debian.html \
		$(DEBIAN)/berkeleydb.sed

	#these are identical for all daemon-* and therefore symlinked
	@cd $(DEBIAN) && find . -maxdepth 1 \
		-regex '^\./exim4-daemon-.*\.\(postinst\|prerm\)$$' \
		-and -not -name 'exim4-daemon-light.*' -delete
	#pwd
	chmod 755 $(DEBIAN)/exim-gencert \
		$(DEBIAN)/lynx-dump-postprocess $(DEBIAN)/script \
		$(DEBIAN)/exim-adduser $(DEBIAN)/exim4_refresh_gnutls-params

override_dh_installchangelogs:
	dh_installchangelogs -pexim4-base doc/ChangeLog
	dh_installchangelogs --no-package=exim4-base \
		-XCHANGES -Xdoc/ChangeLog

override_dh_installppp:
	dh_installppp --name=exim4

override_dh_fixperms:
	dh_fixperms -X/etc/exim4/passwd.client -Xusr/sbin/exim4

override_dh_gencontrol:
	dh_gencontrol -- \
		-VUpstream-Version=$(DEB_VERSION_EPOCH_UPSTREAM) \
		-VMTA-Conflicts="$(shell cat $(DEBIAN)/mtalist)" \
		-Vdist:Provides:exim4-daemon-light="$(PROVIDE_DEFAULT_MTA)"

override_dh_installlogrotate:
	dh_installlogrotate
	dh_installlogrotate --name=exim4-paniclog

override_dh_installinit:
	dh_installinit --noscripts --name=exim4

override_dh_install:
	# install config.h from daemon package, but not from exim4-daemon-light
	dh_install -p exim4-dev \
		$(shell ls -1 b-exim4-daemon-*/build-$(buildname)/config.h | grep -v ^b-exim4-daemon-light/) \
		usr/include/exim4
	dh_install

override_dh_link:
	rm -rf debian/exim4/usr/share/doc/exim4
	dh_link

%:
	dh $@ --no-parallel

.PHONY: pack-configs unpack-configs update-mtaconflicts