summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 4ad0a2af3c231489ca4584d28f8231e9428c013b (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
.POSIX:
.SUFFIXES:

# Source code location and files to watch for changes.
SRC_DIR     := src
BUILD_DIR   := build
SRC_MAIN    := $(SRC_DIR)/main.c $(SRC_DIR)/glad/src/glad.c
WATCH_SRC   := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h")
INC_DIRS    := $(shell find $(SRC_DIR) -type d)
INC_FLAGS   := $(addprefix -I,$(INC_DIRS))

# Output executable.
TARGET := ogl
BIN    := $(BUILD_DIR)/$(TARGET)

# Compiler and linker configuration.
CC             := cc
CFLAGS         := -std=c99 -Wall -Wextra -DBIN_NAME=\"$(TARGET)\" -Wno-missing-braces
CFLAGS         += $(INC_FLAGS)
NASM_FLAGS     ?= -felf64
LDFLAGS        :=
LDLIBS         := -lglfw -lGL
RELEASE_CFLAGS := -DNDEBUG -O2
DEBUG_CFLAGS   := -DDEBUG -O0 -g

.PHONY: build tests clean

# Setup debug/release builds.
#     make clean && make <target> DEBUG=0
#     make clean && make <target> DEBUG=1
DEBUG ?= 0
ifeq ($(DEBUG), 1)
    CFLAGS += $(DEBUG_CFLAGS)
    NASM_FLAGS += -g -F dwarf
else ifeq ($(DEBUG), 2)
    CFLAGS += $(DEBUG_CFLAGS) -fsanitize=address
    NASM_FLAGS += -g -F dwarf
else
    CFLAGS += $(RELEASE_CFLAGS)
endif

main: $(BIN)

$(BIN): $(SRC_MAIN) $(WATCH_SRC) $(BUILD_DIR)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS)

# Create build directory if needed.
$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

run: $(BIN)
	$(BIN) example.bdl

# Remove build directory.
clean:
	rm -rf $(BUILD_DIR)