forked from darkk/redsocks
-
Notifications
You must be signed in to change notification settings - Fork 247
/
Makefile
171 lines (155 loc) · 5.12 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
ifdef DISABLE_SHADOWSOCKS
OBJS := parser.o main.o redsocks.o log.o direct.o ipcache.o autoproxy.o http-connect.o \
socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o socks5-udp.o \
tcpdns.o gen/version.o
CFLAGS +=-fPIC -O3 -DDISABLE_SHADOWSOCKS
FEATURES += DISABLE_SHADOWSOCKS
else
OBJS := parser.o main.o redsocks.o log.o direct.o ipcache.o autoproxy.o encrypt.o shadowsocks.o http-connect.o \
socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o socks5-udp.o shadowsocks-udp.o \
tcpdns.o gen/version.o
CFLAGS +=-fPIC -O3
endif
SRCS := $(OBJS:.o=.c)
CONF := config.h
DEPS := .depend
OUT := redsocks2
VERSION := 0.71
OS := $(shell uname)
LIBS := -levent
override CFLAGS += -D_BSD_SOURCE -D_DEFAULT_SOURCE -Wall
ifeq ($(OS), Linux)
override CFLAGS += -std=c99 -D_XOPEN_SOURCE=600
endif
ifeq ($(OS), FreeBSD)
override CFLAGS +=-I/usr/local/include -L/usr/local//lib
endif
ifeq ($(OS), OpenBSD)
override CFLAGS +=-I/usr/local/include -L/usr/local//lib #same as FreeBSD
endif
ifeq ($(OS), Darwin)
override CFLAGS +=-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
SHELL := /bin/bash
OSX_VERSION := $(shell sw_vers -productVersion | cut -d '.' -f 1,2)
OSX_ROOT_PATH := xnu
OSX_HEADERS_PATH := $(OSX_ROOT_PATH)/$(OSX_VERSION)
OSX_HEADERS := $(OSX_HEADERS_PATH)/net/pfvar.h $(OSX_HEADERS_PATH)/net/radix.h $(OSX_HEADERS_PATH)/libkern/tree.h
override CFLAGS +=-I$(OSX_HEADERS_PATH)
endif
#LDFLAGS += -fwhole-program
ifdef USE_CRYPTO_POLARSSL
override LIBS += -lpolarssl
override CFLAGS += -DUSE_CRYPTO_POLARSSL
$(info Compile with PolarSSL.)
CRYPTO := PolarSSL
else
$(info Compile with OpenSSL by default. To compile with PolarSSL, run 'make USE_CRYPTO_POLARSSL=true' instead.)
CRYPTO := OpenSSL
ifdef ENABLE_HTTPS_PROXY
override OBJS += https-connect.o
override LIBS += -levent_openssl
override CFLAGS += -DENABLE_HTTPS_PROXY
override FEATURES += ENABLE_HTTPS_PROXY
$(info Compile with HTTPS proxy enabled.)
endif
override LIBS += -lssl -lcrypto
ifneq ($(OS), OpenBSD)
override LIBS += -ldl
endif
override CFLAGS += -DUSE_CRYPTO_OPENSSL
endif
ifdef ENABLE_STATIC
override LIBS += -lz
override LDFLAGS += -Wl,-static -static -static-libgcc -s
override FEATURES += STATIC_COMPILE
endif
all: $(OUT)
.PHONY: all clean distclean
tags: *.c *.h
ctags -R
$(CONF):
@case $(OS) in \
Linux*) \
echo "#define USE_IPTABLES" >$(CONF) \
;; \
FreeBSD) \
echo "#define USE_PF" >$(CONF) \
;; \
OpenBSD) \
echo "#define USE_PF" >$(CONF) \
;; \
NetBSD) \
echo "#define USE_PF" >$(CONF) \
;; \
Darwin) \
echo -e "#define USE_PF\n#define _APPLE_" >$(CONF) \
;; \
*) \
echo "Unknown system, only generic firewall code is compiled" 1>&2; \
echo "/* Unknown system, only generic firewall code is compiled */" >$(CONF) \
;; \
esac
# Dependency on .git is useful to rebuild `version.c' after commit, but it breaks non-git builds.
gen/version.c: *.c *.h gen/.build
$(RM) -f [email protected]
echo '/* this file is auto-generated during build */' > [email protected]
echo '#include "../version.h"' >> [email protected]
echo 'const char* redsocks_version = ' >> [email protected]
if [ -d .git ]; then \
echo '"redsocks.git/'`git describe --tags`' $(CRYPTO)"'; \
if [ `git status --porcelain | grep -v -c '^??'` != 0 ]; then \
echo '"-unclean"'; \
fi; \
echo '"\\n"'; \
echo '"Features: $(FEATURES)"'; \
else \
echo '"redsocks/$(VERSION) $(CRYPTO)"'; \
echo '"\\n"'; \
echo '"Features: $(FEATURES)"'; \
fi >> [email protected]
echo ';' >> [email protected]
mv -f [email protected] $@
gen/.build:
mkdir -p gen
touch $@
base.c: $(CONF)
ifeq ($(OS), Darwin)
$(OSX_HEADERS_PATH)/net/pfvar.h:
mkdir -p $(OSX_HEADERS_PATH)/net && curl -o $(OSX_HEADERS_PATH)/net/pfvar.h https://raw.githubusercontent.com/apple/darwin-xnu/master/bsd/net/pfvar.h
$(OSX_HEADERS_PATH)/net/radix.h:
mkdir -p $(OSX_HEADERS_PATH)/net && curl -o $(OSX_HEADERS_PATH)/net/radix.h https://raw.githubusercontent.com/apple/darwin-xnu/master/bsd/net/radix.h
$(OSX_HEADERS_PATH)/libkern/tree.h:
mkdir -p $(OSX_HEADERS_PATH)/libkern && curl -o $(OSX_HEADERS_PATH)/libkern/tree.h https://raw.githubusercontent.com/apple/darwin-xnu/master/libkern/libkern/tree.h
endif
$(DEPS): $(OSX_HEADERS) $(SRCS)
$(CC) -MM $(CFLAGS) $(SRCS) 2>/dev/null >$(DEPS) || \
( \
for I in $(wildcard *.h); do \
export $${I//[-.]/_}_DEPS="`sed '/^\#[ \t]*include \?"\(.*\)".*/!d;s//\1/' $$I`"; \
done; \
echo -n >$(DEPS); \
for SRC in $(SRCS); do \
echo -n "$${SRC%.c}.o: " >>$(DEPS); \
export SRC_DEPS="`sed '/\#[ \t]*include \?"\(.*\)".*/!d;s//\1/' $$SRC | sort`"; \
while true; do \
export SRC_DEPS_OLD="$$SRC_DEPS"; \
export SRC_DEEP_DEPS=""; \
for HDR in $$SRC_DEPS; do \
eval export SRC_DEEP_DEPS="\"$$SRC_DEEP_DEPS \$$$${HDR//[-.]/_}_DEPS\""; \
done; \
export SRC_DEPS="`echo $$SRC_DEPS $$SRC_DEEP_DEPS | sed 's/ */\n/g' | sort -u`"; \
test "$$SRC_DEPS" = "$$SRC_DEPS_OLD" && break; \
done; \
echo $$SRC $$SRC_DEPS >>$(DEPS); \
done; \
)
-include $(DEPS)
$(OUT): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
clean:
$(RM) $(CONF) $(OBJS)
distclean: clean
$(RM) $(OUT)
$(RM) tags $(DEPS)
$(RM) -r gen
$(RM) -r $(OSX_ROOT_PATH)