119 lines
3.4 KiB
Makefile
Raw Normal View History

2025-11-22 16:53:39 +01:00
CC = gcc
2025-11-22 22:22:43 +01:00
CFLAGS = -Wall -Wextra -O2 -Isrc
LDFLAGS = -lm
2025-11-22 16:53:39 +01:00
2025-11-22 22:22:43 +01:00
SRC_DIR = src
TEST_DIR = tests
EXAMPLE_DIR = examples
BUILD_DIR = build
BIN_DIR = bin
2025-11-22 16:53:39 +01:00
2025-11-22 22:22:43 +01:00
TARGET = $(BIN_DIR)/rc
2025-11-22 16:53:39 +01:00
2025-11-22 22:22:43 +01:00
SOURCES = $(SRC_DIR)/main.c \
$(SRC_DIR)/globals.c \
$(SRC_DIR)/tokenizer.c \
$(SRC_DIR)/parser.c \
$(SRC_DIR)/interpreter.c \
$(SRC_DIR)/native_functions.c \
$(SRC_DIR)/string_utils.c
2025-11-22 16:53:39 +01:00
2025-11-22 22:22:43 +01:00
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
2025-11-22 16:53:39 +01:00
2025-11-22 22:22:43 +01:00
TESTS = $(TEST_DIR)/feature_test.rc \
$(TEST_DIR)/endless_loop_test.rc \
$(TEST_DIR)/math_test.rc \
$(TEST_DIR)/string_test.rc \
$(TEST_DIR)/string_manip_test.rc
2025-11-22 16:53:39 +01:00
2025-11-22 22:22:43 +01:00
EXAMPLES = $(EXAMPLE_DIR)/test.rc \
$(EXAMPLE_DIR)/demo.rc \
$(EXAMPLE_DIR)/a.rc
.PHONY: all clean test run-tests run-examples help dirs
all: dirs $(TARGET)
dirs:
@mkdir -p $(BUILD_DIR) $(BIN_DIR)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -o $(TARGET) $(LDFLAGS)
2025-11-22 16:53:39 +01:00
clean:
2025-11-22 22:22:43 +01:00
rm -rf $(BUILD_DIR) $(BIN_DIR)
test: $(TARGET)
@echo "=== Running All Tests ==="
@echo ""
@echo "Running feature tests..."
@$(TARGET) $(TEST_DIR)/feature_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running endless loop test..."
@$(TARGET) $(TEST_DIR)/endless_loop_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running math tests..."
@$(TARGET) $(TEST_DIR)/math_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running string concatenation tests..."
@$(TARGET) $(TEST_DIR)/string_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running string manipulation tests..."
@$(TARGET) $(TEST_DIR)/string_manip_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "=== All Tests Completed ==="
run-feature-test: $(TARGET)
$(TARGET) $(TEST_DIR)/feature_test.rc
run-endless-loop: $(TARGET)
$(TARGET) $(TEST_DIR)/endless_loop_test.rc
run-math-test: $(TARGET)
$(TARGET) $(TEST_DIR)/math_test.rc
run-string-test: $(TARGET)
$(TARGET) $(TEST_DIR)/string_test.rc
run-string-manip: $(TARGET)
$(TARGET) $(TEST_DIR)/string_manip_test.rc
run-example-test: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/test.rc
run-example-demo: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/demo.rc
run-example-a: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/a.rc
2025-11-22 16:53:39 +01:00
help:
2025-11-22 22:22:43 +01:00
@echo "RC - Retoor's C Interpreter"
@echo ""
2025-11-22 16:53:39 +01:00
@echo "Usage:"
2025-11-22 22:22:43 +01:00
@echo " make - Build the interpreter"
@echo " make test - Run all feature tests"
@echo " make clean - Remove all build artifacts"
@echo ""
@echo "Individual Tests:"
@echo " make run-feature-test - Run feature_test.rc (negative numbers, ==, !=)"
@echo " make run-endless-loop - Run endless_loop_test.rc (while(1) test)"
@echo " make run-math-test - Run math_test.rc (math functions)"
@echo " make run-string-test - Run string_test.rc (string concatenation)"
@echo " make run-string-manip - Run string_manip_test.rc (string manipulation & slicing)"
@echo ""
@echo "Examples:"
@echo " make run-example-test - Run test.rc (HTTP server)"
@echo " make run-example-demo - Run demo.rc (HTTP server with counter)"
@echo " make run-example-a - Run a.rc (HTTP server, 100 connections)"
@echo ""
@echo "Directory Structure:"
@echo " src/ - Source code files"
@echo " tests/ - Test programs (.rc files)"
@echo " examples/ - Example programs (.rc files)"
@echo " build/ - Compiled object files"
@echo " bin/ - Final executable (rc)"