220 lines
7.6 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
2025-11-23 13:53:36 +01:00
LDFLAGS = -lm -lpthread
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 \
2025-11-23 00:17:01 +01:00
$(TEST_DIR)/string_manip_test.rc \
2025-11-23 14:30:46 +01:00
$(TEST_DIR)/increment_decrement_test.rc \
$(TEST_DIR)/file_io_test.rc \
$(TEST_DIR)/double_test.rc \
$(TEST_DIR)/break_continue_test.rc \
2025-11-23 15:07:19 +01:00
$(TEST_DIR)/async_io_test.rc \
$(TEST_DIR)/array_test.rc \
$(TEST_DIR)/pointer_test.rc \
$(TEST_DIR)/logical_test.rc \
$(TEST_DIR)/comparison_test.rc \
$(TEST_DIR)/functions_test.rc \
$(TEST_DIR)/trig_test.rc \
$(TEST_DIR)/file_seek_test.rc
2025-11-22 16:53:39 +01:00
2025-11-22 22:30:55 +01:00
EXAMPLES = $(EXAMPLE_DIR)/http_simple.rc \
$(EXAMPLE_DIR)/http_persistent.rc \
2025-11-23 14:30:46 +01:00
$(EXAMPLE_DIR)/http_multi.rc \
$(EXAMPLE_DIR)/async_demo.rc
2025-11-22 22:22:43 +01:00
2025-11-23 00:17:01 +01:00
.PHONY: all clean test run-tests run-examples help
2025-11-22 22:22:43 +01:00
all: dirs $(TARGET)
dirs:
@mkdir -p $(BUILD_DIR) $(BIN_DIR)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
2025-11-23 00:17:01 +01:00
$(TARGET): dirs $(OBJECTS)
2025-11-22 22:22:43 +01:00
$(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 ""
2025-11-23 00:17:01 +01:00
@echo "Running increment decrement tests..."
@$(TARGET) $(TEST_DIR)/increment_decrement_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
2025-11-23 15:07:19 +01:00
@echo "Running file I/O tests..."
@$(TARGET) $(TEST_DIR)/file_io_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running double tests..."
@$(TARGET) $(TEST_DIR)/double_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running break/continue tests..."
@$(TARGET) $(TEST_DIR)/break_continue_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running async I/O tests..."
@$(TARGET) $(TEST_DIR)/async_io_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running array tests..."
@$(TARGET) $(TEST_DIR)/array_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running pointer tests..."
@$(TARGET) $(TEST_DIR)/pointer_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running logical operators tests..."
@$(TARGET) $(TEST_DIR)/logical_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running comparison operators tests..."
@$(TARGET) $(TEST_DIR)/comparison_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running functions tests..."
@$(TARGET) $(TEST_DIR)/functions_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running trigonometry tests..."
@$(TARGET) $(TEST_DIR)/trig_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
@echo "Running file seek tests..."
@$(TARGET) $(TEST_DIR)/file_seek_test.rc 2>&1 | grep -v "Error at token" || true
@echo ""
2025-11-22 22:22:43 +01:00
@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
2025-11-23 00:17:01 +01:00
run-increment-decrement-test: $(TARGET)
$(TARGET) $(TEST_DIR)/increment_decrement_test.rc
2025-11-23 14:30:46 +01:00
run-file-io-test: $(TARGET)
$(TARGET) $(TEST_DIR)/file_io_test.rc
run-double-test: $(TARGET)
$(TARGET) $(TEST_DIR)/double_test.rc
run-break-continue-test: $(TARGET)
$(TARGET) $(TEST_DIR)/break_continue_test.rc
run-async-io-test: $(TARGET)
$(TARGET) $(TEST_DIR)/async_io_test.rc
2025-11-23 15:07:19 +01:00
run-array-test: $(TARGET)
$(TARGET) $(TEST_DIR)/array_test.rc
run-pointer-test: $(TARGET)
$(TARGET) $(TEST_DIR)/pointer_test.rc
run-logical-test: $(TARGET)
$(TARGET) $(TEST_DIR)/logical_test.rc
run-comparison-test: $(TARGET)
$(TARGET) $(TEST_DIR)/comparison_test.rc
run-functions-test: $(TARGET)
$(TARGET) $(TEST_DIR)/functions_test.rc
run-trig-test: $(TARGET)
$(TARGET) $(TEST_DIR)/trig_test.rc
run-file-seek-test: $(TARGET)
$(TARGET) $(TEST_DIR)/file_seek_test.rc
2025-11-22 22:30:55 +01:00
run-http-simple: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/http_simple.rc
2025-11-22 22:22:43 +01:00
2025-11-22 22:30:55 +01:00
run-http-persistent: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/http_persistent.rc
2025-11-22 22:22:43 +01:00
2025-11-22 22:30:55 +01:00
run-http-multi: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/http_multi.rc
2025-11-22 16:53:39 +01:00
2025-11-23 14:30:46 +01:00
run-async-demo: $(TARGET)
$(TARGET) $(EXAMPLE_DIR)/async_demo.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:"
2025-11-23 14:30:46 +01:00
@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)"
2025-11-23 15:07:19 +01:00
@echo " make run-increment-decrement-test - Run increment_decrement_test.rc (++/--)"
2025-11-23 14:30:46 +01:00
@echo " make run-file-io-test - Run file_io_test.rc (file I/O operations)"
@echo " make run-double-test - Run double_test.rc (double data type)"
@echo " make run-break-continue-test - Run break_continue_test.rc (break/continue)"
@echo " make run-async-io-test - Run async_io_test.rc (async I/O)"
2025-11-23 15:07:19 +01:00
@echo " make run-array-test - Run array_test.rc (arrays)"
@echo " make run-pointer-test - Run pointer_test.rc (pointers & dereference)"
@echo " make run-logical-test - Run logical_test.rc (&&, ||)"
@echo " make run-comparison-test - Run comparison_test.rc (<, >, <=, >=)"
@echo " make run-functions-test - Run functions_test.rc (function calls & recursion)"
@echo " make run-trig-test - Run trig_test.rc (sin, cos, tan)"
@echo " make run-file-seek-test - Run file_seek_test.rc (fseek, ftell)"
2025-11-22 22:22:43 +01:00
@echo ""
@echo "Examples:"
2025-11-23 14:30:46 +01:00
@echo " make run-http-simple - Run http_simple.rc (single connection HTTP server)"
@echo " make run-http-persistent - Run http_persistent.rc (persistent HTTP server)"
@echo " make run-http-multi - Run http_multi.rc (HTTP server, 100 connections)"
@echo " make run-async-demo - Run async_demo.rc (comprehensive async I/O demo)"
2025-11-22 22:22:43 +01:00
@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)"