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