review policy for building our pycurl/psycopg2 or not - based on fedora distrib
[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 PLCSSH:=root@$(PLCHOST)
86 endif
87
88 LOCAL_RSYNC_EXCLUDES    := --exclude '*.pyc' 
89 RSYNC_EXCLUDES          := --exclude .svn --exclude CVS --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
90 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
91 RSYNC                   := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
92
93 sync:
94 ifeq (,$(PLCSSH))
95         echo "sync: You must define target host as PLCHOST on the command line"
96         echo " e.g. make sync PLCHOST=private.one-lab.org" ; exit 1
97 else
98         +$(RSYNC) PLC planetlab4.sql migrations $(PLCSSH):/plc/root/usr/share/plc_api/
99         ssh $(PLCSSH) chroot /plc/root apachectl graceful
100 endif
101
102 ####################
103 # All .py files in PLC/
104
105 # the current content of __init__.py
106 PLC_now := $(sort $(shell fgrep -v '"' PLC/__init__.py 2>/dev/null))
107 # what should be declared
108 PLC_paths := $(filter-out %/__init__.py, $(wildcard PLC/*.py))
109 PLC_files := $(sort $(notdir $(PLC_paths:.py=)))
110
111 ifneq ($(PLC_now),$(PLC_files))
112 PLC/__init__.py: force
113 endif
114 PLC/__init__.py: 
115         (echo 'all = """' ; cd PLC; ls -1 *.py | grep -v __init__ | sed -e 's,.py$$,,' ; echo '""".split()') > $@
116
117
118 # the current content of __init__.py
119 METHODS_now := $(sort $(shell fgrep -v '"' PLC/Methods/__init__.py 2>/dev/null))
120 # what should be declared
121 METHODS_paths := $(filter-out %/__init__.py, $(wildcard PLC/Methods/*.py PLC/Methods/system/*.py))
122 METHODS_files := $(sort $(notdir $(subst system/, system., $(METHODS_paths:.py=))))
123
124 ifneq ($(METHODS_now),$(METHODS_files))
125 PLC/Methods/__init__.py: force
126 endif
127 PLC/Methods/__init__.py: 
128         (echo 'methods = """' ; cd PLC/Methods; ls -1 *.py system/*.py | grep -v __init__ | sed -e 's,.py$$,,' -e 's,system/,system.,' ; echo '""".split()') > $@
129
130 force:
131
132 .PHONY: all install force clean index tags $(subdirs) $(modules)
133
134 #################### convenience, for debugging only
135 # make +foo : prints the value of $(foo)
136 # make ++foo : idem but verbose, i.e. foo=$(foo)
137 ++%: varname=$(subst +,,$@)
138 ++%:
139         @echo "$(varname)=$($(varname))"
140 +%: varname=$(subst +,,$@)
141 +%:
142         @echo "$($(varname))"
143