-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
51 lines (38 loc) · 1003 Bytes
/
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
OBJDIR = output
SRC = src
CC = gcc
CFLAGS = -g
LFLAGS = -lm
target = directory
# Find all source files
SOURCES := $(notdir $(shell find . -name "*.c"))
#Convert from .c to .o
OBJECTS := $(SOURCES:.c=.o)
OBJECTS := $(addprefix $(OBJDIR)/,$(OBJECTS))
all: obj_dir $(target)
#Include All Headers folders
HEADERS := $(sort $(dir $(shell find -L . -name "*.h")))
INCLUDE := $(patsubst %,-I%,$(HEADERS))
DIRS := $(sort $(dir $(SOURCES)))
DIRS := $(addsuffix $(OBJDIR)/,$(DIRS))
#DEPS := $(patsubst %.o,%.d,%(OBJECTS))
DEPS := DEP = $(OBJECTS:%.o=%.d)
-include $(DEPS)
#Generate all dependencies files
DEPFLAG = -MMD -MF $(@:.o=.d)
$(target): $(OBJECTS)
$(CC) -o $@ $^ $(LFLAGS)
$(OBJDIR)/%.o: $(SRC)/%.c
$(CC) $(CFLAGS) $(INCLUDE) $(DEPFLAG) -c $< -o $@
obj_dir:
@mkdir -p $(DIRS)
clean:
rm -rf $(OBJDIR)
rm -rf $(target)
rm -rf $(DEPS)
show:
@echo "SOURCES" $(SOURCES)
@echo "OBJECTS" $(OBJECTS)
@echo "HEADERS" $(HEADERS)
@echo "INCLUDE" $(INCLUDE)
@echo "DEPS" $(DEPS)