# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 Median Two Arrays Solution
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Compiler settings
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -Wpedantic -O2
DEBUG_FLAGS = -g -DDEBUG -O0
RELEASE_FLAGS = -O3 -DNDEBUG

# Target executable
TARGET = median_solution
SOURCE = median_two_arrays_solution.cpp

# Default target
all: $(TARGET)

# Build main executable
$(TARGET): $(SOURCE)
	$(CXX) $(CXXFLAGS) -o $(TARGET) $(SOURCE)

# Debug build
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug: $(TARGET)

# Release build  
release: CXXFLAGS += $(RELEASE_FLAGS)
release: $(TARGET)

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

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

# Run with test cases only
test: $(TARGET)
	echo "n" | ./$(TARGET)

# Help target
help:
	@echo "Available targets:"
	@echo "  all     - Build the median solution (default)"
	@echo "  debug   - Build with debug information"
	@echo "  release - Build optimized release version"
	@echo "  clean   - Remove build artifacts"
	@echo "  run     - Build and run the program"
	@echo "  test    - Build and run automated tests only"
	@echo "  help    - Show this help message"

.PHONY: all debug release clean run test help