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