-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
93 lines (68 loc) · 2.59 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
CC = gcc
LD = ld
CLIENT_SRCDIR := client_src
SERVER_SRCDIR := server_src
COMMON_SRCDIR := common_src
BUILDDIR := build
DEPDIR := deps
OUTPUTDIR := bin
SERVER_ROOT := server_root
TARGET_CLIENT := $(OUTPUTDIR)/client
TARGET_SERVER := $(OUTPUTDIR)/server
VPATH = $(CLIENT_SRCDIR) $(SERVER_SRCDIR) $(COMMON_SRCDIR)
WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wsystem-headers
CFLAGS = -g
CPPFLAGS = -I$(CLIENT_SRCDIR) -I$(SERVER_SRCDIR) -I$(COMMON_SRCDIR)
LDFLAGS =
LDLIB = -lreadline
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
CLIENT_SOURCES = $(shell find $(CLIENT_SRCDIR) -type f -name "*.c")
SERVER_SOURCES = $(shell find $(SERVER_SRCDIR) -type f -name "*.c")
COMMON_SOURCES = $(shell find $(COMMON_SRCDIR) -type f -name "*.c")
CLIENT_OBJECTS = $(patsubst $(CLIENT_SRCDIR)/%,$(BUILDDIR)/%,$(CLIENT_SOURCES:.c=.o))
SERVER_OBJECTS = $(patsubst $(SERVER_SRCDIR)/%,$(BUILDDIR)/%,$(SERVER_SOURCES:.c=.o))
COMMON_OBJECTS = $(patsubst $(COMMON_SRCDIR)/%,$(BUILDDIR)/%,$(COMMON_SOURCES:.c=.o))
DEPS = $(patsubst $(CLIENT_SRCDIR)/%,$(DEPDIR)/%,$(CLIENT_SOURCES:.c=.d))
DEPS += $(patsubst $(SERVER_SRCDIR)/%,$(DEPDIR)/%,$(SERVER_SOURCES:.c=.d))
DEPS += $(patsubst $(COMMON_SRCDIR)/%,$(DEPDIR)/%,$(COMMON_SOURCES:.c=.d))
OUTPUT_OPTION = -o $@
COMPILE.c = $(CC) -c $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(WARNINGS)
POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
$(shell mkdir -p $(DEPDIR) > /dev/null)
$(shell mkdir -p $(BUILDDIR) > /dev/null)
$(shell mkdir -p $(OUTPUTDIR) > /dev/null)
$(shell mkdir -p $(SERVER_ROOT) > /dev/null)
all: build link
dependencies:
sudo apt-get install libreadline-dev
build: $(CLIENT_OBJECTS) $(COMMON_OBJECTS) $(SERVER_OBJECTS)
link: $(TARGET_CLIENT) $(TARGET_SERVER)
.PHONY: clean TAGS install cscope
$(TARGET_CLIENT): $(CLIENT_OBJECTS) $(COMMON_OBJECTS)
$(CC) $(LDFLAGS) $(OUTPUT_OPTION) $^ $(LDLIB)
$(TARGET_SERVER): $(SERVER_OBJECTS) $(COMMON_OBJECTS)
$(CC) $(LDFLAGS) $(OUTPUT_OPTION) $^ $(LDLIB)
%.o: %.c
$(BUILDDIR)/%.o: $(CLIENT_SRCDIR)/%.c $(DEPDIR)/%.d
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
$(BUILDDIR)/%.o: $(SERVER_SRCDIR)/%.c $(DEPDIR)/%.d
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
$(BUILDDIR)/%.o: $(COMMON_SRCDIR)/%.c $(DEPDIR)/%.d
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
-include $(DEPS)
TAGS:
find . -name "*.[chS]" | xargs etags -a
cscope:
find . -name "*.[chS]" > cscope.files
cscope -b -q -k
clean:
$(RM) -r -v $(BUILDDIR) $(OUTPUTDIR) $(DEPDIR) $(SERVER_ROOT)
cleanall: clean
$(RM) -v cscope.* TAGS
help:
@echo 'make <all, clean, build, link, dependencies, TAGS, cscope>'