# SPDX-License-Identifier: GPL-3.0-or-later
# pomelo-remote — Pomelo 遠端桌面（RDP：連到 Windows 的遠端桌面）
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)
# RDP 協定用 FreeRDP 函式庫：FreeRDP 3（Ubuntu 24.04 起、Fedora）或 FreeRDP 2（Ubuntu 22.04、Rocky 9）
RDP_PC     := $(shell pkg-config --exists freerdp-client3 && echo freerdp-client3 freerdp3 winpr3 || echo freerdp-client2 freerdp2 winpr2)
RDP_CFLAGS ?= $(shell pkg-config --cflags $(RDP_PC) xcursor xfixes dbus-1) -DWITHOUT_FREERDP_3x_DEPRECATED -DWITHOUT_WINPR_3x_DEPRECATED
RDP_LIBS   ?= $(shell pkg-config --libs $(RDP_PC) xcursor xfixes dbus-1)

all: pomelo-remote pomelo-remote.png

pomelo-remote: pomelo-remote.c session.c secret.c
	$(CC) $(CFLAGS) $(RDP_CFLAGS) $(POMELO_CFLAGS) -o $@ pomelo-remote.c $(POMELO_LIBS) $(RDP_LIBS) -lm $(LDFLAGS)

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

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

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

.PHONY: all install clean
