rpm macro was still referring to python2
[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
9
10 install: python-install tests-install
11
12 clean: python-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         python3 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         python3 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 ##########
50 tests-install:
51         mkdir -p $(DESTDIR)/usr/share/sfa/tests
52         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
53
54 tests-uninstall:
55         rm -rf $(DESTDIR)/usr/share/sfa/tests
56
57 .PHONY: tests-install tests-uninstall
58
59 ########## refreshing methods package metafile
60 # Metafiles - manage Legacy/ and Accessors by hand
61 init := sfa/methods/__init__.py
62
63 index: $(init)
64
65 index-clean:
66         rm $(init)
67
68 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
69 # what should be declared
70 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
71 methods_files := $(sort $(notdir $(methods_paths:.py=)))
72
73 ifneq ($(methods_now),$(methods_files))
74 sfa/methods/__init__.py: force
75 endif
76 sfa/methods/__init__.py:
77         (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()') > $@
78
79 force:
80
81 ##########
82 # a lot of stuff in the working dir is just noise
83 files:
84         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg|pickle)$$'
85
86 git-files:
87         @git ls-files | egrep -v '\.(doc|html|pdf)$$'
88
89 tags:
90         $(MAKE) git-files | xargs etags
91
92 .PHONY: files tags
93
94 signatures:
95         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
96 .PHONY: signatures
97
98 ########## for uploading onto pypi
99 # use pypitest instead for tests (both entries need to be defined in your .pypirc)
100 PYPI_TARGET=pypi
101 PYPI_TARBALL_HOST=root@build.onelab.eu
102 PYPI_TARBALL_TOPDIR=/build/sfa
103
104 # a quick attempt on pypitest did not quite work as expected
105 # I was hoping to register the project using "setup.py register"
106 # but somehow most of my meta data did not make it up there
107 # and I could not find out why
108 # so I went for the manual method instead
109 # there also was a web dialog prompting for a zip file that would
110 # be used to initialize the project's home dir but this too
111 # did not seem to work the way I was trying to use it, so ...
112
113 # this target is still helpful to produce the readme in html from README.md
114 index.zip index.html: README.md
115         python3 readme.py
116
117 # I need to run this on my mac as my pypi
118 # run git pull first as this often comes afet a module-tag
119 # we need to re-run make so the version is right
120 git_pypi: git pypi
121
122 git:
123         git pull
124         $(MAKE) version
125
126 # run this only once the sources are in on the right tag
127 pypi: index.html
128         setup.py sdist upload -r $(PYPI_TARGET)
129         ssh $(PYPI_TARBALL_HOST) mkdir -p $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
130         rsync -ai dist/sfa-$(VERSIONTAG).tar.gz $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
131
132 # cleanup
133 clean: readme-clean
134
135 readme-clean:
136         rm -f index.html index.zip
137
138 ########## sync
139 # 2 forms are supported
140 # (*) if your plc root context has direct ssh access:
141 # make sync PLC=private.one-lab.org
142 # (*) otherwise, for test deployments, use on your testmaster
143 # $ run export
144 # and cut'n paste the export lines before you run make sync
145
146 ifdef PLC
147 SSHURL:=root@$(PLC):/
148 SSHCOMMAND:=ssh root@$(PLC)
149 else
150 ifdef PLCHOSTLXC
151 SSHURL:=root@$(PLCHOSTLXC):/vservers/$(GUESTNAME)
152 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh -o StrictHostKeyChecking=no $(GUESTHOSTNAME)
153 else
154 ifdef PLCHOSTVS
155 SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
156 SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
157 endif
158 endif
159 endif
160
161 synccheck:
162 ifeq (,$(SSHURL))
163         @echo "sync: I need more info from the command line, e.g."
164         @echo "  make sync PLC=boot.planetlab.eu"
165         @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
166         @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
167         @exit 1
168 endif
169
170 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc'
171 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
172 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
173 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
174 RSYNC                   := rsync -ai $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
175
176 CLIENTS = $(shell ls clientbin/*.py)
177
178 BINS =  ./config/sfa-config-tty ./systemd/sfa-setup.sh \
179         ./sfa/server/sfa-start.py \
180         ./clientbin/sfaadmin.py \
181         $(CLIENTS)
182
183 synclib: synccheck
184         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python3.\*/site-packages/
185 syncmigrations:
186         +$(RSYNC) ./sfa/storage/migrations/versions/*.py $(SSHURL)/usr/share/sfa/migrations/versions/
187 syncbin: synccheck
188         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
189 syncservices: synccheck
190         +$(RSYNC) ./systemd/*.service  $(SSHURL)/lib/systemd/system
191         +$(RSYNC) ./systemd/sfa-setup.sh  $(SSHURL)/usr/bin
192 syncconfig:
193         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
194 synctest: synccheck
195         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
196 syncrestart: synccheck
197         -$(SSHCOMMAND) systemctl --system daemon-reload
198         $(SSHCOMMAND) systemctl restart sfa-db
199         $(SSHCOMMAND) systemctl restart sfa-aggregate
200
201 syncmig:
202         +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
203
204
205 # full-fledged
206 sync: synclib syncbin syncservices syncconfig syncrestart
207 syncdeb: synclibdeb syncbin syncservices 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 -ai --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))"