summaryrefslogtreecommitdiff
path: root/Makefile
blob: 98c892761fe4750d8a83e1dec86979f8d198ce29 (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
# Makefile for 6.945
# Copyright (C) 2013  Benjamin Barenblat <bbaren@mit.edu>
#
# This file is a part of 6.947.
#
# 6.947 is is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# 6.947 is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with 6.947.  If not, see <http://www.gnu.org/licenses/>.

# This Makefile is intended to build a CGI executable for use on the MIT SIPB's
# Scripts service.  Attempting to build elsewhere will require modifications.


################################ Configuration ################################

UR = urweb
URFLAGS = -protocol cgi -static

PROJECT = site
PROJECTFLAGS =


################################### Utility ###################################

# Verbosity controls
ifeq ($(V),1)
at =
ech = @true
else
ech = @echo
at = @
endif

project_structures = $(addsuffix .ur, \
	$(shell if grep --silent '^$$' $(1).urp; \
		then sed '1,/^$$/d' $(1).urp; \
		else cat $(1).urp; fi))
project_signatures = $(addsuffix .urs, \
	$(shell if grep --silent '^$$' $(1).urp; \
		then sed '1,/^$$/d' $(1).urp; \
		else cat $(1).urp; fi))
project_deps = $(call project_signatures,$(1)) $(call project_structures,$(1))


################################### Targets ###################################

all:	$(PROJECT).exe

$(PROJECT).exe: $(PROJECT).urp $(call project_deps,$(PROJECT))
	$(ech) "  URWEB $@"
	$(at)$(UR) $(URFLAGS) $(PROJECT)

clean:
	$(ech) "  RM    $(PROJECT).exe"
	$(at)$(RM) $(PROJECT).exe


serve:	$(PROJECT).exe
	$(ech) "  EXEC  $(PROJECT).exe"
	$(at)./$(PROJECT).exe $(PROJECTFLAGS)

# Normally, we'd use inotify for this, but AFS doesn't like inotify, so we get
# to use this nasty hack.
cont:	continual
continual: $(PROJECT).exe
	@while true; do \
		sums=$$(sha256sum $(PROJECT).urp $(call project_deps,$(PROJECT))); \
		$(MAKE) --no-print-directory all V=$(V); \
		newsums=$$(sha256sum $(PROJECT).urp $(call project_deps,$(PROJECT))); \
		while [ "$$sums" = "$$newsums" ]; do \
			sleep 1; \
			newsums=$$(sha256sum $(PROJECT).urp $(call project_deps,$(PROJECT))); \
		done; \
	done


.PHONY:	all clean cont continual serve