-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (42 loc) · 1.43 KB
/
Makefile
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
DEBUG ?= 0
ASAN ?= 0
TEXTURE_DBG ?= 0
ELF := texture2c.elf
CC := clang
INC := -I include -I lib
WARNINGS := -Wall -Wextra -Wpedantic -Wshadow -Werror=implicit-function-declaration -Wvla
CFLAGS := -std=c11
LDFLAGS := -lpng
ifeq ($(DEBUG),0)
OPTFLAGS := -Os
else
OPTFLAGS := -O0 -g3
endif
ifneq ($(TEXTURE_DBG),0)
CFLAGS += -DTEXTURE_DEBUG
endif
ifneq ($(ASAN),0)
CFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
endif
SRC_DIRS := $(shell find src -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
H_FILES := $(foreach dir,$(INC),$(wildcard $(dir)/*.h))
O_FILES := $(foreach f,$(C_FILES:.c=.o),build/$f)
LIB_DIRS := $(shell find lib -type d)
C_LIB_FILES := $(foreach dir,$(LIB_DIRS),$(wildcard $(dir)/*.c))
O_LIB_FILES := $(foreach f,$(C_LIB_FILES:.c=.o),build/$f)
# Main targets
all: $(ELF)
clean:
$(RM) -r build $(ELF)
format:
clang-format-11 -i $(C_FILES) $(H_FILES)
.PHONY: all clean format
# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)) $(foreach dir,$(LIB_DIRS),build/$(dir)))
$(ELF): $(O_FILES) $(O_LIB_FILES)
$(CC) $(INC) $(WARNINGS) $(CFLAGS) $(OPTFLAGS) $(LDFLAGS) -o $@ $^
build/%.o: %.c $(H_FILES)
$(CC) -c $(INC) $(WARNINGS) $(CFLAGS) $(OPTFLAGS) -o $@ $<
build/lib/%.o: lib/%.c
$(CC) -c $(INC) $(WARNINGS) $(CFLAGS) $(OPTFLAGS) -o $@ $<