-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (62 loc) · 2.22 KB
/
Makefile
File metadata and controls
82 lines (62 loc) · 2.22 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
ASSETS = blackbody_ramp docs scenes textures README.md LICENSE
ifeq ($(OS),Windows_NT)
MKDIR = powershell -Command "if (!(Test-Path '$(BUILDDIR)')) { New-Item -ItemType Directory -Path '$(BUILDDIR)' -Force }"
RMDIR = powershell -Command "if (Test-Path '$(BUILDDIR)') { Remove-Item -Recurse -Force '$(BUILDDIR)' }"
MKDESTDIR = powershell -Command "if (!(Test-Path '$(DESTDIR)')) { New-Item -ItemType Directory -Path '$(DESTDIR)' }"
COPY_ASSETS_CMD = powershell -Command "Copy-Item -Path ('$(ASSETS)'.Split(' ')) -Destination '$(DESTDIR)' -Recurse -Force"
COPY_BIN_CMD = powershell -Command "Copy-Item -Path '$(TARGET)' -Destination '$(DESTDIR)' -Force"
EXECUTABLE_EXTENSION=.exe
LIBS=-flto -fuse-ld=lld
else
MKDIR = mkdir -p $(BUILDDIR)
RMDIR = rm -rf $(BUILDDIR)
MKDESTDIR = mkdir -p $(DESTDIR)
COPY_ASSETS_CMD = cp -r $(ASSETS) $(DESTDIR)/
COPY_BIN_CMD = cp $(TARGET) $(DESTDIR)/
EXECUTABLE_EXTENSION=
LIBS=-lm -lpthread -flto
endif
# Compiler and flags
CC = clang
ifeq ($(RELEASE),1)
BUILD_TYPE = release
CFLAGS = -Wall -Wextra -pedantic -flto -funroll-loops -std=c11 -O3 -DNDEBUG -ffast-math
else
BUILD_TYPE = debug
CFLAGS = -Wall -Wextra -pedantic -flto -funroll-loops -std=c11 -O3 -g -march=native -ffast-math
endif
ifeq ($(OS),Windows_NT)
CFLAGS += -D_CRT_SECURE_NO_WARNINGS
endif
LDFLAGS = $(LIBS)
# Directories
SRCDIR = src
BUILDDIR = build/$(BUILD_TYPE)
DESTDIR ?= staging_$(BUILD_TYPE)
# Source files
SRCS = $(SRCDIR)/main.c $(SRCDIR)/tracer.c $(SRCDIR)/vector.c $(SRCDIR)/color.c \
$(SRCDIR)/blackbody.c $(SRCDIR)/bloom.c $(SRCDIR)/image.c $(SRCDIR)/config.c \
$(SRCDIR)/ini.c $(SRCDIR)/parallel.c
# Object files (in build directory)
OBJS = $(SRCS:$(SRCDIR)/%.c=$(BUILDDIR)/%.o)
# Path to the executable
TARGET = $(BUILDDIR)/blackhole_tracer$(EXECUTABLE_EXTENSION)
# Default target
all: $(BUILDDIR) $(TARGET)
# Create build directory
$(BUILDDIR):
$(MKDIR)
# Link the executable
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
# Compile source files into object files
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/*.h | $(BUILDDIR)
$(CC) $(CFLAGS) -c $< -o $@
install: $(TARGET)
$(MKDESTDIR)
$(COPY_ASSETS_CMD)
$(COPY_BIN_CMD)
# Clean up build files
clean:
$(RMDIR)
.PHONY: all clean install