# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Installation directories
PREFIX ?= /usr

# Default target: build all clients
all: cmake-build

# Build C client and plugin using CMake
cmake-build:
	mkdir -p build
	cd build && cmake .. && make

install: install-cmake

# Install C/C++ components (C client, plugins) via CMake
install-cmake: cmake-build
	cd build && cmake --install . --prefix $(PREFIX)

# Build Go client
go-client:
	$(MAKE) -C go-rofs-err-watcher build

# Install Go client
install-go-client: go-client
	install -d $(DESTDIR)$(PREFIX)/bin
	install -m 755 go-rofs-err-watcher/go-rofs-err-watcher $(DESTDIR)$(PREFIX)/bin/go-rofs-err-watcher

# Clean all build artifacts
clean:
	rm -rf build
	$(MAKE) -C go-rofs-err-watcher clean

# Format C/C++ source code using clang-format
fmt:
	find src -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.h' \) -exec clang-format -i {} +

# Update translation files (.ts) for user plugin
lupdate:
	mkdir -p build
	cd build && cmake .. && make user_plugin_lupdate

.PHONY: all clean install go-client cmake-build install-cmake install-go-client fmt lupdate
