c9deb28d1ef8f1ff48a190cd60b109c2f53ab736
[nepi.git] / Makefile
1 SRCDIR      = $(CURDIR)/src
2 TESTDIR     = $(CURDIR)/test
3 TESTLIB     = $(TESTDIR)/lib
4 BUILDDIR    = $(CURDIR)/build/lib
5 DISTDIR     = $(CURDIR)/dist
6
7 PYPATH = $(BUILDDIR):$(TESTLIB):$(PYTHONPATH)
8 COVERAGE = $(or $(shell which coverage), $(shell which python-coverage), \
9            coverage)
10
11 all: clean
12         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" ./setup.py build
13
14 install: all
15         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" ./setup.py install
16
17 test: all
18         retval=0; \
19                for i in `find "$(TESTDIR)" -iname '*.py' -perm -u+x -type f`; do \
20                echo $$i; \
21                PYTHONPATH="$(PYPATH)" $$i -v || retval=$$?; \
22                done; exit $$retval
23
24 ifeq ($(file),)
25 test-one:
26         echo Run $(make) $@ file=test/some/path
27 else
28 test-one: all
29         echo $(file) $(case)
30         PYTHONPATH="$(PYPATH)" $(file) $(case)
31 endif
32
33 test-app:
34         $(MAKE) test-one file=test/resources/linux/application.py case=$(case)
35 test-node:
36         $(MAKE) test-one file=test/resources/linux/node.py case=$(case)
37
38 coverage: all
39         rm -f .coverage
40         for i in `find "$(TESTDIR)" -perm -u+x -type f`; do \
41                 set -e; \
42                 PYTHONPATH="$(PYPATH)" $(COVERAGE) -x $$i -v; \
43                 done
44         $(COVERAGE) -c
45         $(COVERAGE) -r -m `find "$(BUILDDIR)" -name \\*.py -type f`
46         rm -f .coverage
47
48 clean:
49         rm -f $$(find . -name '*.pyc') .coverage *.pcap
50         rm -rf "$(BUILDDIR)"
51
52 distclean: clean
53         rm -rf "$(DISTDIR)"
54
55 MANIFEST:
56         find . -path ./.hg\* -prune -o -path ./build -prune -o \
57                 -name \*.pyc -prune -o -name \*.swp -prune -o \
58                 -name MANIFEST -prune -o -type f -print | \
59                 sed 's#^\./##' | sort > MANIFEST
60
61 dist: MANIFEST
62         ./setup.py sdist
63
64 .PHONY: all clean distclean dist test coverage install MANIFEST
65
66 ########## for uploading onto pypi
67 # this assumes you have an entry 'pypi' in your .pypirc
68 # see pypi documentation on how to create .pypirc
69 LOCAL_ID=$(shell id)
70 ifneq "$(LOCAL_ID)" "$(filter $(LOCAL_ID),parmen)"
71 BUILD_ID=thierry
72 else
73 BUILD_ID=mario
74 endif
75
76 PYPI_TARGET=pypi
77 PYPI_TARBALL_HOST=$(BUILD_ID)@build.onelab.eu
78 PYPI_TARBALL_TOPDIR=/build/nepi
79
80 VERSION=$(shell cat VERSION)
81 VERSIONTAG=nepi-$(VERSION)-pypi
82 VERSIONTAR=nepi-$(VERSION).tar.gz
83 ALREADY_SET=$(shell git tag | grep '^$(VERSIONTAG)$$')
84
85 # run this only once the sources are in on the right tag
86 pypi:
87         @echo "Have you committed all changes (type Ctrl-c if not) ? " ; read _
88         @if [ -n "$(ALREADY_SET)" ] ; then echo "tag $(VERSIONTAG) already set"; false; fi
89         @echo "You are about to release $(VERSION) - OK (Ctrl-c if not) ? " ; read _
90         git tag $(VERSIONTAG)
91         #./setup.py sdist upload -r pypi
92         ./setup.py sdist
93         twine upload dist/* -r pypi
94         @if [ ssh $(PYPI_TARBALL_HOST) ls $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAR) ] ;\
95           then echo "$(VERSIONTAR) already present on $(PYPI_TARBALL_HOST) - ignored" ;\
96           else rsync -av dist/$(VERSIONTAR) $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/ ;\
97           fi
98
99
100 # it can be convenient to define a test entry, say testpypi
101 # that points at the testpypi public site
102 # in this case we do not want to upload anything on the build box though
103
104 testpypi: 
105         #./setup.py sdist upload -r testpypi
106         ./setup.py sdist
107         twine upload dist/* -r testpypi
108
109 #################### convenience, for debugging only
110 # make +foo : prints the value of $(foo)
111 # make ++foo : idem but verbose, i.e. foo=$(foo)
112 ++%: varname=$(subst +,,$@)
113 ++%:
114         @echo "$(varname)=$($(varname))"
115 +%: varname=$(subst +,,$@)
116 +%:
117         @echo "$($(varname))"