Merge pull request #840 from cjkoenig/update_liburcu
[feed/packages.git] / mail / postfix / Makefile
1 #
2 # Copyright (C) 2014 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:=2
12 PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
13 PKG_VERSION:=2.11.3
14 PKG_MD5SUM:=c3f0f51d8865559b40e9350eb3816011
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 +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 endmenu
63 endef
64
65 CCARGS=-DNO_EPOLL -DNO_SIGSETJMP -DNO_NIS
66 AUXLIBS=-L$(STAGING_DIR)/usr/lib
67 default_database_type=cdb
68
69 ifdef CONFIG_POSTFIX_TLS
70 CCARGS+=-DUSE_TLS
71 AUXLIBS+=-lssl -lcrypto
72 endif
73
74 ifdef CONFIG_POSTFIX_SASL
75 CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
76 AUXLIBS+=-lsasl2
77 endif
78
79 ifdef CONFIG_POSTFIX_LDAP
80 CCARGS+=-DHAS_LDAP
81 AUXLIBS+=-lldap -llber
82 endif
83
84 ifdef CONFIG_POSTFIX_CDB
85 CCARGS+=-DHAS_CDB
86 AUXLIBS+=-lcdb
87 endif
88
89 ifdef CONFIG_POSTFIX_DB
90 AUXLIBS+=-ldb
91 CCARGS+=-DHAS_DB
92 ifndef CONFIG_POSTFIX_CDB
93 default_database_type=btree
94 endif
95 else
96 CCARGS+=-DNO_DB
97 endif
98
99 CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
100
101 config_directory=/etc/postfix# also add this to postfix init file
102 sample_directory=/etc/postfix
103 command_directory=/usr/sbin
104 daemon_directory=/usr/libexec/postfix
105 data_directory=/usr/var/lib/postfix
106 queue_directory=/usr/var/spool/postfix
107 mail_spool_directory=/usr/var/mail
108 html_directory=no
109 manpage_directory=no
110 readme_directory=no
111 sendmail_path=/usr/sbin/sendmail
112 newaliases_path=/usr/bin/newaliases
113 mailq_path=/usr/bin/mailq
114
115 ln_suffix=.postfix
116 ln_old_suffix=.old
117
118 define Package/postfix/conffiles
119 $(config_directory)/main.cf
120 $(config_directory)/master.cf
121 $(config_directory)/aliases
122 endef
123
124 define Build/Configure
125 if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
126 echo "Build error: You must select at least one of the DB types";\
127 exit 1;\
128 fi
129
130 cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
131 endef
132
133 define Build/Compile
134 # Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC
135 cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
136 cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
137 echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
138 echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
139 echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
140 echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
141 echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
142 echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
143 echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
144 echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
145 echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
146 echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
147 echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
148 echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
149 echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
150 echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
151 echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
152 echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
153 endef
154
155 define Package/postfix/install
156 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) non-interactive-package
157 $(INSTALL_DIR) $(1)$(mail_spool_directory)
158 $(INSTALL_DIR) $(1)/etc/init.d/
159 $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
160 endef
161
162 define Package/postfix/postinst
163 #!/bin/sh
164
165 if [ -f "$${IPKG_INSTROOT}$(sendmail_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
166 mv "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
167 echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) saved as $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
168 fi
169 if [ ! -f "$${IPKG_INSTROOT}$(sendmail_path)" ]; then
170 ln -s "$${IPKG_INSTROOT}$(sendmail_path)$(ln_suffix)" "$(sendmail_path)"
171 fi
172
173 if [ -f "$${IPKG_INSTROOT}$(newaliases_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
174 mv "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
175 echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) saved as $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
176 fi
177 if [ ! -f "$${IPKG_INSTROOT}$(newaliases_path)" ]; then
178 ln -s "$${IPKG_INSTROOT}$(newaliases_path)$(ln_suffix)" "$(newaliases_path)"
179 fi
180
181 if [ -f "$${IPKG_INSTROOT}$(mailq_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
182 mv "$${IPKG_INSTROOT}$(mailq_path)" "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
183 echo "Warning: $${IPKG_INSTROOT}$(mailq_path) saved as $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
184 fi
185 if [ ! -f "$(mailq_path)" ]; then
186 ln -s "$${IPKG_INSTROOT}$(mailq_path)$(ln_suffix)" "$(mailq_path)"
187 fi
188
189 grep -qc main\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
190 grep -qc master\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
191 grep -qc aliases "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
192
193 touch "$${IPKG_INSTROOT}$(config_directory)"/opkg_postinst
194
195 if [ -z "$${IPKG_INSTROOT}" ]; then
196 ps | grep "postfix/master" | grep -cvq grep >/dev/null && /etc/init.d/postfix reload
197 fi
198
199 endef
200
201 define Package/postfix/prerm
202 #!/bin/sh
203 ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
204 /etc/init.d/postfix disable
205 endef
206
207 define Package/postfix/postrm
208 #!/bin/sh
209 rm -f $${IPKG_INSTROOT}$(config_directory)/aliases.cdb $${IPKG_INSTROOT}$(config_directory)/aliases.db $${IPKG_INSTROOT}$(data_directory)/master.lock
210
211 rm -f "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(mailq_path)"
212
213 if [ -f "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" ]; then
214 mv "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
215 echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) restored from $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
216 fi
217 if [ -f "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" ]; then
218 mv "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
219 echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) restored from $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
220 fi
221 if [ -f "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" ]; then
222 mv "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
223 echo "Warning: $${IPKG_INSTROOT}$(mailq_path) restored from $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
224 fi
225 endef
226
227 $(eval $(call BuildPackage,postfix))