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