forked from darkk/redsocks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
105 lines (88 loc) · 2.84 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
LIBHTTP_VERSION := 2.6.0
LIBHTTP_NAME := http-parser-$(LIBHTTP_VERSION)
LIBHTTP_CFLAGS := -I./http-parser-$(LIBHTTP_VERSION) -L./http-parser-$(LIBHTTP_VERSION)
OBJS := tls.o parser.o main.o redsocks.o log.o http-connect.o socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o dnstc.o gen/version.o
SRCS := $(OBJS:.o=.c)
CONF := config.h
DEPS := .depend
OUT := redsocks
VERSION := 0.4.1-adallom
LIBS := -levent -lhttp_parser
CFLAGS += $(LIBHTTP_CFLAGS)
CFLAGS += -g -O2
override CFLAGS += -std=c99 -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -Wall
all: $(OUT)
.PHONY: all clean distclean http-parser
tags: *.c *.h
ctags -R
$(LIBHTTP_NAME):
wget https://github.com/nodejs/http-parser/archive/v$(LIBHTTP_VERSION).tar.gz
tar -zxf v$(LIBHTTP_VERSION).tar.gz
rm -f v$(LIBHTTP_VERSION).tar.gz
$(LIBHTTP_NAME)/libhttp_parser.o:
cd $(LIBHTTP_NAME) && make package
http-parser: $(LIBHTTP_NAME) $(LIBHTTP_NAME)/libhttp_parser.o
$(CONF):
@case `uname` in \
Linux*) \
echo "#define USE_IPTABLES" >$(CONF) \
;; \
OpenBSD) \
echo "#define USE_PF" >$(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`'"'; \
if [ `git status --porcelain | grep -v -c '^??'` != 0 ]; then \
echo '"-unclean"'; \
fi \
else \
echo '"redsocks/$(VERSION)"'; \
fi >> [email protected]
echo ';' >> [email protected]
mv -f [email protected] $@
gen/.build:
mkdir -p gen
touch $@
base.c: $(CONF)
$(DEPS): $(SRCS)
gcc -MM $(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): http-parser $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
clean:
$(RM) $(OUT) $(CONF) $(OBJS)
distclean: clean
$(RM) tags $(DEPS)
$(RM) -r gen
$(RM) -rf $(LIBHTTP_NAME)