provide a more decent default to SCMURL for version.py when not run from within a...
[sfa.git] / Makefile
1 #
2 ## (Re)builds Python metafile (__init__.py) 
3
4 # overwritten by the specfile
5 DESTDIR="/"
6 PREFIX=/usr
7 ##########
8 all: python wsdl 
9
10 install: python-install wsdl-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 # this used to be 'should-be-redefined-by-specfile' and it indeed should be
24 SCMURL=git://git.onelab.eu/sfa.git
25
26 python: version
27
28 version: sfa/util/version.py 
29 sfa/util/version.py: sfa/util/version.py.in force
30         sed -e "s,@VERSIONTAG@,$(VERSIONTAG),g" -e "s,@SCMURL@,$(SCMURL),g" sfa/util/version.py.in > $@
31
32 # postinstall steps - various cleanups and tweaks for a nicer rpm
33 python-install:
34         python setup.py install --prefix=$(PREFIX) --root=$(DESTDIR)
35         chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
36         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/*egg-info
37         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/sfa/storage/migrations
38         (cd $(DESTDIR)/usr/bin ; ln -s sfi.py sfi; ln -s sfascan.py sfascan; ln -s sfaadmin.py sfaadmin)
39
40 python-clean: version-clean
41         python setup.py clean
42 #       rm $(init)
43
44 version-clean:
45         rm -f sfa/util/version.py
46
47 .PHONY: python version python-install python-clean version-clean 
48 ##########
49 wsdl: 
50         $(MAKE) -C wsdl 
51
52 # propagate DESTDIR from the specfile
53 wsdl-install:
54         $(MAKE) -C wsdl install 
55
56 wsdl-clean:
57         $(MAKE) -C wsdl clean
58
59 .PHONY: wsdl wsdl-install wsdl-clean
60
61 ######################################## debian packaging
62 # The 'debian' target is called from the build with the following variables set 
63 # (see build/Makefile and target_debian)
64 # (.) RPMTARBALL
65 # (.) RPMVERSION
66 # (.) RPMRELEASE
67 # (.) RPMNAME
68 #
69 PROJECT=$(RPMNAME)
70 DEBVERSION=$(RPMVERSION).$(RPMRELEASE)
71 DEBTARBALL=../$(PROJECT)_$(DEBVERSION).orig.tar.bz2
72
73 DATE=$(shell date -u +"%a, %d %b %Y %T")
74
75 debian: debian/changelog debian.source debian.package
76
77 debian/changelog: debian/changelog.in
78         sed -e "s|@VERSION@|$(DEBVERSION)|" -e "s|@DATE@|$(DATE)|" debian/changelog.in > debian/changelog
79
80 debian.source: force 
81         rsync -a $(RPMTARBALL) $(DEBTARBALL)
82
83 debian.package:
84         debuild -uc -us -b 
85
86 debian.clean:
87         $(MAKE) -f debian/rules clean
88         rm -rf build/ MANIFEST ../*.tar.gz ../*.dsc ../*.build
89         find . -name '*.pyc' -delete
90
91 ##########
92 tests-install:
93         mkdir -p $(DESTDIR)/usr/share/sfa/tests
94         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
95
96 tests-uninstall:
97         rm -rf $(DESTDIR)/usr/share/sfa/tests
98
99 .PHONY: tests-install tests-uninstall
100
101 ########## refreshing methods package metafile
102 # Metafiles - manage Legacy/ and Accessors by hand
103 init := sfa/methods/__init__.py 
104
105 index: $(init)
106
107 index-clean:
108         rm $(init)
109
110 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
111 # what should be declared
112 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
113 methods_files := $(sort $(notdir $(methods_paths:.py=)))
114
115 ifneq ($(methods_now),$(methods_files))
116 sfa/methods/__init__.py: force
117 endif
118 sfa/methods/__init__.py: 
119         (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()') > $@
120
121 force:
122
123 ##########
124 # a lot of stuff in the working dir is just noise
125 files:
126         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg|pickle)$$' 
127
128 git-files:
129         @git ls-files | grep -v '\.doc$$'
130
131 tags:   
132         $(MAKE) git-files | xargs etags
133
134 .PHONY: files tags
135
136 signatures:
137         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
138 .PHONY: signatures
139
140 ########## sync
141 # 2 forms are supported
142 # (*) if your plc root context has direct ssh access:
143 # make sync PLC=private.one-lab.org
144 # (*) otherwise, for test deployments, use on your testmaster
145 # $ run export
146 # and cut'n paste the export lines before you run make sync
147
148 ifdef PLC
149 SSHURL:=root@$(PLC):/
150 SSHCOMMAND:=ssh root@$(PLC)
151 else
152 ifdef PLCHOSTLXC
153 SSHURL:=root@$(PLCHOSTLXC):/vservers/$(GUESTNAME)
154 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) virsh -c lxc:/// lxc-enter-namespace $(GUESTNAME) -- /usr/bin/env
155 else
156 ifdef PLCHOSTVS
157 SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
158 SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
159 endif
160 endif
161 endif
162
163 synccheck: 
164 ifeq (,$(SSHURL))
165         @echo "sync: I need more info from the command line, e.g."
166         @echo "  make sync PLC=boot.planetlab.eu"
167         @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
168         @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
169         @exit 1
170 endif
171
172 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc' 
173 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
174 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
175 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
176 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
177
178 CLIENTS = $(shell ls clientbin/*.py)
179
180 BINS =  ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
181         ./sfa/server/sfa-start.py \
182         ./clientbin/sfaadmin.py \
183         $(CLIENTS)
184
185 synclib: synccheck
186         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python2.\*/site-packages/
187 synclibdeb: synccheck
188         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/share/pyshared/
189 syncbin: synccheck
190         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
191 syncinit: synccheck
192         +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
193 syncconfig:
194         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
195 synctest: synccheck
196         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
197 syncrestart: synccheck
198         -$(SSHCOMMAND) systemctl --system daemon-reload
199         $(SSHCOMMAND) service sfa restart
200
201 syncmig:
202         +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
203
204
205 # full-fledged
206 sync: synclib syncbin syncinit syncconfig syncrestart
207 syncdeb: synclibdeb syncbin syncinit syncconfig syncrestart
208 # 99% of the time this is enough
209 syncfast: synclib syncrestart
210
211 .PHONY: synccheck synclib syncbin syncconfig synctest syncrestart sync syncfast
212
213 ##########
214 CLIENTLIBFILES= \
215 sfa/examples/miniclient.py \
216 sfa/__init__.py \
217 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
218 sfa/trust/{certificate,__init__}.py \
219 sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py 
220
221 clientlibsync: 
222         @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
223         rsync -av --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)
224
225 #################### convenience, for debugging only
226 # make +foo : prints the value of $(foo)
227 # make ++foo : idem but verbose, i.e. foo=$(foo)
228 ++%: varname=$(subst +,,$@)
229 ++%:
230         @echo "$(varname)=$($(varname))"
231 +%: varname=$(subst +,,$@)
232 +%:
233         @echo "$($(varname))"