forked from mozilla/pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
331 lines (303 loc) · 10.6 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
REPO = [email protected]:mozilla/pdf.js.git
BUILD_DIR := build
BUILD_TARGET := $(BUILD_DIR)/pdf.js
DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
DEFAULT_TESTS := test_manifest.json
DEFAULT_PYTHON := python2.7
EXTENSION_SRC := ./extensions/
EXTENSION_BASE_VERSION := 4bb289ec499013de66eb421737a4dbb4a9273eda
FIREFOX_EXTENSION_NAME := pdf.js.xpi
FIREFOX_AMO_EXTENSION_NAME := pdf.js.amo.xpi
CHROME_EXTENSION_NAME := pdf.js.crx
all: bundle
# Let folks define custom rules for their clones.
-include local.mk
# JS files needed for pdf.js.
PDF_JS_FILES = \
core.js \
util.js \
canvas.js \
obj.js \
function.js \
charsets.js \
cidmaps.js \
colorspace.js \
crypto.js \
evaluator.js \
fonts.js \
glyphlist.js \
image.js \
metrics.js \
parser.js \
pattern.js \
stream.js \
worker.js \
../external/jpgjs/jpg.js \
jpx.js \
bidi.js \
metadata.js \
$(NULL)
# make server
#
# This target starts a local web server at localhost:8888. This can be
# used for testing all browsers.
server:
@cd test; $(DEFAULT_PYTHON) test.py --port=8888;
# make test
#
# This target runs all the tests excluding the unit-test. This can be used for
# testing all browsers.
test: shell-test browser-test
#
# Create production output (pdf.js, and corresponding changes to web files)
#
production: | bundle
@echo "Preparing web/viewer-production.html"; \
cd web; \
sed '/PDFJSSCRIPT_REMOVE_CORE/d' viewer.html > viewer-1.tmp; \
sed '/PDFJSSCRIPT_INCLUDE_BUILD/ r viewer-snippet.html' viewer-1.tmp > viewer-production.html; \
rm -f *.tmp; \
cd ..
#
# Bundle pdf.js
#
bundle: | $(BUILD_DIR)
@echo "Bundling source files into $(BUILD_TARGET)"
@cd src; \
cat $(PDF_JS_FILES) > all_files.tmp; \
sed '/PDFJSSCRIPT_INCLUDE_ALL/ r all_files.tmp' pdf.js > ../$(BUILD_TARGET); \
sed -i.bak "s/PDFJSSCRIPT_BUNDLE_VER/`git log --format="%h" -n 1`/" ../$(BUILD_TARGET); \
rm -f ../$(BUILD_TARGET).bak; \
rm -f *.tmp; \
cd ..
# make unit-test
#
# This target runs in-browser unit tests with js-test-driver and jasmine unit
# test framework.
unit-test:
@cd test/unit/ ; make ;
# make browser-test
#
# This target runs in-browser tests using two primary arguments: a
# test manifest file, and a browser manifest file. Both are simple
# JSON formats, and examples can be found in the test/ directory. The
# target will inspect the environment for the PDF_TESTS and
# PDF_BROWSERS variables, and use those if found. Otherwise, the
# defaults at the top of this file are used.
ifeq ($(PDF_TESTS),)
PDF_TESTS := $(DEFAULT_TESTS)
endif
ifeq ($(PDF_BROWSERS),)
PDF_BROWSERS := $(DEFAULT_BROWSERS)
endif
browser-test:
@if [ ! -f "test/$(PDF_BROWSERS)" ]; then \
echo "Browser manifest file $(PDF_BROWSERS) does not exist."; \
echo "Try copying one of the examples" \
"in test/resources/browser_manifests/"; \
exit 1; \
fi;
cd test; \
$(DEFAULT_PYTHON) test.py --reftest \
--browserManifestFile=$(PDF_BROWSERS) \
--manifestFile=$(PDF_TESTS)
# # make shell-test
# #
# # This target runs all of the tests that can be run in a JS shell.
# # The shell used is taken from the JS_SHELL environment variable. If
# # that variable is not defined, the script will attempt to use the copy
# # of Rhino that comes with the Closure compiler used for producing the
# # website.
# SHELL_TARGET = $(NULL)
# ifeq ($(JS_SHELL),)
# JS_SHELL := "java -cp $(BUILD_DIR)/compiler.jar"
# JS_SHELL += "com.google.javascript.jscomp.mozilla.rhino.tools.shell.Main"
# SHELL_TARGET = compiler
# endif
#
# shell-test: shell-msg $(SHELL_TARGET) font-test
# shell-msg:
# ifeq ($(SHELL_TARGET), compiler)
# @echo "No JS_SHELL env variable present."
# @echo "The default is to find a copy of Rhino and try that."
# endif
# @echo "JS shell command is: $(JS_SHELL)"
#
# font-test:
# @echo "font test stub."
# make lint
#
# This target runs the Closure Linter on most of our JS files.
# To install gjslint, see:
#
# <http://code.google.com/closure/utilities/docs/linter_howto.html>
SRC_DIRS := src utils web test examples/helloworld extensions/firefox \
extensions/firefox/components extensions/chrome test/unit
GJSLINT_FILES = $(foreach DIR, $(SRC_DIRS), $(wildcard $(DIR)/*.js))
lint:
gjslint --nojsdoc $(GJSLINT_FILES)
# make web
#
# This target produces the website for the project, by checking out
# the gh-pages branch underneath the build directory, and then move
# the various viewer files into place.
#
# TODO: Use the Closure compiler to optimize the pdf.js files.
#
GH_PAGES = $(BUILD_DIR)/gh-pages
web: | production extension compiler pages-repo
@cp $(BUILD_TARGET) $(GH_PAGES)/$(BUILD_TARGET)
@cp -R web/* $(GH_PAGES)/web
@cp web/images/* $(GH_PAGES)/web/images
@cp $(FIREFOX_BUILD_DIR)/$(FIREFOX_EXTENSION_NAME) \
$(FIREFOX_BUILD_DIR)/$(FIREFOX_AMO_EXTENSION_NAME) \
$(FIREFOX_BUILD_DIR)/update.rdf \
$(GH_PAGES)/$(EXTENSION_SRC)/firefox/
@cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html;
@mv -f $(GH_PAGES)/web/viewer-production.html $(GH_PAGES)/web/viewer.html;
@cd $(GH_PAGES); git add -A;
@echo
@echo "Website built in $(GH_PAGES)."
@echo "Don't forget to cd into $(GH_PAGES)/ and issue 'git commit' to push changes."
# make pages-repo
#
# This target clones the gh-pages repo into the build directory. It
# deletes the current contents of the repo, since we overwrite
# everything with data from the master repo. The 'make web' target
# then uses 'git add -A' to track additions, modifications, moves,
# and deletions.
pages-repo: | $(BUILD_DIR)
@if [ ! -d "$(GH_PAGES)" ]; then \
git clone -b gh-pages $(REPO) $(GH_PAGES); \
rm -rf $(GH_PAGES)/*; \
fi;
@mkdir -p $(GH_PAGES)/web;
@mkdir -p $(GH_PAGES)/web/images;
@mkdir -p $(GH_PAGES)/build;
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC)/firefox;
# # make compiler
# #
# # This target downloads the Closure compiler, and places it in the
# # build directory. This target is also useful when the user doesn't
# # have a JS shell available--we can have them use the Rhino shell that
# # comes with Closure.
# COMPILER_URL = http://closure-compiler.googlecode.com/files/compiler-latest.zip
#
# compiler: $(BUILD_DIR)/compiler.zip
# $(BUILD_DIR)/compiler.zip: | $(BUILD_DIR)
# curl $(COMPILER_URL) > $(BUILD_DIR)/compiler.zip;
# cd $(BUILD_DIR); unzip compiler.zip compiler.jar;
# make extension
#
# This target produce a restartless firefox extension containing a
# copy of the pdf.js source.
CONTENT_DIR := content
BUILD_NUMBER := `git log --format=oneline $(EXTENSION_BASE_VERSION).. | wc -l | awk '{print $$1}'`
PDFJSSCRIPT_VERSION := 0.2.$(BUILD_NUMBER)
EXTENSION_WEB_FILES = \
web/images \
web/viewer.css \
web/viewer.js \
web/viewer.html \
web/viewer-production.html \
web/debugger.js \
$(NULL)
FIREFOX_BUILD_DIR := $(BUILD_DIR)/firefox
FIREFOX_BUILD_CONTENT := $(FIREFOX_BUILD_DIR)/$(CONTENT_DIR)/
FIREFOX_CONTENT_DIR := $(EXTENSION_SRC)/firefox/$(CONTENT_DIR)/
FIREFOX_EXTENSION_FILES_TO_COPY = \
*.js \
*.rdf \
*.png \
install.rdf.in \
README.mozilla \
components \
../../LICENSE \
$(NULL)
FIREFOX_EXTENSION_FILES = \
bootstrap.js \
install.rdf \
icon.png \
icon64.png \
components \
content \
LICENSE \
$(NULL)
FIREFOX_MC_EXTENSION_FILES = \
bootstrap.js \
icon.png \
icon64.png \
components \
content \
LICENSE \
$(NULL)
CHROME_BUILD_DIR := $(BUILD_DIR)/chrome
CHROME_CONTENT_DIR := $(EXTENSION_SRC)/chrome/$(CONTENT_DIR)/
CHROME_BUILD_CONTENT := $(CHROME_BUILD_DIR)/$(CONTENT_DIR)/
CHROME_EXTENSION_FILES = \
extensions/chrome/*.json \
extensions/chrome/*.html \
$(NULL)
extension: | production
# Clear out everything in the firefox extension build directory
@rm -Rf $(FIREFOX_BUILD_DIR)
@mkdir -p $(FIREFOX_BUILD_CONTENT)
@mkdir -p $(FIREFOX_BUILD_CONTENT)/$(BUILD_DIR)
@mkdir -p $(FIREFOX_BUILD_CONTENT)/web
@cd extensions/firefox; cp -r $(FIREFOX_EXTENSION_FILES_TO_COPY) ../../$(FIREFOX_BUILD_DIR)/
# Copy a standalone version of pdf.js inside the content directory
@cp $(BUILD_TARGET) $(FIREFOX_BUILD_CONTENT)/$(BUILD_DIR)/
@cp -r $(EXTENSION_WEB_FILES) $(FIREFOX_BUILD_CONTENT)/web/
@rm $(FIREFOX_BUILD_CONTENT)/web/viewer-production.html
# Copy over the firefox extension snippet so we can inline pdf.js in it
@cp web/viewer-snippet-firefox-extension.html $(FIREFOX_BUILD_CONTENT)/web/
# Modify the viewer so it does all the extension only stuff.
@cd $(FIREFOX_BUILD_CONTENT)/web; \
sed -i.bak '/PDFJSSCRIPT_INCLUDE_BUNDLE/ r ../build/pdf.js' viewer-snippet-firefox-extension.html; \
sed -i.bak '/PDFJSSCRIPT_REMOVE_CORE/d' viewer.html; \
sed -i.bak '/PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION/d' viewer.html; \
sed -i.bak '/PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION/ r viewer-snippet-firefox-extension.html' viewer.html; \
rm -f *.bak;
# We don't need pdf.js anymore since its inlined
@rm -Rf $(FIREFOX_BUILD_CONTENT)/$(BUILD_DIR)/;
# Update the build version number
@sed -i.bak "s/PDFJSSCRIPT_VERSION/$(PDFJSSCRIPT_VERSION)/" $(FIREFOX_BUILD_DIR)/install.rdf
@sed -i.bak "s/PDFJSSCRIPT_VERSION/$(PDFJSSCRIPT_VERSION)/" $(FIREFOX_BUILD_DIR)/install.rdf.in
@sed -i.bak "s/PDFJSSCRIPT_VERSION/$(PDFJSSCRIPT_VERSION)/" $(FIREFOX_BUILD_DIR)/update.rdf
@sed -i.bak "s/PDFJSSCRIPT_VERSION/$(PDFJSSCRIPT_VERSION)/" $(FIREFOX_BUILD_DIR)/README.mozilla
@rm -f $(FIREFOX_BUILD_DIR)/*.bak
@find $(FIREFOX_BUILD_DIR) -name ".*" -delete
# Create the xpi
@cd $(FIREFOX_BUILD_DIR); zip -r $(FIREFOX_EXTENSION_NAME) $(FIREFOX_EXTENSION_FILES)
@echo "extension created: " $(FIREFOX_EXTENSION_NAME)
# Build the amo extension too (remove the updateUrl)
@sed -i.bak "/updateURL/d" $(FIREFOX_BUILD_DIR)/install.rdf
@rm -f $(FIREFOX_BUILD_DIR)/*.bak
@cd $(FIREFOX_BUILD_DIR); zip -r $(FIREFOX_AMO_EXTENSION_NAME) $(FIREFOX_EXTENSION_FILES)
@echo "AMO extension created: " $(FIREFOX_AMO_EXTENSION_NAME)
# List all files for mozilla-central
@cd $(FIREFOX_BUILD_DIR); find $(FIREFOX_MC_EXTENSION_FILES) -type f > extension-files
# Clear out everything in the chrome extension build directory
@rm -Rf $(CHROME_BUILD_DIR)
@mkdir -p $(CHROME_BUILD_CONTENT)
@mkdir -p $(CHROME_BUILD_CONTENT)/$(BUILD_DIR)
@mkdir -p $(CHROME_BUILD_CONTENT)/web
@cp -R $(CHROME_EXTENSION_FILES) $(CHROME_BUILD_DIR)/
# Copy a standalone version of pdf.js inside the content directory
@cp $(BUILD_TARGET) $(CHROME_BUILD_CONTENT)/$(BUILD_DIR)/
@cp -r $(EXTENSION_WEB_FILES) $(CHROME_BUILD_CONTENT)/web/
@mv -f $(CHROME_BUILD_CONTENT)/web/viewer-production.html $(CHROME_BUILD_CONTENT)/web/viewer.html
# Create the crx
#TODO
# Make sure there's a build directory.
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)
# make help
#
# This target just prints out a message to read these comments. :)
help:
@echo "Read the comments in the Makefile for guidance.";
.PHONY:: production test browser-test font-test shell-test \
shell-msg lint clean web compiler help server