first draft for node tags & new node groups:
[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 # $Id$
8 #
9
10 # Metafiles
11 init := PLC/__init__.py PLC/Methods/__init__.py
12
13 # Python modules
14 # see PLCAPI.spec for the settings of modules
15 # default is : no extra module get built
16
17 ## Temporarily until we can kill the Fedora Core 2 build
18 #curl_vernum := $(shell printf %d 0x$(shell curl-config --vernum))
19 #pycurl_vernum := $(shell printf %d 0x070d01) # 7.13.1
20 #pycurl_incompatnum := $(shell printf %d 0x071000) # 7.16.0
21 #ifeq ($(shell test $(curl_vernum) -ge $(pycurl_vernum) && echo 1),1)
22 #ifeq ($(shell test $(curl_vernum) -ge $(pycurl_incompatnum) && echo 0),1)
23 #modules += pycurl
24 #endif
25 #endif
26
27 modules-install := $(foreach module, $(modules), $(module)-install)
28 modules-clean := $(foreach module, $(modules), $(module)-clean)
29
30 # Other stuff
31 subdirs := doc php php/xmlrpc
32
33 # autoconf compatible variables
34 DESTDIR := /plc/root
35 datadir := /usr/share
36 bindir := /usr/bin
37
38 PWD := $(shell pwd)
39
40 all: $(init) $(subdirs) $(modules)
41         python setup.py build
42
43 install: $(modules-install)
44         python setup.py install \
45             --install-purelib=$(DESTDIR)/$(datadir)/plc_api \
46             --install-scripts=$(DESTDIR)/$(datadir)/plc_api \
47             --install-data=$(DESTDIR)/$(datadir)/plc_api
48         install -D -m 755 php/xmlrpc/xmlrpc.so $(DESTDIR)/$(shell php-config --extension-dir)/xmlrpc.so
49         install -D -m 755 refresh-peer.py $(DESTDIR)/$(bindir)/refresh-peer.py
50
51 $(subdirs): $(init) $(modules)
52
53 $(subdirs): %:
54         $(MAKE) -C $@
55
56 $(modules):
57         # Install in the current directory so that we can import it while developing
58         cd $@ && \
59             python setup.py build && \
60             python setup.py install_lib --install-dir=$(PWD)
61
62 $(modules-install): %-install:
63         cd $* && \
64             python setup.py install_lib --install-dir=$(DESTDIR)/$(datadir)/plc_api
65
66 $(modules-clean): %-clean:
67         cd $* && python setup.py clean && rm -rf build
68
69 clean: $(modules-clean)
70         find . -name '*.pyc' | xargs rm -f
71         rm -f $(INIT)
72         for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir clean ; done
73         python setup.py clean && rm -rf build
74
75 index: $(init)
76
77 index-clean:
78         rm $(init)
79
80 tags:
81         find . '(' -name '*.py' -o -name '*.sql' -o -name '*.php' -o -name Makefile ')' | xargs etags
82
83 ########## make sync PLCHOST=hostname
84 ifdef PLCHOST
85 ifdef VSERVER
86 PLCSSH:=root@$(PLCHOST):/vservers/$(VSERVER)
87 endif
88 endif
89
90 LOCAL_RSYNC_EXCLUDES    := --exclude '*.pyc' 
91 RSYNC_EXCLUDES          := --exclude .svn --exclude CVS --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
92 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
93 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
94
95 sync:
96 ifeq (,$(PLCSSH))
97         echo "sync: You must define PLCHOST and VSERVER on the command line"
98         echo " e.g. make sync PLCHOST=private.one-lab.org VSERVER=myplc01" ; exit 1
99 else
100         +$(RSYNC) PLC planetlab5.sql migrations $(PLCSSH)/usr/share/plc_api/
101         ssh root@$(PLCHOST) vserver $(VSERVER) exec apachectl graceful
102 endif
103
104 ####################
105 # All .py files in PLC/
106
107 # the current content of __init__.py
108 PLC_now := $(sort $(shell fgrep -v '"' PLC/__init__.py 2>/dev/null))
109 # what should be declared
110 PLC_paths := $(filter-out %/__init__.py, $(wildcard PLC/*.py))
111 PLC_files := $(sort $(notdir $(PLC_paths:.py=)))
112
113 ifneq ($(PLC_now),$(PLC_files))
114 PLC/__init__.py: force
115 endif
116 PLC/__init__.py: 
117         (echo 'all = """' ; cd PLC; ls -1 *.py | grep -v __init__ | sed -e 's,.py$$,,' ; echo '""".split()') > $@
118
119
120 # the current content of __init__.py
121 METHODS_now := $(sort $(shell fgrep -v '"' PLC/Methods/__init__.py 2>/dev/null))
122 # what should be declared
123 METHODS_paths := $(filter-out %/__init__.py, $(wildcard PLC/Methods/*.py PLC/Methods/system/*.py))
124 METHODS_files := $(sort $(notdir $(subst system/, system., $(METHODS_paths:.py=))))
125
126 ifneq ($(METHODS_now),$(METHODS_files))
127 PLC/Methods/__init__.py: force
128 endif
129 PLC/Methods/__init__.py: 
130         (echo 'methods = """' ; cd PLC/Methods; ls -1 *.py system/*.py | grep -v __init__ | sed -e 's,.py$$,,' -e 's,system/,system.,' ; echo '""".split()') > $@
131
132 force:
133
134 .PHONY: all install force clean index tags $(subdirs) $(modules)
135
136 #################### convenience, for debugging only
137 # make +foo : prints the value of $(foo)
138 # make ++foo : idem but verbose, i.e. foo=$(foo)
139 ++%: varname=$(subst +,,$@)
140 ++%:
141         @echo "$(varname)=$($(varname))"
142 +%: varname=$(subst +,,$@)
143 +%:
144         @echo "$($(varname))"
145