convenience
[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 # a lot of stuff in the working dir is just noise
93 scan:
94         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|xml|dg)$$' 
95 tags:   
96         $(MAKE) scan | xargs etags
97
98 .PHONY: scan tags
99
100 signatures:
101         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
102 .PHONY: signatures
103
104 ########## sync
105 # 2 forms are supported
106 # (*) if your plc root context has direct ssh access:
107 # make sync PLC=private.one-lab.org
108 # (*) otherwise, entering through the root context
109 # make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr
110
111 PLCHOST ?= testplc.onelab.eu
112
113 ifdef GUEST
114 ifdef PLCHOST
115 SSHURL:=root@$(PLCHOST):/vservers/$(GUEST)
116 SSHCOMMAND:=ssh root@$(PLCHOST) vserver $(GUEST)
117 endif
118 endif
119 ifdef PLC
120 SSHURL:=root@$(PLC):/
121 SSHCOMMAND:=ssh root@$(PLC)
122 endif
123
124 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc' 
125 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
126 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
127 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
128 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
129
130 CLIENTS = sfi.py sfascan.py getNodes.py getRecord.py setRecord.py \
131 sfiAddAttribute.py sfiAddSliver.py sfiDeleteAttribute.py sfiDeleteSliver.py sfiListNodes.py \
132 sfiListSlivers.py sfadump.py
133
134 BINS =  ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
135         ./sfa/importer/sfa-import-plc.py ./sfa/importer/sfa-nuke-plc.py ./sfa/server/sfa-start.py \
136         $(foreach client,$(CLIENTS),./sfa/client/$(client))
137
138 sync:
139 ifeq (,$(SSHURL))
140         @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line"
141         @echo "  e.g. make sync PLC=private.one-lab.org"
142         @echo "  or   make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr"
143         @exit 1
144 else
145         +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/sfa/
146         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
147         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
148         +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
149         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
150         +$(RSYNC) ./sfa/storage/sfa.sql $(SSHURL)/usr/share/sfa/
151         $(SSHCOMMAND) exec service sfa restart
152 endif
153
154 # 99% of the time this is enough
155 fastsync:
156         +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/sfa/
157         $(SSHCOMMAND) exec service sfa restart
158
159 clientsync:
160         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
161
162 .PHONY: sync fastsync clientsync
163
164 ##########