summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: 1b811aec519f9b7d472a77d23b286d727e8bac70 (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
#!/usr/bin/make -f
# -*- makefile -*-
#
# Robert Leslie <rob@mars.org>
# modified for Postfix by LaMont Jones <lamont@debian.org>
# rewritten by Michael Tokarev <mjt@tls.msk.ru>

export SHELL = /bin/sh -e

DISTRO:=$(shell (lsb_release -is 2>/dev/null || echo Debian) | sed s:Debian:Debian/GNU:)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=+lto
export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/buildtools.mk  # for ${CC}
include /usr/share/dpkg/pkg-info.mk

package=postfix
base=debian/${package}
prvlibdir=/usr/lib/postfix
daemondir=/usr/lib/postfix/sbin
docdir=/usr/share/doc/${package}
maps = cdb ldap lmdb mongodb mysql pcre pgsql sqlite

# sed ERE for postfix-files to select files for the doc package
docfiles-re = \$$(sample|readme|html)_directory

CCARGS += -DDEBIAN \
	-DHAS_PCRE=2 $(shell pcre2-config --cflags) \
	-DHAS_LDAP \
	-DUSE_LDAP_SASL \
	-DHAS_SQLITE \
	-DMYORIGIN_FROM_FILE \
	$(shell getconf LFS_CFLAGS) \
	-DHAS_CDB \
	-DHAS_LMDB \
	-DHAS_MONGODB -I/usr/include/libmongoc-1.0 -I/usr/include/libbson-1.0 \
	-DHAS_MYSQL -I/usr/include/mysql \
	-DHAS_PGSQL -I$(shell pg_config --includedir) \
	-DHAS_SQLITE \
	-DHAS_SSL -I/usr/include/openssl \
	-DUSE_SASL_AUTH -I/usr/include/sasl \
	-DUSE_CYRUS_SASL \
	-DUSE_TLS

AUXLIBS += -lssl -lcrypto -lsasl2 -lpthread

# Extra hardening flags
export DEB_CPPFLAGS_MAINT_APPEND = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3


%:
	dh $@


override_dh_auto_configure:
	touch .makefiles-made
	${MAKE} \
		CCARGS="${CCARGS}" \
		DEBUG='' \
		OPT="${CPPFLAGS} ${CFLAGS} ${LDFLAGS}" \
		PLUGIN_LD="${CC} -shared ${CPPFLAGS} ${CFLAGS} ${LDFLAGS}" \
		AUXLIBS="${AUXLIBS}" \
		AUXLIBS_CDB="-lcdb" \
		AUXLIBS_LDAP="-lldap -llber" \
		AUXLIBS_LMDB="-llmdb" \
		AUXLIBS_MONGODB="-lmongoc-1.0 -lbson-1.0" \
		AUXLIBS_MYSQL="-lmysqlclient" \
		AUXLIBS_PCRE="$(shell pcre2-config --libs8)" \
		AUXLIBS_PGSQL="-lpq" \
		AUXLIBS_SQLITE="-lsqlite3" \
		SHLIB_RPATH="-Wl,-rpath,${prvlibdir} ${LDFLAGS}" \
		shared=yes pie=yes dynamicmaps=yes \
		daemon_directory=${daemondir} \
		shlib_directory=${prvlibdir} \
		manpage_directory=/usr/share/man \
		readme_directory=${docdir} \
		html_directory=${docdir}/html \
	    makefiles

override_dh_auto_build-arch:
	@echo "blhc: ignore-line-regexp: .*for i in single_server\.o multi_server\.o trigger_server\.o master_proto\.o mail_flow\.o event_server\.o dgram_server\.o"

	dh_auto_build -a

	# remove unreproducible paths from makedefs.out
	#  '-ffile-prefix-map=/tmp/reprotest.DMXrtR/const_build_path/const_build_path=.'
	#  'SHLIB_ENV = LD_LIBRARY_PATH=/tmp/reprotest.DMXrtR/const_build_path/const_build_path/lib'
	sed -i 's@\s\+-ffile-prefix-map=\S\+=.\s\+@ @g' conf/makedefs.out
	sed -i 's@SHLIB_ENV = LD_LIBRARY_PATH=\S\+@SHLIB_ENV = /debian-build-path/lib@g' conf/makedefs.out

	sed "s:@@DISTRO@@:$(DISTRO):g" < debian/main.cf.in > conf/main.cf.debian
	sed "s:@@DISTRO@@:$(DISTRO):g" < conf/main.cf > conf/main.cf.dist


override_dh_auto_build-indep:
# man/Makefile.in does not support parallel builds
# on debian we can not create the same contents of the docs,
# since html2text on debian has -nobs forcibly enabled
	${MAKE} -j1 manpages meta/postfix-files

override_dh_auto_install:
# do nothing

override_dh_install-indep:
# note: actual docs goes to postfix package doc dir instead of postix-doc
# (dh_installdocs & dh_installexamples etc does magic on this)
	cp -p AAAREADME meta/README # rename
	dh_installdocs -p ${package}-doc \
		-XULTRIX_README -XMakefile \
		meta/README \
		RELEASE_NOTES-* \
		README_FILES/*_README \
		README_FILES/OVERVIEW \
		COMPATIBILITY \
		PORTING \
		html
	dh_installexamples -p ${package}-doc examples/qmail-local examples/smtpd-policy
	dh_installexamples -p ${package}-doc -Xmain.cf -Xmaster.cf -Xbounce.cf -Xfiles conf/[a-z]*
	dh_installexamples -p ${package}-doc debian/mailqfmt.pl
# instead of grepping postfix-files, we can just create our own listing
# based on what we actually installed, with all renames and other stuff
	sed -nr -e '/ULTRIX|MACOSX|mantools/D' \
	        -e '/${docfiles-re}/p' \
		meta/postfix-files > meta/doc.files
	install -m0644 meta/doc.files -Dt ${base}-doc/etc/postfix/postfix-files.d/


override_dh_install-arch:
# base dirs
	dh_installdirs -p ${package} \
		etc/postfix \
		var/lib/postfix \
		var/spool/postfix \
		usr/sbin usr/bin \
		usr/share/postfix \
		${prvlibdir} \
		${daemondir} \
		etc/postfix/dynamicmaps.cf.d \
		etc/postfix/postfix-files.d \
		etc/postfix/sasl
# main binaries and libs:
	install -m0755 libexec/[a-z]* -t ${base}${daemondir}/
#   these 2 are hard links (see conf/postfix-files):
	ln ${base}${daemondir}/smtp ${base}${daemondir}/lmtp
	ln ${base}${daemondir}/qmgr ${base}${daemondir}/nqmgr
	install -m0755 bin/[a-z]* -t ${base}/usr/sbin/
	install -m0755 lib/libpostfix-*.so -t ${base}${prvlibdir}/
# additional links
	dh_link -p ${package} \
		usr/sbin/sendmail usr/bin/newaliases \
		usr/sbin/sendmail usr/bin/mailq \
		usr/sbin/sendmail usr/lib/sendmail \
		usr/sbin/rmail usr/bin/rmail
# configs etc
	install -m0644 \
		conf/makedefs.out \
		conf/main.cf.dist \
		conf/main.cf.debian \
		debian/main.cf.tls \
		meta/dynamicmaps.cf \
		-t ${base}/usr/share/postfix/
	install -m0644 conf/master.cf \
		-T ${base}/usr/share/postfix/master.cf.dist
	install -m0644 meta/postfix-files -Dt ${base}/etc/postfix/
	sed -i -r '/(${docfiles-re})|LICENSE:/D' \
		${base}/etc/postfix/postfix-files
# manpages
	dh_installman -p ${package} \
		man/man1/*.1 man/man5/*.5 rmail/rmail.8
	for f in man/man8/*.8; do \
	  sed '/^\.TH/s/ 8 / 8postfix /' $$f > ${base}/usr/share/$${f}postfix; \
	done
	sed -i s'@.so man8/bounce.8@.so man8/bounce.8postfix@' \
		${base}/usr/share/man/man8/trace.8postfix \
		${base}/usr/share/man/man8/defer.8postfix
# docs
	dh_installdocs -p ${package} RELEASE_NOTES
	dh_installchangelogs -p ${package} HISTORY
# dynamic maps
	for map in ${maps} ; do \
		pkgdir=${base}-$$map; \
		install lib/postfix-$$map.so -D -t $$pkgdir${prvlibdir}/ ; \
		mkdir -p $$pkgdir/etc/postfix/postfix-files.d ; \
		grep -E "\\b$$map[._]" ${base}/etc/postfix/postfix-files > \
			$$pkgdir/etc/postfix/postfix-files.d/$$map.files ; \
		sed -i "/\\b$$map[._]/D" ${base}/etc/postfix/postfix-files ; \
		{ echo '. /usr/share/postfix/postinst.functions' ; \
		  echo "[ configure != \"\$$1\" ] || addmap \"$$map\"" ; \
		} > debian/postfix-$$map.postinst.debhelper ; \
		{ echo '. /usr/share/postfix/postinst.functions' ; \
		  echo "[ remove != \"\$$1\" -a purge != \"\$$1\" ] || delmap \"$$map\"" ; \
		} > debian/postfix-$$map.prerm.debhelper ; \
	done
# manpages for dynamic maps (there's no cdb_table manpage)
	for map in $(filter-out cdb, ${maps}); do \
		pkgdir=${base}-$$map; \
		mkdir -m755 -p $$pkgdir/usr/share/man/man5 ; \
		mv ${base}/usr/share/man/man5/$${map}_table.5 \
			$$pkgdir/usr/share/man/man5 ; \
	done
# debian-specific and extra addons
	install -m0644 debian/functions -T ${base}/usr/share/postfix/postinst.functions
	install -m0755 debian/configure-instance.sh -t ${base}${prvlibdir}/
	install -m0755 \
		debian/postfix-add-filter \
		debian/postfix-add-policy \
		-t ${base}/usr/sbin/
	install -m0755 auxiliary/collate/collate.pl -T ${base}/usr/sbin/postfix-collate
	txt2man -t postfix-collate -r postfix-$(DEB_VERSION_UPSTREAM) \
		-d '$(shell date -d @$(SOURCE_DATE_EPOCH))' -s 1 \
		auxiliary/collate/README \
		> ${base}/usr/share/man/man1/postfix-collate.1
	install -m0755 auxiliary/qshape/qshape.pl -T ${base}/usr/sbin/qshape
	dh_installman -p ${package} debian/*.8
	install -m0644 debian/postfix.ufw.profile -DT ${base}/etc/ufw/applications.d/postfix
	install -m0644 debian/rsyslog.conf -DT ${base}/etc/rsyslog.d/postfix.conf
	install -m0644 debian/postfix.insserv.conf -DT ${base}/etc/insserv.conf.d/postfix
	install -m0755 debian/ip-up.d   -DT ${base}/etc/ppp/ip-up.d/postfix
	install -m0755 debian/ip-down.d -DT ${base}/etc/ppp/ip-down.d/postfix
	install -m0755 debian/ip-up.d   -DT ${base}/etc/network/if-up.d/postfix
	install -m0755 debian/ip-down.d -DT ${base}/etc/network/if-down.d/postfix
	install -m0755 debian/ip-up.d   -DT ${base}/usr/lib/networkd-dispatcher/routable.d/postfix
	install -m0755 debian/ip-down.d -DT ${base}/usr/lib/networkd-dispatcher/off.d/postfix
	install -m0755 debian/update-libc.d -DT ${base}/etc/resolvconf/update-libc.d/postfix
	if dpkg-vendor --is ubuntu; then \
	    install -m0644 debian/postfix.apport -DT ${base}/usr/share/apport/package-hooks/postfix.py; \
	fi
	install -m0755 debian/postfix_groups.pl -t ${base}${prvlibdir}/

override_dh_installsystemd:
	dh_installsystemd -p ${package} --no-enable --no-start --name postfix-resolvconf
	dh_installsystemd -p ${package} --no-restart-after-upgrade postfix.service
	install -m0755 debian/postfix-instance-generator \
		-Dt ${base}/$(shell pkg-config --variable=systemdsystemgeneratordir systemd)/

execute_before_dh_gencontrol:
	for i in $$(dh_listpackages) ; do \
		cat debian/vars.in >> debian/$$i.substvars ; \
	done
	echo ${package}:Provides=default-mta \
		>> debian/${package}.substvars


override_dh_auto_clean:
	[ ! -f .makefiles-made ] || ${MAKE} tidy
	rm -f .makefiles-made

# Below here is fairly generic really

newtemplate:
	debconf-updatepo

msgstats:
	@cd debian/po && for i in *.po; do x=$$(msgfmt --statistics $$i 2>&1); echo $$i $$x; done; rm -f messages.mo *.po~

msg-email:
	@podebconf-report-po