-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
60 lines (48 loc) · 1.2 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
SRCDIR = src
HDRDIR = include
OBJDIR = build
BINDIR = bin
DEPDIR = dep
CC = gcc
TARGET = main
CFLAGS = -flto -O2 -I$(HDRDIR)
LFLAGS = -lm -pthread
SOURCES := $(wildcard $(SRCDIR)/*.c)
HEADERS := $(wildcard $(HDRDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEPS := $(OBJECTS:$(OBJDIR)/%.o=$(DEPDIR)/%.d)
REMOVE := rm -rf
# Linking
$(BINDIR)/$(TARGET): $(OBJECTS) $(CMN_OBJ)
mkdir -p $(BINDIR)
$(CC) $(LFLAGS) -o $@ $(OBJECTS) $(CMN_OBJ)
@echo "Linking complete"
-include $(DEPS)
# Compilation
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
mkdir -p $(OBJDIR)
mkdir -p $(DEPDIR)
$(CC) -c $(CFLAGS) $< -o $@
$(CC) -I$(HDRDIR) -MM -MT '$(OBJDIR)/$*.o' $(SRCDIR)/$*.c > $(DEPDIR)/$*.d
@echo "Compiled $<"
# Generate file list for cscope
cscope.files: $(SOURCES) $(HEADERS)
echo $(SOURCES) $(HEADERS) > cscope.files
# Generate cscope database
cscope.out: cscope.files
cscope -q -R -b -i cscope.files
.PHONY: clean
clean:
$(REMOVE) $(OBJECTS) $(OBJDIR) $(BINDIR) $(DEPDIR)
@echo "Deleted $<"
.PHONY: remove
remove:
$(REMOVE) $(BINDIR)/$(TARGET)
$(REMOVE) $(OBJECTS)
$(REMOVE) $(DEPS)
$(REMOVE) cscope.*
@echo "Deleted $<"
.PHONY: cscope
cscope: cscope.out
.PHONY: all
all: $(BINDIR)/$(TARGET)