-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (39 loc) · 1.12 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Compiler and compiler flags
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2
# Directories
SRC_DIR = ./src
HEADERS_DIR = ./headers
FONT_DIR = ./font
BUILD_DIR = ./build
# Source and object files
SRCS = $(SRC_DIR)/main.cpp $(SRC_DIR)/print.cpp $(SRC_DIR)/orderbook.cpp
TEST_SRCS = $(SRC_DIR)/test.cpp $(SRC_DIR)/orderbook.cpp
OBJS = $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(SRCS))
TEST_OBJS = $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(TEST_SRCS))
# Output executables
TARGET = main
TEST_TARGET = test
# Default target
all: $(TARGET)
# Rule to build the main executable
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
# Rule to build the test executable
test: $(TEST_OBJS)
$(CXX) $(CXXFLAGS) -o $(BUILD_DIR)/$(TEST_TARGET) $(TEST_OBJS)
# Rule to compile source files to object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Clean build files
clean:
rm -rf $(BUILD_DIR) $(TARGET) $(BUILD_DIR)/$(TEST_TARGET)
# Run the main program
run: $(TARGET)
./$(TARGET)
# Run the tests
run_tests: test
./$(BUILD_DIR)/$(TEST_TARGET)
# Phony targets
.PHONY: all clean run run_tests