forked from danos/iputils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
233 lines (191 loc) · 5.3 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#
# Configuration
#
# Path to parent kernel include files directory
LIBC_INCLUDE=/usr/include
# Libraries
ADDLIB=
# Linker flags
LDFLAG_STATIC=-Wl,-Bstatic
LDFLAG_DYNAMIC=-Wl,-Bdynamic
LDFLAG_CAP=-lcap
LDFLAG_GCRYPT=-lgcrypt -lgpg-error
LDFLAG_NETTLE=-lnettle
LDFLAG_CRYPTO=-lcrypto
LDFLAG_IDN=-lidn2
LDFLAG_RESOLV=-lresolv
LDFLAG_RT=-lrt
LDFLAG_M=-lm
#
# Options
#
# Capability support (with libcap) [yes|static|no]
USE_CAP=yes
# sysfs support
USE_SYSFS=yes
# IDN support [yes|no|static]
USE_IDN=yes
# Do not use getifaddrs [no|yes|static]
WITHOUT_IFADDRS=no
# arping default device (e.g. eth0) []
ARPING_DEFAULT_DEVICE=
# nettle library for ipv6 ping [yes|no|static]
USE_NETTLE=yes
# libgcrypt library for ipv6 ping [no|yes|static]
USE_GCRYPT=no
# Crypto library for ping6 [shared|static|no]
USE_CRYPTO=shared
# Resolv library for ping6 [yes|static]
USE_RESOLV=yes
# ping6 source routing (deprecated by RFC5095) [no|yes|RFC3542]
ENABLE_PING6_RTHDR=no
# rdisc server (-r option) support [no|yes]
ENABLE_RDISC_SERVER=no
# -------------------------------------
# What a pity, all new gccs are buggy and -Werror does not work. Sigh.
# CFLAGS+=-fno-strict-aliasing -Wstrict-prototypes -Wall -Werror -g
CFLAGS?=-O3 -g
CFLAGS+=-fno-strict-aliasing -Wstrict-prototypes -Wall
CPPFLAGS+=-D_GNU_SOURCE
LDLIB=
FUNC_LIB = $(if $(filter static,$(1)),$(LDFLAG_STATIC) $(2) $(LDFLAG_DYNAMIC),$(2))
# USE_GCRYPT: DEF_GCRYPT, LIB_GCRYPT
# USE_CRYPTO: LIB_CRYPTO
ifneq ($(USE_GCRYPT),no)
LIB_CRYPTO = $(call FUNC_LIB,$(USE_GCRYPT),$(LDFLAG_GCRYPT))
DEF_CRYPTO = -DUSE_GCRYPT
else
ifneq ($(USE_NETTLE),no)
LIB_CRYPTO = $(call FUNC_LIB,$(USE_NETTLE),$(LDFLAG_NETTLE))
DEF_CRYPTO = -DUSE_NETTLE
else
ifneq ($(USE_CRYPTO),no)
LIB_CRYPTO = $(call FUNC_LIB,$(USE_CRYPTO),$(LDFLAG_CRYPTO))
DEF_CRYPTO = -DUSE_OPENSSL
endif
endif
endif
# USE_RESOLV: LIB_RESOLV
LIB_RESOLV = $(call FUNC_LIB,$(USE_RESOLV),$(LDFLAG_RESOLV))
# USE_CAP: DEF_CAP, LIB_CAP
ifneq ($(USE_CAP),no)
DEF_CAP = -DCAPABILITIES
LIB_CAP = $(call FUNC_LIB,$(USE_CAP),$(LDFLAG_CAP))
endif
# USE_SYSFS: DEF_SYSFS, LIB_SYSFS
ifneq ($(USE_SYSFS),no)
DEF_SYSFS = -DUSE_SYSFS
endif
# USE_IDN: DEF_IDN, LIB_IDN
ifneq ($(USE_IDN),no)
DEF_IDN = -DUSE_IDN
LIB_IDN = $(call FUNC_LIB,$(USE_IDN),$(LDFLAG_IDN))
endif
# WITHOUT_IFADDRS: DEF_WITHOUT_IFADDRS
ifneq ($(WITHOUT_IFADDRS),no)
DEF_WITHOUT_IFADDRS = -DWITHOUT_IFADDRS
endif
# ENABLE_RDISC_SERVER: DEF_ENABLE_RDISC_SERVER
ifneq ($(ENABLE_RDISC_SERVER),no)
DEF_ENABLE_RDISC_SERVER = -DRDISC_SERVER
endif
# ENABLE_PING6_RTHDR: DEF_ENABLE_PING6_RTHDR
ifneq ($(ENABLE_PING6_RTHDR),no)
DEF_ENABLE_PING6_RTHDR = -DPING6_ENABLE_RTHDR
ifeq ($(ENABLE_PING6_RTHDR),RFC3542)
DEF_ENABLE_PING6_RTHDR += -DPINR6_ENABLE_RTHDR_RFC3542
endif
endif
# -------------------------------------
TARGETS=ping tracepath traceroute6 clockdiff rdisc arping tftpd rarpd
LDLIBS=$(LDLIB) $(ADDLIB)
TODAY=$(shell date +%Y-%m-%d)
DATE=$(shell date -d $(TODAY) +%Y%m%d)
TAG:=$(shell date -d $(TODAY) +s%Y%m%d)
# -------------------------------------
.PHONY: all ninfod clean distclean man html snapshot
all: $(TARGETS)
%.s: %.c
$(COMPILE.c) $< $(DEF_$(patsubst %.o,%,$@)) -S -o $@
%.o: %.c
$(COMPILE.c) $< $(DEF_$(patsubst %.o,%,$@)) -o $@
LINK.o += $(CFLAGS)
$(TARGETS): %: %.o
$(LINK.o) $^ $(LIB_$@) $(LDLIBS) -o $@
# -------------------------------------
# arping
DEF_arping = $(DEF_SYSFS) $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS)
LIB_arping = $(LIB_CAP) $(LIB_IDN) $(LDFLAG_RT)
ifneq ($(ARPING_DEFAULT_DEVICE),)
DEF_arping += -DDEFAULT_DEVICE=\"$(ARPING_DEFAULT_DEVICE)\"
endif
# clockdiff
DEF_clockdiff = $(DEF_CAP)
LIB_clockdiff = $(LIB_CAP)
# ping / ping6
DEF_ping = $(DEF_CAP) $(DEF_IDN) $(DEF_CRYPTO) $(DEF_WITHOUT_IFADDRS)
DEF_ping_common = $(DEF_ping)
DEF_ping6_common = $(DEF_ping)
LIB_ping = $(LIB_CAP) $(LIB_IDN) $(LIB_CRYPTO) $(LIB_RESOLV) $(LDFLAG_M)
ping: ping_common.o ping6_common.o
ping.o ping_common.o ping6_common.o: ping.h in6_flowlabel.h
ping6.o ping6_common.o: ping.h in6_flowlabel.h
# rarpd
DEF_rarpd =
LIB_rarpd =
# rdisc
DEF_rdisc = $(DEF_ENABLE_RDISC_SERVER)
LIB_rdisc =
# tracepath
DEF_tracepath = $(DEF_IDN)
LIB_tracepath = $(LIB_IDN)
# traceroute6
DEF_traceroute6 = $(DEF_CAP) $(DEF_IDN)
LIB_traceroute6 = $(LIB_CAP) $(LIB_IDN)
# tftpd
DEF_tftpd =
DEF_tftpsubs =
LIB_tftpd =
tftpd: tftpsubs.o
tftpd.o tftpsubs.o: tftp.h
# -------------------------------------
# ninfod
ninfod:
@set -e; \
if [ ! -f ninfod/Makefile ]; then \
cd ninfod; \
./configure; \
cd ..; \
fi; \
$(MAKE) -C ninfod
# -------------------------------------
man:
$(MAKE) -C doc man
html:
$(MAKE) -C doc html
clean:
@rm -f *.o $(TARGETS)
@$(MAKE) -C Modules clean
@$(MAKE) -C doc clean
@set -e; \
if [ -f ninfod/Makefile ]; then \
$(MAKE) -C ninfod clean; \
fi
distclean: clean
@set -e; \
if [ -f ninfod/Makefile ]; then \
$(MAKE) -C ninfod distclean; \
fi
# -------------------------------------
RPMBUILD=rpmbuild
RPMTMP=.rpmtmp
snapshot:
@echo "#define SNAPSHOT \"$(TAG)\"" > SNAPSHOT.h
@$(MAKE) man
@git commit -a -m "iputils-$(TAG)"
@git tag -s -m "iputils-$(TAG)" $(TAG)
@git archive --format=tar --prefix=iputils-$(TAG)/ $(TAG) | bzip2 -9 > ../iputils-$(TAG).tar.bz2
rpm:
@git archive --format=tar --prefix=iputils/ HEAD | bzip2 -9 > $(RPMTMP)/iputils.tar.bz2
@$(RPMBUILD) -ta --define 'current yes' $(RPMTMP)/iputils.tar.bz2
@rm -f $(RPMTMP)/iputils.tar.bz2