-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (108 loc) · 3.65 KB
/
Copy pathMakefile
File metadata and controls
130 lines (108 loc) · 3.65 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
121
122
123
124
125
126
127
128
129
130
# N-Body Gravity Simulation Makefile
# Optimized for performance with C++20, OpenMP, and SIMD
# Detect compiler, OS, and architecture
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_S),Darwin)
# macOS with Clang
CXX = clang++
CXXFLAGS = -std=c++20 -O3 -ffast-math -DNDEBUG
CXXFLAGS += -Wall -Wextra -Wpedantic
CXXFLAGS += -Iinclude
# Architecture-specific optimizations
ifeq ($(UNAME_M),arm64)
# Apple Silicon (M1/M2/M3)
CXXFLAGS += -mcpu=apple-m1
else
# Intel Mac
CXXFLAGS += -march=native -mavx2 -mfma
endif
# Note: OpenMP disabled for now on macOS due to complexity
LIBS = -lm
DEBUG_FLAGS = -std=c++20 -O0 -g -Wall -Wextra -Wpedantic -fsanitize=address -fno-omit-frame-pointer -Iinclude
else
# Linux with GCC
CXX = g++
CXXFLAGS = -std=c++20 -O3 -march=native -mtune=native -ffast-math -DNDEBUG
CXXFLAGS += -Wall -Wextra -Wpedantic
CXXFLAGS += -fopenmp -mavx2 -mfma
CXXFLAGS += -Iinclude
LIBS = -fopenmp -lm
DEBUG_FLAGS = -std=c++20 -O0 -g -Wall -Wextra -Wpedantic -fopenmp -Iinclude
endif
# Source files
SRCDIR = src
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
# Test files
TESTDIR = tests
TEST_SOURCES = $(wildcard $(TESTDIR)/*.cpp)
TEST_OBJECTS = $(TEST_SOURCES:.cpp=.o)
# Executables
TARGET = nbody_simulation
TEST_TARGET = test_vector3d
# Libraries (set above based on OS)
# Default target
all: $(TARGET)
# Main executable
$(TARGET): $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
@echo "Built $(TARGET) successfully!"
# Test executable (simplified - only Vector3D test)
test: $(TESTDIR)/test_vector3d.o $(SRCDIR)/Vector3D.o
$(CXX) $(CXXFLAGS) -o $(TEST_TARGET) $^ $(LIBS)
@echo "Built $(TEST_TARGET) successfully!"
@echo "Running tests..."
./$(TEST_TARGET)
# Debug build
debug: CXXFLAGS = $(DEBUG_FLAGS)
debug: $(TARGET)
# Object files
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# Clean
clean:
rm -f $(OBJECTS) $(TEST_OBJECTS) $(TARGET) $(TEST_TARGET)
@echo "Cleaned build files"
# Install dependencies (macOS with Homebrew)
install-deps:
@echo "Installing dependencies..."
@if command -v brew >/dev/null 2>&1; then \
brew install nlohmann-json libomp; \
else \
echo "Homebrew not found. Please install nlohmann-json manually."; \
fi
# Run with default configuration
run: $(TARGET)
./$(TARGET) --preset earth-moon --duration 2629746 --output output/earth_moon_test.csv
# Run solar system simulation
run-solar: $(TARGET)
./$(TARGET) --preset solar-system --duration 31557600 --output output/solar_system.csv
# Quick test run
quick-test: $(TARGET)
./$(TARGET) --preset earth-moon --duration 86400 --timestep 3600 --output output/quick_test.csv
# Performance test
perf-test: $(TARGET)
@echo "Running performance test..."
time ./$(TARGET) --preset solar-system --duration 86400 --no-output --quiet
# Help
help:
@echo "N-Body Gravity Simulation Build System"
@echo "======================================"
@echo "Targets:"
@echo " all - Build main executable (default)"
@echo " test - Build and run Vector3D tests"
@echo " debug - Build with debug flags"
@echo " clean - Remove build files"
@echo " install-deps - Install dependencies (macOS/Homebrew)"
@echo " run - Run Earth-Moon simulation"
@echo " run-solar - Run full solar system simulation"
@echo " quick-test - Quick test run"
@echo " perf-test - Performance benchmark"
@echo " help - Show this help"
@echo ""
@echo "Compiler: $(CXX)"
@echo "Flags: $(CXXFLAGS)"
# Create output directory
$(shell mkdir -p output)
.PHONY: all test debug clean install-deps run run-solar quick-test perf-test help