#!/usr/bin/make -f

DEB_BUILD_DIR := obj-$(DEB_HOST_GNU_TYPE)

%:
	dh $@ --buildsystem=cmake+ninja

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_WEB_APP=ON -DUSE_SYSTEM_NODEJS_MODULES=ON

override_dh_auto_test:
	# No tests configured

override_dh_install:
	dh_install
	# On Ubuntu, prefer system llama.cpp by default
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu 2>/dev/null && echo yes))
	jq '.llamacpp.prefer_system = true' debian/lemonade-server/usr/share/lemonade/defaults.json \
		> debian/lemonade-server/usr/share/lemonade/defaults.json.tmp && \
		mv debian/lemonade-server/usr/share/lemonade/defaults.json.tmp \
		debian/lemonade-server/usr/share/lemonade/defaults.json
endif
