#!/usr/bin/make -f # -*- makefile -*- # # Robert Leslie # modified for Postfix by LaMont Jones # rewritten by Michael Tokarev export SHELL = /bin/sh -e export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=+lto future=+lfs # Extra hardening flags (level 3): # https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level # https://fedoraproject.org/wiki/Changes/Add_FORTIFY_SOURCE%3D3_to_distribution_build_flags export DEB_CPPFLAGS_MAINT_APPEND = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions include /usr/share/dpkg/architecture.mk include /usr/share/dpkg/buildflags.mk include /usr/share/dpkg/buildtools.mk # for ${CC} include /usr/share/dpkg/pkg-info.mk include /usr/share/dpkg/vendor.mk # list of packages we build (cache it to avoid extra execs) export POSTFIX_PACKAGES_2BUILD ?= $(shell dh_listpackages) package=postfix base=debian/${package} prvlibdir=/usr/lib/postfix daemondir=/usr/lib/postfix/sbin docdir=/usr/share/doc/${package} maps = cdb ldap lmdb mysql pcre pgsql sqlite # sed ERE for postfix-files to select files for the doc package docfiles-re = \$$(sample|readme|html)_directory # common defines CCARGS = \ -DDEBIAN \ -DMYORIGIN_FROM_FILE CONFARGS = \ CC="${CC}" \ DEBUG='' \ OPT="${CPPFLAGS} ${CFLAGS} ${LDFLAGS}" AUXLIBS = # shared libs and dynamic modules # can add SHLIB_CFLAGS SHLIB_SUFFIX CONFARGS += \ PLUGIN_LD="${CC} -shared ${LDFLAGS}" \ SHLIB_RPATH="-Wl,-rpath,${prvlibdir} ${LDFLAGS}" \ shlib_directory=${prvlibdir} \ shared=yes pie=yes dynamicmaps=yes # optional stuff CCARGS += \ -DHAS_PCRE=2 $(shell pcre2-config --cflags) \ -DHAS_LDAP \ -DUSE_LDAP_SASL \ -DHAS_SQLITE \ -DHAS_CDB \ -DHAS_LMDB \ -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 \ CONFARGS += \ AUXLIBS_CDB="-lcdb" \ AUXLIBS_LDAP="-lldap -llber" \ AUXLIBS_LMDB="-llmdb" \ AUXLIBS_MYSQL="-lmysqlclient" \ AUXLIBS_PCRE="$(shell pcre2-config --libs8)" \ AUXLIBS_PGSQL="-lpq" \ AUXLIBS_SQLITE="-lsqlite3" \ AUXLIBS += -lssl -lcrypto -lsasl2 -lpthread ifneq (,$(filter ${package}-mongodb,${POSTFIX_PACKAGES_2BUILD})) maps += mongodb CCARGS += -DHAS_MONGODB \ -I/usr/include/libmongoc-1.0 -I/usr/include/libbson-1.0 CONFARGS += AUXLIBS_MONGODB="-lmongoc-1.0 -lbson-1.0" endif %: dh $@ override_dh_auto_configure: ${MAKE} \ CCARGS="${CCARGS}" \ ${CONFARGS} \ AUXLIBS="${AUXLIBS}" \ daemon_directory=${daemondir} \ 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:@DEB_VENDOR@:${DEB_VENDOR}:g" < debian/main.cf.in > conf/main.cf.debian sed "s:@DEB_VENDOR@:${DEB_VENDOR}: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 "postfix-$$map\\.so" ${base}/etc/postfix/postfix-files > \ $$pkgdir/etc/postfix/postfix-files.d/$$map.files ; \ sed -i "/postfix-$$map\\.so/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 # debian-specific and extra addons install -m0644 debian/functions -T ${base}/usr/share/postfix/postinst.functions sed 's/@MULTIARCH@/${DEB_HOST_MULTIARCH}/' debian/configure-instance.in > \ ${base}${prvlibdir}/configure-instance.sh chmod 0755 ${base}${prvlibdir}/configure-instance.sh echo ${package}:Provides=default-mta \ >> debian/${package}.substvars 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 for file in \ /etc/ppp/ip-up.d/postfix /etc/ppp/ip-down.d/postfix \ /etc/network/if-up.d/postfix /etc/network/ip-down.d/postfix \ /etc/resolvconf/update-libc.d/postfix \ /usr/lib/networkd-dispatcher/routable.d/postfix \ /usr/lib/networkd-dispatcher/off.d/postfix \ /usr/lib/NetworkManager/dispatcher.d/postfix \ ; do \ install -m0755 debian/update-resolvconf -DT ${base}$$file; \ done $(if $(filter ${DEB_VENDOR},Ubuntu),\ install -m0644 debian/postfix.apport -DT ${base}/usr/share/apport/package-hooks/postfix.py) 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 install -m0755 debian/postfix-add-filter debian/postfix-add-policy -t ${base}/usr/sbin/ dh_installman -p ${package} debian/postfix-add-filter.8 debian/postfix-add-policy.8 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)/ clean: [ ! -f conf/makedefs.out ] || ${MAKE} tidy dh_clean conf/main.cf.debian conf/main.cf.dist # 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