forked from eycorsican/go-tun2socks
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
117 lines (100 loc) · 3.29 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
114
115
116
117
GOCMD=go
XGOCMD=xgo
GOBUILD=$(GOCMD) build
GORUN=$(GOCMD) run
GOCLEAN=$(GOCMD) clean
DEBUG_LDFLAGS=''
RELEASE_LDFLAGS='-s -w'
BUILDDIR=$(shell pwd)/build
CMDDIR=$(shell pwd)/cmd/tun2socks
PROGRAM=tun2socks
SRC_DIR=$(shell pwd)/core
LWIP_SRC_DIR=$(SRC_DIR)/src
LWIP_INCLUDE_DIR=$(LWIP_SRC_DIR)/include
LWIP_HEADERS_DIR=$(LWIP_INCLUDE_DIR)/lwip
CORE_FILES=$(LWIP_SRC_DIR)/core/init.c \
$(LWIP_SRC_DIR)/core/def.c \
$(LWIP_SRC_DIR)/core/dns.c \
$(LWIP_SRC_DIR)/core/inet_chksum.c \
$(LWIP_SRC_DIR)/core/ip.c \
$(LWIP_SRC_DIR)/core/mem.c \
$(LWIP_SRC_DIR)/core/memp.c \
$(LWIP_SRC_DIR)/core/netif.c \
$(LWIP_SRC_DIR)/core/pbuf.c \
$(LWIP_SRC_DIR)/core/raw.c \
$(LWIP_SRC_DIR)/core/stats.c \
$(LWIP_SRC_DIR)/core/sys.c \
$(LWIP_SRC_DIR)/core/tcp.c \
$(LWIP_SRC_DIR)/core/tcp_in.c \
$(LWIP_SRC_DIR)/core/tcp_out.c \
$(LWIP_SRC_DIR)/core/timeouts.c \
$(LWIP_SRC_DIR)/core/udp.c
CORE_4_FILES=$(LWIP_SRC_DIR)/core/ipv4/autoip.c \
$(LWIP_SRC_DIR)/core/ipv4/dhcp.c \
$(LWIP_SRC_DIR)/core/ipv4/etharp.c \
$(LWIP_SRC_DIR)/core/ipv4/icmp.c \
$(LWIP_SRC_DIR)/core/ipv4/igmp.c \
$(LWIP_SRC_DIR)/core/ipv4/ip4_frag.c \
$(LWIP_SRC_DIR)/core/ipv4/ip4.c \
$(LWIP_SRC_DIR)/core/ipv4/ip4_addr.c
CORE_6_FILES=$(LWIP_SRC_DIR)/core/ipv6/dhcp6.c \
$(LWIP_SRC_DIR)/core/ipv6/ethip6.c \
$(LWIP_SRC_DIR)/core/ipv6/icmp6.c \
$(LWIP_SRC_DIR)/core/ipv6/inet6.c \
$(LWIP_SRC_DIR)/core/ipv6/ip6.c \
$(LWIP_SRC_DIR)/core/ipv6/ip6_addr.c \
$(LWIP_SRC_DIR)/core/ipv6/ip6_frag.c \
$(LWIP_SRC_DIR)/core/ipv6/mld6.c \
$(LWIP_SRC_DIR)/core/ipv6/nd6.c
CUSTOM_SRC_FILES=$(LWIP_SRC_DIR)/custom/sys_arch.c
CUSTOM_INCLUDE_FILES=$(LWIP_SRC_DIR)/custom/arch
CUSTOM_HEADER_FILES=$(LWIP_SRC_DIR)/custom/lwipopts.h
define copy_files
cp $(CORE_FILES) $(SRC_DIR)/
cp $(CORE_4_FILES) $(SRC_DIR)/
cp $(CORE_6_FILES) $(SRC_DIR)/
cp $(CUSTOM_SRC_FILES) $(SRC_DIR)/
cp -r $(CUSTOM_INCLUDE_FILES) $(LWIP_INCLUDE_DIR)/
cp -r $(CUSTOM_HEADER_FILES) $(LWIP_HEADERS_DIR)/
endef
define clear_files
rm -rf $(SRC_DIR)/*.c
rm -rf $(LWIP_INCLUDE_DIR)/arch
rm -rf $(LWIP_HEADERS_DIR)/lwipopts.h
endef
define with_copied_files
$(call copy_files)
eval $(1)
$(call clear_files)
endef
DBUILD_CMD="cd $(CMDDIR) && $(GOBUILD) -race -ldflags $(DEBUG_LDFLAGS) -o $(BUILDDIR)/$(PROGRAM) -v"
BUILD_CMD="cd $(CMDDIR) && $(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BUILDDIR)/$(PROGRAM) -v"
XBUILD_CMD="cd $(BUILDDIR) && $(XGOCMD) -ldflags $(RELEASE_LDFLAGS) --targets=*/* $(CMDDIR)"
RELEASE_CMD="cd $(BUILDDIR) && $(XGOCMD) -ldflags $(RELEASE_LDFLAGS) --targets=linux/amd64,darwin/amd64,windows/amd64 $(CMDDIR)"
WINDOWS_CMD="cd $(BUILDDIR) && $(XGOCMD) -ldflags $(RELEASE_LDFLAGS) --targets=windows/amd64 $(CMDDIR)"
all: build
build:
mkdir -p $(BUILDDIR)
$(call with_copied_files,$(BUILD_CMD))
dbuild:
mkdir -p $(BUILDDIR)
$(call with_copied_files,$(DBUILD_CMD))
windows:
mkdir -p $(BUILDDIR)
$(call with_copied_files,$(WINDOWS_CMD))
xbuild:
mkdir -p $(BUILDDIR)
$(call with_copied_files,$(XBUILD_CMD))
release:
mkdir -p $(BUILDDIR)
$(call with_copied_files,$(RELEASE_CMD))
copy:
$(call copy_files)
clean:
rm -rf $(BUILDDIR)
$(call clear_files)
cleancache:
# go build cache may need to cleanup if changing C source code
$(GOCLEAN) -cache
rm -rf $(BUILDDIR)
$(call clear_files)