Slave.run: run a command using Unix.execute
[hcoop/domtool2.git] / Makefile
1 # Supported flags
2 # BUILD32=1 Target 32-bit x86 (Doesn't Work)
3 # TC=1 Stop after typchecking when building using mlton
4 # DEBUG=1 Keep debugging information when building using mlton
5
6 all: mlton bin/vmailpasswd elisp/domtool-tables.el
7
8 bin/vmailpasswd: src/mail/vmailpasswd.c
9 $(CC) $(CFLAGS) -lcrypt -o $@ $<
10
11 ifeq ($(BUILD32), 1)
12 CFLAGS += -m32
13 endif
14
15 COMMON_DEPS := configDefault/config.sig configDefault/configDefault.sml \
16 openssl/openssl_sml.so pcre/pcre_sml.so config.sml
17
18 EMACS_DIR := /usr/local/share/emacs/site-lisp/domtool-mode
19
20 clean:
21 rm -f bin/*
22 rm -f openssl/openssl_sml.so
23 rm -f openssl/openssl_sml.o
24 rm -f pcre/pcre_sml.so
25 rm -f pcre/pcre_sml.o
26
27 config.sml:
28 /bin/echo -e 'structure Config :> CONFIG = struct\nopen ConfigDefault\nend' > $@
29
30 .PHONY: all mlton smlnj install install_sos
31
32 mlton: bin/domtool-server bin/domtool-client bin/domtool-slave \
33 bin/domtool-admin bin/domtool-doc bin/dbtool bin/vmail \
34 bin/smtplog bin/setsa bin/mysql-fixperms bin/webbw bin/domtool-tail \
35 bin/fwtool bin/domtool-config
36
37 smlnj: $(COMMON_DEPS) openssl/smlnj/FFI/libssl.h.cm pcre/smlnj/FFI/libpcre.h.cm \
38 src/domtool.cm
39 CFLAGS += -m32
40
41 configDefault/config.sig: config/core/core.sig src/config.sig.header \
42 configDefault/*.csg configDefault/*.cfs \
43 src/config.sig.footer
44 cat configDefault/*.csg \
45 src/config.sig.header \
46 configDefault/*.cfs \
47 src/config.sig.footer \
48 >configDefault/config.sig
49
50 configDefault/configDefault.sml: config/core/core.sml src/configDefault.sml.header \
51 configDefault/*.cfg src/configDefault.sml.footer
52 cat src/configDefault.sml.header \
53 configDefault/*.cfg \
54 src/configDefault.sml.footer \
55 >configDefault/configDefault.sml
56
57 openssl/openssl_sml.o: openssl/openssl_sml.c
58 gcc $(CFLAGS) -fPIC -c openssl/openssl_sml.c -o openssl/openssl_sml.o
59
60 openssl/openssl_sml.so: openssl/openssl_sml.o
61 gcc $(CFLAGS) -shared -Wl,-soname,openssl_sml.so \
62 -o openssl/openssl_sml.so \
63 openssl/openssl_sml.o -lssl
64
65 pcre/pcre_sml.o: pcre/pcre_sml.c
66 gcc $(CFLAGS) -fPIC -c pcre/pcre_sml.c -o pcre/pcre_sml.o
67
68 pcre/pcre_sml.so: pcre/pcre_sml.o
69 gcc $(CFLAGS) -shared -Wl,-soname,pcre_sml.so \
70 -o pcre/pcre_sml.so \
71 pcre/pcre_sml.o -lpcre
72
73 src/domtool.cm: src/prefix.cm src/sources
74 cat src/prefix.cm src/sources >src/domtool.cm
75
76 MAKE_MLB_BASE := cat src/prefix.mlb src/sources src/suffix.mlb \
77 | sed 's/^\(.*\).grm$$/\1.grm.sig\n\1.grm.sml/' \
78 | sed 's/^\(.*\).lex$$/\1.lex.sml/'
79
80 src/domtool-server.mlb: src/prefix.mlb src/sources src/suffix.mlb
81 $(MAKE_MLB_BASE) >src/domtool-server.mlb
82 echo "main-server.sml" >>src/domtool-server.mlb
83
84 src/domtool-client.mlb: src/prefix.mlb src/sources src/suffix.mlb
85 $(MAKE_MLB_BASE) >src/domtool-client.mlb
86 echo "main-client.sml" >>src/domtool-client.mlb
87
88 src/domtool-slave.mlb: src/prefix.mlb src/sources src/suffix.mlb
89 $(MAKE_MLB_BASE) >src/domtool-slave.mlb
90 echo "main-slave.sml" >>src/domtool-slave.mlb
91
92 src/domtool-admin.mlb: src/prefix.mlb src/sources src/suffix.mlb
93 $(MAKE_MLB_BASE) >src/domtool-admin.mlb
94 echo "main-admin.sml" >>src/domtool-admin.mlb
95
96 src/domtool-doc.mlb: src/prefix.mlb src/sources src/suffix.mlb
97 $(MAKE_MLB_BASE) >src/domtool-doc.mlb
98 echo "main-doc.sml" >>src/domtool-doc.mlb
99
100 src/dbtool.mlb: src/prefix.mlb src/sources src/suffix.mlb
101 $(MAKE_MLB_BASE) >src/dbtool.mlb
102 echo "main-dbtool.sml" >>src/dbtool.mlb
103
104 src/vmail.mlb: src/prefix.mlb src/sources src/suffix.mlb
105 $(MAKE_MLB_BASE) >src/vmail.mlb
106 echo "main-vmail.sml" >>src/vmail.mlb
107
108 src/setsa.mlb: src/prefix.mlb src/sources src/suffix.mlb
109 $(MAKE_MLB_BASE) >src/setsa.mlb
110 echo "main-setsa.sml" >>src/setsa.mlb
111
112 src/smtplog.mlb: src/prefix.mlb src/sources src/suffix.mlb
113 $(MAKE_MLB_BASE) >src/smtplog.mlb
114 echo "main-smtplog.sml" >>src/smtplog.mlb
115
116 src/mysql-fixperms.mlb: src/prefix.mlb src/sources src/suffix.mlb
117 $(MAKE_MLB_BASE) >src/mysql-fixperms.mlb
118 echo "main-mysql-fixperms.sml" >>src/mysql-fixperms.mlb
119
120 src/fwtool.mlb: src/prefix.mlb src/sources src/suffix.mlb
121 $(MAKE_MLB_BASE) >src/fwtool.mlb
122 echo "main-fwtool.sml" >>src/fwtool.mlb
123
124 src/domtool-config.mlb: src/prefix.mlb src/sources src/suffix.mlb
125 $(MAKE_MLB_BASE) >src/domtool-config.mlb
126 echo "main-config.sml" >>src/domtool-config.mlb
127
128 openssl/smlnj/FFI/libssl.h.cm: openssl/openssl_sml.h
129 cd openssl/smlnj ; ml-nlffigen -d FFI -lh LibsslH.libh -include ../libssl-h.sml \
130 -cm libssl.h.cm -D__builtin_va_list="void*" \
131 ../openssl_sml.h
132
133 openssl/mlton/FFI/libssl.h.mlb: openssl/openssl_sml.h
134 cd openssl/mlton ; mlnlffigen -dir FFI -libhandle LibsslH.libh -include ../libssl-h.sml \
135 -mlbfile libssl.h.mlb -cppopt -D__builtin_va_list="void*" \
136 ../openssl_sml.h
137
138 pcre/smlnj/FFI/libpcre.h.cm: pcre/pcre_sml.h
139 cd pcre/smlnj ; ml-nlffigen -d FFI -lh LibpcreH.libh -include ../libpcre-h.sml \
140 -cm libpcre.h.cm -D__builtin_va_list="void*" \
141 ../pcre_sml.h
142
143 pcre/mlton/FFI/libpcre.h.mlb: pcre/pcre_sml.h
144 cd pcre/mlton ; mlnlffigen -dir FFI -libhandle LibpcreH.libh -include ../libpcre-h.sml \
145 -mlbfile libpcre.h.mlb -cppopt -D__builtin_va_list="void*" \
146 ../pcre_sml.h
147
148 %.lex.sml: %.lex
149 mllex $<
150
151 %.grm.sig %.grm.sml: %.grm
152 mlyacc $<
153
154 COMMON_MLTON_DEPS := openssl/mlton/FFI/libssl.h.mlb \
155 pcre/mlton/FFI/libpcre.h.mlb \
156 src/domtool.lex.sml \
157 src/domtool.grm.sig src/domtool.grm.sml \
158 $(COMMON_DEPS) src/*.sig src/*.sml \
159 src/plugins/*.sig src/plugins/*.sml \
160 src/mail/*.sig src/mail/*.sml
161
162 MLTON := mlton -link-opt -ldl
163
164 ifeq ($(BUILD32),1)
165 MLTON += -codegen c -target i386 -cc-opt -m32
166 endif
167
168 ifeq ($(DEBUG), 1)
169 MLTON += -const 'Exn.keepHistory true'
170 endif
171
172 ifeq ($(TC), 1)
173 MLTON += -stop tc
174 endif
175
176 bin/domtool-server: $(COMMON_MLTON_DEPS) src/domtool-server.mlb
177 $(MLTON) -output bin/domtool-server src/domtool-server.mlb
178
179 bin/domtool-client: $(COMMON_MLTON_DEPS) src/domtool-client.mlb
180 $(MLTON) -output bin/domtool-client src/domtool-client.mlb
181
182 bin/domtool-slave: $(COMMON_MLTON_DEPS) src/domtool-slave.mlb
183 $(MLTON) -output bin/domtool-slave src/domtool-slave.mlb
184
185 bin/domtool-admin: $(COMMON_MLTON_DEPS) src/domtool-admin.mlb
186 $(MLTON) -output bin/domtool-admin src/domtool-admin.mlb
187
188 bin/domtool-doc: $(COMMON_MLTON_DEPS) src/domtool-doc.mlb
189 $(MLTON) -output bin/domtool-doc src/domtool-doc.mlb
190
191 bin/dbtool: $(COMMON_MLTON_DEPS) src/dbtool.mlb
192 $(MLTON) -output bin/dbtool src/dbtool.mlb
193
194 bin/vmail: $(COMMON_MLTON_DEPS) src/vmail.mlb
195 $(MLTON) -output bin/vmail src/vmail.mlb
196
197 bin/setsa: $(COMMON_MLTON_DEPS) src/setsa.mlb
198 $(MLTON) -output bin/setsa src/setsa.mlb
199
200 bin/smtplog: $(COMMON_MLTON_DEPS) src/smtplog.mlb
201 $(MLTON) -output bin/smtplog src/smtplog.mlb
202
203 bin/mysql-fixperms: $(COMMON_MLTON_DEPS) src/mysql-fixperms.mlb
204 $(MLTON) -output bin/mysql-fixperms src/mysql-fixperms.mlb
205
206 bin/fwtool: $(COMMON_MLTON_DEPS) src/fwtool.mlb
207 $(MLTON) -output bin/fwtool src/fwtool.mlb
208
209 bin/webbw: $(COMMON_MLTON_DEPS) src/stats/webbw.mlb src/stats/*.sml
210 mlton -output bin/webbw src/stats/webbw.mlb
211
212 bin/domtool-tail: $(COMMON_MLTON_DEPS) src/tail/tail.mlb src/tail/*.sml
213 mlton -output bin/domtool-tail src/tail/tail.mlb
214
215 bin/domtool-config: $(COMMON_MLTON_DEPS) src/domtool-config.mlb src/main-config.sml
216 $(MLTON) -output bin/domtool-config src/domtool-config.mlb
217
218 elisp/domtool-tables.el: lib/*.dtl bin/domtool-doc
219 bin/domtool-doc -basis -emacs >$@
220
221 install_sos:
222 cp openssl/openssl_sml.so /usr/local/lib/
223 cp pcre/pcre_sml.so /usr/local/lib/
224
225 install: install_sos
226 cp scripts/domtool-publish /usr/local/sbin/
227 cp scripts/domtool-reset-global /usr/local/sbin/
228 cp scripts/domtool-reset-local /usr/local/sbin/
229 cp scripts/domtool-adduser /usr/local/bin/
230 cp scripts/domtool-addcert /usr/local/bin/
231 cp scripts/domtool-readdcerts /usr/local/bin/
232 cp scripts/domtool-addacl /usr/local/bin/
233 cp scripts/domtool-rmuser /usr/local/bin/
234 cp scripts/domtool-admin-sudo /usr/local/bin/
235 cp scripts/domtool-server-logged /usr/local/bin/
236 cp scripts/domtool-slave-logged /usr/local/bin/
237 cp scripts/domtool-server /etc/init.d/
238 cp scripts/domtool-slave /etc/init.d/
239 -cp bin/domtool-server /usr/local/sbin/
240 -cp bin/domtool-slave /usr/local/sbin/
241 -cp bin/domtool-client /usr/local/bin/domtool
242 -cp bin/domtool-admin /usr/local/bin/
243 -cp bin/domtool-doc /usr/local/bin/
244 -cp bin/dbtool /usr/local/bin/
245 -cp bin/fwtool /usr/local/bin/
246 -cp bin/vmail /usr/local/bin/
247 -cp bin/setsa /usr/local/bin/
248 -cp bin/smtplog /usr/local/bin/
249 -cp bin/mysql-fixperms /usr/local/bin/
250 -cp bin/vmailpasswd /usr/local/bin/
251 -cp bin/webbw /usr/local/sbin/
252 -cp bin/domtool-tail /usr/local/bin/
253 -chmod +s /usr/local/bin/domtool-tail
254 cp bin/domtool-config /usr/local/bin/
255 cp src/plugins/domtool-postgres /usr/local/sbin/
256 cp src/plugins/domtool-mysql /usr/local/sbin/
257 -mkdir -p $(EMACS_DIR)
258 cp elisp/*.el $(EMACS_DIR)/
259
260 .PHONY: grab_lib install_server install_slave
261
262 grab_lib:
263 rsync -r --delete /afs/hcoop.net/common/etc/domtool/lib/* lib/
264
265 install_serverslave:
266 /etc/init.d/domtool-server stop
267 /etc/init.d/domtool-slave stop
268 make install
269 /etc/init.d/domtool-server start
270 /etc/init.d/domtool-slave start
271
272 install_server:
273 /etc/init.d/domtool-server stop
274 make install
275 /etc/init.d/domtool-server start
276
277 install_slave:
278 /etc/init.d/domtool-slave stop
279 make install
280 /etc/init.d/domtool-slave start