#!/usr/bin/make -f

# output every command that modifies files on the build system.
export DH_VERBOSE = 1

export HOME=$(CURDIR)/debian/fakehome
export PATH := $(PATH):$(CURDIR)/debian/bin
export NODE_OPTIONS=--openssl-legacy-provider

include /usr/share/dpkg/architecture.mk

ifeq ($(DEB_HOST_ARCH),amd64)
	VSCODE_ARCH := x64
else ifeq ($(DEB_HOST_ARCH),arm64)
	VSCODE_ARCH := arm64
else ifeq ($(DEB_HOST_ARCH),armhf)
	VSCODE_ARCH := armhf
else
	$(error 'unsupported architecture')
endif


%:
	dh $@

override_dh_auto_build:
	npm install
	node --max-old-space-size=10240 ./node_modules/gulp/bin/gulp.js compile

	./debian/undo-telemetry.sh
	
	node --max_old_space_size=4096 ./node_modules/gulp/bin/gulp.js vscode-linux-$(VSCODE_ARCH)-min
	node build/lib/electron

override_dh_shlibdeps:
	# dpkg-shlibdeps: error fails because missing libraries.
	# several compiled parts are downloaded during the build
	dpkg-shlibdeps -edebian/code-oss/usr/lib/code-oss/code-oss

execute_after_dh_install:
	mv debian/code-oss/usr/lib/code-oss/resources/app/out-vscode-min/ debian/code-oss/usr/lib/code-oss/resources/app/out

override_dh_dwz:
#	dh_dwz -Xchrome -Xcode-oss -X*.so

override_dh_strip:
#ifeq ($(DEB_HOST_ARCH),arm64)
#	dh_strip -Xkeytar.node
#else
#	dh_strip
#endif
