no longer buildrequires nor requires pip2 packages
[sfa.git] / Makefile
1 #
2 ## (Re)builds Python metafile (__init__.py)
3 #
4 # overwritten by the specfile
5 DESTDIR="/"
6 PREFIX=/usr
7
8 ##########
9 all: python
10
11 install: python-install tests-install
12
13 clean: python-clean
14
15 uninstall: python-uninstall tests-uninstall
16
17 .PHONY: all install clean uninstall
18
19 ##########
20 rpmversion:=$(shell rpm -q --specfile sfa.spec --queryformat="%{version}\n" | head -1)
21 # somehow %{taglevel} is empty, turns out %{release} has what we want
22 rpmtaglevel:=$(shell rpm -q --specfile sfa.spec --queryformat="%{release}\n" 2> /dev/null | head -1)
23 VERSIONTAG=$(rpmversion)-$(rpmtaglevel)
24 # this used to be 'should-be-redefined-by-specfile' and it indeed should be
25 SCMURL=git://git.onelab.eu/sfa.git
26
27 python: version
28
29 version: sfa/util/version.py
30 sfa/util/version.py: sfa/util/version.py.in force
31         sed -e "s,@VERSIONTAG@,$(VERSIONTAG),g" -e "s,@SCMURL@,$(SCMURL),g" sfa/util/version.py.in > $@
32
33 # postinstall steps - various cleanups and tweaks for a nicer rpm
34 python-install:
35         python2 setup.py install --prefix=$(PREFIX) --root=$(DESTDIR)
36         chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
37         rm -rf $(DESTDIR)/usr/lib*/python2*/site-packages/*egg-info
38         rm -rf $(DESTDIR)/usr/lib*/python2*/site-packages/sfa/storage/migrations
39         (cd $(DESTDIR)/usr/bin ; ln -s sfi.py sfi; ln -s sfascan.py sfascan; ln -s sfaadmin.py sfaadmin)
40
41 python-clean: version-clean
42         python2 setup.py clean
43 #       rm $(init)
44
45 version-clean:
46         rm -f sfa/util/version.py
47
48 .PHONY: python version python-install python-clean version-clean
49 ##########
50 wsdl:
51         $(MAKE) -C wsdl
52
53 # propagate DESTDIR from the specfile
54 wsdl-install:
55         $(MAKE) -C wsdl install
56
57 wsdl-clean:
58         $(MAKE) -C wsdl clean
59
60 .PHONY: wsdl wsdl-install wsdl-clean
61
62 ##########
63 tests-install:
64         mkdir -p $(DESTDIR)/usr/share/sfa/tests
65         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
66
67 tests-uninstall:
68         rm -rf $(DESTDIR)/usr/share/sfa/tests
69
70 .PHONY: tests-install tests-uninstall
71
72 ########## refreshing methods package metafile
73 # Metafiles - manage Legacy/ and Accessors by hand
74 init := sfa/methods/__init__.py
75
76 index: $(init)
77
78 index-clean:
79         rm $(init)
80
81 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
82 # what should be declared
83 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
84 methods_files := $(sort $(notdir $(methods_paths:.py=)))
85
86 ifneq ($(methods_now),$(methods_files))
87 sfa/methods/__init__.py: force
88 endif
89 sfa/methods/__init__.py:
90         (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()') > $@
91
92 force:
93
94 ##########
95 # a lot of stuff in the working dir is just noise
96 files:
97         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg|pickle)$$'
98
99 git-files:
100         @git ls-files | egrep -v '\.(doc|html|pdf)$$'
101
102 tags:
103         $(MAKE) git-files | xargs etags
104
105 .PHONY: files tags
106
107 signatures:
108         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
109 .PHONY: signatures
110
111 ########## for uploading onto pypi
112 # use pypitest instead for tests (both entries need to be defined in your .pypirc)
113 PYPI_TARGET=pypi
114 PYPI_TARBALL_HOST=root@build.onelab.eu
115 PYPI_TARBALL_TOPDIR=/build/sfa
116
117 # a quick attempt on pypitest did not quite work as expected
118 # I was hoping to register the project using "setup.py register"
119 # but somehow most of my meta data did not make it up there
120 # and I could not find out why
121 # so I went for the manual method instead
122 # there also was a web dialog prompting for a zip file that would
123 # be used to initialize the project's home dir but this too
124 # did not seem to work the way I was trying to use it, so ...
125
126 # this target is still helpful to produce the readme in html from README.md
127 index.zip index.html: README.md
128         python readme.py
129
130 # I need to run this on my mac as my pypi
131 # run git pull first as this often comes afet a module-tag
132 # we need to re-run make so the version is right
133 git_pypi: git pypi
134
135 git:
136         git pull
137         $(MAKE) version
138
139 # run this only once the sources are in on the right tag
140 pypi: index.html
141         setup.py sdist upload -r $(PYPI_TARGET)
142         ssh $(PYPI_TARBALL_HOST) mkdir -p $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
143         rsync -av dist/sfa-$(VERSIONTAG).tar.gz $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
144
145 # cleanup
146 clean: readme-clean
147
148 readme-clean:
149         rm -f index.html index.zip
150
151 ########## sync
152 # 2 forms are supported
153 # (*) if your plc root context has direct ssh access:
154 # make sync PLC=private.one-lab.org
155 # (*) otherwise, for test deployments, use on your testmaster
156 # $ run export
157 # and cut'n paste the export lines before you run make sync
158
159 ifdef PLC
160 SSHURL:=root@$(PLC):/
161 SSHCOMMAND:=ssh root@$(PLC)
162 else
163 ifdef PLCHOSTLXC
164 SSHURL:=root@$(PLCHOSTLXC):/vservers/$(GUESTNAME)
165 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh -o StrictHostKeyChecking=no $(GUESTHOSTNAME)
166 else
167 ifdef PLCHOSTVS
168 SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
169 SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
170 endif
171 endif
172 endif
173
174 synccheck:
175 ifeq (,$(SSHURL))
176         @echo "sync: I need more info from the command line, e.g."
177         @echo "  make sync PLC=boot.planetlab.eu"
178         @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
179         @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
180         @exit 1
181 endif
182
183 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc'
184 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
185 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
186 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
187 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
188
189 CLIENTS = $(shell ls clientbin/*.py)
190
191 BINS =  ./config/sfa-config-tty ./systemd/sfa-setup.sh \
192         ./sfa/server/sfa-start.py ./clientbin/sfaadmin.py keyconvert/keyconvert.py \
193         $(CLIENTS)
194
195 synclib: synccheck
196         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python2.\*/site-packages/
197 synclib3: synccheck
198         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python3.\*/site-packages/
199 synclibdeb: synccheck
200         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/share/pyshared/
201 syncmigrations:
202         +$(RSYNC) ./sfa/storage/migrations/versions/*.py $(SSHURL)/usr/share/sfa/migrations/versions/
203 syncbin: synccheck
204         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
205 syncservices: synccheck
206         +$(RSYNC) ./systemd/*.service  $(SSHURL)/lib/systemd/system
207         +$(RSYNC) ./systemd/sfa-setup.sh  $(SSHURL)/usr/bin
208 syncconfig:
209         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
210 synctest: synccheck
211         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
212 syncrestart: synccheck
213         -$(SSHCOMMAND) systemctl --system daemon-reload
214         $(SSHCOMMAND) systemctl restart sfa-db
215         $(SSHCOMMAND) systemctl restart sfa-aggregate
216
217 syncmig:
218         +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
219
220
221 # full-fledged
222 sync: synclib syncbin syncservices syncconfig syncrestart
223 syncdeb: synclibdeb syncbin syncservices syncconfig syncrestart
224 # 99% of the time this is enough
225 syncfast: synclib syncrestart
226
227 .PHONY: synccheck synclib syncbin syncconfig synctest syncrestart sync syncfast
228
229 ##########
230 CLIENTLIBFILES= \
231 sfa/examples/miniclient.py \
232 sfa/__init__.py \
233 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
234 sfa/trust/{certificate,__init__}.py \
235 sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py
236
237 clientlibsync:
238         @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
239         rsync -av --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)
240
241 #################### convenience, for debugging only
242 # make +foo : prints the value of $(foo)
243 # make ++foo : idem but verbose, i.e. foo=$(foo)
244 ++%: varname=$(subst +,,$@)
245 ++%:
246         @echo "$(varname)=$($(varname))"
247 +%: varname=$(subst +,,$@)
248 +%:
249         @echo "$($(varname))"