UNPKG

10.7 kBPlain TextView Raw
1OS := $(shell uname)
2BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
3
4SRC_GLSL := $(shell find src -type f -name '*.glsl')
5SRC_SHADER_JS := $(patsubst %shader.glsl,%shader.js,$(SRC_GLSL))
6SRC_JS := $(filter-out $(SRC_SHADER_JS),$(shell find src -name '*.js'))
7SRC_JSDOC = $(shell find src -type f -name '*.jsdoc')
8
9SPEC_JS := $(shell find test/spec -type f -name '*.js')
10SPEC_RENDERING_JS := $(shell find test_rendering/spec -name '*.js')
11
12EXAMPLES := $(shell find examples -type f)
13EXAMPLES_HTML := $(filter-out examples/index.html,$(shell find examples -maxdepth 1 -type f -name '*.html'))
14EXAMPLES_JS := $(patsubst %.html,%.js,$(EXAMPLES_HTML))
15
16BUILD_EXAMPLES := $(subst examples,build/examples,$(EXAMPLES)) build/examples/index.js
17
18BUILD_HOSTED := build/hosted/$(BRANCH)
19BUILD_HOSTED_EXAMPLES := $(addprefix $(BUILD_HOSTED)/,$(EXAMPLES))
20BUILD_HOSTED_EXAMPLES_JS := $(addprefix $(BUILD_HOSTED)/,$(EXAMPLES_JS))
21
22UNPHANTOMABLE_EXAMPLES = examples/shaded-relief.html examples/raster.html examples/region-growing.html examples/color-manipulation.html
23CHECK_EXAMPLE_TIMESTAMPS = $(patsubst examples/%.html,build/timestamps/check-%-timestamp,$(filter-out $(UNPHANTOMABLE_EXAMPLES),$(EXAMPLES_HTML)))
24
25TASKS_JS := $(shell find tasks -name '*.js')
26
27ifeq (CYGWIN,$(findstring CYGWIN,$(OS)))
28 CLOSURE_LIB = $(shell cygpath -u $(shell node -e 'process.stdout.write(require("closure-util").getLibraryPath())'))
29else
30 CLOSURE_LIB = $(shell node -e 'process.stdout.write(require("closure-util").getLibraryPath())')
31endif
32
33ifeq ($(OS),Darwin)
34 STAT_COMPRESSED = stat -f ' compressed: %z bytes'
35 STAT_UNCOMPRESSED = stat -f 'uncompressed: %z bytes'
36else
37 STAT_COMPRESSED = stat -c ' compressed: %s bytes'
38 STAT_UNCOMPRESSED = stat -c 'uncompressed: %s bytes'
39endif
40
41.PHONY: default
42default: help
43
44.PHONY: help
45help:
46 @echo
47 @echo "The most common targets are:"
48 @echo
49 @echo "- install Install node dependencies"
50 @echo "- serve Start dev server for running examples and tests"
51 @echo "- test Run unit tests in the console"
52 @echo "- check Perform a number of checks on the code"
53 @echo "- clean Remove generated files"
54 @echo "- help Display this help message"
55 @echo
56 @echo "Other less frequently used targets are:"
57 @echo
58 @echo "- build Build ol.js, ol-debug.js, ol.js.map and ol.css"
59 @echo "- lint Check the code with the linter"
60 @echo "- ci Run the full continuous integration process"
61 @echo "- apidoc Build the API documentation using JSDoc"
62 @echo "- cleanall Remove all the build artefacts"
63 @echo "- check-deps Check if the required dependencies are installed"
64 @echo
65
66.PHONY: apidoc
67apidoc: build/timestamps/jsdoc-$(BRANCH)-timestamp
68
69.PHONY: build
70build: build/ol.css build/ol.js build/ol-debug.js build/ol.js.map
71
72.PHONY: check
73check: lint build/ol.js test
74
75.PHONY: check-examples
76check-examples: $(CHECK_EXAMPLE_TIMESTAMPS)
77
78.PHONY: check-deps
79check-deps: EXECUTABLES = git node python java
80check-deps:
81 @for exe in $(EXECUTABLES) ;\
82 do \
83 which $${exe} > /dev/null && \
84 echo "Program $${exe} OK" || \
85 echo "Program $${exe} MISSING!" ;\
86 done ;\
87
88.PHONY: ci
89ci: lint build test test-rendering package compile-examples check-examples apidoc
90
91.PHONY: compile-examples
92compile-examples: build/compiled-examples/all.combined.js
93
94.PHONY: clean
95clean:
96 rm -f build/timestamps/eslint-timestamp
97 rm -f build/timestamps/check-*-timestamp
98 rm -f build/ol.css
99 rm -f build/ol.js
100 rm -f build/ol.js.map
101 rm -f build/ol-debug.js
102 rm -f build/test_requires.js
103 rm -f build/test_rendering_requires.js
104 rm -rf build/examples
105 rm -rf build/compiled-examples
106 rm -rf build/package
107 rm -rf $(BUILD_HOSTED)
108
109.PHONY: cleanall
110cleanall:
111 rm -rf build
112
113.PHONY: css
114css: build/ol.css
115
116.PHONY: examples
117examples: $(BUILD_EXAMPLES)
118
119.PHONY: install
120install: build/timestamps/node-modules-timestamp
121
122.PHONY: lint
123lint: build/timestamps/eslint-timestamp
124
125.PHONY: npm-install
126npm-install: build/timestamps/node-modules-timestamp
127
128.PHONY: shaders
129shaders: $(SRC_SHADER_JS)
130
131.PHONY: serve
132serve: build/test_requires.js build/test_rendering_requires.js
133 node tasks/serve.js
134
135.PHONY: test
136test: build/timestamps/node-modules-timestamp build/test_requires.js
137 node tasks/test.js
138
139.PHONY: test-coverage
140test-coverage: build/timestamps/node-modules-timestamp
141 node tasks/test-coverage.js
142
143.PHONY: test-rendering
144test-rendering: build/timestamps/node-modules-timestamp \
145 build/test_rendering_requires.js
146 @rm -rf build/slimerjs-profile
147 @mkdir -p build/slimerjs-profile
148 @cp -r test_rendering/slimerjs-profile/* build/slimerjs-profile/
149 node tasks/test-rendering.js
150
151.PHONY: host-examples
152host-examples: $(BUILD_HOSTED_EXAMPLES) \
153 $(BUILD_HOSTED)/build/ol.js \
154 $(BUILD_HOSTED)/build/ol-debug.js \
155 $(BUILD_HOSTED)/css/ol.css \
156 $(BUILD_HOSTED)/examples/loader.js \
157 $(BUILD_HOSTED)/examples/index.js \
158 $(BUILD_HOSTED)/build/ol-deps.js
159
160.PHONY: host-libraries
161host-libraries: build/timestamps/node-modules-timestamp
162 @rm -rf $(BUILD_HOSTED)/closure-library
163 @mkdir -p $(BUILD_HOSTED)/closure-library
164 @cp -r $(CLOSURE_LIB)/* $(BUILD_HOSTED)/closure-library/
165 @rm -rf $(BUILD_HOSTED)/ol/ol
166 @mkdir -p $(BUILD_HOSTED)/ol/ol
167 @cp -r src/ol/* $(BUILD_HOSTED)/ol/ol/
168 @rm -rf $(BUILD_HOSTED)/ol.ext
169 @mkdir -p $(BUILD_HOSTED)/ol.ext
170 @cp -r build/ol.ext/* $(BUILD_HOSTED)/ol.ext/
171
172$(BUILD_EXAMPLES): $(EXAMPLES) package.json
173 @mkdir -p $(@D)
174 @node tasks/build-examples.js
175
176build/timestamps/check-%-timestamp: $(BUILD_HOSTED)/examples/%.html \
177 $(BUILD_HOSTED)/examples/%.js \
178 $(filter $(BUILD_HOSTED)/examples/resources/%,$(BUILD_HOSTED_EXAMPLES)) \
179 $(filter $(BUILD_HOSTED)/examples/data/%,$(BUILD_HOSTED_EXAMPLES)) \
180 $(BUILD_HOSTED)/examples/loader.js \
181 $(BUILD_HOSTED)/build/ol.js \
182 $(BUILD_HOSTED)/css/ol.css
183 @mkdir -p $(@D)
184 node tasks/check-example.js $<
185 @touch $@
186
187build/compiled-examples/all.js: $(EXAMPLES_JS)
188 @mkdir -p $(@D)
189 @python bin/combine-examples.py $^ > $@
190
191build/compiled-examples/all.combined.js: config/examples-all.json build/compiled-examples/all.js \
192 $(SRC_JS) $(SRC_SHADER_JS) \
193 build/timestamps/node-modules-timestamp
194 @mkdir -p $(@D)
195 node tasks/build.js $< $@
196
197build/compiled-examples/%.json: config/example.json build/examples/%.js \
198 build/timestamps/node-modules-timestamp
199 @mkdir -p $(@D)
200 @sed -e 's|{{id}}|$*|' $< > $@
201
202build/compiled-examples/%.combined.js: build/compiled-examples/%.json \
203 $(SRC_JS) $(SRC_SHADER_JS) \
204 build/timestamps/node-modules-timestamp
205 @mkdir -p $(@D)
206 node tasks/build.js $< $@
207
208build/timestamps/jsdoc-$(BRANCH)-timestamp: config/jsdoc/api/index.md \
209 config/jsdoc/api/conf.json $(SRC_JS) \
210 $(SRC_SHADER_JS) \
211 $(shell find config/jsdoc/api/template -type f) \
212 build/timestamps/node-modules-timestamp
213 @mkdir -p $(@D)
214 @rm -rf $(BUILD_HOSTED)/apidoc
215 ./node_modules/.bin/jsdoc config/jsdoc/api/index.md -c config/jsdoc/api/conf.json --package package.json -d $(BUILD_HOSTED)/apidoc
216 @touch $@
217
218$(BUILD_HOSTED_EXAMPLES_JS): $(BUILD_HOSTED)/examples/%.js: build/examples/%.js
219 @mkdir -p $(@D)
220 @python bin/split-example.py $< $(@D)
221
222$(BUILD_HOSTED)/examples/loader.js: bin/loader_hosted_examples.js
223 @mkdir -p $(@D)
224 @cp $< $@
225
226$(BUILD_HOSTED)/examples/%: build/examples/%
227 @mkdir -p $(@D)
228 @cp $< $@
229
230$(BUILD_HOSTED)/build/ol.js: build/ol.js
231 @mkdir -p $(@D)
232 @cp $< $@
233
234$(BUILD_HOSTED)/build/ol-debug.js: build/ol-debug.js
235 @mkdir -p $(@D)
236 @cp $< $@
237
238$(BUILD_HOSTED)/css/ol.css: build/ol.css
239 @mkdir -p $(@D)
240 @cp $< $@
241
242$(BUILD_HOSTED)/build/ol-deps.js: host-libraries
243 @mkdir -p $(@D)
244 @python $(CLOSURE_LIB)/closure/bin/build/depswriter.py \
245 --root_with_prefix "src ../../../ol" \
246 --root_with_prefix "build/ol.ext ../../../ol.ext" \
247 --root $(BUILD_HOSTED)/closure-library/closure/goog \
248 --root_with_prefix "$(BUILD_HOSTED)/closure-library/third_party ../../third_party" \
249 --output_file $@
250
251build/timestamps/eslint-timestamp: $(SRC_JS) $(SPEC_JS) $(SPEC_RENDERING_JS) \
252 $(TASKS_JS) $(EXAMPLES_JS) \
253 build/timestamps/node-modules-timestamp
254 @mkdir -p $(@D)
255 @echo "Running eslint..."
256 @./node_modules/.bin/eslint tasks test test_rendering src examples
257 @touch $@
258
259build/timestamps/node-modules-timestamp: package.json
260 @mkdir -p $(@D)
261 npm install
262 @touch $@
263
264build/ol.css: css/ol.css build/timestamps/node-modules-timestamp
265 @mkdir -p $(@D)
266 @echo "Running cleancss..."
267 @./node_modules/.bin/cleancss $< > $@
268
269build/ol.js: config/ol.json $(SRC_JS) $(SRC_SHADER_JS) \
270 build/timestamps/node-modules-timestamp
271 @mkdir -p $(@D)
272 node tasks/build.js $< $@
273 @$(STAT_UNCOMPRESSED) $@
274 @cp $@ /tmp/
275 @gzip /tmp/ol.js
276 @$(STAT_COMPRESSED) /tmp/ol.js.gz
277 @rm /tmp/ol.js.gz
278
279build/ol.js.map: config/ol.json $(SRC_JS) $(SRC_SHADER_JS) \
280 build/timestamps/node-modules-timestamp
281 @mkdir -p $(@D)
282 node tasks/build.js $< $@
283
284build/ol-debug.js: config/ol-debug.json $(SRC_JS) $(SRC_SHADER_JS) \
285 build/timestamps/node-modules-timestamp
286 @mkdir -p $(@D)
287 node tasks/build.js $< $@
288 @$(STAT_UNCOMPRESSED) $@
289 @cp $@ /tmp/
290 @gzip /tmp/ol-debug.js
291 @$(STAT_COMPRESSED) /tmp/ol-debug.js.gz
292 @rm /tmp/ol-debug.js.gz
293
294build/test_requires.js: $(SPEC_JS) $(SRC_JS)
295 @mkdir -p $(@D)
296 @node tasks/generate-requires.js $^ > $@
297
298build/test_rendering_requires.js: $(SPEC_RENDERING_JS)
299 @mkdir -p $(@D)
300 @node tasks/generate-requires.js $^ > $@
301
302%shader.js: %shader.glsl src/ol/webgl/shader.mustache bin/pyglslunit.py build/timestamps/node-modules-timestamp
303 @python bin/pyglslunit.py --input $< | ./node_modules/.bin/mustache - src/ol/webgl/shader.mustache > $@
304
305.PHONY: package
306package:
307 @rm -rf build/package
308 @cp -r package build
309 @cd ./src && cp -r ol/* ../build/package
310 @rm build/package/typedefs.js
311 @cp css/ol.css build/package
312 ./node_modules/.bin/jscodeshift --transform transforms/module.js build/package
313 npm run lint-package