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