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