# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 Letter Combinations Solution
#
# Makefile for Letter Combinations of Phone Number solution

# Compiler settings
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -g
TARGET = letter_combinations
MAIN_SOURCE = main_letter_combinations.cc
LIB_SOURCE = LetterCombinations.cc
SOURCES = $(MAIN_SOURCE) $(LIB_SOURCE)
HEADERS = LetterCombinations.h
OBJECTS = $(SOURCES:.cc=.o)
TEST_TARGET = test_letter_combinations
TEST_SOURCE = test_letter_combinations.cc

# Default target
all: $(TARGET)

# Build the executable
$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJECTS)

# Compile source files
%.o: %.cc $(HEADERS)
	$(CXX) $(CXXFLAGS) -c $< -o $@

# Run the program
run: $(TARGET)
	./$(TARGET)

# Build and run test suite
test: $(TEST_TARGET)
	@echo "Running comprehensive test suite..."
	./$(TEST_TARGET)

# Build test executable
$(TEST_TARGET): $(TEST_SOURCE) $(LIB_SOURCE) $(HEADERS)
	$(CXX) $(CXXFLAGS) -o $(TEST_TARGET) $(TEST_SOURCE) $(LIB_SOURCE)

# Run with sample input
demo: $(TARGET)
	@echo "Running demo with sample input..."
	@echo "23" | ./$(TARGET)

# Clean build artifacts
clean:
	rm -f $(OBJECTS) $(TARGET) $(TEST_TARGET)

# Debug build
debug: CXXFLAGS += -DDEBUG -g3
debug: $(TARGET)

# Release build
release: CXXFLAGS += -DNDEBUG -O3
release: clean $(TARGET)

# Install (optional)
install: $(TARGET)
	cp $(TARGET) /usr/local/bin/

# Uninstall (optional)
uninstall:
	rm -f /usr/local/bin/$(TARGET)

# Show help
help:
	@echo "Available targets:"
	@echo "  all      - Build the program (default)"
	@echo "  run      - Build and run the program"
	@echo "  test     - Build and run comprehensive test suite"
	@echo "  demo     - Build and run with sample input"
	@echo "  clean    - Remove build artifacts"
	@echo "  debug    - Build with debug symbols"
	@echo "  release  - Build optimized release version"
	@echo "  install  - Install to /usr/local/bin"
	@echo "  uninstall- Remove from /usr/local/bin"
	@echo "  help     - Show this help message"

# Declare phony targets
.PHONY: all run test demo clean debug release install uninstall help