1# @(#) GNU Makefile for udpxy project
2#
3# Copyright 2008-2012 Pavel V. Cherenkov
4#
5#  This file is part of udpxy.
6#
7#  udpxy is free software: you can redistribute it and/or modify
8#  it under the terms of the GNU General Public License as published by
9#  the Free Software Foundation, either version 3 of the License, or
10#  (at your option) any later version.
11#
12#  udpxy is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#  GNU General Public License for more details.
16#
17#  You should have received a copy of the GNU General Public License
18#  along with udpxy.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21.SUFFIXES : .o .c .d
22
23EXEC := udpxy
24UDPXREC := udpxrec
25
26STRIP := /usr/bin/strip
27GZIP  := /bin/gzip
28
29MKDEPOPT := -MM
30DEBUG_ON := -g
31
32ALL_CFLAGS = -W -Wall -Werror --pedantic $(CFLAGS)
33
34SYSTEM=$(shell uname 2>/dev/null)
35ifneq (,$(filter $(SYSTEM),FreeBSD Darwin))
36MAKE := gmake
37GZIP := /usr/bin/gzip
38endif
39
40BUILDFILE = BUILD
41BUILDNO := `cat $(BUILDFILE)`
42
43BTYPEFILE = BLDTYPE
44BTYPE := `cat $(BTYPEFILE) | tr -d '"'`
45
46VERSIONFILE = VERSION
47VERSION := `cat $(VERSIONFILE) | tr -d '"'`
48
49PATCHFILE = PATCH
50PATCHNO := `cat $(PATCHFILE)`
51
52CHANGEFILE := CHANGES
53READMEFILE := README
54
55ifndef PREFIX
56	PREFIX := /usr/local
57endif
58
59INSTALLROOT := $(DESTDIR)$(PREFIX)
60
61ARCDIR = ..
62ARCFILE := $(ARCDIR)/$(EXEC).$(VERSION).$(BUILDNO)-$(PATCHNO)-$(BTYPE).tar.gz
63
64DEBUG_OPT  := $(COPT) $(DEBUG_ON) -DTRACE_MODULE
65PROD_OPT   := $(COPT) -DNDEBUG -DTRACE_MODULE
66LEAN_OPT   := $(COPT) -DNDEBUG
67
68UTILDIR := util
69
70SLOOP_FILES := sloop_p.c sloop_s.c
71
72UDPXY_MAN1   := udpxy.1
73UDPXREC_MAN1 := udpxrec.1
74
75UDPXY_MANPAGE_EN := doc/en/$(UDPXY_MAN1)
76# UDPXY_MANPAGE_RU := doc/ru/$(UDPXY_MAN1)
77
78UDPXREC_MANPAGE_EN := doc/en/$(UDPXREC_MAN1)
79# UDPXYREC_MANPAGE_RU := doc/ru/$(UDPXREC_MAN1)
80
81MANPAGE_DIR := $(DESTDIR)/usr/share/man/man1
82
83DOCDIR := doc
84DOCFILES := *.txt $(DOCDIR)
85
86SRC := udpxy.c sloop.c rparse.c util.c prbuf.c ifaddr.c ctx.c mkpg.c \
87	rtp.c uopt.c dpkt.c netop.c extrn.c main.c
88
89ifneq (yes,$(NO_UDPXREC))
90	SRC   += udpxrec.c
91	CDEFS += -DUDPXREC_MOD
92endif
93
94OBJ := ${SRC:.c=.o}
95
96DEPFILE := $(EXEC).dep
97CORES := core.* core
98
99.PHONY: clean distclean distro install uninstall all \
100debug ldebug rdebug lean verify touch incbuild 
101
102.c.o :
103	$(CC) $(ALL_CFLAGS) $(CPPFLAGS) $(CDEFS) $(COPT) -c $< -o $@
104
105release:
106	@echo -e "\nMaking a [release] version (use 'debug' target as an alternative)\n"
107	@$(MAKE) all "COPT=${PROD_OPT}" "CFLAGS=${CFLAGS}" "CDEFS=${CDEFS}" "CPPFLAGS=${CPPFLAGS}"
108
109debug:
110	@echo -e "\nMaking a [debug] version (use 'release' target as an alternative)\n"
111	@$(MAKE) all "COPT=${DEBUG_OPT}" "CFLAGS=${CFLAGS}" "CDEFS=${CDEFS}" "CPPFLAGS=${CPPFLAGS}"
112
113lean:
114	@echo -e "\nMaking a [lean] version (minimal size)\n"
115	@$(MAKE) all "COPT=${LEAN_OPT}" "CFLAGS=${CFLAGS}" "CDEFS=${CDEFS}" "CPPFLAGS=${CPPFLAGS}"
116
117ldebug:
118	@echo -e "\nMaking a [lean] version with debug info\n"
119	@$(MAKE) all "COPT=${LEAN_OPT} ${DEBUG_ON}" "CFLAGS=${CFLAGS}" "CDEFS=${CDEFS}" "CPPFLAGS=${CPPFLAGS}"
120
121rdebug:
122	@echo -e "\nMaking a [release] version with debug info\n"
123	@$(MAKE) all "COPT=${PROD_OPT} ${DEBUG_ON}" "CDEFS=${CDEFS}" "CPPFLAGS=${CPPFLAGS}"
124
125verify:
126	@echo -e "\nVerifying all build targets\n"
127	@$(MAKE) clean
128	@$(MAKE) release
129	@$(MAKE) clean
130	@$(MAKE) lean
131	@$(MAKE) clean
132	@$(MAKE) ldebug
133	@$(MAKE) clean
134	@$(MAKE) rdebug
135	@$(MAKE) clean
136	@$(MAKE) debug
137	@$(MAKE) clean
138
139mk_deps := $(CC) $(CFLAGS) $(CDEFS) $(MKDEPOPT) $(SRC)
140
141all:	$(DEPFILE) $(EXEC)
142
143$(DEPFILE): $(SRC)
144	$(mk_deps) > $(DEPFILE)
145
146$(EXEC) : $(DEPFILE) $(OBJ)
147	@rm -f $(EXEC)
148	$(CC) $(CFLAGS) $(LDFLAGS) $(COPT) -o $(EXEC) $(OBJ)
149	@ls -l $(EXEC)
150ifneq (yes, $(NO_UDPXREC))
151	@rm -f $(UDPXREC)
152	ln -s $(EXEC) $(UDPXREC)
153endif
154
155clean:
156	rm -f $(CORES) $(DEPFILE) $(OBJ) $(EXEC) $(UDPXREC)
157
158distclean: clean
159
160incbuild:
161	@expr `cat $(BUILDFILE)` + 1 > $(BUILDFILE)
162	@echo "Set build number to: `cat $(BUILDFILE)`"
163	@$(MAKE) touch
164
165DISTRO_DIR := udpxy-$(VERSION).$(BUILDNO)-$(PATCHNO)
166DISTRO_FILES := $(SRC) $(SLOOP_FILES) *.h Makefile $(DOCFILES) $(BUILDFILE) $(BTYPEFILE) \
167	$(VERSIONFILE) $(CHANGEFILE) $(READMEFILE) $(PATCHFILE)
168
169distro: dist
170
171dist:
172	@rm -fr $(DISTRO_DIR)
173	@mkdir  $(DISTRO_DIR)
174	@mkdir  $(DISTRO_DIR)/$(UTILDIR)
175	cp -R $(DISTRO_FILES) $(DISTRO_DIR)
176	tar -cvzf $(ARCFILE) $(DISTRO_DIR)
177	@ls -l $(ARCFILE)
178	@rm -fr $(DISTRO_DIR)
179
180install: $(EXEC)
181	@mkdir -p -m 755 $(INSTALLROOT)/bin
182	@cp $(EXEC) $(INSTALLROOT)/bin
183	@ls -l $(INSTALLROOT)/bin/$(EXEC)
184	@mkdir -p -m 755 $(MANPAGE_DIR)
185	@$(GZIP) -c $(UDPXY_MANPAGE_EN) > $(MANPAGE_DIR)/$(UDPXY_MAN1).gz
186ifneq (yes, $(NO_UDPXREC))
187	@cp $(UDPXREC) $(INSTALLROOT)/bin/$(UDPXREC)
188	@ls -l $(INSTALLROOT)/bin/$(UDPXREC)
189	@$(GZIP) -c $(UDPXREC_MANPAGE_EN) > $(MANPAGE_DIR)/$(UDPXREC_MAN1).gz
190endif
191	@echo "Installation of udpxy is complete"
192
193install-strip: install
194	$(STRIP) $(INSTALLROOT)/bin/$(EXEC)
195	@ls -l $(INSTALLROOT)/bin/$(EXEC)
196	@echo "udpxy executable stripped"
197
198uninstall:
199	@rm -f $(INSTALLROOT)/bin/$(EXEC) $(INSTALLROOT)/bin/$(UDPXREC)
200	@rm -f $(MANPAGE_DIR)/$(UDPXY_MAN1).gz $(MANPAGE_DIR)/$(UDPXREC_MAN1).gz
201	@echo "udpxy successfully uninstalled"
202
203ifneq ($(MAKECMDGOALS), clean)
204-include $(DEPFILE)
205endif
206
207# __EOF__
208
209