forked from CindyJS/CindyJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
135 lines (110 loc) · 3.3 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
all: js_make
$(JS_MAKE)
clean:
$(RM) -r build
.PHONY: all clean
.DELETE_ON_ERROR:
######################################################################
## Download stuff either using curl or wget
######################################################################
CURL=curl
WGET=wget
CURL_CMD=$(shell $(CURL) --version > /dev/null 2>&1 && echo $(CURL) -o)
WGET_CMD=$(shell $(WGET) --version > /dev/null 2>&1 && echo $(WGET) -O)
DOWNLOAD=$(if $(CURL_CMD),$(CURL_CMD),$(if $(WGET_CMD),$(WGET_CMD),$(error curl or wget is required to automatically download required tools)))
######################################################################
## Download Node.js with npm to run ECMAScript tools
######################################################################
NODE_OS:=$(subst Darwin,darwin,$(subst Linux,linux,$(shell uname -s)))
NODE_ARCH:=$(subst x86_64,x64,$(subst i386,x86,$(subst i686,x86,$(shell uname -m))))
NODE_VERSION:=14.17.4
NODE_URLBASE:=http://nodejs.org/dist
NODE_BASENAME:=node-v$(NODE_VERSION)-$(NODE_OS)-$(NODE_ARCH)
NODE_TAR:=$(NODE_BASENAME).tar.gz
NODE_URL:=$(NODE_URLBASE)/v$(NODE_VERSION)/$(NODE_TAR)
ifeq ($(CURDIR),)
CURDIR:=$(shell pwd)
endif
NODE:=node
NPM:=npm
cmd_needed=$(shell $(1) >/dev/null 2>&1 || echo needed)
NODE_NEEDED:=$(call cmd_needed,$(NODE) make/check-node-version.js)
ifeq ($(NODE_NEEDED),needed)
ifeq ($(call cmd_needed,nodejs make/check-node-version.js),)
NODE:=nodejs
NODE_NEEDED:=
endif
endif
NPM_NEEDED:=$(call cmd_needed,$(NPM) -version)
NPM_DOWNLOADED:=download/$(NODE_BASENAME)/bin/npm
NPM_WRAPPER:=
ifneq ($(NODE),node)
NPM_WRAPPER:=build/bin/node
endif
NPM_DEP:=$(if $(NODE_NEEDED)$(NPM_NEEDED),$(NPM_DOWNLOADED),$(NPM_WRAPPER))
NODE_PATH:=PATH=$(if $(NPM_DEP),$(CURDIR)/$(dir $(NPM_DEP)):,)$$PATH
NPM_CMD:=$(if $(NPM_DEP),$(NODE_PATH) npm,$(NPM))
NODE_CMD:=$(if $(NPM_DEP),$(NODE_PATH) node,$(NODE))
JS_MAKE=$(NODE_CMD) make/index.js build=$(build)
download/arch/$(NODE_TAR):
mkdir -p $(@D)
$(DOWNLOAD) $@ $(NODE_URL)
download/$(NODE_BASENAME)/bin/npm: download/arch/$(NODE_TAR)
rm -rf download/$(NODE_BASENAME) download/node
cd download && tar xzf arch/$(NODE_TAR)
test -e $@
touch $@
build/bin/node:
mkdir -p $(@D)
echo '#!/bin/sh' >> $@
echo 'exec $(NODE) "$$@"' >> $@
chmod a+x $@
js_make: $(NPM_DEP)
.PHONY: js_make
######################################################################
## Build different flavors of Cindy.js
######################################################################
# Specify build=release on the command line to run closure compiler
build=release
build/js/Cindy.plain.js: js_make
$(JS_MAKE) plain
build/js/ours.js: js_make
$(JS_MAKE) ours
build/js/exposed.js: js_make
$(JS_MAKE) exposed
build/js/Cindy.closure.js: js_make
$(JS_MAKE) closure
build/js/Cindy.js: js_make
$(JS_MAKE) Cindy.js
######################################################################
## Forward targets to make/index.js
######################################################################
fwdtargets = \
alltests \
beautified \
beautify \
cindy3d \
cindy3d-dbg \
cindygl \
cindygl-dbg \
cindyprint \
cindyleap \
cindyxr \
ComplexCurves \
deploy \
eslint \
forbidden \
jshint \
katex \
live \
nodetest \
proxy \
ref \
soundfonts \
symbolic \
tests \
textattr \
unittests
$(fwdtargets): js_make
$(JS_MAKE) $@
.PHONY: $(fwdtargets)