# SPDX-License-Identifier: GPL-3.0-or-later
# pomelo-paint — Pomelo 繪圖
PREFIX ?= /usr/local
CFLAGS ?= -Os -pipe -Wall -Wextra -Wno-unused-parameter -Wno-format-truncation
POMELO_CFLAGS ?= $(shell pkg-config --cflags pomelo)
POMELO_LIBS   ?= $(shell pkg-config --libs pomelo)
# 圖片解碼跟看圖共用 ../pomelo-viewer/formats.c（giflib、libwebp；HEIC／AVIF 執行時才載入 libheif）
IMG_CFLAGS ?= -I../pomelo-viewer $(shell pkg-config --cflags libwebp libwebpdemux)
IMG_LIBS   ?= -lgif $(shell pkg-config --libs libwebp libwebpdemux) -ljpeg

all: pomelo-paint pomelo-paint.png

pomelo-paint: pomelo-paint.c ops.c ../pomelo-viewer/formats.c
	$(CC) $(CFLAGS) $(POMELO_CFLAGS) $(IMG_CFLAGS) -pthread -o $@ pomelo-paint.c $(POMELO_LIBS) $(IMG_LIBS) -ldl -lm $(LDFLAGS)

pomelo-paint.png: pomelo-paint
	LD_LIBRARY_PATH="$(LD_LIBRARY_PATH)" ./pomelo-paint --icon $@

install: all
	install -Dm755 pomelo-paint $(DESTDIR)$(PREFIX)/bin/pomelo-paint
	install -Dm644 pomelo-paint.desktop $(DESTDIR)$(PREFIX)/share/applications/pomelo-paint.desktop
	install -Dm644 pomelo-paint.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/256x256/apps/pomelo-paint.png

clean:
	rm -f pomelo-paint pomelo-paint.png

.PHONY: all install clean
