1##
2##  tcpproxy
3##
4##  tcpproxy is a simple tcp connection proxy which combines the
5##  features of rinetd and 6tunnel. tcpproxy supports IPv4 and
6##  IPv6 and also supports connections from IPv6 to IPv4
7##  endpoints and vice versa.
8##
9##
10##  Copyright (C) 2010-2015 Christian Pointner <equinox@spreadspace.org>
11##
12##  This file is part of tcpproxy.
13##
14##  tcpproxy is free software: you can redistribute it and/or modify
15##  it under the terms of the GNU General Public License as published by
16##  the Free Software Foundation, either version 3 of the License, or
17##  any later version.
18##
19##  tcpproxy is distributed in the hope that it will be useful,
20##  but WITHOUT ANY WARRANTY; without even the implied warranty of
21##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22##  GNU General Public License for more details.
23##
24##  You should have received a copy of the GNU General Public License
25##  along with tcpproxy. If not, see <http://www.gnu.org/licenses/>.
26##
27
28ifneq ($(MAKECMDGOALS),distclean)
29include include.mk
30endif
31
32EXECUTABLE := tcpproxy
33
34C_OBJS := log.o \
35          options.o \
36          cfg_parser.o \
37          slist.o \
38          string_list.o \
39          sig_handler.o \
40          tcp.o \
41          listener.o \
42          clients.o \
43          tcpproxy.o
44
45C_SRCS := $(C_OBJS:%.o=%.c)
46
47.PHONY: clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge
48
49all: $(EXECUTABLE)
50
51cfg_parser.c: cfg_parser.rl
52	$(RAGEL) -C -G2 -o $@ $<
53
54cfg_parser.dot: cfg_parser.rl
55	$(RAGEL) -V -p -o $@ $<
56
57cfg_parser.png: cfg_parser.dot
58	@dot -Tpng $< > $@
59
60%.d: %.c
61	@set -e; rm -f $@; \
62  $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
63  sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
64  rm -f $@.$$$$; echo '(re)building $@'
65
66ifneq ($(MAKECMDGOALS),distclean)
67-include $(C_SRCS:%.c=%.d)
68endif
69
70$(EXECUTABLE): $(C_OBJS)
71	$(CC) $(C_OBJS) -o $@ $(LDFLAGS)
72
73%.o: %.c
74	$(CC) $(CFLAGS) -c $<
75
76strip: $(EXECUTABLE)
77	$(STRIP) -s $(EXECUTABLE)
78
79
80distclean: cleanall
81	find . -name *.o -exec rm -f {} \;
82	find . -name "*.\~*" -exec rm -rf {} \;
83	rm -f include.mk
84	rm -f config.h
85
86clean:
87	rm -f *.o
88	rm -f *.d
89	rm -f *.d.*
90	rm -f cfg_parser.c
91	rm -f cfg_parser.png cfg_parser.dot
92	rm -f $(EXECUTABLE)
93
94cleanall: clean
95	$(MAKE) --directory="../doc/" clean
96
97manpage:
98	$(MAKE) --directory="../doc/" manpage
99
100
101INSTALL_TARGETS := install-bin install-systemd install-etc
102REMOVE_TARGETS := remove-bin remove-systemd remove-etc
103
104ifdef MANDIR
105INSTALL_TARGETS += install-man
106REMOVE_TARGETS += remove-man
107endif
108
109ifdef EXAMPLESDIR
110INSTALL_TARGETS += install-examples
111REMOVE_TARGETS += remove-examples
112endif
113
114install: all $(INSTALL_TARGETS)
115
116install-bin: $(EXECUTABLE)
117	$(INSTALL) -d $(DESTDIR)$(BINDIR)
118	$(INSTALL) -m 755 $(EXECUTABLE) $(DESTDIR)$(BINDIR)
119
120install-systemd:
121	$(INSTALL) -d $(DESTDIR)$(SYSTEMDDIR)
122	$(INSTALL) -m 644 ../contrib/systemd.service $(DESTDIR)$(SYSTEMDDIR)/$(EXECUTABLE).service
123
124install-etc:
125	$(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d/
126	$(INSTALL) -m 755 ../contrib/initscript $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
127	$(INSTALL) -d $(DESTDIR)$(ETCDIR)/default/
128	$(INSTALL) -m 644 ../contrib/default $(DESTDIR)$(ETCDIR)/default/$(EXECUTABLE)
129	@ echo "# $(EXECUTABLE) configuration file" > $(DESTDIR)$(ETCDIR)/$(EXECUTABLE).conf
130	@ echo "# example configurations can be found at $(EXAMPLESDIR)/$(EXECUTABLE)" >> $(DESTDIR)$(ETCDIR)/$(EXECUTABLE).conf
131
132install-examples:
133	$(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)
134	$(INSTALL) -m 644 ../contrib/example.conf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
135
136install-man: manpage
137	$(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
138	$(INSTALL) -m 644 ../doc/tcpproxy.8 $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
139
140uninstall: remove
141
142remove: $(REMOVE_TARGETS)
143
144remove-bin:
145	rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)
146
147remove-systemd:
148	rm -f $(DESTDIR)$(SYSTEMDDIR)/$(EXECUTABLE).service
149
150remove-etc:
151	rm -f $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
152
153remove-examples:
154	rm -rf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
155
156remove-man:
157	rm -f $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
158
159purge: remove
160	rm -f $(DESTDIR)$(ETCDIR)/$(EXECUTABLE).conf
161	rm -f $(DESTDIR)$(ETCDIR)/default/$(EXECUTABLE)
162