diff --git a/Makefile b/Makefile index 7d346b9..7b6b4d4 100644 --- a/Makefile +++ b/Makefile @@ -78,13 +78,10 @@ $(OUT)/libdcurl.so: $(OBJS) $(VECHO) " LD\t$@\n" $(Q)$(CC) -shared -o $@ $^ $(LDFLAGS) -# FIXME: script "tests/test-multi_pow.py" depends on PyIOTA package, and we -# have to check in advance, otherwise python3 would complain as following: -# ModuleNotFoundError: No module named 'iota' $(OUT)/test-multi_pow_%: tests/test-multi_pow_%.py $(OUT)/libdcurl.so - @echo "#!/usr/bin/env python3" > $@ - @cat $< >> $@ - @chmod +x $@ + $(Q)echo "#!$(PYTHON)" > $@ + $(call py_prepare_cmd) + $(Q)chmod +x $@ $(OUT)/test-%.done: $(OUT)/test-% $(Q)$(PRINTF) "*** Validating $< ***\n" @@ -97,4 +94,5 @@ distclean: clean $(RM) local.mk include mk/common.mk +include mk/python.mk -include $(deps) diff --git a/mk/python.mk b/mk/python.mk new file mode 100644 index 0000000..b88a92e --- /dev/null +++ b/mk/python.mk @@ -0,0 +1,14 @@ +PYTHON = python3 +PYTHON := $(shell which $(PYTHON)) +ifndef PYTHON +$(error "python3 is required.") +endif + +# check "iota" module in Python installation +PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \ + echo 1 || echo 0) +ifeq ("$(PY_CHECK_MOD_IOTA)","1") + py_prepare_cmd = $(Q)cat $< >> $@ +else + py_prepare_cmd = $(warning "skip $@ because PyIOTA is not installed.") +endif