diff options
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 56 |
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. | ||
5 | SRC_DIR := src | ||
6 | BUILD_DIR := build | ||
7 | SRC_MAIN := $(SRC_DIR)/main.c | ||
8 | WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h") | ||
9 | INC_DIRS := $(shell find $(SRC_DIR) -type d) | ||
10 | INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | ||
11 | |||
12 | # Output executable. | ||
13 | TARGET := ogl | ||
14 | BIN := $(BUILD_DIR)/$(TARGET) | ||
15 | |||
16 | # Compiler and linker configuration. | ||
17 | CC := cc | ||
18 | CFLAGS := -Wall -Wextra -pedantic -DBIN_NAME=\"$(TARGET)\" -Wno-missing-braces | ||
19 | CFLAGS += $(INC_FLAGS) | ||
20 | NASM_FLAGS ?= -felf64 | ||
21 | LDFLAGS := | ||
22 | LDLIBS := -lglfw -framework OpenGL | ||
23 | RELEASE_CFLAGS := -DNDEBUG -O2 | ||
24 | DEBUG_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 | ||
31 | DEBUG ?= 0 | ||
32 | ifeq ($(DEBUG), 1) | ||
33 | CFLAGS += $(DEBUG_CFLAGS) | ||
34 | NASM_FLAGS += -g -F dwarf | ||
35 | else ifeq ($(DEBUG), 2) | ||
36 | CFLAGS += $(DEBUG_CFLAGS) -fsanitize=address | ||
37 | NASM_FLAGS += -g -F dwarf | ||
38 | else | ||
39 | CFLAGS += $(RELEASE_CFLAGS) | ||
40 | endif | ||
41 | |||
42 | main: $(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 | |||
51 | run: $(BIN) | ||
52 | $(BIN) example.bdl | ||
53 | |||
54 | # Remove build directory. | ||
55 | clean: | ||
56 | rm -rf $(BUILD_DIR) | ||