review make sync to push code on a vplc that is lxc-hosted
[plcapi.git] / Makefile
1 #
2 # (Re)builds Python metafiles (__init__.py) and documentation
3 #
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2005 The Trustees of Princeton University
6 #
7
8 # python-pycurl and python-psycopg2 avail. from fedora 5
9 # we used to ship our own version of psycopg2 and pycurl, for fedora4
10 # starting with 5.0, support for these two modules is taken out
11
12 # Other stuff - doc not implicit, it's redone by myplc-docs
13 subdirs := php/xmlrpc
14
15 # autoconf compatible variables
16 DESTDIR := /
17 datadir := /usr/share
18 bindir := /usr/bin
19
20 PWD := $(shell pwd)
21
22 all: $(subdirs) 
23         python setup.py build
24
25 install: 
26         python setup.py install \
27             --install-purelib=$(DESTDIR)/$(datadir)/plc_api \
28             --install-scripts=$(DESTDIR)/$(datadir)/plc_api \
29             --install-data=$(DESTDIR)/$(datadir)/plc_api
30         install -D -m 755 php/xmlrpc/xmlrpc.so $(DESTDIR)/$(shell php-config --extension-dir)/xmlrpc.so
31
32 $(subdirs): %:
33         $(MAKE) -C $@
34
35 clean: 
36         find . -name '*.pyc' | xargs rm -f
37         rm -f $(INIT)
38         for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir clean ; done
39         python setup.py clean && rm -rf build
40
41 index:
42         echo "This step is obsolete"
43
44 ##########
45
46 force:
47
48 .PHONY: all install force clean index tags $(subdirs)
49
50 #################### devel tools
51 tags:
52         find . '(' -name '*.py' -o -name '*.sql' -o -name '*.php' -o -name Makefile -o -name '[0-9][0-9][0-9]*' ')' | fgrep -v '.git/' | xargs etags
53
54 .PHONY: tags
55
56 ########## sync
57 # 2 forms are supported
58 # (*) if your plc root context has direct ssh access:
59 # make sync PLC=private.one-lab.org
60 # (*) otherwise, under a vs-capable box, using /vservers/<> and vserver exec
61 # make sync PLCHOST=vs64-1.pl.sophia.inria.fr GUEST=2012.04.02--f14-32-1-vplc26
62 # (*) with an lxc-capable box, using /var/lib/lxc/<>/rootfs and ssh 
63 # make sync PLCHOSTLXC=lxc64-1.pls.sophia.inria.fr GUEST=2012.04.02--lxc16-1-vplc25
64
65 PLCHOST ?= testplc.onelab.eu
66
67 ifdef PLCHOSTLXC
68 VPLCNAME=$(lastword $(subst -, ,$(GUEST)))
69 SSHURL:=root@$(PLCHOST):/var/lib/lxc/$(GUEST)/rootfs
70 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh $(VPLCNAME)
71 else
72 ifdef GUEST
73 SSHURL:=root@$(PLCHOST):/vservers/$(GUEST)
74 SSHCOMMAND:=ssh root@$(PLCHOST) vserver $(GUEST) exec
75 endif
76 endif
77 ifdef PLC
78 SSHURL:=root@$(PLC):/
79 SSHCOMMAND:=ssh root@$(PLC)
80 endif
81
82 LOCAL_RSYNC_EXCLUDES    := --exclude '*.pyc' --exclude Accessors_site.py
83 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
84 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
85 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
86
87 sync:
88 ifeq (,$(SSHURL))
89         @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line"
90         @echo "  e.g. make sync PLC=boot.planetlab.eu"
91         @echo "  or   make sync PLCHOST=testplc.onelab.eu GUEST=vplc03.inria.fr"
92         @exit 1
93 else
94         +$(RSYNC) plcsh PLC planetlab5.sql migrations aspects $(SSHURL)/usr/share/plc_api/
95         +$(RSYNC) db-config.d/ $(SSHURL)/etc/planetlab/db-config.d/
96         +$(RSYNC) plc.d/ $(SSHURL)/etc/plc.d/
97         $(SSHCOMMAND) apachectl graceful
98 endif
99
100 #################### convenience, for debugging only
101 # make +foo : prints the value of $(foo)
102 # make ++foo : idem but verbose, i.e. foo=$(foo)
103 ++%: varname=$(subst +,,$@)
104 ++%:
105         @echo "$(varname)=$($(varname))"
106 +%: varname=$(subst +,,$@)
107 +%:
108         @echo "$($(varname))"
109