# Makefile for calcx - Generated by TheGrid Build Agent
# Project: calcx (A simple CLI calculator program)
# Stack: g++, make

# Compiler settings
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2

# Directory structure
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin

# Output binary name
TARGET = $(BIN_DIR)/calcx

# Source and Object files
# We expect the g++ agent to generate these files based on the YAML commands
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
OBJS = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS))

# Default target
all: directories $(TARGET)

# Create necessary directories
directories:
	@mkdir -p $(SRC_DIR)
	@mkdir -p $(OBJ_DIR)
	@mkdir -p $(BIN_DIR)

# Link the final binary
$(TARGET): $(OBJS)
	@echo "[Make Agent] Linking $(TARGET)..."
	$(CXX) $(CXXFLAGS) -o $@ $^
	@echo "[Make Agent] Build successful! Run with ./$(TARGET)"

# Compile object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
	@echo "[Make Agent] Compiling $<..."
	$(CXX) $(CXXFLAGS) -c $< -o $@

# Clean up build artifacts
clean:
	@echo "[Make Agent] Cleaning up build files..."
	rm -rf $(OBJ_DIR) $(BIN_DIR)

# Target used by TheGrid to check if the build passes
grid_verify: clean all
	@echo "[Make Agent] Verification build complete."

.PHONY: all directories clean grid_verify