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