summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorAlex Sanchez Brotons <alex@alexsb.xyz>2022-08-20 11:13:29 +0200
committerAlex Sanchez Brotons <alex@alexsb.xyz>2022-08-20 11:13:29 +0200
commita11a4738f7b2c09001b1328b12f8022a3d635ecd (patch)
treef534a14dc74bcd1787dc540d175366a16881b8a6 /Makefile
downloadogl-monotext-a11a4738f7b2c09001b1328b12f8022a3d635ecd.tar.gz
ogl-monotext-a11a4738f7b2c09001b1328b12f8022a3d635ecd.zip
Initial commit
Setting up a build process for a macOS OpenGL application.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile56
1 files changed, 56 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..57c2774
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,56 @@
1.POSIX:
2.SUFFIXES:
3
4# Source code location and files to watch for changes.
5SRC_DIR := src
6BUILD_DIR := build
7SRC_MAIN := $(SRC_DIR)/main.c
8WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h")
9INC_DIRS := $(shell find $(SRC_DIR) -type d)
10INC_FLAGS := $(addprefix -I,$(INC_DIRS))
11
12# Output executable.
13TARGET := ogl
14BIN := $(BUILD_DIR)/$(TARGET)
15
16# Compiler and linker configuration.
17CC := cc
18CFLAGS := -Wall -Wextra -pedantic -DBIN_NAME=\"$(TARGET)\" -Wno-missing-braces
19CFLAGS += $(INC_FLAGS)
20NASM_FLAGS ?= -felf64
21LDFLAGS :=
22LDLIBS := -lglfw -framework OpenGL
23RELEASE_CFLAGS := -DNDEBUG -O2
24DEBUG_CFLAGS := -DDEBUG -O0 -g
25
26.PHONY: build tests clean
27
28# Setup debug/release builds.
29# make clean && make <target> DEBUG=0
30# make clean && make <target> DEBUG=1
31DEBUG ?= 0
32ifeq ($(DEBUG), 1)
33 CFLAGS += $(DEBUG_CFLAGS)
34 NASM_FLAGS += -g -F dwarf
35else ifeq ($(DEBUG), 2)
36 CFLAGS += $(DEBUG_CFLAGS) -fsanitize=address
37 NASM_FLAGS += -g -F dwarf
38else
39 CFLAGS += $(RELEASE_CFLAGS)
40endif
41
42main: $(BIN)
43
44$(BIN): $(SRC_MAIN) $(WATCH_SRC) $(BUILD_DIR)
45 $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS)
46
47# Create build directory if needed.
48$(BUILD_DIR):
49 mkdir -p $(BUILD_DIR)
50
51run: $(BIN)
52 $(BIN) example.bdl
53
54# Remove build directory.
55clean:
56 rm -rf $(BUILD_DIR)