Skip to content

Commit

Permalink
Move python specific into PY subdirectories
Browse files Browse the repository at this point in the history
Change logic to provide both python2 and python3 in PYTHON variable.
If set to empty, nothing is built. If set to specific, only that is
built. Simplify logic. Makes a bit uglier error reports when something
fails.
  • Loading branch information
pemensik committed Feb 28, 2021
1 parent 021e254 commit dbc3527
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 30 deletions.
49 changes: 19 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ SIZE = $(CROSS_PREFIX)size
STRIP = $(CROSS_PREFIX)strip
SHLIB = $(CC) -shared
STRIPLIB = $(STRIP) --strip-unneeded
SWIG = swig
PYTHON ?= -all-
PYTHON ?= python2 python3

SOVERSION = 1

Expand Down Expand Up @@ -77,7 +76,7 @@ DOCS = \

LIB = $(LIB_LGPIO) $(LIB_RGPIO)

ALL = $(LIB) rgpiod rgs DOC/.docs
ALL = $(LIB) rgpiod rgs DOC/.docs lgpio.py

LINK_LGPIO = -L. -llgpio -pthread -lrt
LINK_RGPIO = -L. -lrgpio -pthread -lrt
Expand All @@ -101,17 +100,16 @@ DOC/.docs: $(DOCS)
@[ -d "DOC" ] && cd DOC && ./cdoc || echo "*** No DOC directory ***"
touch DOC/.docs

lgpio.py: $(LIB_LGPIO)
@for PBIN in $(PYTHON); do \
if $$PBIN --version >&/dev/null; then \
$(MAKE) -C PY_LGPIO build-python PYTHON=$$PBIN $(MAKEFLAGS) || \
echo "*** build of $$PBIN lgpio.py failed ***"; \
fi; \
done
clean:
rm -f *.o *.i *.s *~ $(ALL) *.so.$(SOVERSION)

ifeq ($(DESTDIR),)
PYBUILDARGS =
PYINSTALLARGS =
else
PYBUILDARGS = --include-dirs=$(DESTDIR)$(includedir) --library-dirs=$(DESTDIR)$(libdir)
PYINSTALLARGS = --root=$(DESTDIR)
endif

html: $(ALL)
@[ -d "DOC" ] && cd DOC && ./makedoc || echo "*** No DOC directory ***"

Expand All @@ -137,25 +135,16 @@ ifeq ($(DESTDIR),)
ldconfig
endif

install-python:
(cd PY_RGPIO && $(PYTHON) setup.py -q install $(PYINSTALLARGS)) || echo "*** install of Python rgpio.py failed ***";
if type -p $(SWIG) >&/dev/null; then \
(cd PY_LGPIO && $(SWIG) -python lgpio.i) || echo "*** need swig package to install lgpio.py ***"; \
(cd PY_LGPIO && \
$(PYTHON) setup.py build_ext $(PYBUILDARGS) && \
$(PYTHON) setup.py -q install $(PYINSTALLARGS) ) || \
echo "*** install of Python lgpio.py failed ***"; \
fi

install: $(ALL) install-native
if [ "$(PYTHON)" = '-all-' ]; then \
python2 --version >&/dev/null && \
$(MAKE) install-python PYTHON=python2 $(MAKEFLAGS); \
python3 --version >&/dev/null && \
$(MAKE) install-python PYTHON=python3 $(MAKEFLAGS); \
elif [ -n "$(PYTHON)" ]; then \
$(MAKE) install-python $(MAKEFLAGS); \
fi
install-python: lgpio.py
@for PBIN in $(PYTHON); do \
if $$PBIN --version >&/dev/null; then \
$(MAKE) -C PY_RGPIO install PYTHON=$$PBIN $(MAKEFLAGS) && \
$(MAKE) -C PY_LGPIO install PYTHON=$$PBIN $(MAKEFLAGS) || \
echo "*** install of $$PBIN modules failed ***"; \
fi; \
done

install: $(ALL) install-native install-python

uninstall:
rm -f $(DESTDIR)$(includedir)/lgpio.h
Expand Down
32 changes: 32 additions & 0 deletions PY_LGPIO/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SWIG = swig
PYTHON ?= python3

ifeq ($(DESTDIR),)
PYBUILDARGS =
PYINSTALLARGS =
else
PYBUILDARGS = --include-dirs=$(DESTDIR)$(includedir) --library-dirs=$(DESTDIR)$(libdir)
PYINSTALLARGS = --root=$(DESTDIR)
endif

all: build-python

build-python: lgpio.i
@if type -p $(SWIG) >&/dev/null; then \
$(SWIG) -python lgpio.i && \
$(PYTHON) setup.py build_ext $(PYBUILDARGS); \
else \
echo "*** need swig package to install lgpio.py ***"; \
fi

lgpio_wrap.c: build-python

install-python:
@if type -p $(SWIG) >&/dev/null; then \
$(PYTHON) setup.py -q install $(PYINSTALLARGS); \
fi

install: install-python

clean:
rm -f lgpio_wrap.c
17 changes: 17 additions & 0 deletions PY_RGPIO/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PYTHON ?= python3

ifeq ($(DESTDIR),)
PYINSTALLARGS =
else
PYINSTALLARGS = --root=$(DESTDIR)
endif

all: build-python

build-python:
@$(PYTHON) setup.py build

install-python: build-python
@$(PYTHON) setup.py -q install $(PYINSTALLARGS)

install: install-python

0 comments on commit dbc3527

Please sign in to comment.