#!/usr/bin/make -f

export PYBUILD_NAME=jupyterlab
export JUPYTERLAB_DIR=$(CURDIR)/debian/python3-jupyterlab/usr/share/jupyter/lab
PYVERS=$(shell python3 -c 'import sysconfig;print (sysconfig.get_python_version())')
BUILD_EXTENSIONS=galata/extension

%:
	dh $@ --with python3 --buildsystem=pybuild

execute_after_dh_auto_build:
	cd jupyterlab/staging && \
	pkgjs-install-minimal && \
	webpack --config webpack.prod.config.js

execute_after_dh_install:
	mkdir -p $(JUPYTERLAB_DIR)
	for i in $(shell py3versions -s) ; do ln -s ../../../python3/dist-packages/jupyterlab/staging ../../../python3/dist-packages/jupyterlab/node-version-check.js debian/python3-jupyterlab/usr/lib/$$i/dist-packages/jupyterlab/ ; done
	set -e ; TMPDIR=$$(mktemp -d) ; HOME=$$TMPDIR PYTHONPATH=$(CURDIR)/debian/python3-jupyterlab/usr/lib/python$(PYVERS)/dist-packages/ debian/python3-jupyterlab/usr/bin/jupyter-lab build ; rm -r $$TMPDIR/
	# for i in $(BUILD_EXTENSIONS) ; do echo Building extension $$i ; TMPDIR=$$(mktemp -d) ; HOME=$$TMPDIR PYTHONPATH=$(CURDIR)/debian/python3-jupyterlab/usr/lib/python$(PYVERS)/dist-packages/ debian/python3-jupyterlab/usr/bin/jupyter-labextension build $$i ; rm -r $$TMPDIR/ ; done
	for i in call-bind get-intrinsic @xtuc/long ; do rm -r $(CURDIR)/debian/python3-jupyterlab/usr/share/jupyter/lab/staging/node_modules/$$i ; done

override_dh_auto_test:
	@echo "Tests disabled because of missing depends"

override_dh_auto_clean:
	dh_auto_clean -O--buildsystem=pybuild || true
