1#
2# Configuration
3#
4
5# CC
6CC=gcc
7# Path to parent kernel include files directory
8LIBC_INCLUDE=/usr/include
9# Libraries
10ADDLIB=
11# Linker flags
12LDFLAG_STATIC=-Wl,-Bstatic
13LDFLAG_DYNAMIC=-Wl,-Bdynamic
14LDFLAG_CAP=-lcap
15LDFLAG_GNUTLS=-lgnutls-openssl
16LDFLAG_CRYPTO=-lcrypto
17LDFLAG_IDN=-lidn
18LDFLAG_RESOLV=-lresolv
19LDFLAG_SYSFS=-lsysfs
20
21#
22# Options
23#
24
25# Capability support (with libcap) [yes|static|no]
26USE_CAP=yes
27# sysfs support (with libsysfs - deprecated) [no|yes|static]
28USE_SYSFS=no
29# IDN support (experimental) [no|yes|static]
30USE_IDN=no
31
32# Do not use getifaddrs [no|yes|static]
33WITHOUT_IFADDRS=no
34# arping default device (e.g. eth0) []
35ARPING_DEFAULT_DEVICE=
36
37# GNU TLS library for ping6 [yes|no|static]
38USE_GNUTLS=yes
39# Crypto library for ping6 [shared|static]
40USE_CRYPTO=shared
41# Resolv library for ping6 [yes|static]
42USE_RESOLV=yes
43# ping6 source routing (deprecated by RFC5095) [no|yes|RFC3542]
44ENABLE_PING6_RTHDR=no
45
46# rdisc server (-r option) support [no|yes]
47ENABLE_RDISC_SERVER=no
48
49# -------------------------------------
50# What a pity, all new gccs are buggy and -Werror does not work. Sigh.
51# CCOPT=-fno-strict-aliasing -Wstrict-prototypes -Wall -Werror -g
52CCOPT=-fno-strict-aliasing -Wstrict-prototypes -Wall -g
53CCOPTOPT=-O3
54GLIBCFIX=-D_GNU_SOURCE
55DEFINES=
56LDLIB=
57
58FUNC_LIB = $(if $(filter static,$(1)),$(LDFLAG_STATIC) $(2) $(LDFLAG_DYNAMIC),$(2))
59
60# USE_GNUTLS: DEF_GNUTLS, LIB_GNUTLS
61# USE_CRYPTO: LIB_CRYPTO
62ifneq ($(USE_GNUTLS),no)
63	LIB_CRYPTO = $(call FUNC_LIB,$(USE_GNUTLS),$(LDFLAG_GNUTLS))
64	DEF_CRYPTO = -DUSE_GNUTLS
65else
66	LIB_CRYPTO = $(call FUNC_LIB,$(USE_CRYPTO),$(LDFLAG_CRYPTO))
67endif
68
69# USE_RESOLV: LIB_RESOLV
70LIB_RESOLV = $(call FUNC_LIB,$(USE_RESOLV),$(LDFLAG_RESOLV))
71
72# USE_CAP:  DEF_CAP, LIB_CAP
73ifneq ($(USE_CAP),no)
74	DEF_CAP = -DCAPABILITIES
75	LIB_CAP = $(call FUNC_LIB,$(USE_CAP),$(LDFLAG_CAP))
76endif
77
78# USE_SYSFS: DEF_SYSFS, LIB_SYSFS
79ifneq ($(USE_SYSFS),no)
80	DEF_SYSFS = -DUSE_SYSFS
81	LIB_SYSFS = $(call FUNC_LIB,$(USE_SYSFS),$(LDFLAG_SYSFS))
82endif
83
84# USE_IDN: DEF_IDN, LIB_IDN
85ifneq ($(USE_IDN),no)
86	DEF_IDN = -DUSE_IDN
87	LIB_IDN = $(call FUNC_LIB,$(USE_IDN),$(LDFLAG_IDN))
88endif
89
90# WITHOUT_IFADDRS: DEF_WITHOUT_IFADDRS
91ifneq ($(WITHOUT_IFADDRS),no)
92	DEF_WITHOUT_IFADDRS = -DWITHOUT_IFADDRS
93endif
94
95# ENABLE_RDISC_SERVER: DEF_ENABLE_RDISC_SERVER
96ifneq ($(ENABLE_RDISC_SERVER),no)
97	DEF_ENABLE_RDISC_SERVER = -DRDISC_SERVER
98endif
99
100# ENABLE_PING6_RTHDR: DEF_ENABLE_PING6_RTHDR
101ifneq ($(ENABLE_PING6_RTHDR),no)
102	DEF_ENABLE_PING6_RTHDR = -DPING6_ENABLE_RTHDR
103ifeq ($(ENABLE_PING6_RTHDR),RFC3542)
104	DEF_ENABLE_PING6_RTHDR += -DPINR6_ENABLE_RTHDR_RFC3542
105endif
106endif
107
108# -------------------------------------
109IPV4_TARGETS=tracepath ping clockdiff rdisc arping tftpd rarpd
110IPV6_TARGETS=tracepath6 traceroute6 ping6
111TARGETS=$(IPV4_TARGETS) $(IPV6_TARGETS)
112
113CFLAGS=$(CCOPTOPT) $(CCOPT) $(GLIBCFIX) $(DEFINES)
114LDLIBS=$(LDLIB) $(ADDLIB)
115
116UNAME_N:=$(shell uname -n)
117LASTTAG:=$(shell git describe HEAD | sed -e 's/-.*//')
118TODAY=$(shell date +%Y/%m/%d)
119DATE=$(shell date --date $(TODAY) +%Y%m%d)
120TAG:=$(shell date --date=$(TODAY) +s%Y%m%d)
121
122
123# -------------------------------------
124.PHONY: all ninfod clean distclean man html check-kernel modules snapshot
125
126all: $(TARGETS)
127
128%.s: %.c
129	$(COMPILE.c) $< $(DEF_$(patsubst %.o,%,$@)) -S -o $@
130%.o: %.c
131	$(COMPILE.c) $< $(DEF_$(patsubst %.o,%,$@)) -o $@
132$(TARGETS): %: %.o
133	$(LINK.o) $^ $(LIB_$@) $(LDLIBS) -o $@
134
135# -------------------------------------
136# arping
137DEF_arping = $(DEF_SYSFS) $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS)
138LIB_arping = $(LIB_SYSFS) $(LIB_CAP) $(LIB_IDN)
139
140ifneq ($(ARPING_DEFAULT_DEVICE),)
141DEF_arping += -DDEFAULT_DEVICE=\"$(ARPING_DEFAULT_DEVICE)\"
142endif
143
144# clockdiff
145DEF_clockdiff = $(DEF_CAP)
146LIB_clockdiff = $(LIB_CAP)
147
148# ping / ping6
149DEF_ping_common = $(DEF_CAP) $(DEF_IDN)
150DEF_ping  = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS)
151LIB_ping  = $(LIB_CAP) $(LIB_IDN)
152DEF_ping6 = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) $(DEF_ENABLE_PING6_RTHDR) $(DEF_CRYPTO)
153LIB_ping6 = $(LIB_CAP) $(LIB_IDN) $(LIB_RESOLV) $(LIB_CRYPTO)
154
155ping: ping_common.o
156ping6: ping_common.o
157ping.o ping_common.o: ping_common.h
158ping6.o: ping_common.h in6_flowlabel.h
159
160# rarpd
161DEF_rarpd =
162LIB_rarpd =
163
164# rdisc
165DEF_rdisc = $(DEF_ENABLE_RDISC_SERVER)
166LIB_rdisc =
167
168# tracepath
169DEF_tracepath = $(DEF_IDN)
170LIB_tracepath = $(LIB_IDN)
171
172# tracepath6
173DEF_tracepath6 = $(DEF_IDN)
174LIB_tracepath6 =
175
176# traceroute6
177DEF_traceroute6 = $(DEF_CAP) $(DEF_IDN)
178LIB_traceroute6 = $(LIB_CAP) $(LIB_IDN)
179
180# tftpd
181DEF_tftpd =
182DEF_tftpsubs =
183LIB_tftpd =
184
185tftpd: tftpsubs.o
186tftpd.o tftpsubs.o: tftp.h
187
188# -------------------------------------
189# ninfod
190ninfod:
191	@set -e; \
192		if [ ! -f ninfod/Makefile ]; then \
193			cd ninfod; \
194			./configure; \
195			cd ..; \
196		fi; \
197		$(MAKE) -C ninfod
198
199# -------------------------------------
200# modules / check-kernel are only for ancient kernels; obsolete
201check-kernel:
202ifeq ($(KERNEL_INCLUDE),)
203	@echo "Please, set correct KERNEL_INCLUDE"; false
204else
205	@set -e; \
206	if [ ! -r $(KERNEL_INCLUDE)/linux/autoconf.h ]; then \
207		echo "Please, set correct KERNEL_INCLUDE"; false; fi
208endif
209
210modules: check-kernel
211	$(MAKE) KERNEL_INCLUDE=$(KERNEL_INCLUDE) -C Modules
212
213# -------------------------------------
214man:
215	$(MAKE) -C doc man
216
217html:
218	$(MAKE) -C doc html
219
220clean:
221	@rm -f *.o $(TARGETS)
222	@$(MAKE) -C Modules clean
223	@$(MAKE) -C doc clean
224	@set -e; \
225		if [ -f ninfod/Makefile ]; then \
226			$(MAKE) -C ninfod clean; \
227		fi
228
229distclean: clean
230	@set -e; \
231		if [ -f ninfod/Makefile ]; then \
232			$(MAKE) -C ninfod distclean; \
233		fi
234
235# -------------------------------------
236snapshot:
237	@if [ x"$(UNAME_N)" != x"pleiades" ]; then echo "Not authorized to advance snapshot"; exit 1; fi
238	@echo "[$(TAG)]" > RELNOTES.NEW
239	@echo >>RELNOTES.NEW
240	@git log --no-merges $(LASTTAG).. | git shortlog >> RELNOTES.NEW
241	@echo >> RELNOTES.NEW
242	@cat RELNOTES >> RELNOTES.NEW
243	@mv RELNOTES.NEW RELNOTES
244	@sed -e "s/^%define ssdate .*/%define ssdate $(DATE)/" iputils.spec > iputils.spec.tmp
245	@mv iputils.spec.tmp iputils.spec
246	@echo "static char SNAPSHOT[] = \"$(TAG)\";" > SNAPSHOT.h
247	@$(MAKE) -C doc snapshot
248	@$(MAKE) man
249	@git commit -a -m "iputils-$(TAG)"
250	@git tag -s -m "iputils-$(TAG)" $(TAG)
251	@git archive --format=tar --prefix=iputils-$(TAG)/ $(TAG) | bzip2 -9 > ../iputils-$(TAG).tar.bz2
252
253