Merge pull request #512 from galfert/node_binary_fix
[remotestorage.js] / Makefile
1 NODEJS         = node
2 DOC_BIN        = naturaldocs
3 DOC_DIR        = ./doc/code
4 DOC_CONFIG_DIR = ./doc/config
5 DOC_CUSTOM_CSS = custom-1
6 UGLIFY_BIN     = ./node_modules/.bin/uglifyjs
7 SOURCE_DIR     = ./src
8 ASSETS_DIR     = ./assets
9 ASSETS_OUT     = $(SOURCE_DIR)/assets.js
10 DOC_INPUTS     = -i $(SOURCE_DIR)
11 SOURCES        = ${shell find $(SOURCE_DIR) -name "*.js"}
12
13 DEFAULT_COMPONENTS = core widget baseclient caching modules debug legacy googledrive dropbox
14 NOCACHE_COMPONENTS = core widget baseclient modules debug legacy googledrive dropbox
15 NODEJS_COMPONENTS  = core baseclient caching modules legacy nodejs
16
17
18 default: help
19
20 help:
21         @echo "help           - display this text"
22         @echo "all            - build regular, minified AMD and nodejs targets, plus all -nocache targets"
23         @echo "build          - build remotestorage.js"
24         @echo "build-amd      - build remotestorage.js with AMD wrapper"
25         @echo "build-node     - build remotestorage.js suitable for nodejs"
26         @echo "build-nocache  - build remotestorage.js without caching (plus AMD and .min versions of that)"
27         @echo "minify         - minify remotestorage.js -> remotestorage.min.js"
28         @echo "compile-assets - compile $(ASSETS_DIR)/* into $(ASSETS_OUT)"
29         @echo "clean          - remove all builds and editor swapfiles"
30
31
32 all: compile-assets build build-amd minify build-nocache build-node doc
33
34 build-all: all
35 minify: remotestorage.min.js
36 build: remotestorage.js
37 build-amd: remotestorage.amd.js
38 build-node: remotestorage-node.js
39 build-nocache: remotestorage-nocache.js remotestorage-nocache.min.js remotestorage-nocache.amd.js
40 compile-assets: $(ASSETS_OUT)
41
42 .PHONY: help buildserver build-all compile-assets minify build doc clean
43
44 %.min.js: %.js
45 #       uglifyjs $< -o $@ --mangle --wrap --export-all
46         $(UGLIFY_BIN) -o $@ $<
47         mv $@ $@.tmp
48         head -n1 $< > $@
49         cat $@.tmp >> $@
50         rm $@.tmp
51
52 remotestorage.js: $(SOURCES)
53         $(NODEJS) build/do-build.js remotestorage.js $(DEFAULT_COMPONENTS)
54
55 remotestorage.amd.js: $(SOURCES)
56         $(NODEJS) build/do-build.js remotestorage.amd.js --amd $(DEFAULT_COMPONENTS)
57
58 remotestorage-node.js: $(SOURCES)
59         $(NODEJS) build/do-build.js remotestorage-node.js --node $(NODEJS_COMPONENTS)
60
61 # remotestorage.min.js: remotestorage.js
62 #       uglifyjs remotestorage.js -o remotestorage.min.js --mangle --wrap --export-all
63 # ## copy version header from original (uglifyjs strips all comments):
64 #       mv remotestorage.min.js remotestorage.min.js.tmp
65 #       head -n1 remotestorage.js > remotestorage.min.js
66 #       cat remotestorage.min.js.tmp >> remotestorage.min.js
67 #       rm remotestorage.min.js.tmp
68
69 remotestorage-nocache.js: $(SOURCES)
70         $(NODEJS) build/do-build.js $@ $(NOCACHE_COMPONENTS)
71
72 remotestorage-nocache.amd.js: $(SOURCES)
73         $(NODEJS) build/do-build.js $@ --amd $(NOCACHE_COMPONENTS)
74
75 $(ASSETS_OUT): $(ASSETS_DIR)/*
76         $(NODEJS) build/compile-assets.js $(ASSETS_DIR) $(ASSETS_OUT)
77
78 doc:
79         mkdir -p $(DOC_DIR) $(DOC_CONFIG_DIR)
80         $(DOC_BIN) $(DOC_INPUTS) -o html $(DOC_DIR) -p $(DOC_CONFIG_DIR) -s Default $(DOC_CUSTOM_CSS)
81
82 clean:
83         rm -f remotestorage.js remotestorage.min.js remotestorage.amd.js remotestorage-nocache.js remotestorage-nocache.amd.js remotestorage-nocache.min.js ${shell find -name "*~"} ${shell find -name "*.swp"}