# SPDX-License-Identifier: GPL-3.0-or-later
# pomelo-input — Pomelo 輸入法（XIM 伺服器＋給 Qt 程式的 IBus 協定；注音用 libchewing，其他引擎執行時才 dlopen）
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)
PKGS = xcb xcb-shape xcb-keysyms xcb-imdkit cairo-xcb chewing dbus-1
DEP_CFLAGS ?= $(shell pkg-config --cflags $(PKGS))
DEP_LIBS   ?= $(shell pkg-config --libs $(PKGS))
CHEWING_VER ?= $(shell pkg-config --modversion chewing 2>/dev/null || echo ?)
VER_FLAGS = -DCHEWING_VERSION=\"$(CHEWING_VER)\"

all: pomelo-input

SRCS = pomelo-input.c ibus.c eng-chewing.c eng-hangul.c eng-rime.c eng-anthy.c eng-viet.c

pomelo-input: $(SRCS) engine.h ic.h third-party/rime_api.h
	$(CC) $(CFLAGS) $(VER_FLAGS) $(POMELO_CFLAGS) $(DEP_CFLAGS) -o $@ $(SRCS) $(POMELO_LIBS) $(DEP_LIBS) -ldl -lm $(LDFLAGS)

install: all
	install -Dm755 pomelo-input $(DESTDIR)$(PREFIX)/bin/pomelo-input
	install -Dm755 ibus-daemon.stub $(DESTDIR)$(PREFIX)/lib/pomelo-input/qt-ibus/ibus-daemon

clean:
	rm -f pomelo-input

.PHONY: all install clean
