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