# extensions/configure/RULES_PYTHON

ifdef T_A
ifeq ($(findstring Host,$(VALID_BUILDS)),Host)

SWIG ?= swig

vpath %.py $(USR_VPATH) $(ALL_SRC_DIRS)

# The optional PYTHON_INSTALL_LOCATION environment variable 
# should be set to <python install site directory>/site-packages
PYTHON_INSTALL_LOCATION ?= $(INSTALL_LOCATION)/lang/python

INSTALL_PYTHON = $(PYTHON_INSTALL_LOCATION)/$(PYTHON_PACKAGE)

PYTHON_PACKAGE_PTH = $(addsuffix .pth,$(PYTHON_PACKAGE))
INSTALL_PYTHON_PACKAGE_PTH = $(addprefix $(PYTHON_INSTALL_LOCATION)/,$(PYTHON_PACKAGE_PTH))

PYTHON_SCRIPTS = $(filter-out $(LOADABLE_LIBRARY),$(PYTHON_MODULES))
PYTHON_LIBRARY = $(filter $(LOADABLE_LIBRARY),$(PYTHON_MODULES))
PYTHON_SHRLIBNAME = $(PYTHON_LIBRARY:%=$(LOADABLE_SHRLIB_PREFIX)%$(LOADABLE_SHRLIB_SUFFIX))

INSTALL_PYTHONS = $(addprefix $(INSTALL_PYTHON)/,$(PYTHON_SCRIPTS))
INSTALL_PYTHONS += $(addprefix $(INSTALL_PYTHON)/,$(PYTHON_SHRLIBNAME))

buildInstall: $(INSTALL_PYTHONS) $(INSTALL_PYTHON_PACKAGE_PTH)

$(INSTALL_PYTHON)/%: %
	@echo "Installing python modules $@"
	@$(INSTALL) -d -m 644 $< $(INSTALL_PYTHON)

$(INSTALL_PYTHON)/%: ../%
	@echo "Installing python modules $@"
	@$(INSTALL) -d -m 644 $< $(INSTALL_PYTHON)

$(PYTHON_INSTALL_LOCATION)/%: %
	@echo "Installing python pth file $@"
	@$(INSTALL) -d -m 644 $< $(PYTHON_INSTALL_LOCATION)

$(PYTHON_PACKAGE_PTH):
	@echo $(PYTHON_PACKAGE) > $@

%_wrap.c: ../%.i
	$(SWIG) -python -o $@ $< 

ifdef BASE_3_15
clean:
else
clean::
endif
	@$(RM) *.py *.so *.pth

endif
endif
