#!/usr/bin/make -f

PKG    := linglong-store
OPT    := /opt/linglong-store
BUNDLE := $(CURDIR)/linglong-store
PKGDIR := $(CURDIR)/debian/$(PKG)
DOCDIR := $(PKGDIR)/usr/share/doc/$(PKG)

%:
	@echo "unsupported target '$@' (this package does not use debhelper/dh)" >&2
	@exit 1

build:
	@echo "linglong-store: prebuilt Flutter bundle, nothing to compile"

clean:
	rm -rf $(PKGDIR) debian/files

binary binary-arch: build
	rm -rf $(PKGDIR)
	install -d -m 0755 $(PKGDIR)$(OPT)
	cp -a $(BUNDLE)/. $(PKGDIR)$(OPT)/
	install -d -m 0755 $(PKGDIR)/usr/bin
	install -m 0755 debian/linglong-store.launcher $(PKGDIR)/usr/bin/$(PKG)
	install -d -m 0755 $(PKGDIR)/usr/share/applications
	install -m 0644 debian/linglong-store.desktop \
		$(PKGDIR)/usr/share/applications/$(PKG).desktop
	install -d -m 0755 $(PKGDIR)/usr/share/icons/hicolor/256x256/apps
	install -m 0644 $(BUNDLE)/logo.png \
		$(PKGDIR)/usr/share/icons/hicolor/256x256/apps/$(PKG).png
	install -d -m 0755 $(PKGDIR)/usr/share/metainfo
	install -m 0644 debian/linglong-store.appdata.xml \
		$(PKGDIR)/usr/share/metainfo/$(PKG).appdata.xml
	install -d -m 0755 $(DOCDIR)
	install -m 0644 debian/copyright $(DOCDIR)/copyright
	gzip -9n -c debian/changelog > $(DOCDIR)/changelog.gz
	install -d -m 0755 $(PKGDIR)/DEBIAN
	dpkg-gencontrol -p$(PKG) -P$(PKGDIR)
	dpkg-deb --root-owner-group -Zxz --build $(PKGDIR) $(CURDIR)/..
