summaryrefslogtreecommitdiff
path: root/Makefile
blob: 7c50323c78e5a5e26dcca75d89f1120aa362fa66 (plain)
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
CC := clang
INCLUDES := -I./include -Ideps/glfw-3.3.8/include/GLFW
CFLAGS := -Wall -Wextra -O2 $(INCLUDES)
LDFLAGS := -lglfw

# Detect OS
UNAME_S := $(shell uname -s)

# Directories
SRC_DIR := src
BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/objs
SHADER_DIR := assets/shaders
SHADER_OUT_DIR := $(BUILD_DIR)/shaders
EXAMPLES_DIR := examples

# Source files
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))

# Library outputs
STATIC_LIB := $(BUILD_DIR)/libceleritas.a
ifeq ($(UNAME_S),Darwin)
    SHARED_LIB := $(BUILD_DIR)/libceleritas.dylib
    SHARED_FLAGS := -dynamiclib
    LDFLAGS += -framework Foundation -framework CoreFoundation -framework CoreGraphics -framework AppKit
else
    SHARED_LIB := $(BUILD_DIR)/libceleritas.so
    SHARED_FLAGS := -shared
endif

## Makefile notes
# $@ - target of current rule
# $^ - prerequisites of current rule separated by spaces
# $< - first prerequisite file only

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
	@mkdir -p $(OBJ_DIR)
	$(CC) $(CFLAGS) -c $< -o $@

$(SHARED_LIB): $(OBJS)
	@mkdir -p $(BUILD_DIR)
	$(CC) $(SHARED_FLAGS) -o $@ $^ $(LDFLAGS)

$(STATIC_LIB): $(OBJS)
	@mkdir -p $(BUILD_DIR)
	ar rcs $@ $^

shared: $(SHARED_LIB)

static: $(STATIC_LIB)

.PHONY: all
all: shared static

.PHONY: triangle
triangle: build/triangle.bin

build/triangle.bin: $(EXAMPLES_DIR)/triangle.c $(STATIC_LIB)
		@mkdir -p $(BUILD_DIR)
		$(CC) $(CFLAGS) $< -o $@ -L$(BUILD_DIR) -lceleritas $(LDFLAGS)

.PHONY: clean
clean:
	rm -rf $(BUILD_DIR)