summaryrefslogtreecommitdiff
path: root/Makefile.in
blob: a7c785e5cdbeb4472e83c30532d6ec68fe850a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
BIN      := @BIN@
LIB      := @LIB@
INCLUDE  := @INCLUDE@
SITELISP := @SITELISP@

LIB_UR   := $(LIB)/ur
LIB_C    := $(LIB)/c
LIB_JS   := $(LIB)/js

LD_MAJOR := 1
LD_MINOR := 0

all: smlnj mlton c

.PHONY: all smlnj mlton c clean install package

smlnj: src/urweb.cm
mlton: bin/urweb

OBJS := memmem mhash urweb request queue http cgi fastcgi
SOS  := urweb urweb_http urweb_cgi urweb_fastcgi
c: $(OBJS:%=lib/c/%.o) $(SOS:%=lib/c/lib%.so.$(LD_MAJOR).$(LD_MINOR))

clean:
	rm -f src/*.mlton.grm.* src/*.mlton.lex.* \
		src/urweb.cm src/urweb.mlb \
		lib/c/*.o lib/c/*.so.*
	rm -rf .cm src/.cm

lib/c/%.do: src/c/%.c include/*.h
	gcc -fPIC -Wimplicit -O3 -I include -c $< -o $@ $(CFLAGS)

lib/c/%.o: src/c/%.c include/*.h
	gcc -Wimplicit -O3 -I include -c $< -o $@ $(CFLAGS)

URWEB_OS := memmem urweb queue request mhash
lib/c/liburweb.so.$(LD_MAJOR).$(LD_MINOR): $(URWEB_OS:%=lib/c/%.do)
	gcc -shared -Wl,-soname,liburweb.so.$(LD_MAJOR) -o $@ $^

lib/c/liburweb_%.so.$(LD_MAJOR).$(LD_MINOR): lib/c/%.do
	gcc -shared -Wl,-soname,liburweb_$*.so.$(LD_MAJOR) -o $@ $^

src/urweb.cm: src/prefix.cm src/sources
	cat src/prefix.cm src/sources \
	>src/urweb.cm

src/urweb.mlb: src/prefix.mlb src/sources src/suffix.mlb
	cat src/prefix.mlb src/sources src/suffix.mlb \
	| sed 's/^\(.*\).grm$$/\1.mlton.grm.sig:\1.mlton.grm.sml/; y/:/\n/' \
	| sed 's/^\(.*\).lex$$/\1.mlton.lex.sml/' \
	>$@

%.mlton.lex: %.lex
	cp $< $@
%.mlton.grm: %.grm
	cp $< $@

%.mlton.lex.sml: %.mlton.lex
	mllex $<

%.mlton.grm.sig %.mlton.grm.sml: %.mlton.grm
	mlyacc $<

MLTON := mlton

ifdef DEBUG
	MLTON += -const 'Exn.keepHistory true'
endif

ifdef PROFILE
	MLTON += -profile $(PROFILE)
endif

bin/urweb: src/compiler.mlb src/urweb.mlb src/*.sig src/*.sml \
		src/urweb.mlton.lex.sml \
		src/urweb.mlton.grm.sig src/urweb.mlton.grm.sml
	$(MLTON) -output $@ src/compiler.mlb

install:
	mkdir -p $(BIN)
	cp bin/urweb $(BIN)/
	mkdir -p $(LIB_UR)
	cp lib/ur/*.urs $(LIB_UR)/
	cp lib/ur/*.ur $(LIB_UR)/
	mkdir -p $(LIB_C)
	cp lib/c/*.o $(LIB_C)/
	cp lib/c/*.so.$(LD_MAJOR).$(LD_MINOR) $(LIB)/..
	mkdir -p $(LIB_JS)
	cp lib/js/*.js $(LIB_JS)/
	mkdir -p $(INCLUDE)
	cp include/*.h $(INCLUDE)/
	mkdir -p $(SITELISP)
	cp src/elisp/*.el $(SITELISP)/
	ln -sf liburweb.so.$(LD_MAJOR) $(LIB)/../liburweb.so
	ln -sf liburweb_http.so.$(LD_MAJOR) $(LIB)/../liburweb_http.so
	ln -sf liburweb_cgi.so.$(LD_MAJOR) $(LIB)/../liburweb_cgi.so
	ln -sf /liburweb_fastcgi.so.$(LD_MAJOR) $(LIB)/../liburweb_fastcgi.so
	ldconfig

package:
	hg archive -t tgz -X tests /tmp/urweb.tgz