1
0

Makefile 12 KB

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