-
Notifications
You must be signed in to change notification settings - Fork 62
/
Makefile
111 lines (89 loc) · 2.78 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
# Makefile for hev-socks5-tproxy
PROJECT=hev-socks5-tproxy
CROSS_PREFIX :=
PP=$(CROSS_PREFIX)cpp
CC=$(CROSS_PREFIX)gcc
STRIP=$(CROSS_PREFIX)strip
CCFLAGS=-O3 -pipe -Wall -Werror $(CFLAGS) \
-I$(SRCDIR)/misc \
-I$(SRCDIR)/core/include \
-I$(THIRDPARTDIR)/yaml/src \
-I$(THIRDPARTDIR)/hev-task-system/include
LDFLAGS=-L$(THIRDPARTDIR)/yaml/bin -lyaml \
-L$(THIRDPARTDIR)/hev-task-system/bin -lhev-task-system \
-lpthread
SRCDIR=src
BINDIR=bin
CONFDIR=conf
BUILDDIR=build
INSTDIR=/usr/local
THIRDPARTDIR=third-part
CONFIG=$(CONFDIR)/main.yml
TARGET=$(BINDIR)/hev-socks5-tproxy
THIRDPARTS=$(THIRDPARTDIR)/yaml $(THIRDPARTDIR)/hev-task-system
-include build.mk
CCFLAGS+=$(VERSION_CFLAGS)
CCSRCS=$(filter %.c,$(SRCFILES))
ASSRCS=$(filter %.S,$(SRCFILES))
LDOBJS=$(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(CCSRCS)) \
$(patsubst $(SRCDIR)/%.S,$(BUILDDIR)/%.o,$(ASSRCS))
DEPEND=$(LDOBJS:.o=.dep)
BUILDMSG="\e[1;31mBUILD\e[0m %s\n"
LINKMSG="\e[1;34mLINK\e[0m \e[1;32m%s\e[0m\n"
STRIPMSG="\e[1;34mSTRIP\e[0m \e[1;32m%s\e[0m\n"
CLEANMSG="\e[1;34mCLEAN\e[0m %s\n"
INSTMSG="\e[1;34mINST\e[0m %s -> %s\n"
UNINSMSG="\e[1;34mUNINS\e[0m %s\n"
ENABLE_DEBUG :=
ifeq ($(ENABLE_DEBUG),1)
CCFLAGS+=-g -O0 -DENABLE_DEBUG
STRIP=true
endif
ENABLE_STATIC :=
ifeq ($(ENABLE_STATIC),1)
CCFLAGS+=-static
endif
V :=
ECHO_PREFIX := @
ifeq ($(V),1)
undefine ECHO_PREFIX
endif
.PHONY: all clean install uninstall tp-build tp-clean
all : $(TARGET)
tp-build : $(THIRDPARTS)
@$(foreach dir,$^,$(MAKE) --no-print-directory -C $(dir);)
tp-clean : $(THIRDPARTS)
@$(foreach dir,$^,$(MAKE) --no-print-directory -C $(dir) clean;)
clean : tp-clean
$(ECHO_PREFIX) $(RM) -rf $(BINDIR) $(BUILDDIR)
@printf $(CLEANMSG) $(PROJECT)
install : $(INSTDIR)/bin/$(PROJECT) $(INSTDIR)/etc/$(PROJECT).yml
uninstall :
$(ECHO_PREFIX) $(RM) -rf $(INSTDIR)/bin/$(PROJECT)
@printf $(UNINSMSG) $(INSTDIR)/bin/$(PROJECT)
$(ECHO_PREFIX) $(RM) -rf $(INSTDIR)/etc/$(PROJECT).yml
@printf $(UNINSMSG) $(INSTDIR)/etc/$(PROJECT).yml
$(INSTDIR)/bin/$(PROJECT) : $(TARGET)
$(ECHO_PREFIX) install -d -m 0755 $(dir $@)
$(ECHO_PREFIX) install -m 0755 $< $@
@printf $(INSTMSG) $< $@
$(INSTDIR)/etc/$(PROJECT).yml : $(CONFIG)
$(ECHO_PREFIX) install -d -m 0755 $(dir $@)
$(ECHO_PREFIX) install -m 0644 $< $@
@printf $(INSTMSG) $< $@
$(TARGET) : $(LDOBJS) tp-build
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(CC) $(CCFLAGS) -o $@ $(LDOBJS) $(LDFLAGS)
@printf $(LINKMSG) $@
$(ECHO_PREFIX) $(STRIP) $@
@printf $(STRIPMSG) $@
$(BUILDDIR)/%.dep : $(SRCDIR)/%.c
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(PP) $(CCFLAGS) -MM -MT$(@:.dep=.o) -MF$@ $< 2>/dev/null
$(BUILDDIR)/%.o : $(SRCDIR)/%.c
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(CC) $(CCFLAGS) -c -o $@ $<
@printf $(BUILDMSG) $<
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPEND)
endif