-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
57 lines (41 loc) · 1.13 KB
/
Copy pathMakefile
File metadata and controls
57 lines (41 loc) · 1.13 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
# Makefile for myRaytracer
# Originally built with run.sh (2012), converted to Makefile (2026)
CXX := g++
CXXFLAGS := -O2 -std=c++11 -MMD -MP
TARGET := myRaytracer
# Source root
SRCDIR := raytracer
# Include directories (every subdirectory under raytracer/)
INCLUDES := $(shell find $(SRCDIR) -type d | sed 's/^/-I/')
INCLUDES += -I/usr/include/x86_64-linux-gnu/
# Libraries
LDLIBS := -ltiff -ljpeg
# Build directory
BUILDDIR := build
# Discover all .cpp source files
SRCS := $(shell find $(SRCDIR) -name '*.cpp')
# Map sources to object files in build/
OBJS := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRCS))
# Dependency files generated by -MMD
DEPS := $(OBJS:.o=.d)
# Default target
all: $(TARGET)
# Link
$(TARGET): $(OBJS)
$(CXX) $(OBJS) -o $@ $(LDLIBS)
@echo "Built $(TARGET)"
# Compile
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Include dependency files (if they exist)
-include $(DEPS)
# Run the ray tracer
run: $(TARGET)
./$(TARGET)
# Clean build artifacts
clean:
rm -rf $(BUILDDIR) $(TARGET)
# Full rebuild
rebuild: clean all
.PHONY: all clean rebuild run