oops, need a debian target
[myslice.git] / Makefile
1 SHELL = /bin/bash
2
3 MAKE-SILENT = $(MAKE) --no-print-directory
4
5 ### first purpose, build and install from the specfile
6 all: build
7
8 force:
9
10 DESTDIR := /
11 datadir := /usr/share
12 bindir := /usr/bin
13
14 PWD := $(shell pwd)
15
16 build: static templates
17         python setup.py build
18
19 install: 
20         python setup.py install \
21             --install-purelib=$(DESTDIR)/$(datadir)/myslice \
22             --install-scripts=$(DESTDIR)/$(datadir)/myslice \
23             --install-data=$(DESTDIR)/$(datadir)/myslice
24
25 ####################
26 debian: static templates debian/changelog debian.source debian.package
27
28 debian/changelog: debian/changelog.in
29         sed -e "s|@VERSION@|$(DEBVERSION)|" -e "s|@DATE@|$(DATE)|" debian/changelog.in > debian/changelog
30
31 debian.source: force 
32         rsync -a $(RPMTARBALL) $(DEBTARBALL)
33
34 debian.package:
35         debuild -uc -us -b 
36
37 debian.clean:
38         $(MAKE) -f debian/rules clean
39         rm -rf build/ MANIFEST ../*.tar.gz ../*.dsc ../*.build
40         find . -name '*.pyc' -delete
41
42
43 #################### third-party layout is kind of special 
44 # because we have differents versions, and also we 
45 # try to preserve the file structure from upstream
46 # so let's handle this manually
47 THIRD-PARTY-RESOURCES =
48 # ignore variants, use the main symlink third-party/bootstrap
49 THIRD-PARTY-RESOURCES += $(shell ls third-party/bootstrap/*/*)
50 # just the single js as identified with a symlink
51 THIRD-PARTY-RESOURCES += $(shell ls third-party/datatables/js/dataTables.js)
52 THIRD-PARTY-RESOURCES += $(shell ls third-party/datatables/js/dataTables.bootstrap.js)
53 THIRD-PARTY-RESOURCES += $(shell ls third-party/datatables/css/dataTables.bootstrap.css)
54 # likewise
55 THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery/js/jquery.js)
56 THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery/js/jquery.min.js)
57 # for storing the visible status of plugins
58 THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-html5storage/jquery.html5storage.js)
59 THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-html5storage/jquery.html5storage.min.js)
60 # creating queries uuids on the fly
61 THIRD-PARTY-RESOURCES += $(shell ls third-party/uuid/Math.uuid.js)
62 # spin comes in plain or min, + the jquery plugin, and our own settings
63 THIRD-PARTY-RESOURCES += $(shell ls third-party/spin/*.js)
64 # used in QueryCode
65 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/scripts/shCore.js)
66 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/scripts/shAutoloader.js)
67 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/scripts/shBrushPython.js)
68 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/scripts/shBrushRuby.js)
69 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/styles/shCore.css)
70 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/styles/shCoreDefault.css)
71 THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/styles/shThemeDefault.css)
72
73
74 thirdparty-js:
75         @find $(THIRD-PARTY-RESOURCES) -name '*.js'
76 thirdparty-css:
77         @find $(THIRD-PARTY-RESOURCES) -name '*.css'
78 thirdparty-img:
79         @find $(THIRD-PARTY-RESOURCES) -name '*.png' -o -name '*.ico'
80
81 # we might have any of these as templates - e.g. ./unfold/templates/plugin-init.js
82 # so if there's a /templates/ in the path ignore the file
83 local-js: force
84         @find . -type f -name '*.js' | egrep -v '/all-(static|templates)/|/third-party/|/templates/'
85 local-css: force
86         @find . -type f -name '*.css' | egrep -v 'all-(static|templates)/|/third-party/|/templates/'
87 local-img: force
88         @find . -type f -name '*.png' -o -name '*.ico' | egrep -v 'all-(static|templates)/|/third-party/|/templates/'
89
90 list-js: thirdparty-js local-js
91 list-css: thirdparty-css local-css
92 list-img: thirdparty-img local-img
93
94 # having templates in a templates/ subdir is fine most of the time except for plugins
95 plugins-templates: force
96         @find plugins -type f -name '*.html' 
97 local-templates: force
98         @$(foreach tmpl,$(shell find . -name templates),ls -1 $(tmpl)/*;)
99
100 list-templates: plugins-templates local-templates
101
102 #################### manage static contents (extract from all the modules into the single all-static location)
103 static run-static static-run: force
104         mkdir -p ./all-static/js all-static/css all-static/img
105         ln -sf $(foreach x,$(shell $(MAKE-SILENT) list-js),../../$(x)) ./all-static/js
106         ln -sf $(foreach x,$(shell $(MAKE-SILENT) list-css),../../$(x)) ./all-static/css
107         ln -sf $(foreach x,$(shell $(MAKE-SILENT) list-img),../../$(x)) ./all-static/img
108
109 clean-static static-clean: force
110         rm -rf ./all-static
111
112 all-static: clean-static run-static
113
114 #################### manage templates for the plugin area
115 templates run-templates templates-run: force
116         mkdir -p all-templates
117         ln -sf $(foreach x,$(shell $(MAKE-SILENT) list-templates),../$(x)) ./all-templates
118
119 clean-templates templates-clean: force
120         rm -rf ./all-templates
121
122 all-templates: clean-templates run-templates
123
124 ####################
125 list-all list-resources: list-templates list-js list-css list-img
126
127 #################### compute emacs tags
128 # list files under git but exclude third-party stuff like bootstrap and jquery
129 myfiles: force
130         @git ls-files | egrep -v 'insert(_|-)above|third-party/|play/'
131
132 # in general it's right to rely on the contents as reported by git
133 tags: force
134         $(MAKE-SILENT) myfiles | xargs etags
135
136 # however sometimes we have stuff not yet added, so in this case
137 ftags: force
138         find . -type f | fgrep -v '/.git/' | xargs etags
139
140 #################### sync : push current code on a (devel) box running myslice
141 SSHURL:=root@$(MYSLICEBOX):/
142 SSHCOMMAND:=ssh root@$(MYSLICEBOX)
143
144 ### rsync options
145 # the config file should probably not be overridden ??
146 # --exclude settings.py 
147 LOCAL_RSYNC_EXCLUDES    := --exclude '*.pyc' --exclude config.py --exclude all-static --exclude all-templates --exclude '*.sqlite3'  --exclude play/ 
148 # usual excludes
149 RSYNC_EXCLUDES          := --exclude .git --exclude '*~' --exclude TAGS --exclude .DS_Store $(LOCAL_RSYNC_EXCLUDES) 
150 # make -n will propagate as rsync -n 
151 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
152 # putting it together
153 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
154
155 # xxx until we come up with a packaging this is going to be a wild guess
156 # on debian04 I have stuff in /usr/share/myslice and a symlink in /root/myslice
157 #INSTALLED=/usr/share/myslice
158 INSTALLED=/root/myslice
159
160 sync:
161 ifeq (,$(MYSLICEBOX))
162         @echo "you need to set MYSLICEBOX, like in e.g."
163         @echo "  $(MAKE) MYSLICEBOX=debian04.pl.sophia.inria.fr "$@""
164         @exit 1
165 else
166         +$(RSYNC) ./ $(SSHURL)/$(INSTALLED)/
167 endif
168
169 # xxx likewise until we run this under apache it's probably hard to restart from here
170 restart:
171 ifeq (,$(MYSLICEBOX))
172         @echo "you need to set MYSLICEBOX, like in e.g."
173         @echo "  $(MAKE) MYSLICEBOX=debian04.pl.sophia.inria.fr "$@""
174         @exit 1
175 else
176         @echo "$@" target not yet implemented - for an apache based depl it would read ...; exit; @$(SSHCOMMAND) /etc/init.d/apache2 restart
177 endif