-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
113 lines (73 loc) · 1.99 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Thie is working now! Most of credits to: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
# Also referenced:
# make manual: https://www.gnu.org/software/make/manual/html_node/index.html
# Ruoshui on 20191105
# Email complaints to: [email protected]
# space-separated list of source files
SRCS = main.c helper.c # Place all .c files here
# name for executable
EXE = main
# USAGE: Change above variables to suit your needs
ifeq ($(filter $(DEBUG), false f FALSE F), )
DEBUG_FLAG = -ggdb3
endif
# flags to pass compiler
CFLAGS = $(DEBUG_FLAG) -std=gnu11
# compiler to use
CC = gcc
# Ruoshui: my computer doesn't have gcc; so this will change CC to clang if "which gcc" outputs nothing
ifeq (, $(shell which gcc))
CC = clang
endif
OBJDIR := obj
# automatically generated list of object files
OBJS = $(SRCS:%.c=$(OBJDIR)/%.o)
# default target
$(EXE): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)
DEPDIR := $(OBJDIR)/.deps
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
$(OBJDIR)/%.o : %.c $(DEPDIR)/%.d | $(DEPDIR)
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(DEPDIR): ; @mkdir -p $@
DEPFILES := $(SRCS:%.c=$(DEPDIR)/%.d)
$(DEPFILES):
include $(wildcard $(DEPFILES))
.PHONY: clean run autorun
# housekeeping
clean:
rm -f $(EXE)
rm -rf obj
run:
./$(EXE)
autorun: $(EXE)
./$(EXE)
# OLD MAKEFILE:
# # compiler to use
# CC = gcc
# ifeq (, $(shell which gcc))
# CC = clang
# endif
# # flags to pass compiler
# CFLAGS = -ggdb3 -std=c11
# # name for executable
# EXE = main
# # space-separated list of header files
# HDRS = llist.h songlib.h
# # space-separated list of source files
# SRCS = main.c llist.c songlib.c
# # automatically generated list of object files
# OBJS = $(SRCS:.c=.o)
# # default target
# $(EXE): $(OBJS) $(HDRS) Makefile
# $(CC) $(CFLAGS) -o $@ $(OBJS)
# # dependencies
# $(OBJS): $(HDRS) Makefile
# .PHONY: clean run
# # housekeeping
# clean:
# rm -f core $(EXE) *.o
# rm -rf obj
# run:
# ./$(EXE)