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