#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

LLHTTPVERSION = $(shell pkgjs-pjson llhttp version)
LLHTTPMAJORVERSION = $(shell pkgjs-pjson llhttp version|perl -pe 's/\..*//')
export SONAME = libllhttp.so.$(LLHTTPVERSION)
export SONAMEALIAS = libllhttp.so.$(LLHTTPMAJORVERSION)
LIBLLHTTPVERSION = $(LLHTTPVERSION)~$(DEB_VERSION)

zz:
	echo $(LLHTTPMAJORVERSION)

%:
	dh $@

override_dh_auto_test:
	# autopkgtest only

execute_after_dh_auto_install:
	cd llhttp && $(MAKE) install DESTDIR=../debian/tmp PREFIX=/usr LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
	dh_auto_install --buildsystem=cmake -Dllhttp/release

execute_after_dh_install:
	rm -f debian/node-undici/usr/share/nodejs/undici/lib/web/fetch/LICENSE
	rm -f debian/node-undici/usr/share/nodejs/@fastify/busboy/deps/dicer/LICENSE

execute_after_dh_clean:
	rm -rf obj-*
	rm -f lib/llhttp/llhttp_simd-wasm.js
	rm -f lib/llhttp/llhttp_simd.wasm

override_dh_makeshlibs:
	dh_makeshlibs -a -- -plibllhttp9.2

override_dh_gencontrol:
	dh_gencontrol -pnode-undici -- -v$(DEB_VERSION)
	dh_gencontrol -plibllhttp-dev -- -v$(LLHTTPVERSION)~$(DEB_VERSION) \
		-Vlibllhttp:Version=$(LIBLLHTTPVERSION) \
		-DHomepage=https://github.com/nodejs/llhttp
	dh_gencontrol -pnode-llhttp -- -v$(LLHTTPVERSION)~$(DEB_VERSION) \
		-DHomepage=https://github.com/nodejs/llhttp
	dh_gencontrol -plibllhttp9.2 -- -v$(LLHTTPVERSION)~$(DEB_VERSION) \
		-DHomepage=https://github.com/nodejs/llhttp
