-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (47 loc) · 1 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
57
58
59
60
61
62
63
64
65
66
# Project directories:
dir_src := src
dir_inc := include
dir_obj := obj
dir_bin := bin
dirs_inc := $(dir_inc)
# Tools:
cc := gcc
ld := $(cc)
# Defines:
cdefines := _REENTRANT
# Libraries:
libs :=\
SDL2
# Precompiler flags:
dflags := $(patsubst %,-D%,$(cdefines))
iflags := $(patsubst %,-I%,$(dirs_inc))
# Compiler flags:
cflags := -std=gnu17 -Wall -g3
# Linker flags:
lflags := $(patsubst %,-l%,$(libs))
# Object list:
obj_names :=\
line-renderer\
main
obj_files := $(patsubst %,$(dir_obj)/%.o,$(obj_names))
# Binary list:
bin := $(dir_bin)/bresenham
.phony: all rebuild run clean
all: $(bin)
rebuild: clean $(bin)
run: $(bin)
$(bin)
clean:
if [ -d $(dir_obj) ]; then rm -rf $(dir_obj); fi
if [ -d $(dir_bin) ]; then rm -rf $(dir_bin); fi
# Directories
$(dir_obj):
mkdir -p $@
$(dir_bin):
mkdir -p $@
# Objects:
$(dir_obj)/%.o: $(dir_src)/%.c | $(dir_obj)
$(cc) -c $(strip $(cflags) $(dflags) $(iflags)) -o $@ $<
# Binaries:
$(bin): $(obj_files) | $(dir_bin)
$(ld) $(strip $(lflags)) -o $@ $^