Merge Master in geni-v3 conflict resolution
[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
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 ##########
65 debian: version
66         $(MAKE) -f Makefile.debian debian
67 debian.clean: 
68         $(MAKE) -f Makefile.debian clean
69
70 ##########
71 tests-install:
72         mkdir -p $(DESTDIR)/usr/share/sfa/tests
73         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
74
75 tests-uninstall:
76         rm -rf $(DESTDIR)/usr/share/sfa/tests
77
78 .PHONY: tests-install tests-uninstall
79
80 ########## refreshing methods package metafile
81 # Metafiles - manage Legacy/ and Accessors by hand
82 init := sfa/methods/__init__.py 
83
84 index: $(init)
85
86 index-clean:
87         rm $(init)
88
89 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
90 # what should be declared
91 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
92 methods_files := $(sort $(notdir $(methods_paths:.py=)))
93
94 ifneq ($(methods_now),$(methods_files))
95 sfa/methods/__init__.py: force
96 endif
97 sfa/methods/__init__.py: 
98         (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()') > $@
99
100 force:
101
102 ##########
103 # a lot of stuff in the working dir is just noise
104 scan:
105         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg|pickle)$$' 
106 tags:   
107         $(MAKE) scan | xargs etags
108
109 .PHONY: scan tags
110
111 signatures:
112         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
113 .PHONY: signatures
114
115 ########## sync
116 # 2 forms are supported
117 # (*) if your plc root context has direct ssh access:
118 # make sync PLC=private.one-lab.org
119 # (*) otherwise, for test deployments, use on your testmaster
120 # $ run export
121 # and cut'n paste the export lines before you run make sync
122
123 ifdef PLC
124 SSHURL:=root@$(PLC):/
125 SSHCOMMAND:=ssh root@$(PLC)
126 else
127 ifdef PLCHOSTLXC
128 SSHURL:=root@$(PLCHOSTLXC):/var/lib/lxc/$(GUESTNAME)/rootfs
129 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh $(GUESTHOSTNAME)
130 else
131 ifdef PLCHOSTVS
132 SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
133 SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
134 endif
135 endif
136 endif
137
138 synccheck: 
139 ifeq (,$(SSHURL))
140         @echo "sync: I need more info from the command line, e.g."
141         @echo "  make sync PLC=boot.planetlab.eu"
142         @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
143         @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
144         @exit 1
145 endif
146
147 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc' 
148 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
149 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
150 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
151 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
152
153 CLIENTS = $(shell ls clientbin/*.py)
154
155 BINS =  ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
156         ./sfa/server/sfa-start.py \
157         ./clientbin/sfaadmin.py \
158         $(CLIENTS)
159
160 synclib: synccheck
161         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python2.\*/site-packages/
162 synclibdeb: synccheck
163         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/share/pyshared/
164 syncbin: synccheck
165         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
166 syncinit: synccheck
167         +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
168 syncconfig:
169         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
170 synctest: synccheck
171         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
172 syncrestart: synccheck
173         $(SSHCOMMAND) service sfa restart
174
175 syncmig:
176         +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
177
178
179 # full-fledged
180 sync: synclib syncbin syncinit syncconfig syncrestart
181 syncdeb: synclibdeb syncbin syncinit syncconfig syncrestart
182 # 99% of the time this is enough
183 syncfast: synclib syncrestart
184
185 .PHONY: synccheck synclib syncbin syncconfig synctest syncrestart sync syncfast
186
187 ##########
188 CLIENTLIBFILES= \
189 sfa/examples/miniclient.py \
190 sfa/__init__.py \
191 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
192 sfa/trust/{certificate,__init__}.py \
193 sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py 
194
195 clientlibsync: 
196         @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
197         rsync -av --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)