# syd-tui: syd terminal user interface
# Makefile: Makefile for syd-tui
#
# Copyright (c) 2025, 2026 Ali Polatel <alip@chesswob.org>
#
# SPDX-License-Identifier: GPL-3.0

# Package name and version
PACKAGE= syd-tui

# Git root
GITROOT= $(shell git rev-parse --show-toplevel || pwd)

# Build profile
PROFILE?= release

# Installation directories
PREFIX= $(HOME)/.local
BIN_DIR = $(PREFIX)/bin

# Cargo and Installer
CARGO?= cargo
INSTALL?= install

# Cargo flags
CARGOFLAGS?= -j$(shell nproc)

# Path to the binary
ifeq ($(PROFILE), debug)
	BIN= $(GITROOT)/target/debug/$(PACKAGE)
else
	BIN= $(GITROOT)/target/release/$(PACKAGE)
	CARGOFLAGS+= --release
endif

# Default target
all: $(BIN)

# QA targets
fmt:
	$(CARGO) fmt
lint:
	$(CARGO) deny check
	$(CARGO) acl -n || true
	$(CARGO) clippy $(CARGOFLAGS)

# Install and Uninstall Targets
install: $(BIN)
	$(INSTALL) -d $(BIN_DIR)
	$(INSTALL) -m 755 $(BIN) $(BIN_DIR)
uninstall:
	rm -f $(BIN_DIR)/$(PACKAGE)

# Check target
check: test

test: $(BIN)
	$(CARGO) test $(CARGOFLAGS)

# Clean Target
clean:
	$(CARGO) clean

$(BIN):
	$(CARGO) build $(CARGOFLAGS)

# Phony Targets
.PHONY: all clean check test install uninstall fmt lint
