Merge branch 'master' of ssh://git.onelab.eu/git/sfa
[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  
34 python-install:
35         python setup.py install --root=$(DESTDIR)       
36         chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
37
38 python-clean: version-clean
39         python setup.py clean
40 #       rm $(init)
41
42 version-clean:
43         rm -f sfa/util/version.py
44
45 .PHONY: python version python-install python-clean version-clean xmlbuilder-install 
46 ##########
47 wsdl: 
48         $(MAKE) -C wsdl 
49
50 # propagate DESTDIR from the specfile
51 wsdl-install:
52         $(MAKE) -C wsdl install 
53
54 wsdl-clean:
55         $(MAKE) -C wsdl clean
56
57 .PHONY: wsdl wsdl-install wsdl-clean
58
59 ##########
60 tests-install:
61         mkdir -p $(DESTDIR)/usr/share/sfa/tests
62         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
63
64 tests-uninstall:
65         rm -rf $(DESTDIR)/usr/share/sfa/tests
66
67 .PHONY: tests-install tests-uninstall
68
69 ########## refreshing methods package metafile
70 # Metafiles - manage Legacy/ and Accessors by hand
71 init := sfa/methods/__init__.py 
72
73 index: $(init)
74
75 index-clean:
76         rm $(init)
77
78 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
79 # what should be declared
80 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
81 methods_files := $(sort $(notdir $(methods_paths:.py=)))
82
83 ifneq ($(methods_now),$(methods_files))
84 sfa/methods/__init__.py: force
85 endif
86 sfa/methods/__init__.py: 
87         (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()') > $@
88
89 force:
90
91 ##########
92 tags:   
93         find . -type f | egrep -v '/\.git/|/\.svn/|TAGS|AA-|~$$|\.(py[co]|doc|html|pdf|png|svg|out|bak|xml|dg)$$' | xargs etags
94 .PHONY: tags
95
96 signatures:
97         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
98 .PHONY: signatures
99
100 ########## sync
101 # 2 forms are supported
102 # (*) if your plc root context has direct ssh access:
103 # make sync PLC=private.one-lab.org
104 # (*) otherwise, entering through the root context
105 # make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr
106
107 PLCHOST ?= testplc.onelab.eu
108
109 ifdef GUEST
110 ifdef PLCHOST
111 SSHURL:=root@$(PLCHOST):/vservers/$(GUEST)
112 SSHCOMMAND:=ssh root@$(PLCHOST) vserver $(GUEST)
113 endif
114 endif
115 ifdef PLC
116 SSHURL:=root@$(PLC):/
117 SSHCOMMAND:=ssh root@$(PLC)
118 endif
119
120 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc' 
121 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
122 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
123 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
124 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
125
126 CLIENTS = sfi.py sfascan.py getNodes.py getRecord.py setRecord.py \
127 sfiAddAttribute.py sfiAddSliver.py sfiDeleteAttribute.py sfiDeleteSliver.py sfiListNodes.py \
128 sfiListSlivers.py sfadump.py
129
130 BINS =  ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
131         ./sfa/importer/sfa-import-plc.py ./sfa/importer/sfa-nuke-plc.py ./sfa/server/sfa-start.py \
132         $(foreach client,$(CLIENTS),./sfa/client/$(client))
133
134 sync:
135 ifeq (,$(SSHURL))
136         @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line"
137         @echo "  e.g. make sync PLC=private.one-lab.org"
138         @echo "  or   make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr"
139         @exit 1
140 else
141         +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/sfa/
142         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
143         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
144         +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
145         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
146         +$(RSYNC) ./sfa/storage/sfa.sql $(SSHURL)/usr/share/sfa/
147         $(SSHCOMMAND) exec service sfa restart
148 endif
149
150 # 99% of the time this is enough
151 fastsync:
152         +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/sfa/
153         $(SSHCOMMAND) exec service sfa restart
154
155 clientsync:
156         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
157
158 .PHONY: sync fastsync clientsync
159
160 ##########