# client/Makefile - Filature client side: the dev wrapper, the report
# engine and its GTK3 front end. Never needed on the server.
#
# Copyright (C) 2026 SliTaz GNU/Linux - BSD License, see ../LICENSE

CC      ?= cc
CFLAGS  ?= -O2
WERROR  ?= -Werror
CFLAGS  += -Wall -Wextra $(WERROR)
PREFIX  ?= /usr
DESTDIR ?=

ICONS   = ../data/icons/hicolor
SIZES   = scalable 16x16 22x22 24x24 32x32 48x48 64x64 128x128

PKGS    = gtk+-3.0
GTK_CFLAGS = $(shell pkg-config --cflags $(PKGS))
GTK_LIBS   = $(shell pkg-config --libs $(PKGS))

all: filature-report-gtk

filature-report-gtk: filature-report-gtk.c
	$(CC) $(CFLAGS) $(GTK_CFLAGS) $(LDFLAGS) -o $@ $< $(GTK_LIBS)

install-client:
	install -Dm755 fil $(DESTDIR)$(PREFIX)/bin/fil
	$(MAKE) install-icon ICON=filature

install-report: filature-report-gtk
	install -Dm755 filature-report $(DESTDIR)$(PREFIX)/bin/filature-report
	install -Dm755 filature-report-gtk $(DESTDIR)$(PREFIX)/bin/filature-report-gtk
	install -Dm644 filature-report.desktop \
		$(DESTDIR)$(PREFIX)/share/applications/filature-report.desktop
	$(MAKE) install-icon ICON=filature-report

# hicolor: SVG + PNG sizes (GTK2 panels render the SVG black)
install-icon:
	for s in $(SIZES); do \
		install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/$$s/apps; \
		install -m644 $(ICONS)/$$s/apps/$(ICON).* \
			$(DESTDIR)$(PREFIX)/share/icons/hicolor/$$s/apps; \
	done

clean:
	rm -f filature-report-gtk

.PHONY: all install-client install-report install-icon clean
