blob: 106c18a9596ec130aab0f0baa1ff2a0519b724c5 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
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
8include $(TOPDIR)/rules.mk
9
10PKG_NAME:=postfix
11PKG_VERSION:=3.5.8
12PKG_RELEASE:=1
13
14PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
15PKG_SOURCE_URL:= \
16 https://de.postfix.org/ftpmirror/official/ \
17 http://ftp.porcupine.org/mirrors/postfix-release/official/
18PKG_HASH:=22582628cf3edc18c5155c9ff44543dd95a9435fb68135d76a99f572cb07456f
19
20PKG_MAINTAINER:=Denis Shulyaka <Shulyaka@gmail.com>
21PKG_LICENSE:=IPL-1.0
22PKG_LICENSE_FILES:=LICENSE
23PKG_CPE_ID:=cpe:/a:postfix:postfix
24
25PKG_CONFIG_DEPENDS:= \
26 CONFIG_POSTFIX_TLS \
27 CONFIG_POSTFIX_SASL \
28 CONFIG_POSTFIX_LDAP \
29 CONFIG_POSTFIX_CDB \
30 CONFIG_POSTFIX_DB \
31 CONFIG_POSTFIX_SQLITE \
32 CONFIG_POSTFIX_MYSQL \
33 CONFIG_POSTFIX_PGSQL \
34 CONFIG_POSTFIX_PCRE \
35 CONFIG_POSTFIX_EAI \
36
37include $(INCLUDE_DIR)/package.mk
38
39define Package/postfix
40 SECTION:=mail
41 CATEGORY:=Mail
42 TITLE:=Postfix Mail Transmit Agent
43 USERID:= \
44 postfix=25:postfix=25 \
45 postdrop=26:postdrop=26
46 URL:=http://www.postfix.org/
47 DEPENDS:=+POSTFIX_CDB:tinycdb +POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_SQLITE:libsqlite3 +POSTFIX_MYSQL:libmysqlclient +POSTFIX_PGSQL:libpq +POSTFIX_EAI:icu +POSTFIX_PCRE:libpcre
48endef
49
50define Package/postfix/description
51 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.
52endef
53
54define Package/postfix/config
55 menu "Select postfix build options"
56 config POSTFIX_TLS
57 bool "TLS support"
58 default y
59 help
60 Implements TLS support in postfix (using OpenSSL).
61 config POSTFIX_SASL
62 bool "SASL support"
63 default y
64 help
65 Implements SASL support in postfix (using Cyrus SASL).
66 config POSTFIX_LDAP
67 bool "LDAP support"
68 default y
69 help
70 Implements LDAP support in postfix (using OpenLDAP).
71 config POSTFIX_DB
72 bool "BerkeleyDB support"
73 default n
74 help
75 Implements support for btree and hash files using Berkeley DB.
76 config POSTFIX_CDB
77 bool "CDB support"
78 default y
79 help
80 Implements support for cdb files using tinycdb
81 config POSTFIX_SQLITE
82 bool "SQLITE support"
83 default y
84 help
85 Implements support for SQLite3 DB
86 config POSTFIX_MYSQL
87 bool "MYSQL support"
88 default n
89 help
90 Implements support for MySQL
91 config POSTFIX_PGSQL
92 bool "PostgreSQL support"
93 default n
94 help
95 Implement support for PostgreSQL
96 config POSTFIX_PCRE
97 bool "PCRE support"
98 default y
99 help
100 Implement support for Perl Compatible Regular Expressions
101 config POSTFIX_EAI
102 bool "SMTPUTF8 support"
103 default n
104 help
105 Enable Postfix support for Email Address Internationalization
106 (EAI) as defined in RFC 6531 (SMTPUTF8 extension), RFC 6532
107 (Internationalized email headers) and RFC 6533
108 (Internationalized delivery status notifications).
109 Since version 3.0, Postfix fully supports UTF-8 email
110 addresses and UTF-8 message header values.
111 endmenu
112endef
113
114CCARGS=-DNO_NIS -fcommon
115AUXLIBS=-L$(STAGING_DIR)/usr/lib
116
117ifdef CONFIG_POSTFIX_TLS
118 CCARGS+=-DUSE_TLS
119 AUXLIBS+=-lssl -lcrypto
120endif
121
122ifdef CONFIG_POSTFIX_SASL
123 CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
124 AUXLIBS+=-lsasl2
125endif
126
127ifdef CONFIG_POSTFIX_LDAP
128 CCARGS+=-DHAS_LDAP
129 AUXLIBS+=-lldap -llber
130endif
131
132ifdef CONFIG_POSTFIX_CDB
133 CCARGS+=-DHAS_CDB
134 AUXLIBS+=-lcdb
135 ifndef default_database_type
136 default_database_type=cdb
137 endif
138endif
139
140ifdef CONFIG_POSTFIX_DB
141 AUXLIBS+=-ldb
142 CCARGS+=-DHAS_DB
143 ifndef default_database_type
144 default_database_type=btree
145 endif
146else
147 CCARGS+=-DNO_DB
148endif
149
150ifdef CONFIG_POSTFIX_SQLITE
151 CCARGS+=-DHAS_SQLITE -I$(STAGING_DIR)/usr/include/
152 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lsqlite3 -lpthread
153endif
154
155ifdef CONFIG_POSTFIX_MYSQL
156 CCARGS+=-DHAS_MYSQL -I$(STAGING_DIR)/usr/include/mysql
157 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lmysqlclient -lz -lm
158endif
159
160ifdef CONFIG_POSTFIX_PGSQL
161 CCARGS+=-DHAS_PGSQL -I$(STAGING_DIR)/usr/include/
162 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lpq
163endif
164
165ifdef CONFIG_POSTFIX_PCRE
166 CCARGS+=-DHAS_PCRE -I$(STAGING_DIR)/usr/include/
167 AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lpcre
168else
169 CCARGS+=-DNO_PCRE
170endif
171
172ifdef CONFIG_POSTFIX_EAI
173 AUXLIBS+=-licuuc
174 CCARGS+=-DHAS_EAI
175 smtputf8_conf = yes
176else
177 CCARGS+=-DNO_EAI
178 smtputf8_conf = no
179endif
180
181CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
182TARGET_LDFLAGS += $(if $(CONFIG_USE_GLIBC),-lresolv)
183
184# prevent postfix-install from executing postconf at build time
185# by explicitly providing the default values to postfix-install
186config_directory=/etc/postfix
187sample_directory=/etc/postfix
188command_directory=/usr/sbin
189daemon_directory=/usr/libexec/postfix
190html_directory=no
191manpage_directory=no
192readme_directory=no
193sendmail_path=/usr/sbin/sendmail
194newaliases_path=/usr/bin/newaliases
195mailq_path=/usr/bin/mailq
196shlib_directory=/usr/lib/postfix
197meta_directory=/etc/postfix
198data_directory=/usr/var/lib/postfix
199queue_directory=/usr/var/spool/postfix
200mail_spool_directory=/usr/var/mail
201
202ln_suffix=.postfix
203ln_suffix_pre_pf=.pre-postfix
204ln_suffix_legacy=.old
205
206define Package/postfix/conffiles
207$(config_directory)
208endef
209
210define Build/Configure
211 if [ "$(default_database_type)" = "" ]; then \
212 echo "Build error: CDB or BerkeleyDB support must be enabled."; \
213 exit 1; \
214 fi
215 cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
216endef
217
218define Build/Compile
219 # 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
220 cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS) $(TARGET_CFLAGS) $(TARGET_LDFLAGS)'
221 $(foreach p, \
222 default_database_type config_directory command_directory daemon_directory \
223 shlib_directory manpage_directory data_directory queue_directory \
224 mail_spool_directory, \
225 echo "$(p) = $($(p))" >> $(PKG_BUILD_DIR)/conf/main.cf;)
226endef
227
228define Package/postfix/install
229 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
230 $(INSTALL_DIR) $(1)/etc/init.d/
231 $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
232endef
233
234define Package/postfix/postinst
235#!/bin/sh
236
237for syml in $(sendmail_path) $(newaliases_path) $(mailq_path); do
238 file=$${IPKG_INSTROOT}$${syml}
239 if [ -f "$${file}$(ln_suffix_legacy)" ]; then
240 # update files saved by legacy versions of Postfix postinst script
241 mv "$${file}$(ln_suffix_legacy)" "$${file}$(ln_suffix_pre_pf)"
242 fi
243 if [ -f "$${file}" ]; then
244 linktarget=$$(basename $$(readlink "$${file}"))
245 postfixf=$$(basename "$${syml}")$(ln_suffix)
246 if [ $${linktarget} != $${postfixf} ]; then
247 mv "$${file}" "$${file}$(ln_suffix_pre_pf)"
248 echo "Info: $${file} saved as $${file}$(ln_suffix_pre_pf)"
249 fi
250 fi
251 if [ ! -f "$${file}" ]; then
252 ln -s "$${syml}$(ln_suffix)" "$${file}"
253 fi
254done
255# fix file/dir ownership in data_directory and queue_directory
256if [ -z "$${IPKG_INSTROOT}" ]; then
257 postfix set-permissions
258fi
259
260endef
261
262define Package/postfix/postrm
263#!/bin/sh
264rm -f "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"
265
266for syml in "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"; do
267 file=$${IPKG_INSTROOT}$${syml}
268 if [ -f "$${file}$(ln_suffix_legacy)" ]; then
269 # update files saved by legacy versions of Postfix postinst script
270 mv "$${file}$(ln_suffix_legacy)" "$${file}$(ln_suffix_pre_pf)"
271 fi
272 if [ -f "$${syml}$(ln_suffix_pre_pf)" ]; then
273 mv "$${syml}$(ln_suffix_pre_pf)" "$${syml}"
274 echo "Info: $${syml}$(ln_suffix_pre_pf) restored as $${syml}"
275 fi
276done
277endef
278
279$(eval $(call BuildPackage,postfix))