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