# TermTCP CLI - Makefile
# Simple command-line TCP client

CC = gcc
CFLAGS = -Wall -Wextra -O2 -std=gnu99 -D_XOPEN_SOURCE_EXTENDED
LDFLAGS = -lm -lncursesw

TARGET = termtcp
SOURCE = termtcp_cli.c
OBJECT = $(SOURCE:.c=.o)

# Default target
all: $(TARGET)

# Build executable
$(TARGET): $(OBJECT)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
	@echo "Build complete: $(TARGET)"
	@ls -lh $(TARGET)

# Compile
%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

# Debug build
debug: CFLAGS += -g -O0 -DDEBUG
debug: clean $(TARGET)
	@echo "Debug build complete"

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

# Clean
clean:
	rm -f $(OBJECT) $(TARGET)
	@echo "Clean complete"

# Install to system
install: $(TARGET)
	install -m 755 $(TARGET) /usr/local/bin/
	@echo "Installed $(TARGET) to /usr/local/bin/"

# Uninstall from system
uninstall:
	rm -f /usr/local/bin/$(TARGET)
	@echo "Uninstalled $(TARGET)"

# Static analysis (if available)
lint:
	@which cppcheck > /dev/null && cppcheck --quiet $(SOURCE) || echo "cppcheck not found"

# Help
help:
	@echo "TermTCP CLI Build Targets:"
	@echo "  make              - Build the application"
	@echo "  make debug        - Build with debug symbols"
	@echo "  make run          - Build and run"
	@echo "  make clean        - Remove build artifacts"
	@echo "  make install      - Install to /usr/local/bin/"
	@echo "  make uninstall    - Remove from /usr/local/bin/"
	@echo "  make lint         - Run static analysis"
	@echo "  make help         - Show this message"

.PHONY: all debug run clean install uninstall lint help
