jw-pkg/make/py-mod.mk
Jan Lindemann 42e01d9dd8 py-mod.mk: Fix python version conditional
Signed-off-by: Jan Lindemann <jan@janware.com>
2019-06-11 07:41:45 +00:00

49 lines
1.6 KiB
Makefile

include $(MODDIR)/make/defs.mk
include $(MODDIR)/make/py-defs.mk
include $(MODDIR)/make/dirs.mk
include $(MODDIR)/make/dev-utils.mk
PY_INIT_TMPL = $(wildcard __init__.py.tmpl)
PY_SED_EXTRACT_EXPORT ?= /\(class\|def\) ..*\# *export/ !d; s/\(class\|def\) *//; s/[(:].*//
#leftparen := (
#PY_EXPORT ?= $(shell sed '/\(class\|def\) ..*\# *export/ !d; s/\(class\|def\) *//; s/[$(leftparen):].*//' $(PY_SRC_PY))
all: $(PY_PYC)
install: install-dirs.done install-reg.done
clean: py.clean
distclean:
py.clean:
$(RM) -f *.done *.pyc
/bin/bash $(MOD_SCRIPT_DIR)/scm.sh clean -f __init__.py
$(RM) -rf __pycache__
install-dirs.done:
$(INSTALL) -d -m $(PYMODDIRMODE) -o $(PYMODDIROWNER) -g $(PYMODDIRGROUP) $(PY_INSTALL_DIRS)
touch $@
install-reg.done: install-dirs.done $(PY_INSTALLED_REG)
touch $@
$(PY_INSTALL_DIR_PY)/%.py: %.py
$(INSTALL) -p -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@
ifneq ($(PYTHON_VERSION),3)
%.pyc: %.py
else
__pycache__/%.cpython-37.pyc: %.py
endif
$(PYTHON) -c "import py_compile; py_compile.compile(\"$<\", doraise=True)"
ifeq ($(PYTHON_VERSION),3)
$(PY_INSTALL_DIR_PY)/__pycache__/%.cpython-37.pyc: __pycache__/%.cpython-37.pyc
else
$(PY_INSTALL_DIR_PY)/%.pyc: %.pyc
endif
$(INSTALL) -p -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@
__init__.py: $(PY_INIT_TMPL) $(filter-out __init__.py,$(PY_SRC_PY))
if [ "$(PY_INIT_TMPL)" ]; then cat "$(PY_INIT_TMPL)" > $@.tmp; else > $@.tmp; fi
/bin/bash +H $(MOD_SCRIPT_DIR)/python-tools.sh create-init -m $(PY_MOD) -e "$(PY_SED_EXTRACT_EXPORT)" *.py | tee -a $@.tmp
mv $@.tmp $@