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

export DH_VERBOSE=1

MIN_KEEPASS_VERSION=$(shell sed -n "/plgx-prereq-kp:/ s|.*plgx-prereq-kp:\([0-9\.]*\).*|\1|p" KeePassRPC/KeePassRPC.csproj | sort -uV | tail -n1)

%:
	dh $@ --with=cli

override_dh_auto_build:
	# Build Jayrock*.dll
	LC_ALL=C.UTF-8 xbuild /target:Jayrock /property:Configuration=Release /property:Deterministic=True
	cp -a Jayrock/bin/net-4.0/release/*.dll KeePassRPC
	#cp -a ../Jayrock*dll KeePassRPC

	# Build Fleck2.dll
	# https://github.com/luckyrat/Fleck2
	cd Fleck2 && LC_ALL=C.UTF-8 xbuild /target:Fleck2 /property:Configuration=Release /property:Deterministic=True /p:TargetFrameworkVersion=v3.5
	cp -a Fleck2/src/bin/Release/*.dll KeePassRPC
	#cp -a ../Fleck2.dll KeePassRPC

	# Build DomainPublicSuffix.dll
	# https://github.com/luckyrat/domain-public-suffix
	cd DomainPublicSuffix/ && LC_ALL=C.UTF-8 xbuild /target:domain-public-suffix /property:Configuration=Release /property:Deterministic=True
	cp -a DomainPublicSuffix/domain-public-suffix/bin/Release/*.dll KeePassRPC
	#cp -a ../DomainPublicSuffix.dll KeePassRPC

	# Build KeePassRPC.plgx
	LC_ALL=C.UTF-8 xbuild /target:KeePassRPC /property:Configuration=Release /property:ProjectName=KeePassRPC /property:Deterministic=True
	#keepass2 --plgx-create KeePassRPC

execute_before_dh_gencontrol:
	echo "Min-Keepass-Version=$(MIN_KEEPASS_VERSION)" >> debian/keepass2-plugin-keepassrpc.substvars
