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