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