- must build modules before subdirs
[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.9 2006/12/15 16:19:49 mlhuang Exp $
8 #
9
10 # Metafiles
11 init := PLC/__init__.py PLC/Methods/__init__.py
12
13 # Python modules
14 modules := psycopg2 pycurl
15 modules-install := $(foreach module, $(modules), $(module)-install)
16 modules-clean := $(foreach module, $(modules), $(module)-clean)
17
18 # Other stuff
19 subdirs := doc php php/xmlrpc
20
21 # autoconf compatible variables
22 DESTDIR := /plc/root
23 datadir := /usr/share
24 bindir := /usr/bin
25
26 PWD := $(shell pwd)
27
28 all: $(init) $(subdirs) $(modules)
29         python setup.py build
30
31 install: $(modules-install)
32         python setup.py install \
33             --install-purelib=$(DESTDIR)/$(datadir)/plc_api \
34             --install-scripts=$(DESTDIR)/$(datadir)/plc_api \
35             --install-data=$(DESTDIR)/$(datadir)/plc_api
36         install -D -m 755 php/xmlrpc/xmlrpc.so $(DESTDIR)/$(shell php-config --extension-dir)/xmlrpc.so
37
38 $(subdirs): $(init) $(modules)
39
40 $(subdirs): %:
41         $(MAKE) -C $@
42
43 $(modules):
44         # Install in the current directory so that we can import it while developing
45         cd $@ && \
46             python setup.py build && \
47             python setup.py install_lib --install-dir=$(PWD)
48
49 $(modules-install): %-install:
50         cd $* && \
51             python setup.py install_lib --install-dir=$(DESTDIR)/$(datadir)/plc_api
52
53 $(modules-clean): %-clean:
54         cd $* && python setup.py clean && rm -rf build
55
56 clean: $(modules-clean)
57         find . -name '*.pyc' | xargs rm -f
58         rm -f $(INIT)
59         for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir clean ; done
60         python setup.py clean && rm -rf build
61
62 index: $(init)
63
64 tags:
65         find . '(' -name '*.py' -o -name '*.sql' -o -name '*.php' -o -name Makefile ')' | xargs etags
66
67 # All .py files in PLC/
68 PLC := $(filter-out %/__init__.py, $(wildcard PLC/*.py))
69 PLC_init := all = '$(notdir $(PLC:.py=))'.split()
70
71 PLC/__init__.py:
72         echo "$(PLC_init)" >$@
73
74 ifneq ($(sort $(PLC_init)), $(sort $(shell cat PLC/__init__.py 2>/dev/null)))
75 PLC/__init__.py: force
76 endif
77
78 # All .py files in PLC/Methods/ and PLC/Methods/system/
79 METHODS := $(filter-out %/__init__.py, $(wildcard PLC/Methods/*.py PLC/Methods/system/*.py))
80 Methods_init := methods = '$(notdir $(subst system/, system., $(METHODS:.py=)))'.split()
81
82 PLC/Methods/__init__.py:
83         echo "$(Methods_init)" >$@
84
85 ifneq ($(sort $(Methods_init)), $(sort $(shell cat PLC/Methods/__init__.py 2>/dev/null)))
86 PLC/Methods/__init__.py: force
87 endif
88
89 force:
90
91 .PHONY: all install force clean index tags $(subdirs) $(modules)