Rework Makefile to better classify files.
[mkws-moved-to-github.git] / src / Makefile
1 HANDLEBARS_FILE = handlebars-v1.1.2.js
2 JQUERY_FILE = jquery-1.10.0.min.js
3 JQUERY_JSON_FILE = jquery.json-2.4.js
4 PP2_FILE = pz2.js
5
6 HANDLEBARS_URL = http://builds.handlebarsjs.com.s3.amazonaws.com/${HANDLEBARS_FILE}
7 JQUERY_URL = http://code.jquery.com/${JQUERY_FILE}
8 JQUERY_JSON_URL = https://jquery-json.googlecode.com/files/${JQUERY_JSON_FILE}
9 PP2_URL = http://git.indexdata.com/?p=pazpar2.git;a=blob_plain;f=js/${PP2_FILE};hb=HEAD
10
11 JQUERY_UI_URL = http://code.jquery.com/ui/1.10.3/jquery-ui.js
12 VERSION = $(shell tr -d '\012' < VERSION)
13
14 COMPONENTS = mkws-handlebars.js \
15         mkws-core.js mkws-team.js mkws-filter.js \
16         mkws-widgets.js mkws-widget-termlists.js \
17         mkws-widget-authname.js mkws-widget-categories.js mkws-widget-log.js \
18         mkws-widget-record.js mkws-widget-builder.js
19
20 GENERATED = ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE} \
21         mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js
22
23 INSTALLABLE = mkws-jquery.js VERSION NEWS $(GENERATED)
24
25 INSTALLED = $(INSTALLABLE:%=../tools/htdocs/%)
26
27 **make-default**: ../tools/htdocs/mkws.js
28
29 install: $(INSTALLED)
30
31 uninstall:
32         rm -f $(INSTALLED)
33
34 ../tools/htdocs/%: %
35         rm -f $@ && cp -p $? $@ && chmod 444 $@
36
37 all: mkws.min.js mkws-complete.min.js
38
39 mkws-js mkws-complete.js: Makefile mkws.js mkws-jquery.js ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE}
40         ( set -e; \
41           echo "/*! Copyright (c) 2013-2014 IndexData ApS. http://indexdata.com"; \
42           echo "   Licence: GPL, http://www.indexdata.com/licences/gpl"; \
43           echo "   created at: $$(date)"; \
44           echo "   mkws.js GIT id: $$(git log mkws.js | head -n 1 | perl -npe 's,\S+\s+,,')"; \
45           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>,')"; \
46           echo "*/"; \
47           cat ${JQUERY_FILE}; \
48           cat ${JQUERY_JSON_FILE}; \
49           cat ${HANDLEBARS_FILE}; \
50           cat ${PP2_FILE}; \
51           cat  mkws.js; \
52           cat  mkws-jquery.js; \
53         ) > mkws-complete.js.new
54         mv -f mkws-complete.js.new mkws-complete.js
55
56 %.min.js: %.js
57         yui-compressor $? > $@.new
58         mv -f $@.new $@
59
60 mkws-syntax-check:
61         yui-compressor mkws.js >/dev/null
62
63 ${HANDLEBARS_FILE}:
64         curl -sSf ${HANDLEBARS_URL} -o $@.tmp
65         mv -f $@.tmp $@
66
67 ${JQUERY_FILE}:
68         curl -sSf ${JQUERY_URL} -o $@.new
69         perl -npe 's,sourceMappingURL=jquery.*map,,' $@.new > $@
70         rm -f $@.new
71
72 ${JQUERY_JSON_FILE}:
73         curl -sSf ${JQUERY_JSON_URL} -o $@.tmp
74         mv -f $@.tmp $@
75
76 ${PP2_FILE}:
77         curl -sSf "${PP2_URL}" -o $@.tmp
78         mv -f $@.tmp $@
79
80 release: mkws.js mkws-complete.js mkws.min.js mkws-complete.min.js
81         @if [ -f releases/mkws-$(VERSION).js ]; then \
82                 echo "*** There is already a release $(VERSION)"; \
83         else \
84                 cp -p mkws.js releases/mkws-$(VERSION).js; \
85                 cp -p mkws.min.js releases/mkws-$(VERSION).min.js; \
86                 cp -p mkws-complete.js releases/mkws-complete-$(VERSION).js; \
87                 cp -p mkws-complete.min.js releases/mkws-complete-$(VERSION).min.js; \
88                 echo "Made release $(VERSION)"; \
89         fi
90
91 mkws.js: $(COMPONENTS) Makefile
92         rm -f $@
93         cat $(COMPONENTS) > $@
94         chmod 444 $@
95
96 distclean: clean
97         rm -f *.orig *.bak *.rej
98
99 clean:
100         rm -f ${GENERATED}
101