Merge pull request #4853 from StevenHessing/noddos
[feed/packages.git] / mail / postfix / Makefile
1 #
2 # Copyright (C) 2014-2015 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 include $(TOPDIR)/rules.mk
9
10 PKG_NAME:=postfix
11 PKG_RELEASE:=3
12 PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
13 PKG_VERSION:=3.2.2
14 PKG_HASH:=d06849418d119d09366997b2b481bb23f737629769b4e4a52da42fb3ad8b0576
15 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
16 PKG_MAINTAINER:=Denis Shulyaka <Shulyaka@gmail.com>
17 PKG_LICENSE:=IPL-1.0
18 PKG_LICENSE_FILES:=LICENSE
19 PKG_BUILD_DEPENDS:=+POSTFIX_CDB:tinycdb
20 PKG_CONFIG_DEPENDS:= \
21 CONFIG_POSTFIX_TLS \
22 CONFIG_POSTFIX_SASL \
23 CONFIG_POSTFIX_LDAP \
24 CONFIG_POSTFIX_CDB \
25 CONFIG_POSTFIX_DB \
26 CONFIG_POSTFIX_SQLITE \
27 CONFIG_POSTFIX_PGSQL \
28 CONFIG_POSTFIX_PCRE \
29 CONFIG_POSTFIX_EAI \
30
31 include $(INCLUDE_DIR)/package.mk
32
33 define Package/postfix
34 SECTION:=mail
35 CATEGORY:=Mail
36 TITLE:=Postfix Mail Transmit Agent
37 URL:=http://www.postfix.org/
38 DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_SQLITE:libsqlite3 +POSTFIX_PGSQL:libpq +POSTFIX_EAI:icu +POSTFIX_PCRE:libpcre
39 endef
40
41 define Package/postfix/description
42 Postfix is Wietse Venema's mailer that started life as an alternative to the widely-used Sendmail program. Postfix attempts to be fast, easy to administer, and secure, while at the same time being sendmail compatible enough to not upset existing users. Thus, the outside has a sendmail-ish flavor, but the inside is completely different.
43 endef
44
45 define Package/postfix/config
46 menu "Select postfix build options"
47 config POSTFIX_TLS
48 bool "TLS support"
49 default y
50 help
51 Implements TLS support in postfix (using OpenSSL).
52 config POSTFIX_SASL
53 bool "SASL support"
54 default y
55 help
56 Implements SASL support in postfix (using Cyrus SASL).
57 config POSTFIX_LDAP
58 bool "LDAP support"
59 default y
60 help
61 Implements LDAP support in postfix (using OpenLDAP).
62 config POSTFIX_DB
63 bool "BerkeleyDB support"
64 default n
65 help
66 Implements support for btree files using Berkeley DB. Note that hash files support is not compiled into Berkeley DB OpenWRT distribution
67 config POSTFIX_CDB
68 bool "CDB support"
69 default y
70 help
71 Implements support for cdb files using tinycdb
72 config POSTFIX_SQLITE
73 bool "SQLITE support"
74 default y
75 help
76 Implements support for SQLite3 DB
77 config POSTFIX_PGSQL
78 bool "PostgreSQL support"
79 default n
80 help
81 Implement support for PostgreSQL
82 config POSTFIX_PCRE
83 bool "PCRE support"
84 default n
85 help
86 Implement support for Perl Compatible Regular Expressions
87 config POSTFIX_EAI
88 bool "SMTPUTF8 support"
89 default n
90 help
91 Enable Postfix support for Email Address Internationalization
92 (EAI) as defined in RFC 6531 (SMTPUTF8 extension), RFC 6532
93 (Internationalized email headers) and RFC 6533
94 (Internationalized delivery status notifications).
95 Since version 3.0, Postfix fully supports UTF-8 email
96 addresses and UTF-8 message header values.
97 endmenu
98 endef
99
100 CCARGS=-DNO_NIS
101 AUXLIBS=-L$(STAGING_DIR)/usr/lib
102 default_database_type=cdb
103
104 ifdef CONFIG_POSTFIX_TLS
105 CCARGS+=-DUSE_TLS
106 AUXLIBS+=-lssl -lcrypto
107 endif
108
109 ifdef CONFIG_POSTFIX_SASL
110 CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
111 AUXLIBS+=-lsasl2
112 endif
113
114 ifdef CONFIG_POSTFIX_LDAP
115 CCARGS+=-DHAS_LDAP
116 AUXLIBS+=-lldap -llber
117 endif
118
119 ifdef CONFIG_POSTFIX_CDB
120 CCARGS+=-DHAS_CDB
121 AUXLIBS+=-lcdb
122 endif
123
124 ifdef CONFIG_POSTFIX_DB
125 AUXLIBS+=-ldb
126 CCARGS+=-DHAS_DB
127 ifndef CONFIG_POSTFIX_CDB
128 default_database_type=btree
129 endif
130 else
131 CCARGS+=-DNO_DB
132 endif
133
134 ifdef CONFIG_POSTFIX_SQLITE
135 CCARGS+=-DHAS_SQLITE -I$(STAGING_DIR)/usr/include/
136 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lsqlite3 -lpthread
137 endif
138
139 ifdef CONFIG_POSTFIX_PGSQL
140 CCARGS+=-DHAS_PGSQL -I$(STAGING_DIR)/usr/include/
141 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lpq
142 endif
143
144 ifdef CONFIG_POSTFIX_PCRE
145 CCARGS+=-DHAS_PCRE -I$(STAGING_DIR)/usr/include/
146 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lpcre
147 else
148 CCARGS+=-DNO_PCRE
149 endif
150
151 ifdef CONFIG_POSTFIX_EAI
152 AUXLIBS+=-licuuc
153 CCARGS+=-DHAS_EAI
154 smtputf8_conf = yes
155 else
156 CCARGS+=-DNO_EAI
157 smtputf8_conf = no
158 endif
159
160 CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
161
162 config_directory=/etc/postfix# also add this to postfix init file
163 sample_directory=/etc/postfix
164 command_directory=/usr/sbin
165 daemon_directory=/usr/libexec/postfix
166 data_directory=/usr/var/lib/postfix
167 queue_directory=/usr/var/spool/postfix
168 mail_spool_directory=/usr/var/mail
169 html_directory=no
170 manpage_directory=no
171 readme_directory=no
172 sendmail_path=/usr/sbin/sendmail
173 newaliases_path=/usr/bin/newaliases
174 mailq_path=/usr/bin/mailq
175 shlib_directory=/usr/lib/postfix
176 meta_directory=/etc/postfix
177
178 ln_suffix=.postfix
179 ln_old_suffix=.old
180
181 define Package/postfix/conffiles
182 $(config_directory)/main.cf
183 $(config_directory)/master.cf
184 $(config_directory)/aliases
185 $(config_directory)/virtual
186 endef
187
188 define Build/Configure
189 if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
190 echo "Build error: You must select at least one of the DB types";\
191 exit 1;\
192 fi
193
194 cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
195 endef
196
197 # Steps to regenerate files/main.cf.default:
198 #
199 # 1. Compile the package with current file
200 # 2. Execute the following command on target device:
201 # postconf -d > /tmp/main.cf.new
202 # 3. Transfer /tmp/main.cf.new file to the build system
203 # 4. Execute the following command:
204 # cat /tmp/main.cf.new | ( echo '# DO NOT EDIT THIS FILE. EDIT THE MAIN.CF FILE INSTEAD. THE'; echo '# TEXT HERE JUST SHOWS DEFAULT SETTINGS BUILT INTO POSTFIX.'; echo '#'; grep -v ^alias_maps\ = |grep -v ^alias_database\ = |grep -v ^command_directory\ = |grep -v ^config_directory\ = |grep -v ^daemon_directory\ = |grep -v ^data_directory\ = |grep -v ^default_database_type\ = |grep -v ^html_directory\ = |grep -v ^mail_spool_directory\ = |grep -v ^mailq_path\ = |grep -v ^manpage_directory\ = |grep -v ^meta_directory\ = |grep -v ^mydomain\ = |grep -v ^myhostname\ = |grep -v ^mynetworks\ = |grep -v ^mynetworks_style\ = |grep -v ^newaliases_path\ = |grep -v ^queue_directory\ = |grep -v ^readme_directory\ = |grep -v ^sample_directory\ = |grep -v ^sendmail_path\ = |grep -v ^shlib_directory\ = |grep -v ^smtputf8_enable\ = |grep -v ^virtual_maps\ = |grep -v ^process_id\ = ) > files/main.cf.default
205 # 5. Done. Now you can rebuild the package with new main.cf.default.
206 #
207
208 define Build/Compile
209 # Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC as a workaround
210 cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
211 cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
212 echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
213 echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
214 echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
215 echo "virtual_maps = $(default_database_type):$(config_directory)/virtual" >> $(PKG_BUILD_DIR)/conf/main.cf.default
216 echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
217 echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
218 echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
219 echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
220 echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
221 echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
222 echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
223 echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
224 echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
225 echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
226 echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
227 echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
228 echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
229 echo "shlib_directory = $(shlib_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
230 echo "meta_directory = $(meta_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
231 echo "smtputf8_enable = $(smtputf8_conf)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
232 endef
233
234 define Package/postfix/install
235 cd $(PKG_BUILD_DIR); $(MAKE) install_root=$(1) command_directory=$(command_directory) daemon_directory=$(daemon_directory) data_directory=$(data_directory) html_directory=$(html_directory) mail_owner=postfix mailq_path=$(mailq_path)$(ln_suffix) manpage_directory=$(manpage_directory) newaliases_path=$(newaliases_path)$(ln_suffix) queue_directory=$(queue_directory) readme_directory=$(readme_directory) sendmail_path=$(sendmail_path)$(ln_suffix) setgid_group=postdrop sample_directory=$(sample_directory) config_directory=$(config_directory) shlib_directory=$(shlib_directory) meta_directory=$(meta_directory) mail_version=$(PKG_VERSION) non-interactive-package
236 $(INSTALL_DIR) $(1)$(mail_spool_directory)
237 $(INSTALL_DIR) $(1)/etc/init.d/
238 $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
239 endef
240
241 define Package/postfix/postinst
242 #!/bin/sh
243
244 if [ -f "$${IPKG_INSTROOT}$(sendmail_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
245 mv "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
246 echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) saved as $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
247 fi
248 if [ ! -f "$${IPKG_INSTROOT}$(sendmail_path)" ]; then
249 ln -s "$(sendmail_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
250 fi
251
252 if [ -f "$${IPKG_INSTROOT}$(newaliases_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
253 mv "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
254 echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) saved as $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
255 fi
256 if [ ! -f "$${IPKG_INSTROOT}$(newaliases_path)" ]; then
257 ln -s "$(newaliases_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
258 fi
259
260 if [ -f "$${IPKG_INSTROOT}$(mailq_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
261 mv "$${IPKG_INSTROOT}$(mailq_path)" "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
262 echo "Warning: $${IPKG_INSTROOT}$(mailq_path) saved as $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
263 fi
264 if [ ! -f "$(mailq_path)" ]; then
265 ln -s "$(mailq_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
266 fi
267
268 grep -qc main\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
269 grep -qc master\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
270 grep -qc aliases "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
271 grep -qc virtual "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/virtual" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
272
273 touch "$${IPKG_INSTROOT}$(config_directory)"/opkg_postinst
274
275 if [ -z "$${IPKG_INSTROOT}" ]; then
276 ps | grep "postfix/master" | grep -cvq grep >/dev/null && /etc/init.d/postfix restart
277 fi
278
279 endef
280
281 define Package/postfix/prerm
282 #!/bin/sh
283 ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
284 /etc/init.d/postfix disable
285 endef
286
287 define Package/postfix/postrm
288 #!/bin/sh
289 rm -f $${IPKG_INSTROOT}$(config_directory)/aliases.cdb $${IPKG_INSTROOT}$(config_directory)/aliases.db $${IPKG_INSTROOT}$(data_directory)/master.lock
290
291 rm -f $${IPKG_INSTROOT}$(config_directory)/virtual.cdb $${IPKG_INSTROOT}$(config_directory)/virtual.db
292
293 rm -f "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(mailq_path)"
294
295 if [ -f "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" ]; then
296 mv "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
297 echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) restored from $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
298 fi
299 if [ -f "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" ]; then
300 mv "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
301 echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) restored from $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
302 fi
303 if [ -f "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" ]; then
304 mv "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
305 echo "Warning: $${IPKG_INSTROOT}$(mailq_path) restored from $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
306 fi
307 endef
308
309 $(eval $(call BuildPackage,postfix))