]> git.cworth.org Git - lmno.games/blob - Makefile
tictactoe: Integrate the standard LMNO styling
[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         @chmod a-w $@
45 else
46 react.js: deps/react.development.js
47         $(call quiet,CP) $^ $@
48
49 react-dom.js: deps/react-dom.development.js
50         $(call quiet,CP) $^ $@
51
52 export BABEL_ENV=development
53 %.js: %.jsx
54         $(call quiet,BABEL) $^ --out-file $@
55         @chmod a-w $@
56 endif
57
58 # The user has not set any verbosity, default to quiet mode and inform the
59 # user how to enable verbose compiles.
60 ifeq ($(V),)
61 quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
62 quiet = @printf $(quiet_DOC)$(eval quiet_DOC:=)"$(1) $(or $(2),$@)\n"; $($(word 1, $(1)))
63 WGET_VERBOSE_FLAGS=--quiet
64 endif
65 # The user has explicitly enabled quiet compilation.
66 ifeq ($(V),0)
67 quiet = @printf "$(1) $(or $(2),$@)\n"; $($(word 1, $(1)))
68 WGET_VERBOSE_FLAGS=--quiet
69 endif
70 # Otherwise, print the full command line.
71 quiet ?= $($(word 1, $(1)))
72 WGET_VERBOSE_FLAGS ?= --no-verbose
73
74 SHA512=sha512sum --strict -c
75 .PHONY: deps
76 deps: $(REACT_DOWNLOADS)
77         $(call quiet,SHA512) deps/*.sha512
78
79 DOWNLOAD=wget $(WGET_VERBOSE_FLAGS) -nc -P deps
80 deps/%.js:
81         $(call quiet,DOWNLOAD) https://unpkg.com/react@16/umd/$@
82         $(call quiet,SHA512) $(patsubst %,%.sha512,$@)
83
84 deploy:
85         rm -rf .deploy-source
86         git clone . .deploy-source
87         cp deps/*.js .deploy-source/deps
88         make -C .deploy-source deps
89         make -C .deploy-source LMNO_BUILD=production
90         rm -rf .deploy-source/.git
91         (cd .deploy-source; rsync -avz \
92                 $(DO_NOT_DEPLOY:%=--exclude=%) \
93                 --exclude=$(DO_NOT_DELETE) \
94                 --delete \
95                 --delete-after \
96                 ./ $(DEPLOY_HOST):$(DEPLOY_DIR) )
97         rm -rf .deploy-source
98
99 clean:
100         rm -f $(JS_TARGETS)
101         rm -f $(REACT_DEPS)
102         rm -f deps/*.js