-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (99 loc) · 3.16 KB
/
Makefile
File metadata and controls
120 lines (99 loc) · 3.16 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# CodeQL Tracing Playground - Makefile
# Demonstrates various build patterns for CodeQL tracing testing
# Compiler settings
CXX := g++
CXXFLAGS := -std=c++17 -Wall -Wextra -Wpedantic
# Directories
SRC_DIR := src
GEN_DIR := src/generated
BUILD_DIR := build
SCRIPTS_DIR := scripts
# Source files (explicit list for clarity in tracing)
SOURCES := $(SRC_DIR)/main.cpp \
$(SRC_DIR)/utils.cpp \
$(SRC_DIR)/math_ops.cpp
# Object files
OBJECTS := $(BUILD_DIR)/main.o \
$(BUILD_DIR)/utils.o \
$(BUILD_DIR)/math_ops.o
# Generated files
GENERATED_CONFIG := $(GEN_DIR)/config.h
# Output binary
TARGET := $(BUILD_DIR)/playground
# Debug mode handling
# Usage: make DEBUG=1
ifdef DEBUG
CXXFLAGS += -g -O0 -DDEBUG_MODE
$(info Building in DEBUG mode with -g and -DDEBUG_MODE)
else
CXXFLAGS += -O2
$(info Building in RELEASE mode with -O2)
endif
# Include paths
INCLUDES := -I$(SRC_DIR)
# Phony targets (not actual files)
.PHONY: all clean generate run rebuild help
# Default target
all: $(TARGET)
# Help target
help:
@echo "CodeQL Tracing Playground - Build System"
@echo ""
@echo "Targets:"
@echo " all - Build the project (default)"
@echo " clean - Remove all build artifacts"
@echo " generate - Generate config.h only"
@echo " run - Build and run the program"
@echo " rebuild - Clean and rebuild"
@echo " help - Show this help message"
@echo ""
@echo "Options:"
@echo " DEBUG=1 - Build with debug flags (-g -DDEBUG_MODE)"
@echo ""
@echo "Examples:"
@echo " make - Build release version"
@echo " make DEBUG=1 - Build debug version"
@echo " make clean - Remove build artifacts"
@echo " make run - Build and run"
@echo " make run DEBUG=1 - Build debug and run"
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Generate config.h using the script
# This is a phony-like target that always regenerates
$(GENERATED_CONFIG): $(SCRIPTS_DIR)/generate_config.sh
@echo "Generating config.h..."
@./$(SCRIPTS_DIR)/generate_config.sh $(GENERATED_CONFIG)
# Explicit generate target
generate: $(GENERATED_CONFIG)
# Compile main.cpp
# Note: Depends on generated config.h
$(BUILD_DIR)/main.o: $(SRC_DIR)/main.cpp $(SRC_DIR)/utils.h $(SRC_DIR)/math_ops.h $(GENERATED_CONFIG) | $(BUILD_DIR)
@echo "Compiling main.cpp..."
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Compile utils.cpp
$(BUILD_DIR)/utils.o: $(SRC_DIR)/utils.cpp $(SRC_DIR)/utils.h | $(BUILD_DIR)
@echo "Compiling utils.cpp..."
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Compile math_ops.cpp
$(BUILD_DIR)/math_ops.o: $(SRC_DIR)/math_ops.cpp $(SRC_DIR)/math_ops.h | $(BUILD_DIR)
@echo "Compiling math_ops.cpp..."
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Link all object files into the final executable
$(TARGET): $(OBJECTS)
@echo "Linking $(TARGET)..."
$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@
@echo "Build complete: $(TARGET)"
# Run the program
run: $(TARGET)
@echo "Running $(TARGET)..."
@echo ""
@./$(TARGET)
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR)
rm -f $(GENERATED_CONFIG)
@echo "Clean complete."
# Rebuild from scratch
rebuild: clean all