# Sengoku: Road to Unification - desktop edition
# SPDX-License-Identifier: GPL-2.0-or-later
FPC ?= fpc
LAZARUS ?= /usr/lib/lazarus/4.4
LCL = -Fu$(LAZARUS)/lcl/units/x86_64-linux -Fu$(LAZARUS)/lcl/units/x86_64-linux/gtk2 -Fu$(LAZARUS)/components/lazutils/lib/x86_64-linux -Fu$(LAZARUS)/packager/units/x86_64-linux
VERSION := $(shell sed -n "s/^ *SengokuVersion = '\(.*\)';/\1/p" src/desktop.pas)
RELEASE = dist/Sengoku-$(VERSION)-x64.msi dist/sengoku_$(VERSION)_amd64.deb dist/sengoku-$(VERSION)-source.tar.gz
.PHONY: all test gui-test deb msi dist clean
all:
	python3 tools/prepare-link.py
	mkdir -p build/linux bin/linux
	$(FPC) -B -O2 -Xs -Flbuild/link -Fusrc $(LCL) -FUbuild/linux -FEbin/linux -osengoku src/sengoku-gui.lpr
test:
	mkdir -p build/tests
	$(FPC) -B -O2 -Fusrc -FUbuild/tests -FEbuild/tests -osengoku-tests -Cr -Co src/sengoku.pas
	build/tests/sengoku-tests --self-test
gui-test: all
	SENGOKU_MUTE=1 xvfb-run -a bin/linux/sengoku --gui-test build/gui-test.png
deb: all test
	python3 tools/package.py
msi:
	sh tools/build-win64.sh --msi
# the four release files, made afresh: Windows installer, Debian package, source, checksums
dist: test gui-test
	rm -f $(addprefix $(CURDIR)/,$(RELEASE)) $(CURDIR)/dist/SHA256SUMS
	python3 tools/package.py
	sh tools/build-win64.sh --msi
	cd dist && sha256sum $(notdir $(RELEASE)) > SHA256SUMS
clean:
	rm -rf $(CURDIR)/build $(CURDIR)/bin/linux $(CURDIR)/bin/windows
