do not use broken lxc-enter-namespace
[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 ########## for uploading onto pypi
141 # use pypitest instead for tests (both entries need to be defined in your .pypirc)
142 PYPI_TARGET=pypi
143 PYPI_TARBALL_HOST=root@build.onelab.eu
144 PYPI_TARBALL_TOPDIR=/build/sfa
145
146 # a quick attempt on pypitest did not quite work as expected
147 # I was hoping to register the project using "setup.py register"
148 # but somehow most of my meta data did not make it up there
149 # and I could not find out why
150 # so I went for the manual method instead
151 # there also was a web dialog prompting for a zip file that would
152 # be used to initialize the project's home dir but this too 
153 # did not seem to work the way I was trying to use it, so ...
154
155 # this target is still helpful to produce the readme in html from README.md
156 index.zip index.html: README.md
157         python readme.py
158
159 # I need to run this on my mac as my pypi
160 # run git pull first as this often comes afet a module-tag
161 # we need to re-run make so the version is right
162 git_pypi: git pypi
163
164 git: 
165         git pull
166         $(MAKE) version
167
168 # run this only once the sources are in on the right tag
169 pypi: index.html
170         setup.py sdist upload -r $(PYPI_TARGET)
171         ssh $(PYPI_TARBALL_HOST) mkdir -p $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
172         rsync -av dist/sfa-$(VERSIONTAG).tar.gz $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
173
174 # cleanup
175 clean: readme-clean
176
177 readme-clean:
178         rm -f index.html index.zip
179
180 ########## sync
181 # 2 forms are supported
182 # (*) if your plc root context has direct ssh access:
183 # make sync PLC=private.one-lab.org
184 # (*) otherwise, for test deployments, use on your testmaster
185 # $ run export
186 # and cut'n paste the export lines before you run make sync
187
188 ifdef PLC
189 SSHURL:=root@$(PLC):/
190 SSHCOMMAND:=ssh root@$(PLC)
191 else
192 ifdef PLCHOSTLXC
193 SSHURL:=root@$(PLCHOSTLXC):/vservers/$(GUESTNAME)
194 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh -o StrictHostKeyChecking=no $(GUESTHOSTNAME)
195 else
196 ifdef PLCHOSTVS
197 SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
198 SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
199 endif
200 endif
201 endif
202
203 synccheck: 
204 ifeq (,$(SSHURL))
205         @echo "sync: I need more info from the command line, e.g."
206         @echo "  make sync PLC=boot.planetlab.eu"
207         @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
208         @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
209         @exit 1
210 endif
211
212 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc' 
213 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
214 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
215 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
216 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
217
218 CLIENTS = $(shell ls clientbin/*.py)
219
220 BINS =  ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
221         ./sfa/server/sfa-start.py \
222         ./clientbin/sfaadmin.py \
223         $(CLIENTS)
224
225 synclib: synccheck
226         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python2.\*/site-packages/
227 synclibdeb: synccheck
228         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/share/pyshared/
229 syncbin: synccheck
230         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
231 syncinit: synccheck
232         +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
233 syncconfig:
234         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
235 synctest: synccheck
236         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
237 syncrestart: synccheck
238         -$(SSHCOMMAND) systemctl --system daemon-reload
239         $(SSHCOMMAND) service sfa restart
240
241 syncmig:
242         +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
243
244
245 # full-fledged
246 sync: synclib syncbin syncinit syncconfig syncrestart
247 syncdeb: synclibdeb syncbin syncinit syncconfig syncrestart
248 # 99% of the time this is enough
249 syncfast: synclib syncrestart
250
251 .PHONY: synccheck synclib syncbin syncconfig synctest syncrestart sync syncfast
252
253 ##########
254 CLIENTLIBFILES= \
255 sfa/examples/miniclient.py \
256 sfa/__init__.py \
257 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
258 sfa/trust/{certificate,__init__}.py \
259 sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py 
260
261 clientlibsync: 
262         @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
263         rsync -av --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)
264
265 #################### convenience, for debugging only
266 # make +foo : prints the value of $(foo)
267 # make ++foo : idem but verbose, i.e. foo=$(foo)
268 ++%: varname=$(subst +,,$@)
269 ++%:
270         @echo "$(varname)=$($(varname))"
271 +%: varname=$(subst +,,$@)
272 +%:
273         @echo "$($(varname))"