first stab at packaging on fedora
[myslice.git] / Makefile
1 ### first purpose, build and install from the specfile
2 all: build
3
4 force:
5
6 DESTDIR := /
7 datadir := /usr/share
8 bindir := /usr/bin
9
10 PWD := $(shell pwd)
11
12 build:
13         python setup.py build
14
15 install: 
16         python setup.py install \
17             --install-purelib=$(DESTDIR)/$(datadir)/myslice \
18             --install-scripts=$(DESTDIR)/$(datadir)/myslice \
19             --install-data=$(DESTDIR)/$(datadir)/myslice
20
21
22 #################### compute emacs tags
23 # list files under git but exclude third-party stuff like bootstrap and jquery
24 myfiles: force
25         @git ls-files | egrep -v 'insert(_|-)above|/third-party/|/play/'
26
27 # in general it's right to rely on the contents as reported by git
28 tags: force
29         $(MAKE) myfiles | xargs etags
30
31 # however sometimes we have stuff not yet added, so in this case
32 ftags: force
33         find . -type f | fgrep -v '/.git/' | xargs etags
34
35 #################### third-party layout is kind of special 
36 # because we have differents versions and all
37 THIRD-PARTY-RESOURCES =
38 # ignore variants, use the main symlink third-party/bootstrap
39 THIRD-PARTY-RESOURCES += $(shell ls third-party/bootstrap/*/*)
40 # just the single js as identified with a symlink
41 THIRD-PARTY-RESOURCES += $(shell ls third-party/datatables/js/dataTables.js)
42 # likewise
43 THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery/js/jquery.js)
44 # spin comes in plain or min, + the jquery plugin, and our own settings
45 THIRD-PARTY-RESOURCES += $(shell ls third-party/spin/*.js)
46
47 thirdparty-js:
48         @find $(THIRD-PARTY-RESOURCES) -name '*.js'
49 thirdparty-css:
50         @find $(THIRD-PARTY-RESOURCES) -name '*.css'
51 thirdparty-img:
52         @find $(THIRD-PARTY-RESOURCES) -name '*.png'
53
54 # we might have any of these as templates - e.g. ./engine/templates/plugin-setenv.js
55 # so if there's a /templates/ in the path ignore the file
56 other-js: force
57         @find . -type f -name '*.js' | egrep -v '/all-(static|templates)/|/third-party/|/templates/'
58 other-css: force
59         @find . -type f -name '*.css' | egrep -v 'all-(static|templates)/|/third-party/|/templates/'
60 other-img: force
61         @find . -type f -name '*.png' | egrep -v 'all-(static|templates)/|/third-party/|/templates/'
62
63 list-js: thirdparty-js other-js
64 list-css: thirdparty-css other-css
65 list-img: thirdparty-img other-img
66
67 # having templates in a templates/ subdir is fine most of the time except for plugins
68 list-templates: force
69         @find plugins -type f -name '*.html' 
70
71 #################### manage static contents (extract from all the modules into the single all-static location)
72 static run-static static-run: force
73         mkdir -p ./all-static/js all-static/css all-static/img
74         ln -sf $(foreach x,$(shell $(MAKE) list-js),../../$(x)) ./all-static/js
75         ln -sf $(foreach x,$(shell $(MAKE) list-css),../../$(x)) ./all-static/css
76         ln -sf $(foreach x,$(shell $(MAKE) list-img),../../$(x)) ./all-static/img
77 #       rsync -av $(shell $(MAKE) list-js) ./all-static/js
78 #       rsync -av $(shell $(MAKE) list-css) ./all-static/css
79 #       rsync -av $(shell $(MAKE) list-img) ./all-static/img
80
81 clean-static static-clean: force
82         rm -rf ./all-static
83
84 all-static: clean-static run-static
85
86 #################### manage templates for the plugin area
87 templates run-templates templates-run: force
88         mkdir -p all-templates
89         ln -sf $(foreach x,$(shell $(MAKE) list-templates),../$(x)) ./all-templates
90 #       rsync -av $(shell $(MAKE) list-templates) ./all-templates
91
92 clean-templates templates-clean: force
93         rm -rf ./all-templates
94
95 all-templates: clean-templates run-templates
96
97 ####################
98 list-all list-resources: list-templates list-js list-css list-img
99
100 #################### sync : push current code on a (devel) box running myslice
101 SSHURL:=root@$(MYSLICEBOX):/
102 SSHCOMMAND:=ssh root@$(MYSLICEBOX)
103
104 ### rsync options
105 # the config file should probably not be overridden ??
106 # --exclude settings.py 
107 LOCAL_RSYNC_EXCLUDES    := --exclude '*.pyc' --exclude config.py --exclude all-static --exclude all-templates --exclude '*.sqlite3' 
108 # usual excludes
109 RSYNC_EXCLUDES          := --exclude .git --exclude '*~' --exclude TAGS --exclude .DS_Store $(LOCAL_RSYNC_EXCLUDES) 
110 # make -n will propagate as rsync -n 
111 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
112 # putting it together
113 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
114
115 # xxx until we come up with a packaging this is going to be a wild guess
116 # on debian04 I have stuff in /usr/share/myslice and a symlink in /root/myslice
117 #INSTALLED=/usr/share/myslice
118 INSTALLED=/root/myslice
119
120 sync:
121 ifeq (,$(MYSLICEBOX))
122         @echo "you need to set MYSLICEBOX, like in e.g."
123         @echo "  $(MAKE) MYSLICEBOX=debian04.pl.sophia.inria.fr "$@""
124         @exit 1
125 else
126         +$(RSYNC) ./ $(SSHURL)/$(INSTALLED)/
127 endif
128
129 # xxx likewise until we run this under apache it's probably hard to restart from here
130 restart:
131 ifeq (,$(MYSLICEBOX))
132         @echo "you need to set MYSLICEBOX, like in e.g."
133         @echo "  $(MAKE) MYSLICEBOX=debian04.pl.sophia.inria.fr "$@""
134         @exit 1
135 else
136         @echo "$@" target not yet implemented - for an apache based depl it would read ...; exit; @$(SSHCOMMAND) /etc/init.d/apache2 restart
137 endif