Merge pull request #3373 from bobafetthotmail/patch-6
[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:=1
12 PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
13 PKG_VERSION:=3.1.3
14 PKG_MD5SUM:=28a1dedbbbedfcf5fc09fd88bac116b6
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
21 include $(INCLUDE_DIR)/package.mk
22
23 define Package/postfix
24 SECTION:=mail
25 CATEGORY:=Mail
26 TITLE:=Postfix Mail Transmit Agent
27 URL:=http://www.postfix.org/
28 DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_EAI:icu +libpcre
29 endef
30
31 define Package/postfix/description
32 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.
33 endef
34
35 define Package/postfix/config
36 menu "Select postfix build options"
37 config POSTFIX_TLS
38 bool "TLS support"
39 default y
40 help
41 Implements TLS support in postfix (using OpenSSL).
42 config POSTFIX_SASL
43 bool "SASL support"
44 default y
45 help
46 Implements SASL support in postfix (using Cyrus SASL).
47 config POSTFIX_LDAP
48 bool "LDAP support"
49 default y
50 help
51 Implements LDAP support in postfix (using OpenLDAP).
52 config POSTFIX_DB
53 bool "BerkeleyDB support"
54 default n
55 help
56 Implements support for btree files using Berkeley DB. Note that hash files support is not compiled into Berkeley DB OpenWRT distribution
57 config POSTFIX_CDB
58 bool "CDB support"
59 default y
60 help
61 Implements support for cdb files using tinycdb
62 config POSTFIX_EAI
63 bool "SMTPUTF8 support"
64 default n
65 help
66 Enable Postfix support for Email Address Internationalization
67 (EAI) as defined in RFC 6531 (SMTPUTF8 extension), RFC 6532
68 (Internationalized email headers) and RFC 6533
69 (Internationalized delivery status notifications).
70 Since version 3.0, Postfix fully supports UTF-8 email
71 addresses and UTF-8 message header values.
72 endmenu
73 endef
74
75 CCARGS=-DNO_NIS
76 AUXLIBS=-L$(STAGING_DIR)/usr/lib
77 default_database_type=cdb
78
79 ifdef CONFIG_POSTFIX_TLS
80 CCARGS+=-DUSE_TLS
81 AUXLIBS+=-lssl -lcrypto
82 endif
83
84 ifdef CONFIG_POSTFIX_SASL
85 CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
86 AUXLIBS+=-lsasl2
87 endif
88
89 ifdef CONFIG_POSTFIX_LDAP
90 CCARGS+=-DHAS_LDAP
91 AUXLIBS+=-lldap -llber
92 endif
93
94 ifdef CONFIG_POSTFIX_CDB
95 CCARGS+=-DHAS_CDB
96 AUXLIBS+=-lcdb
97 endif
98
99 ifdef CONFIG_POSTFIX_DB
100 AUXLIBS+=-ldb
101 CCARGS+=-DHAS_DB
102 ifndef CONFIG_POSTFIX_CDB
103 default_database_type=btree
104 endif
105 else
106 CCARGS+=-DNO_DB
107 endif
108
109 ifdef CONFIG_POSTFIX_EAI
110 AUXLIBS+=-licuuc
111 CCARGS+=-DHAS_EAI
112 smtputf8_conf = yes
113 else
114 CCARGS+=-DNO_EAI
115 smtputf8_conf = no
116 endif
117
118 CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
119
120 config_directory=/etc/postfix# also add this to postfix init file
121 sample_directory=/etc/postfix
122 command_directory=/usr/sbin
123 daemon_directory=/usr/libexec/postfix
124 data_directory=/usr/var/lib/postfix
125 queue_directory=/usr/var/spool/postfix
126 mail_spool_directory=/usr/var/mail
127 html_directory=no
128 manpage_directory=no
129 readme_directory=no
130 sendmail_path=/usr/sbin/sendmail
131 newaliases_path=/usr/bin/newaliases
132 mailq_path=/usr/bin/mailq
133 shlib_directory=/usr/lib/postfix
134 meta_directory=/etc/postfix
135
136 ln_suffix=.postfix
137 ln_old_suffix=.old
138
139 define Package/postfix/conffiles
140 $(config_directory)/main.cf
141 $(config_directory)/master.cf
142 $(config_directory)/aliases
143 $(config_directory)/virtual
144 endef
145
146 define Build/Configure
147 if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
148 echo "Build error: You must select at least one of the DB types";\
149 exit 1;\
150 fi
151
152 cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
153 endef
154
155 # Steps to regenerate files/main.cf.default:
156 #
157 # 1. Compile the package with current file
158 # 2. Execute the following command on target device:
159 # postconf -d > /tmp/main.cf.new
160 # 3. Transfer /tmp/main.cf.new file to the build system
161 # 4. Execute the following command:
162 # 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
163 # 5. Done. Now you can rebuild the package with new main.cf.default.
164 #
165
166 define Build/Compile
167 # 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
168 cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
169 cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
170 echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
171 echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
172 echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
173 echo "virtual_maps = $(default_database_type):$(config_directory)/virtual" >> $(PKG_BUILD_DIR)/conf/main.cf.default
174 echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
175 echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
176 echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
177 echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
178 echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
179 echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
180 echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
181 echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
182 echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
183 echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
184 echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
185 echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
186 echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
187 echo "shlib_directory = $(shlib_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
188 echo "meta_directory = $(meta_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
189 echo "smtputf8_enable = $(smtputf8_conf)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
190 endef
191
192 define Package/postfix/install
193 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
194 $(INSTALL_DIR) $(1)$(mail_spool_directory)
195 $(INSTALL_DIR) $(1)/etc/init.d/
196 $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
197 endef
198
199 define Package/postfix/postinst
200 #!/bin/sh
201
202 if [ -f "$${IPKG_INSTROOT}$(sendmail_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
203 mv "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
204 echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) saved as $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
205 fi
206 if [ ! -f "$${IPKG_INSTROOT}$(sendmail_path)" ]; then
207 ln -s "$${IPKG_INSTROOT}$(sendmail_path)$(ln_suffix)" "$(sendmail_path)"
208 fi
209
210 if [ -f "$${IPKG_INSTROOT}$(newaliases_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
211 mv "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
212 echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) saved as $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
213 fi
214 if [ ! -f "$${IPKG_INSTROOT}$(newaliases_path)" ]; then
215 ln -s "$${IPKG_INSTROOT}$(newaliases_path)$(ln_suffix)" "$(newaliases_path)"
216 fi
217
218 if [ -f "$${IPKG_INSTROOT}$(mailq_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
219 mv "$${IPKG_INSTROOT}$(mailq_path)" "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
220 echo "Warning: $${IPKG_INSTROOT}$(mailq_path) saved as $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
221 fi
222 if [ ! -f "$(mailq_path)" ]; then
223 ln -s "$${IPKG_INSTROOT}$(mailq_path)$(ln_suffix)" "$(mailq_path)"
224 fi
225
226 grep -qc main\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
227 grep -qc master\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
228 grep -qc aliases "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
229 grep -qc virtual "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/virtual" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
230
231 touch "$${IPKG_INSTROOT}$(config_directory)"/opkg_postinst
232
233 if [ -z "$${IPKG_INSTROOT}" ]; then
234 ps | grep "postfix/master" | grep -cvq grep >/dev/null && /etc/init.d/postfix restart
235 fi
236
237 endef
238
239 define Package/postfix/prerm
240 #!/bin/sh
241 ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
242 /etc/init.d/postfix disable
243 endef
244
245 define Package/postfix/postrm
246 #!/bin/sh
247 rm -f $${IPKG_INSTROOT}$(config_directory)/aliases.cdb $${IPKG_INSTROOT}$(config_directory)/aliases.db $${IPKG_INSTROOT}$(data_directory)/master.lock
248
249 rm -f $${IPKG_INSTROOT}$(config_directory)/virtual.cdb $${IPKG_INSTROOT}$(config_directory)/virtual.db
250
251 rm -f "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(mailq_path)"
252
253 if [ -f "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" ]; then
254 mv "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
255 echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) restored from $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
256 fi
257 if [ -f "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" ]; then
258 mv "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
259 echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) restored from $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
260 fi
261 if [ -f "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" ]; then
262 mv "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
263 echo "Warning: $${IPKG_INSTROOT}$(mailq_path) restored from $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
264 fi
265 endef
266
267 $(eval $(call BuildPackage,postfix))