# Makefile for G-Wolves HSK Pro Battery Reader

# Compiler and flags
CC = gcc
CFLAGS = -Wall -O2
LIBS = -lusb-1.0

# Target binary
TARGET = gwolves-battery

# Source files
SRC = gwolves-battery.c

# Installation directory
INSTALL_DIR = $(HOME)/.local/bin

# Default target
all: $(TARGET)

# Build the binary
$(TARGET): $(SRC)
	$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LIBS)

# Install to ~/.local/bin
install: $(TARGET)
	@echo "Installing $(TARGET) to $(INSTALL_DIR)..."
	@mkdir -p $(INSTALL_DIR)
	@cp $(TARGET) $(INSTALL_DIR)/
	@chmod +x $(INSTALL_DIR)/$(TARGET)
	@echo "✅ Installed to $(INSTALL_DIR)/$(TARGET)"
	@echo ""
	@echo "Make sure $(INSTALL_DIR) is in your PATH:"
	@echo "  export PATH=\"\$$HOME/.local/bin:\$$PATH\""

# Uninstall from ~/.local/bin
uninstall:
	@echo "Removing $(TARGET) from $(INSTALL_DIR)..."
	@rm -f $(INSTALL_DIR)/$(TARGET)
	@echo "✅ Uninstalled"

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	@rm -f $(TARGET)
	@echo "✅ Clean"

# Test the binary
test: $(TARGET)
	@echo "Testing $(TARGET)..."
	@./$(TARGET) all

# Show help
help:
	@echo "G-Wolves HSK Pro Battery Reader - Makefile"
	@echo ""
	@echo "Targets:"
	@echo "  make          - Build the binary"
	@echo "  make install  - Build and install to ~/.local/bin"
	@echo "  make uninstall- Remove from ~/.local/bin"
	@echo "  make clean    - Remove build artifacts"
	@echo "  make test     - Build and test"
	@echo "  make help     - Show this help"

.PHONY: all install uninstall clean test help
