diff --git a/make/cleandirs.mk b/make/cleandirs.mk new file mode 100644 index 00000000..0caa28c2 --- /dev/null +++ b/make/cleandirs.mk @@ -0,0 +1,28 @@ +.NOTPARALLEL: + +all: do.all +install: do.install +clean: do.clean +distclean: do.distclean + +include $(JWBDIR)/make/defs.mk + +SUBDIRS ?= $(FIND_SUBDIRS) + +ifeq ($(FORCE_REBUILD_CLEANDIRS),true) + SUBDIRS_ALL = $(SUBDIRS) + SUBDIRS_INSTALL = $(SUBDIRS) +else + SUBDIRS_ALL ?= + SUBDIRS_INSTALL ?= +endif + +do.all: + set -e; for d in $(SUBDIRS_ALL); do make -wC $$d $*; done + +do.install: + set -e; for d in $(SUBDIRS_INSTALL); do make -wC $$d $*; done + +do.%: + set -e; for d in $(SUBDIRS); do make -wC $$d $*; done + $(RM) -rf $(TEXTCLEAN) $(CLEAN) *.done *~ .*.swp *.tmp core *.rep dirs-*.done diff --git a/make/ldlibpath.mk b/make/ldlibpath.mk new file mode 100644 index 00000000..2c12aab7 --- /dev/null +++ b/make/ldlibpath.mk @@ -0,0 +1,17 @@ +# jan's utility modules +# (c) 2001-2005 jannet it services +# contact@jannet.de +# $Id$ + +LD_LIB_PATH_ENV := $(LD_LIBRARY_PATH) +EXE_SEARCH_PATH_ENV := $(PATH) +LD_LIB_PATH_LDFLAGS = $(shell echo $(FINAL_LDFLAGS) | $(SED) 's/^-[^L] *[^ ]*/ /g; s/[ ]-[^L] *[^ ]*/ /g; s/-L[ ]*\([^ ]*\)[ ]*/\1:/g') + +ifeq ($(TARGET),mingw) +DLL_PATH = $(shell echo $(LD_LIBRARY_PATH) | $(SED) 's/:/;/g');$(CROSS_TOOL_DIR)/bin +endif + +#export LD_LIBRARY_PATH = $(shell echo $(strip $(LD_LIB_PATH_LDFLAGS):$(LD_LIB_PATH):$(LD_LIB_PATH_ENV)) | $(SED) 's/ /:/g; s/::/:/g') +LD_LIBRARY_PATH := $(call proj_query, ldlibpath $(PROJECT) $(PREREQ_BUILD)) +export LD_LIBRARY_PATH +export PATH := $(call proj_query, exepath $(PROJECT) $(PREREQ_BUILD)):$(EXE_SEARCH_PATH_ENV) diff --git a/make/profile.mk b/make/profile.mk new file mode 100644 index 00000000..1ac3c0d7 --- /dev/null +++ b/make/profile.mk @@ -0,0 +1,26 @@ +# generic utility modules +# (c) 2001 jannet it services +# contact@jannet.de +# $Id$ + +PATH_PROFILE ?= path-$(PROJECT).sh +EXE_SH = + +ifeq ($(PROFILE),) + PROFILE = $(PATH_PROFILE) +endif + +PROFILE += $(filter-out $(PATH_PROFILE),$(wildcard *.sh)) + +include $(JWBDIR)/make/defs.mk +include $(JWBDIR)/make/rules.mk + +all: $(PROFILE) +install: install_files_PROFILE +clean: allclean localclean doneclean textclean clean.profile + +path-%.sh: + @echo "export PATH=\$$PATH:$(INSTALL_EXEDIR)" > $@.tmp + mv $@.tmp $@ +clean.profile: + /bin/bash $(JWB_SCRIPT_DIR)/scm.sh clean -f $(PROFILE) diff --git a/make/py-defs.mk b/make/py-defs.mk new file mode 100644 index 00000000..c3a7a76d --- /dev/null +++ b/make/py-defs.mk @@ -0,0 +1,119 @@ +ENV_PYTHONPATH := $(PYTHONPATH) + +include $(JWBDIR)/make/py-version.mk + +ifeq ($(DEVELOPMENT),true) + PY_SITE_PACKAGES_PATH := $(PREFIX)/python$(PYTHON_VERSION)/site-packages +else + PY_SITE_PACKAGES_PATH := $(shell $(PYTHON) -c "import site; print([d for d in site.getsitepackages() if d.find('/local/') == -1][0])") +endif + +ifndef PY_PREREQ_BUILD + PY_PREREQ_BUILD := $(shell $(proj_query_cmd) pkg-requires --subsections jw -d ' ' -p --no-version build $(PROJECT)) +endif + +ifndef PY_PREREQ_BUILD_DIRS + PY_PREREQ_BUILD_DIRS := $(shell $(proj_query_cmd) proj-dir $(PY_PREREQ_BUILD)) +endif + +PY_MYPY ?= mypy --ignore-missing-imports --no-namespace-packages + +PY_SRC_PY ?= $(wildcard *.py) +PY_ALL_PY = $(PY_SRC_PY) + +ifneq ($(PYTHON_MAJOR),3) + PY_PYC = $(patsubst %.py,%.pyc,$(PY_ALL_PY)) +else + PY_CPYTHON_PREFIX := $(shell $(PYTHON) -c "import sys; print('cpython-{}{}'.format(sys.version_info[0],sys.version_info[1]))") + PY_PYC = $(patsubst %.py,__pycache__/%.$(PY_CPYTHON_PREFIX).pyc,$(PY_ALL_PY)) +endif + +ifneq ($(PY_INSTALL_DIR),) + PY_INSTALL_DIR_PY ?= $(PY_INSTALL_DIR) +endif + +# deduce PY_INSTALL_DIR_PY from working directory below .. python/ +ifeq ($(PY_INSTALL_DIR_PY),) + PY_INSTALL_PKG_MOD ?= $(shell $(ECHO) $(CWD) | $(SED) 's%.*/python/%%; s%/.*%%') + PY_INSTALL_SUB_MOD ?= $(shell $(ECHO) $(CWD) | $(SED) "s%.*/$(PY_INSTALL_PKG_MOD)\(/\|$$\)%%") + ifneq ($(PY_INSTALL_SUB_MOD),) + PY_INSTALL_MOD ?= $(PY_INSTALL_PKG_MOD)/$(PY_INSTALL_SUB_MOD) + else + PY_INSTALL_MOD ?= $(PY_INSTALL_PKG_MOD) + endif + PY_MOD ?= $(subst /,.,$(PY_INSTALL_MOD)) + PY_ALL_PY += __init__.py + PY_INSTALL_DIR_PY ?= $(ENV_PREFIX)$(PY_SITE_PACKAGES_PATH)/$(patsubst .,/,$(PY_INSTALL_MOD)) +else + ifeq ($(PY_INSTALL_DIR_PY),) + $(error PY_INSTALL_DIR_PY is undefined) + endif +endif + +ifeq ($(PYTHON_MAJOR),3) + PY_INSTALL_DIR_PYC ?= $(PY_INSTALL_DIR_PY)/__pycache__ +else + PY_INSTALL_DIR_PYC ?= $(PY_INSTALL_DIR_PY) +endif + +PY_INSTALL ?= true +PY_INSTALL_REG ?= true +ifneq ($(PY_INSTALL),true) + PY_INSTALL_REG = false +endif +PY_INSTALL_PYC ?= true +ifneq ($(PY_INSTALL_REG),true) + PY_INSTALL_PYC = false +endif + +PY_INSTALL_DIRS ?= $(sort $(PY_INSTALL_DIR_PY) $(PY_INSTALL_DIR_PYC)) +PY_INSTALLED_PY = $(addprefix $(PY_INSTALL_DIR_PY)/,$(sort $(PY_ALL_PY))) +ifeq ($(PY_INSTALL_PYC),true) + PY_INSTALLED_PYC = $(addprefix $(PY_INSTALL_DIR_PY)/,$(PY_PYC)) +endif +ifeq ($(PY_INSTALL_REG),true) + PY_INSTALLED_REG = $(PY_INSTALLED_PY) $(PY_INSTALLED_PYC) +endif + +ifeq ($(origin PYTHONPATH),undefined) + PYTHONPATH := $(call proj_query, pythonpath $(PROJECT) $(PY_PREREQ_RUN)) +endif +#PYTHONPATH = $(subst $(space),,$(ENV_PYTHONPATH)$(foreach d,$(PY_MODULE_DIRS),:$(d))) +MYPYPATH = $(PYTHONPATH) +export PYTHONPATH MYPYPATH + +# not used anywhere +#PY_PROJ_MODULE_DIRS ?= $(wildcard $(foreach subdir,/tools/python /src/python,$(addsuffix $(subdir),$(TOPDIR) $(PY_PREREQ_BUILD_DIRS)))) +#PY_MODULE_DIRS ?= $(PY_PROJ_MODULE_DIRS) +#PY_MODULES ?= $(PY_PROJ_MODULES) +#PY_PROJ_MODULES += $(dir $(wildcard $(PY_MODULE_DIRS)/*/__init__.py)) + +ifneq ($(PY_DEFS_MK_INCLUDED),true) +all: +clean: pyc.clean + +echo-py: + @echo "PYTHON = $(PYTHON)" + @echo "PY_INSTALL_DIR_PY = $(PY_INSTALL_DIR_PY)" + @echo "PROJECT = $(PROJECT)" + @echo "PY_SITE_PACKAGES_PATH = $(PY_SITE_PACKAGES_PATH)" + @echo "PY_MODULES = $(PY_MODULES)" + @echo "PYTHONPATH = $(PYTHONPATH)" + @echo "MYPYPATH = $(MYPYPATH)" + @echo "PY_INSTALL_MOD = $(PY_INSTALL_MOD)" + @echo "PY_INSTALL_SUB_MOD = $(PY_INSTALL_SUB_MOD)" + # not used anywhere" + #@echo "PY_PROJ_MODULE_DIRS = $(PY_PROJ_MODULE_DIRS)" + #@echo "PY_MODULE_DIRS = $(PY_MODULE_DIRS)" + +pyc.clean: + $(RM) -rf $(wildcard *.pyc) __pycache__ +libpath: py-libpath +py-libpath: + @echo export PYTHONPATH=$(PYTHONPATH) + @echo export MYPYPATH=$(MYPYPATH) +endif + +PY_DEFS_MK_INCLUDED := true + +include $(JWBDIR)/make/ldlibpath.mk diff --git a/make/py-mod.mk b/make/py-mod.mk new file mode 100644 index 00000000..4e86506c --- /dev/null +++ b/make/py-mod.mk @@ -0,0 +1,24 @@ +include $(JWBDIR)/make/defs.mk +include $(JWBDIR)/make/py-defs.mk +include $(JWBDIR)/make/dirs.mk +include $(JWBDIR)/make/dev-utils.mk + +PY_INIT_TMPL = $(wildcard __init__.py.tmpl) +PY_SED_EXTRACT_EXPORT ?= /\(\(class\|def\)\s\+[a-zA-Z_].*\|^ *\S\+\s*=.*\)\# *export/ !d; /^\s*\#/ d; s/\(async\)* *\(class\|def\) *//; s/[(:=].*// +PY_INIT_FILTER ?= cat + +#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: + +include $(JWBDIR)/make/py-rules.mk + +__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 $(JWB_SCRIPT_DIR)/python-tools.sh create-init -m $(PY_MOD) -e "$(PY_SED_EXTRACT_EXPORT)" \ + $(filter-out __init__.py,$(PY_ALL_PY)) $(SUBDIRS_TO_ITERATE) | $(PY_INIT_FILTER) | tee -a $@.tmp + mv $@.tmp $@ diff --git a/make/py-mods.mk b/make/py-mods.mk new file mode 100644 index 00000000..07579e3a --- /dev/null +++ b/make/py-mods.mk @@ -0,0 +1,14 @@ +include $(JWBDIR)/make/defs.mk +include $(JWBDIR)/make/py-defs.mk +include $(JWBDIR)/make/dirs.mk +include $(JWBDIR)/make/dev-utils.mk +include $(JWBDIR)/make/py-rules.mk + +all: +install: +clean: py.clean +distclean: + +ifeq ($(PY_RUN_CHECK_AFTER_BUILD),true) +all: check +endif diff --git a/make/py-rules.mk b/make/py-rules.mk new file mode 100644 index 00000000..aaa8f3d0 --- /dev/null +++ b/make/py-rules.mk @@ -0,0 +1,33 @@ +all: + +py.clean: + $(RM) -f *.done *.pyc *.rep + /bin/bash $(JWB_SCRIPT_DIR)/scm.sh clean -f __init__.py + $(RM) -rf __pycache__ .mypy_cache + +install-dirs.done: + $(INSTALL) -d -m $(PYJWBDIRMODE) -o $(PYJWBDIROWNER) -g $(PYJWBDIRGROUP) $(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_MAJOR),3) +%.pyc: %.py +else +__pycache__/%.$(PY_CPYTHON_PREFIX).pyc: %.py +endif + $(PYTHON) -c "import py_compile; py_compile.compile(\"$<\", doraise=True)" + +ifeq ($(PYTHON_MAJOR),3) +$(PY_INSTALL_DIR_PY)/__pycache__/%.$(PY_CPYTHON_PREFIX).pyc: __pycache__/%.$(PY_CPYTHON_PREFIX).pyc +else +$(PY_INSTALL_DIR_PY)/%.pyc: %.pyc +endif + $(INSTALL) -p -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@ + +check: + $(PY_MYPY) $(shell /bin/bash $(JWB_SCRIPT_DIR)/scm.sh ls-files | grep '\.py$$')