-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
82 lines (66 loc) · 2.69 KB
/
Makefile
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
# If you're reading this, please contact Sebastiaan Joosten
# Reason: this script was made for a single setup
# it is probably not suitable for your machine
# remainder of these comments are for my future self
# Idea: check where this makefile is run
# if on server, install cgi
# if local, sync with server and call 'make' on server
# directory that must exist server-side only (for establishing that we are on the server)
homedir = /home/sjoosten/
# directory that must exist developer-side only (for establishing that we are on the developer code)
devdir = /Users/sjc/
# server address from the client side
server = [email protected]
# remaining directories are server side:
# installation directory for cgi scripts
installdir = $(homedir)public_html/cs30/
maincgi = $(installdir)cs30.cgi
srcdir = cgi/
staticdir = static/
mainhs = $(srcdir)CGI.hs
datadir = $(homedir)cs30data/ # a writable directory
hidir = .tmp
choose : $(homedir) $(devdir)
$(devdir) :
@echo "We may be running on server, attempt cgi script install"
@$(MAKE) all
$(homedir) :
@echo "We may be running on dev machine, attempt sync"
@$(MAKE) sync
all : checkserver cgi dir
.PHONY : checkdev sync
# run a check to ensure we're on the dev machine
checkdev :
@test -e $(devdir) || (echo "This makefile is intended to help Sebastiaan install his software on a server, you should call 'stack' directly instead, per the README instructions" && exit 1)
# run a check to ensure we're on the server
checkserver :
@test -e $(homedir)
sync : checkdev
@echo "Synchronising code with server:"
rsync -varz --exclude=".?*" --exclude="data" --exclude="dist*" --exclude="cs30.cabal" --delete-after . $(server):cs30
@echo "\nBuilding code server-side:"
ssh -t $(server) "cd cs30/&&make all"
# directory structure
dir : checkserver $(installdir) $(hidir)
# cgi executables
cgi : $(maincgi)
$(hidir) :
mkdir -p $(hidir)
$(datadir) :
mkdir -p $(datadir)
chmod 711 $(datadir)
$(installdir) : $(shell find $(staticdir) -type f -name '*')
mkdir -p $(installdir)
chmod 755 $(installdir)
echo "WARNING: files in this directory are generated automatically and may be overwritten." > $(installdir)WARNING.md
cp -R $(staticdir)* $(installdir)
$(maincgi) : dir $(mainhs) $(datadir)
printf "$(datadir)" > data/dir
@/usr/local/bin/stack build cs30:cs30.cgi --copy-bins --local-bin-path=$(installdir)
@chmod 755 $(maincgi)
# Q: Why is there no make clean?
# I put in absolute paths to install scripts on the server.
# If I allowed 'clean' that removes all created files,
# there would be a chance of taking the server down inadvertently.
# Moreover, there is no safe way to remove the directory itself.
# Deleting $(installdir) should be done manually.