Update Handlebars
[mkws-moved-to-github.git] / tools / htdocs / Makefile
1 # Copyright (c) 2013-2014 IndexData ApS. http://indexdata.com
2
3 SRC=   ../../src
4
5 HANDLEBARS_FILE = handlebars-v1.3.0.js
6 JQUERY_FILE = jquery-1.10.0.min.js
7 JQUERY_JSON_FILE = jquery.json-2.4.js
8 PP2_FILE = pz2.js
9
10 HANDLEBARS_URL = http://builds.handlebarsjs.com.s3.amazonaws.com/${HANDLEBARS_FILE}
11 JQUERY_URL = http://code.jquery.com/${JQUERY_FILE}
12 JQUERY_JSON_URL = https://jquery-json.googlecode.com/files/${JQUERY_JSON_FILE}
13 PP2_URL = http://git.indexdata.com/?p=pazpar2.git;a=blob_plain;f=js/${PP2_FILE};hb=HEAD
14
15 JQUERY_UI_URL = http://code.jquery.com/ui/1.10.3/jquery-ui.js
16 VERSION = $(shell tr -d '\012' < ${SRC}/VERSION)
17
18 COMPONENTS = ${SRC}/mkws-handlebars.js \
19         ${SRC}/mkws-core.js \
20         ${SRC}/mkws-team.js \
21         ${SRC}/mkws-filter.js \
22         ${SRC}/mkws-templates.js \
23         ${SRC}/mkws-popup.js \
24         ${SRC}/mkws-widget.js \
25         ${SRC}/mkws-widget-main.js \
26         ${SRC}/mkws-widget-termlists.js \
27         ${SRC}/mkws-widget-authname.js \
28         ${SRC}/mkws-widget-categories.js \
29         ${SRC}/mkws-widget-log.js \
30         ${SRC}/mkws-widget-record.js \
31         ${SRC}/mkws-widget-reference.js \
32         ${SRC}/mkws-widget-builder.js
33
34 GENERATED = ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE} \
35         mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js mkws-templates.js
36
37 **make-default**: all
38
39 all: mkws.min.js mkws-complete.min.js
40
41 mkws-js mkws-complete.js: Makefile mkws.js ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE}
42         ( set -e; \
43           echo "/*! Copyright (c) 2013-2014 IndexData ApS. http://indexdata.com"; \
44           echo "   Licence: GPL, http://www.indexdata.com/licences/gpl"; \
45           echo "   created at: $$(date)"; \
46           echo "   MKWS GIT id: $$(git show | head -n 1 | perl -npe 's,\S+\s+,,')"; \
47           echo "   pz2.js GIT id: $$(curl -sSf 'http://git.indexdata.com/?p=pazpar2.git;a=rss' | egrep '<guid' | head -1 | perl -ne 'print "$$1\n" if m,.*=([0-9a-f]+)</guid>,')"; \
48           echo "*/"; \
49           cat ${JQUERY_FILE}; \
50           cat ${JQUERY_JSON_FILE}; \
51           echo 'mkws_jQuery = jQuery.noConflict(true);'; \
52           cat ${HANDLEBARS_FILE}; \
53           cat ${PP2_FILE}; \
54           cat  mkws.js; \
55         ) > mkws-complete.js.tmp
56         mv -f mkws-complete.js.tmp mkws-complete.js
57
58 %.min.js: %.js
59         yui-compressor $? > $@.tmp
60         mv -f $@.tmp $@
61
62 mkws-syntax-check:
63         yui-compressor mkws.js >/dev/null
64
65 ${HANDLEBARS_FILE}:
66         curl -sSf ${HANDLEBARS_URL} -o $@.tmp
67         mv -f $@.tmp $@
68
69 ${JQUERY_FILE}:
70         curl -sSf ${JQUERY_URL} -o $@.tmp
71         perl -npe 's,sourceMappingURL=jquery.*map,,' $@.tmp > $@
72         rm -f $@.tmp
73
74 ${JQUERY_JSON_FILE}:
75         curl -sSf ${JQUERY_JSON_URL} -o $@.tmp
76         mv -f $@.tmp $@
77
78 ${PP2_FILE}:
79         curl -sSf "${PP2_URL}" -o $@.tmp
80         mv -f $@.tmp $@
81
82 release: mkws.js mkws-complete.js mkws.min.js mkws-complete.min.js
83         @if [ -f ${SRC}/releases/mkws-$(VERSION).js ]; then \
84                 echo "*** There is already a release $(VERSION)"; \
85         else \
86                 cp -p mkws.js ${SRC}/releases/mkws-$(VERSION).js; \
87                 cp -p mkws.min.js ${SRC}/releases/mkws-$(VERSION).min.js; \
88                 cp -p mkws-complete.js ${SRC}/releases/mkws-complete-$(VERSION).js; \
89                 cp -p mkws-complete.min.js ${SRC}/releases/mkws-complete-$(VERSION).min.js; \
90                 echo "Made release $(VERSION)"; \
91         fi
92
93 mkws.js: mkws-templates.js $(COMPONENTS) Makefile
94         rm -f $@
95         cat ${COMPONENTS} > $@.tmp
96         mv -f $@.tmp $@
97         chmod 444 $@
98
99 mkws-templates.js:
100         handlebars -n mkws.defaultTemplates ${SRC}/*.templates/*.handlebars -f ${SRC}/mkws-templates.js
101
102 mkws-html-includes: 
103         echo $(COMPONENTS) | perl -npe "s,${SRC},,g; s/\s+/\0/g" | \
104           perl -n0e 'chomp(); print qq{    <script type="text/javascript" src="src$$_"></script>\n}'
105
106 distclean: clean
107         @echo "(No need for distclean, 'make clean' is fine)"
108
109 clean:
110         rm -f ${GENERATED}
111
112 help:
113         @echo "make [ all | release | clean | distclean ]"
114         @echo "     [ mkws-syntax-check ]"