summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: 80c87e8d9b6f8d0555f24693195a0954951792d0 (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
#!/usr/bin/make -f

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

SHELL=/bin/bash -O extglob
PIGEONHOLE_DIR=$(CURDIR)/pigeonhole

export DEB_BUILD_MAINT_OPTIONS=hardening=+all optimize=+lto

# LP: 1636781 - strip incompatible default linker option
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
  export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions
endif

DOV_DEB_CFLAGS=
DOV_DEB_CXXFLAGS=
DOV_DEB_LDFLAGS=

# Ensure that stacktrace generation works:
DOV_DEB_LDFLAGS += -rdynamic
include /usr/share/dpkg/architecture.mk
ifneq ($(filter armel armhf hppa mips64el mipsel riscv64 sparc64, $(DEB_HOST_ARCH)),)
  DOV_DEB_CFLAGS += -funwind-tables
  DOV_DEB_CXXFLAGS += -funwind-tables
endif

# Extra hardening flags
DOV_DEB_CFLAGS += -fstack-clash-protection
DOV_DEB_CXXFLAGS += -fstack-clash-protection
DOV_DEB_LDFLAGS += -fstack-clash-protection


export DEB_CFLAGS_MAINT_APPEND = $(DOV_DEB_CFLAGS)
export DEB_CXXFLAGS_MAINT_APPEND = $(DOV_DEB_CXXFLAGS)
export DEB_LDFLAGS_MAINT_APPEND = $(DOV_DEB_LDFLAGS)


ifeq ($(DEB_HOST_ARCH_OS),linux)
  CONFIGURE_APPARMOR = --with-apparmor
endif

# Macros to help move files to the module packages
CORE_DIR=$(CURDIR)/debian/dovecot-core
PKG_DIR=$(CURDIR)/debian/dovecot-PKG
MOVE=install -d $(PKG_DIR:PKG=$(2))/$(dir $(1)); mv $(CORE_DIR)/$(1) $(PKG_DIR:PKG=$(2))/$(dir $(1));

# Files to move from dovecot-core to the individual packages. Files added to
# <addon>_files will be automatically moved from dovecot's tree to the
# respective package.
auth-lua_files = usr/lib/dovecot/modules/auth/libauthdb_lua.so

imapd_files = usr/lib/dovecot/imap* \
	      usr/lib/dovecot/modules/lib??_imap_!(*sieve*) \
	      usr/share/dovecot/conf.d/??-imap*

pop3d_files = usr/lib/dovecot/pop3* \
	      usr/share/dovecot/conf.d/??-pop3*

lmtpd_files = usr/lib/dovecot/lmtp* \
	      usr/share/dovecot/conf.d/??-lmtp*

managesieved_files = usr/lib/dovecot/managesieve* \
		     usr/lib/dovecot/modules/settings/libmanagesieve*

submissiond_files = usr/lib/dovecot/submission* \
	           usr/share/dovecot/conf.d/??-submission.conf

pgsql_files = usr/lib/dovecot/modules/auth/libdriver_pgsql* \
	      usr/lib/dovecot/modules/dict/libdriver_pgsql* \
	      usr/lib/dovecot/modules/libdriver_pgsql*

mysql_files = usr/lib/dovecot/modules/auth/libdriver_mysql* \
	      usr/lib/dovecot/modules/dict/libdriver_mysql* \
	      usr/lib/dovecot/modules/libdriver_mysql*

sqlite_files = usr/lib/dovecot/modules/auth/libdriver_sqlite* \
	       usr/lib/dovecot/modules/dict/libdriver_sqlite* \
	       usr/lib/dovecot/modules/libdriver_sqlite*

gssapi_files = usr/lib/dovecot/modules/auth/libmech_gssapi*

ldap_files = usr/lib/dovecot/modules/auth/libauthdb_ldap* \
	     usr/lib/dovecot/modules/dict/libdict_ldap* \
	     usr/lib/dovecot/libdovecot-ldap* \
	     usr/share/dovecot/*-ldap.conf.ext \
	     usr/share/dovecot/conf.d/*-ldap.conf.ext

sieve_files = usr/bin/sieve* \
	      usr/lib/dovecot/modules/lib??_sieve* \
	      usr/lib/dovecot/modules/lib??_imap_*sieve* \
	      usr/lib/dovecot/modules/doveadm/lib??_doveadm_sieve* \
	      usr/lib/dovecot/modules/sieve \
	      usr/lib/dovecot/libdovecot-sieve* \
	      usr/share/man/man1/sieve*

solr_files = usr/lib/dovecot/modules/lib??_fts_solr_*

dev_files = usr/include/* \
	    usr/lib/dovecot/dovecot-config \
	    usr/share/aclocal/*.m4

%:
	dh $@

override_dh_autoreconf:
	dh_autoreconf debian/autogen.sh

override_dh_auto_configure:
	KRB5CONFIG=krb5-config.mit systemdsystemunitdir=/lib/systemd/system dh_auto_configure -- \
	            --with-ldap=plugin \
	            --with-ssl=openssl \
	            --with-sql=plugin \
	            --with-pgsql \
	            --with-mysql \
	            --with-sqlite \
	            --with-gssapi=plugin \
	            --with-solr \
	            --with-ioloop=best \
		    --with-icu \
	            --with-libwrap \
	            --without-lucene \
		    $(CONFIGURE_APPARMOR) \
		    --with-lz4 \
		    --with-lua=plugin \
		    --with-sodium \
		    --libdir=\$${prefix}/lib \
	            --libexecdir=\$${prefix}/lib \
		    --docdir=\$${prefix}/share/doc/dovecot-core \
	            --with-moduledir=\$${prefix}/lib/dovecot/modules \
		    --with-rundir=/run/dovecot \
	            --disable-rpath \
	            --disable-static
	
	$(MAKE) dovecot-config
	# remove unreproducible '-ffile-prefix-map=/build/1st/dovecot-2.3.10.1+dfsg1=.'
	#                       '-fdebug-prefix-map=/build/dovecot-O55xqn/dovecot-2.3.10.1+dfsg1=.'
	sed -i 's/\s\+-ffile-prefix-map=\S\+=.\s\+/ /g' dovecot-config
	sed -i 's/\s\+-fdebug-prefix-map=\S\+=.\s\+/ /g' dovecot-config
	
	# Pigeonhole
	touch $(PIGEONHOLE_DIR)/stamp.h.in
	dh_auto_configure -D $(PIGEONHOLE_DIR) -- \
	        --with-dovecot=../ \
	        --libdir=\$${prefix}/lib \
		--libexecdir=\$${prefix}/lib \
		--disable-static

override_dh_auto_build:
	# Remove all-settings.c and let it be re-generated from the (patched)
	# component settings files.
	rm -f src/config/all-settings.c
	dh_auto_build
	dh_auto_build -D $(PIGEONHOLE_DIR)

override_dh_auto_clean:
	dh_auto_clean
	dh_auto_clean -D $(PIGEONHOLE_DIR)

override_dh_auto_install:
	# Install everything under dovecot-core
	$(MAKE) install DESTDIR=$(CORE_DIR)
	$(MAKE) -C $(PIGEONHOLE_DIR) install DESTDIR=$(CORE_DIR)
	rm `find $(CURDIR)/debian -name '*.la'`
	rm $(CORE_DIR)/etc/dovecot/README
	rm $(CORE_DIR)/usr/lib/dovecot/decode2text.sh

override_dh_install:
	# dh_auto_install has installed everything in the dovecot-core package.
	# Run dh_install to install additional files from the source directory
	# or debian/ to the individual packages. NOTE: there is nothing in
	# debian/tmp!
	dh_install
	install -D -o root -g root -m 0755 $(CORE_DIR)/usr/share/doc/dovecot-core/mkcert.sh \
		$(CORE_DIR)/usr/share/dovecot/mkcert.sh
	rm $(CORE_DIR)/usr/share/doc/dovecot-core/mkcert.sh
	rm $(CORE_DIR)/usr/share/doc/dovecot-core/dovecot-openssl.cnf
	rm $(CORE_DIR)/usr/share/doc/dovecot-core/solr-schema.xml
	rm -rf $(CORE_DIR)/usr/share/doc/dovecot-core/example-config
	
	$(foreach package,$(patsubst dovecot-%,%,$(shell dh_listpackages)),\
		$(foreach file,$($(package)_files),\
			$(call MOVE,$(file),$(package))))
	
	rmdir $(CORE_DIR)/usr/include
	rmdir $(CORE_DIR)/usr/share/aclocal
	install -d $(PKG_DIR:PKG=dev)/usr/share/dovecot
	grep ABI_VERSION config.h \
		| perl -ne '/"(.+)\(.+\)"/ && print $$1' \
		| tr '[A-Z]' '[a-z]' > $(PKG_DIR:PKG=dev)/usr/share/dovecot/dovecot-abi
	
	# Install apport hook
	install -D -m 644 debian/source_dovecot.py $(CURDIR)/debian/dovecot-core/usr/share/apport/package-hooks/dovecot-core.py

	install -D -m644 debian/dovecot-imapd.ufw.profile debian/dovecot-imapd/etc/ufw/applications.d/dovecot-imapd
	install -D -m644 debian/dovecot-pop3d.ufw.profile debian/dovecot-pop3d/etc/ufw/applications.d/dovecot-pop3d

override_dh_installpam:
	dh_installpam -pdovecot-core --name=dovecot

override_dh_installinit:
	dh_installinit -pdovecot-core --name=dovecot -u"defaults 20"

override_dh_installsystemd:
	dh_installsystemd -pdovecot-core dovecot.service
	dh_installsystemd -pdovecot-core --no-enable dovecot.socket

override_dh_gencontrol:
	dh_gencontrol -- -Vdovecot:ABI-Version=$(shell cat $(CURDIR)/debian/dovecot-dev/usr/share/dovecot/dovecot-abi)

override_dh_makeshlibs:
	# Do not add an ldconfig trigger; none of the dovecot shared libraries
	# are public.
	dh_makeshlibs -n

override_dh_installdocs:
	dh_installdocs
	cp pigeonhole/README	$(CORE_DIR)/usr/share/doc/dovecot-core/pigeonhole.README
	cp pigeonhole/NEWS	$(CORE_DIR)/usr/share/doc/dovecot-core/pigeonhole.NEWS