first draft of an added support for migrations in the db schema
[sfa.git] / Makefile
1 #
2 ## (Re)builds Python metafile (__init__.py) 
3
4 # overwritten by the specfile
5 DESTDIR="/"
6
7 ##########
8 all: python wsdl 
9
10 install: python-install wsdl-install xmlbuilder-install tests-install
11
12 clean: python-clean wsdl-clean 
13
14 uninstall: python-uninstall tests-uninstall
15
16 .PHONY: all install clean uninstall
17
18 ##########
19 rpmversion:=$(shell rpm -q --specfile sfa.spec --queryformat="%{version}\n" | head -1)
20 # somehow %{taglevel} is empty, turns out %{release} has what we want
21 rpmtaglevel:=$(shell rpm -q --specfile sfa.spec --queryformat="%{release}\n" 2> /dev/null | head -1)
22 VERSIONTAG=$(rpmversion)-$(rpmtaglevel)
23 SCMURL=should-be-redefined-by-specfile
24
25 python: version
26
27 version: sfa/util/version.py
28 sfa/util/version.py: sfa/util/version.py.in
29         sed -e "s,@VERSIONTAG@,$(VERSIONTAG),g" -e "s,@SCMURL@,$(SCMURL),g" sfa/util/version.py.in > $@
30
31 xmlbuilder-install:
32         cd xmlbuilder-0.9 && python setup.py install --root=$(DESTDIR) && cd -
33         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/*egg-info
34
35 # postinstall steps - various cleanups and tweaks for a nicer rpm
36 python-install:
37         python setup.py install --root=$(DESTDIR)       
38         chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
39         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/*egg-info
40         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/sfa/storage/sfa.sql
41         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/sfa/storage/migrations
42         (cd $(DESTDIR)/usr/bin ; ln -s sfi.py sfi; ln -s sfascan.py sfascan)
43
44 python-clean: version-clean
45         python setup.py clean
46 #       rm $(init)
47
48 version-clean:
49         rm -f sfa/util/version.py
50
51 .PHONY: python version python-install python-clean version-clean xmlbuilder-install 
52 ##########
53 wsdl: 
54         $(MAKE) -C wsdl 
55
56 # propagate DESTDIR from the specfile
57 wsdl-install:
58         $(MAKE) -C wsdl install 
59
60 wsdl-clean:
61         $(MAKE) -C wsdl clean
62
63 .PHONY: wsdl wsdl-install wsdl-clean
64
65 ##########
66 tests-install:
67         mkdir -p $(DESTDIR)/usr/share/sfa/tests
68         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
69
70 tests-uninstall:
71         rm -rf $(DESTDIR)/usr/share/sfa/tests
72
73 .PHONY: tests-install tests-uninstall
74
75 ########## refreshing methods package metafile
76 # Metafiles - manage Legacy/ and Accessors by hand
77 init := sfa/methods/__init__.py 
78
79 index: $(init)
80
81 index-clean:
82         rm $(init)
83
84 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
85 # what should be declared
86 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
87 methods_files := $(sort $(notdir $(methods_paths:.py=)))
88
89 ifneq ($(methods_now),$(methods_files))
90 sfa/methods/__init__.py: force
91 endif
92 sfa/methods/__init__.py: 
93         (echo '## Please use make index to update this file' ; echo 'all = """' ; cd sfa/methods; ls -1 *.py | grep -v __init__ | sed -e 's,.py$$,,' ; echo '""".split()') > $@
94
95 force:
96
97 ##########
98 # a lot of stuff in the working dir is just noise
99 scan:
100         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg)$$' 
101 tags:   
102         $(MAKE) scan | xargs etags
103
104 .PHONY: scan tags
105
106 signatures:
107         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
108 .PHONY: signatures
109
110 ########## sync
111 # 2 forms are supported
112 # (*) if your plc root context has direct ssh access:
113 # make sync PLC=private.one-lab.org
114 # (*) otherwise, entering through the root context
115 # make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr
116
117 PLCHOST ?= testplc.onelab.eu
118
119 ifdef GUEST
120 ifdef PLCHOST
121 SSHURL:=root@$(PLCHOST):/vservers/$(GUEST)
122 SSHCOMMAND:=ssh root@$(PLCHOST) vserver $(GUEST)
123 endif
124 endif
125 ifdef PLC
126 SSHURL:=root@$(PLC):/
127 SSHCOMMAND:=ssh root@$(PLC)
128 endif
129
130 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc' 
131 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
132 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
133 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
134 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
135
136 CLIENTS = $(shell ls sfa/clientbin/*.py)
137
138 BINS =  ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
139         ./sfa/importer/sfa-import-plc.py ./sfa/importer/sfa-nuke-plc.py ./sfa/server/sfa-start.py \
140         $(CLIENTS)
141
142 synccheck: 
143 ifeq (,$(SSHURL))
144         @echo "*sync: You must define, either PLC, or PLCHOST & GUEST, on the command line"
145         @echo "  e.g. make sync PLC=private.one-lab.org"
146         @echo "  or   make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr"
147         @exit 1
148 endif
149
150 sync: synccheck
151         +$(RSYNC) --relative ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/
152         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
153         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
154         +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
155         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
156         +$(RSYNC) ./sfa/storage/{sfa.sql,migrations} $(SSHURL)/usr/share/sfa/
157         $(SSHCOMMAND) exec service sfa restart
158
159 # 99% of the time this is enough
160 fastsync: synccheck
161         +$(RSYNC) --relative ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/
162         $(SSHCOMMAND) exec service sfa restart
163
164 clientsync: synccheck
165         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
166
167 ricasync: synccheck
168         +$(RSYNC) --relative ./sfa/fd ./sfa/generic/fd.py ./sfa/rspecs/versions/federica.py $(SSHURL)/usr/lib\*/python2.\*/site-packages/
169         $(SSHCOMMAND) exec service sfa restart
170
171 .PHONY: synccheck sync fastsync clientsync ricasync
172
173 ##########
174 CLIENTLIBFILES= \
175 sfa/examples/miniclient.py \
176 sfa/__init__.py \
177 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
178 sfa/trust/{certificate,__init__}.py \
179 sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py 
180
181 clientlibsync: 
182         @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
183         rsync -av --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)