Files
interpreter-cpp/Makefile
Karma Riuk c943380d58 moved the utils for the parser to a global utils
folder for the tests (that utils is includable
only by the tests and not the src code, I added a
compiler flag only for the tests in the makefile,
but the compiler_flags.txt is global for the lsp,
gotta be careful with that)
2025-07-19 13:27:25 +02:00

80 lines
2.7 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -------------------------------------------------------------------
# Projectwide settings
# -------------------------------------------------------------------
CXX := g++
CXXFLAGS := -std=c++17 -Wall -Wextra -Iinclude -Isrc -MMD -MP
CXXFLAGS_TESTS := -Itest/utils
LDFLAGS :=
SRC_DIR := src
TEST_DIR := test
BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/objs
BIN_DIR := $(BUILD_DIR)/bin
# -------------------------------------------------------------------
# Source & object lists
# -------------------------------------------------------------------
SRC_CPP := $(shell find $(SRC_DIR) -name '*.cpp')
TEST_CPP := $(shell find $(TEST_DIR) -name '*.cpp')
OBJ := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_CPP))
TEST_OBJ := $(patsubst $(TEST_DIR)/%.cpp,$(OBJ_DIR)/test/%.o,$(TEST_CPP))
DEPFILES := $(OBJ:.o=.d) $(TEST_OBJ:.o=.d)
# Identify your “real” main.cpp so we can exclude it from tests
MAIN_SRC := $(SRC_DIR)/main.cpp
MAIN_OBJ := $(MAIN_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
SRC_OBJS_NO_MAIN := $(filter-out $(MAIN_OBJ),$(OBJ))
# Binaries
TARGET := $(BIN_DIR)/monkey
TEST_TARGET := $(BIN_DIR)/monkey_tests
# -------------------------------------------------------------------
# Toplevel rules
# -------------------------------------------------------------------
.PHONY: all clean run tests valgrind
all: $(TARGET) $(TEST_TARGET)
valgrind: CXXFLAGS += -O0 -g
valgrind: $(TEST_TARGET)
valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes $(TEST_TARGET)
clean:
@rm -rf $(BUILD_DIR)
# -------------------------------------------------------------------
# Build & run
# -------------------------------------------------------------------
run: $(TARGET)
@$(TARGET)
test: $(TEST_TARGET)
@$(TEST_TARGET) $(if $(TEST),--test-case="$(TEST)") $(if $(SUBCASE),--subcase="$(SUBCASE)")
# -------------------------------------------------------------------
# Link binaries
# -------------------------------------------------------------------
$(TARGET): $(OBJ)
@mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $^ -o $@
$(TEST_TARGET): $(SRC_OBJS_NO_MAIN) $(TEST_OBJ)
@mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $^ -o $@
# -------------------------------------------------------------------
# Compile rules
# -------------------------------------------------------------------
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/test/%.o: $(TEST_DIR)/%.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(CXXFLAGS_TESTS) -c $< -o $@
# -------------------------------------------------------------------
# Autoinclude dependencies
# -------------------------------------------------------------------
-include $(DEPFILES)