1#
2# xbs-compatible wrapper Makefile for postfix
3#
4
5PROJECT=postfix
6OPEN_SOURCE_VERSION=2.11.0
7
8SHELL := /bin/sh
9
10# Sane defaults, which are typically overridden on the command line.
11SRCROOT=
12OBJROOT=$(SRCROOT)
13SYMROOT=$(OBJROOT)
14DSTROOT=/usr/local
15SDKROOT=
16RC_ARCHS=
17CFLAGS=-g -Os $(RC_CFLAGS)
18
19WARN = -Wall -Wno-comment -Wformat -Wimplicit -Wmissing-prototypes \
20	-Wparentheses -Wstrict-prototypes -Wswitch -Wuninitialized \
21	-Wunused -Wno-missing-braces
22
23BuildDirectory	= $(OBJROOT)/Build
24TMPDIR		= $(OBJROOT)/Build/tmp
25Sources		= $(SRCROOT)
26
27SMTPSTONE	= $(BuildDirectory)/$(PROJECT)/src/smtpstone/qmqp-sink $(BuildDirectory)/$(PROJECT)/src/smtpstone/smtp-sink \
28			$(BuildDirectory)/$(PROJECT)/src/smtpstone/qmqp-source $(BuildDirectory)/$(PROJECT)/src/smtpstone/smtp-source
29
30ifneq "" "$(SDKROOT)"
31  CC_PATH = $(shell xcrun -find -sdk $(SDKROOT) cc)
32else
33  CC_PATH = $(shell xcrun -find cc)
34endif
35
36install :: copy-src apply-patches build-postfix install-postfix archive-strip-binaries \
37		post-install install-extras set-defaults
38
39clean : ;
40
41installhdrs : ;
42
43installsrc :
44	@echo "***** installsrc"
45	[ ! -d $(SRCROOT)/$(PROJECT) ] && mkdir -p $(SRCROOT)/$(PROJECT)
46	tar cf - . | (cd $(SRCROOT) ; tar xfp -)
47	find $(SRCROOT) -type d -name CVS -print0 | xargs -0 rm -rf
48	@echo "***** installsrc complete"
49
50copy-src :
51	@echo "***** copy source"
52	$(_v) /bin/mkdir -p $(BuildDirectory)/$(PROJECT)
53	$(_v) /bin/mkdir -p $(TMPDIR)
54	$(_v) /bin/cp -rpf $(Sources)/$(PROJECT) $(BuildDirectory)
55	@echo "***** copy source complete"
56
57apply-patches :
58	@echo "***** applying patches"
59	#cd "$(BuildDirectory)/$(PROJECT)" && patch -p1 < "$(SRCROOT)/patches/postfix-2.9-patch03.txt"
60	#cd "$(BuildDirectory)/$(PROJECT)" && patch -p1 < "$(SRCROOT)/patches/postfix-2.9-patch04.txt"
61	@echo "***** applying patches complete"
62	@echo "***** creating MIG API files "
63	$(_v) cd $(BuildDirectory)/$(PROJECT)/src/global && mig -v "$(SDKROOT)/usr/local/include/opendirectory/DSlibinfoMIG.defs"
64	@echo "***** creating MIG API files complete"
65
66build-postfix :
67	@echo "***** building $(PROJECT)"
68	@echo "*** build environment = $(ENV)"
69	$(ENV) $(MAKE) -C $(BuildDirectory)/$(PROJECT) makefiles CC="$(CC_PATH)" OPT=" -DNO_NETINFO \
70			-DUSE_TLS -DUSE_CYRUS_SASL -DUSE_SASL_AUTH -D__APPLE_OS_X_SERVER__ \
71			-DEVENTS_STYLE=EVENTS_STYLE_KQUEUE \
72			-DHAS_DEV_URANDOM -DUSE_SYSV_POLL -DHAS_PCRE -DHAS_LDAP $(WARN)\
73			-I$(SDKROOT)/usr/include \
74			-I$(SDKROOT)/usr/include/sasl \
75			-I$(SDKROOT)/usr/local/include \
76			-F$(SDKROOT)/System/Library/Frameworks \
77			-F$(SDKROOT)/System/Library/PrivateFrameworks \
78			$(CFLAGS)" AUXLIBS="-L$(SDKROOT)/usr/lib -lssl -lsasl2.2.0.1 -lgssapi_krb5 -lldap"
79	$(ENV) $(MAKE) -C $(BuildDirectory)/$(PROJECT)
80	@echo "*** building: smtpstone"
81	cd $(BuildDirectory)/postfix/src/smtpstone && make all
82	@echo "***** building $(PROJECT) complete"
83
84install-postfix :
85	@echo "***** installing $(PROJECT)"
86	@echo "*** executing $(SHELL) -x postfix-install"
87	cd $(BuildDirectory)/$(PROJECT) && \
88	$(SHELL) -x postfix-install -non-interactive \
89		install_root=$(DSTROOT) \
90		tempdir=$(OBJROOT) \
91		mail_owner=_postfix \
92		setgid_group=_postdrop \
93		config_directory=/private/etc/postfix \
94		daemon_directory=/usr/libexec/postfix \
95		command_directory=/usr/sbin \
96		queue_directory=/private/var/spool/postfix \
97		sendmail_path=/usr/sbin/sendmail \
98		newaliases_path=/usr/bin/newaliases \
99		mailq_path=/usr/bin/mailq \
100		manpage_directory=/usr/share/man \
101		sample_directory=/usr/share/doc/postfix/examples \
102		html_directory=/usr/share/doc/postfix/html \
103		data_directory=/private/var/lib/postfix \
104		readme_directory=/usr/share/doc/postfix
105	@echo "****** installing $(PROJECT) complete"
106
107archive-strip-binaries :
108	@echo "****** archiving & stripping binaries"
109	rm -r $(BuildDirectory)/$(PROJECT)/src/local/local.dSYM
110	for file in $(DSTROOT)/usr/{{s,}bin,libexec/postfix}/* $(SMTPSTONE); do \
111		echo "*** Processing $${file##*/} (from $${file})"; \
112		if [ ! -e "$(SYMROOT)/$${file##*/}" ]; then \
113			echo "** /bin/cp $${file} $(SYMROOT)"; \
114			/bin/cp $${file} $(SYMROOT); \
115		fi; \
116		if [ -e "$(SYMROOT)/$${file##*/}.dSYM" ]; then \
117			echo "** ...odd, dSYM already exists."; \
118		else \
119			echo "** /usr/bin/dsymutil --out=$(SYMROOT)/$${file##*/}.dSYM $${file}"; \
120			/usr/bin/dsymutil --out=$(SYMROOT)/$${file##*/}.dSYM $${file}; \
121		fi; \
122		strip -x $${file}; \
123	done
124	@echo "***** archiving & stripping binaries complete"
125
126post-install :
127	@echo "***** post-install $(PROJECT)"
128	@echo "*** executing $(SHELL) -x post-install"
129	cd $(BuildDirectory)/$(PROJECT) && \
130	$(SHELL) -x conf/post-install set-permissions \
131		mail_owner=_postfix \
132		setgid_group=_postdrop \
133		install_root=$(DSTROOT) \
134		tempdir=$(OBJROOT) \
135		config_directory=$(DSTROOT)/private/etc/postfix \
136		daemon_directory=$(DSTROOT)/usr/libexec/postfix \
137		command_directory=$(DSTROOT)/usr/sbin \
138		queue_directory=$(DSTROOT)/private/var/spool/postfix \
139		sendmail_path=$(DSTROOT)/usr/sbin/sendmail \
140		newaliases_path=$(DSTROOT)/usr/bin/newaliases \
141		mailq_path=$(DSTROOT)/usr/bin/mailq \
142		manpage_directory=$(DSTROOT)/usr/share/man \
143		sample_directory=$(DSTROOT)/usr/share/doc/postfix/examples \
144		html_directory=$(DSTROOT)/usr/share/doc/postfix/html \
145		data_directory=$(DSTROOT)/private/var/lib/postfix \
146		readme_directory=$(DSTROOT)/usr/share/doc/postfix
147	@echo "*****  post-install $(PROJECT) complete"
148
149install-extras : 
150	@echo "***** installing extras"
151	@echo "*** installing directories"
152	install -d -m 755 $(DSTROOT)/System/Library/LaunchDaemons
153	install -d -m 755 $(DSTROOT)/usr/libexec/postfix/scripts
154	install -d -m 755 $(DSTROOT)/usr/share/man/man1
155	install -d -m 755 $(DSTROOT)/usr/local/OpenSourceVersions
156	install -d -m 755 $(DSTROOT)/usr/local/OpenSourceLicenses
157	install -d -m 755 $(DSTROOT)/usr/share/doc/postfix/html
158	install -d -m 755 $(DSTROOT)/usr/share/doc/postfix/examples
159	install -d -m 755 $(DSTROOT)/private/var/db
160	install -d -m 755 $(DSTROOT)/private/var/lib
161	install -d -m 755 $(DSTROOT)/private/var/spool
162	ln -s postfix/aliases $(DSTROOT)/private/etc
163	@echo "*** installing default config files"
164	rm  $(DSTROOT)/private/etc/postfix/master.cf
165	install -m 0644 $(SRCROOT)/Postfix.Config/main.cf.default $(DSTROOT)/private/etc/postfix
166	install -m 0644 $(SRCROOT)/Postfix.Config/main.cf.default $(DSTROOT)/private/etc/postfix/main.cf
167	install -m 0644 $(SRCROOT)/Postfix.Config/master.cf.default $(DSTROOT)/private/etc/postfix
168	install -m 0644 $(SRCROOT)/Postfix.Config/master.cf.default $(DSTROOT)/private/etc/postfix/master.cf
169	install -m 0644 $(SRCROOT)/Postfix.LaunchDaemons/org.postfix.master.plist \
170			$(DSTROOT)/System/Library/LaunchDaemons/org.postfix.master.plist
171	install -m 0755 $(SRCROOT)/Postfix.ServerSetup/set_credentials.sh $(DSTROOT)/usr/libexec/postfix/set_credentials.sh
172	@echo "*** Installing smtpstone binaries"
173	install -s -m 0755 $(BuildDirectory)/$(PROJECT)/src/smtpstone/qmqp-sink $(DSTROOT)/usr/libexec/postfix
174	install -s -m 0755 $(BuildDirectory)/$(PROJECT)/src/smtpstone/smtp-sink $(DSTROOT)/usr/libexec/postfix
175	install -s -m 0755 $(BuildDirectory)/$(PROJECT)/src/smtpstone/qmqp-source $(DSTROOT)/usr/libexec/postfix
176	install -s -m 0755 $(BuildDirectory)/$(PROJECT)/src/smtpstone/smtp-source $(DSTROOT)/usr/libexec/postfix
177	@echo "*** Installing open source version files"
178	install -m 0444 $(SRCROOT)/Postfix.OpenSourceInfo/Postfix.plist $(DSTROOT)/usr/local/OpenSourceVersions
179	install -m 0444 $(SRCROOT)/Postfix.OpenSourceInfo/Postfix.txt $(DSTROOT)/usr/local/OpenSourceLicenses
180	@echo "*** installing custome runtime files"
181	#install -m 644 $(SRCROOT)/Postfix.Config/postfix-files $(DSTROOT)/private/etc/postfix/postfix-files
182	#rm $(DSTROOT)/usr/libexec/postfix/postfix-files
183	#ln -s ../../../etc/postfix/postfix-files $(DSTROOT)/usr/libexec/postfix/postfix-files
184	install -m 755 $(SRCROOT)/postfix/examples/smtpd-policy/greylist.pl $(DSTROOT)/usr/libexec/postfix
185	install -m 0644 $(SRCROOT)/Postfix.Config/custom_header_checks $(DSTROOT)/private/etc/postfix
186	cd $(DSTROOT)/usr/bin && ln -s ../sbin/sendmail newaliases
187	cd $(DSTROOT)/usr/bin && ln -s ../sbin/sendmail mailq
188	install -m 640 $(SRCROOT)/Postfix.Config/aliases.db $(DSTROOT)/private/etc/aliases.db
189	@echo "***** installing extras complete"
190
191set-defaults :
192	@echo "***** setting default cofig values"
193	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e mail_owner=_postfix
194	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e setgid_group=_postdrop
195	#$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e mydomain_fallback=localhost
196	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e queue_directory=/private/var/spool/postfix
197	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e command_directory=/usr/sbin
198	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e daemon_directory=/usr/libexec/postfix
199	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e sendmail_path=/usr/sbin/sendmail
200	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e newaliases_path=/usr/bin/newaliases
201	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e mailq_path=/usr/bin/mailq
202	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e manpage_directory=/usr/share/man
203	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e sample_directory=/usr/share/doc/postfix/examples
204	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e html_directory=/usr/share/doc/postfix/html
205	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e readme_directory=/usr/share/doc/postfix
206	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e message_size_limit=10485760
207	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e mailbox_size_limit=0
208	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e biff=no
209	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e mynetworks='127.0.0.0/8, [::1]/128'
210	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e smtpd_client_restrictions='permit_mynetworks permit_sasl_authenticated permit'
211	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e recipient_delimiter=+
212	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e tls_random_source=dev:/dev/urandom
213	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e smtpd_tls_ciphers=medium
214	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e inet_protocols=all
215	$(DSTROOT)/usr/sbin/postconf -c $(DSTROOT)/private/etc/postfix -e inet_interfaces=loopback-only
216	@echo "****** setting default cofig values complete"
217
218.PHONY: clean installhdrs installsrc build install pre-install
219