]> git.cworth.org Git - lmno.games/blob - Makefile
Makefile: Add support to use babel to compile React code using JSX
[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 ifeq ($(LMNO_BUILD),production)
33 react.js: deps/react.production.min.js
34         cp $^ $@
35
36 react-dom.js: deps/react-dom.production.min.js
37         cp $^ $@
38
39 %.js: %.jsx
40         BABEL_ENV=production babeljs $^ --out-file $@
41 else
42 react.js: deps/react.development.js
43         cp $^ $@
44
45 react-dom.js: deps/react-dom.development.js
46         cp $^ $@
47
48 %.js: %.jsx
49         BABEL_ENV=development babeljs $^ --out-file $@
50 endif
51
52 checksums: $(REACT_DOWNLOADS)
53         sha512sum --strict -c checksums.sha512
54
55 deps/react.development.js:
56         wget -nv -nc -P deps https://unpkg.com/react@16/umd/react.development.js
57
58 deps/react-dom.development.js:
59         wget -nv -nc -P deps https://unpkg.com/react-dom@16/umd/react-dom.development.js
60
61 deps/react.production.min.js:
62         wget -nv -nc -P deps https://unpkg.com/react@16/umd/react.production.min.js
63
64 deps/react-dom.production.min.js:
65         wget -nv -nc -P deps https://unpkg.com/react-dom@16/umd/react-dom.production.min.js
66
67 deploy:
68         rm -rf .deploy-source
69         git clone . .deploy-source
70         make -C .deploy-source LMNO_BUILD=production
71         rm -rf .deploy-source/.git
72         (cd .deploy-source; rsync -avz \
73                 $(DO_NOT_DEPLOY:%=--exclude=%) \
74                 --exclude=$(DO_NOT_DELETE) \
75                 --delete \
76                 --delete-after \
77                 ./ $(DEPLOY_HOST):$(DEPLOY_DIR) )
78         rm -rf .deploy-source
79
80 clean:
81         rm -f $(JS_TARGETS)
82         rm -f $(REACT_DEPS)
83         rm -f $(REACT_DOWNLOADS)