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