]> git.cworth.org Git - lmno.games/blob - Makefile
Delay the "Connection lost" message by a second
[lmno.games] / Makefile
1 DEPLOY_HOST=lmno.games
2 DEPLOY_DIR=/srv/lmno.games/www
3 DO_NOT_DEPLOY=Makefile deps *.jsx .babelrc .gitignore README
4 DO_NOT_DELETE=flempires
5
6 REACT_DEPS=react.js react-dom.js
7 REACT_DOWNLOADS=\
8   deps/react.development.js \
9   deps/react-dom.development.js \
10   deps/react.production.min.js \
11   deps/react-dom.production.min.js
12
13 JSX_SOURCE=$(wildcard */*.jsx)
14 JS_TARGETS=$(JSX_SOURCE:.jsx=.js)
15
16 all: $(JS_TARGETS) $(REACT_DEPS)
17
18 # Execute either of the following to build things:
19 #
20 #    For a development build:
21 #
22 #       make
23 #
24 #    For a production build:
25 #
26 #       make LMNO_BUILD=production
27 #
28 # Note: To switch between these two, either issue a "make clean"
29 #       or otherwise start in a clean source tree (such as a
30 #       after a fresh "git clone" or use "git clean -f -x -d).
31 #
32 CP=cp
33 BABEL=babeljs
34 ifeq ($(LMNO_BUILD),production)
35 react.js: deps/react.production.min.js
36         $(call quiet,CP) $^ $@
37
38 react-dom.js: deps/react-dom.production.min.js
39         $(call quiet,CP) $^ $@
40
41 export BABEL_ENV=production
42 %.js: %.jsx
43         $(call quiet,BABEL) $^ --out-file $@
44 else
45 react.js: deps/react.development.js
46         $(call quiet,CP) $^ $@
47
48 react-dom.js: deps/react-dom.development.js
49         $(call quiet,CP) $^ $@
50
51 export BABEL_ENV=development
52 %.js: %.jsx
53         $(call quiet,BABEL) $^ --out-file $@
54 endif
55
56 # The user has not set any verbosity, default to quiet mode and inform the
57 # user how to enable verbose compiles.
58 ifeq ($(V),)
59 quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
60 quiet = @printf $(quiet_DOC)$(eval quiet_DOC:=)"$(1) $(or $(2),$@)\n"; $($(word 1, $(1)))
61 WGET_VERBOSE_FLAGS=--quiet
62 endif
63 # The user has explicitly enabled quiet compilation.
64 ifeq ($(V),0)
65 quiet = @printf "$(1) $(or $(2),$@)\n"; $($(word 1, $(1)))
66 WGET_VERBOSE_FLAGS=--quiet
67 endif
68 # Otherwise, print the full command line.
69 quiet ?= $($(word 1, $(1)))
70 WGET_VERBOSE_FLAGS ?= --no-verbose
71
72 SHA512=sha512sum --strict -c
73 .PHONY: deps
74 deps: $(REACT_DOWNLOADS)
75         $(call quiet,SHA512) deps/*.sha512
76
77 DOWNLOAD=wget $(WGET_VERBOSE_FLAGS) -nc -P deps
78 deps/react.%.js:
79         $(call quiet,DOWNLOAD) https://unpkg.com/react@16/umd/$(@:deps/%=%)
80         $(call quiet,SHA512) $(@:%=%.sha512)
81
82 deps/react-dom.%.js:
83         $(call quiet,DOWNLOAD) https://unpkg.com/react-dom@16/umd/$(@:deps/%=%)
84         $(call quiet,SHA512) $(@:%=%.sha512)
85
86 deploy:
87         rm -rf .deploy-source
88         git clone . .deploy-source
89         cp deps/*.js .deploy-source/deps
90         make -C .deploy-source deps
91         make -C .deploy-source LMNO_BUILD=production
92         rm -rf .deploy-source/.git
93         (cd .deploy-source; rsync -avz \
94                 $(DO_NOT_DEPLOY:%=--exclude=%) \
95                 --exclude=$(DO_NOT_DELETE) \
96                 --delete \
97                 --delete-after \
98                 ./ $(DEPLOY_HOST):$(DEPLOY_DIR) )
99         rm -rf .deploy-source
100
101 clean:
102         rm -f $(JS_TARGETS)
103         rm -f $(REACT_DEPS)
104         rm -f deps/*.js