Lorenzo Colitti | 313379e | 2013-07-11 01:07:11 +0900 | [diff] [blame] | 1 | # |
| 2 | # Configuration |
| 3 | # |
| 4 | |
| 5 | # CC |
| 6 | CC=gcc |
| 7 | # Path to parent kernel include files directory |
| 8 | LIBC_INCLUDE=/usr/include |
| 9 | # Libraries |
| 10 | ADDLIB= |
| 11 | # Linker flags |
| 12 | LDFLAG_STATIC=-Wl,-Bstatic |
| 13 | LDFLAG_DYNAMIC=-Wl,-Bdynamic |
| 14 | LDFLAG_CAP=-lcap |
| 15 | LDFLAG_GNUTLS=-lgnutls-openssl |
| 16 | LDFLAG_CRYPTO=-lcrypto |
| 17 | LDFLAG_IDN=-lidn |
| 18 | LDFLAG_RESOLV=-lresolv |
| 19 | LDFLAG_SYSFS=-lsysfs |
| 20 | |
| 21 | # |
| 22 | # Options |
| 23 | # |
| 24 | |
| 25 | # Capability support (with libcap) [yes|static|no] |
| 26 | USE_CAP=yes |
| 27 | # sysfs support (with libsysfs - deprecated) [no|yes|static] |
| 28 | USE_SYSFS=no |
| 29 | # IDN support (experimental) [no|yes|static] |
| 30 | USE_IDN=no |
| 31 | |
| 32 | # Do not use getifaddrs [no|yes|static] |
| 33 | WITHOUT_IFADDRS=no |
| 34 | # arping default device (e.g. eth0) [] |
| 35 | ARPING_DEFAULT_DEVICE= |
| 36 | |
| 37 | # GNU TLS library for ping6 [yes|no|static] |
| 38 | USE_GNUTLS=yes |
| 39 | # Crypto library for ping6 [shared|static] |
| 40 | USE_CRYPTO=shared |
| 41 | # Resolv library for ping6 [yes|static] |
| 42 | USE_RESOLV=yes |
| 43 | # ping6 source routing (deprecated by RFC5095) [no|yes|RFC3542] |
| 44 | ENABLE_PING6_RTHDR=no |
| 45 | |
| 46 | # rdisc server (-r option) support [no|yes] |
| 47 | ENABLE_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 |
| 52 | CCOPT=-fno-strict-aliasing -Wstrict-prototypes -Wall -g |
| 53 | CCOPTOPT=-O3 |
| 54 | GLIBCFIX=-D_GNU_SOURCE |
| 55 | DEFINES= |
| 56 | LDLIB= |
| 57 | |
| 58 | FUNC_LIB = $(if $(filter static,$(1)),$(LDFLAG_STATIC) $(2) $(LDFLAG_DYNAMIC),$(2)) |
| 59 | |
| 60 | # USE_GNUTLS: DEF_GNUTLS, LIB_GNUTLS |
| 61 | # USE_CRYPTO: LIB_CRYPTO |
| 62 | ifneq ($(USE_GNUTLS),no) |
| 63 | LIB_CRYPTO = $(call FUNC_LIB,$(USE_GNUTLS),$(LDFLAG_GNUTLS)) |
| 64 | DEF_CRYPTO = -DUSE_GNUTLS |
| 65 | else |
| 66 | LIB_CRYPTO = $(call FUNC_LIB,$(USE_CRYPTO),$(LDFLAG_CRYPTO)) |
| 67 | endif |
| 68 | |
| 69 | # USE_RESOLV: LIB_RESOLV |
| 70 | LIB_RESOLV = $(call FUNC_LIB,$(USE_RESOLV),$(LDFLAG_RESOLV)) |
| 71 | |
| 72 | # USE_CAP: DEF_CAP, LIB_CAP |
| 73 | ifneq ($(USE_CAP),no) |
| 74 | DEF_CAP = -DCAPABILITIES |
| 75 | LIB_CAP = $(call FUNC_LIB,$(USE_CAP),$(LDFLAG_CAP)) |
| 76 | endif |
| 77 | |
| 78 | # USE_SYSFS: DEF_SYSFS, LIB_SYSFS |
| 79 | ifneq ($(USE_SYSFS),no) |
| 80 | DEF_SYSFS = -DUSE_SYSFS |
| 81 | LIB_SYSFS = $(call FUNC_LIB,$(USE_SYSFS),$(LDFLAG_SYSFS)) |
| 82 | endif |
| 83 | |
| 84 | # USE_IDN: DEF_IDN, LIB_IDN |
| 85 | ifneq ($(USE_IDN),no) |
| 86 | DEF_IDN = -DUSE_IDN |
| 87 | LIB_IDN = $(call FUNC_LIB,$(USE_IDN),$(LDFLAG_IDN)) |
| 88 | endif |
| 89 | |
| 90 | # WITHOUT_IFADDRS: DEF_WITHOUT_IFADDRS |
| 91 | ifneq ($(WITHOUT_IFADDRS),no) |
| 92 | DEF_WITHOUT_IFADDRS = -DWITHOUT_IFADDRS |
| 93 | endif |
| 94 | |
| 95 | # ENABLE_RDISC_SERVER: DEF_ENABLE_RDISC_SERVER |
| 96 | ifneq ($(ENABLE_RDISC_SERVER),no) |
| 97 | DEF_ENABLE_RDISC_SERVER = -DRDISC_SERVER |
| 98 | endif |
| 99 | |
| 100 | # ENABLE_PING6_RTHDR: DEF_ENABLE_PING6_RTHDR |
| 101 | ifneq ($(ENABLE_PING6_RTHDR),no) |
| 102 | DEF_ENABLE_PING6_RTHDR = -DPING6_ENABLE_RTHDR |
| 103 | ifeq ($(ENABLE_PING6_RTHDR),RFC3542) |
| 104 | DEF_ENABLE_PING6_RTHDR += -DPINR6_ENABLE_RTHDR_RFC3542 |
| 105 | endif |
| 106 | endif |
| 107 | |
| 108 | # ------------------------------------- |
| 109 | IPV4_TARGETS=tracepath ping clockdiff rdisc arping tftpd rarpd |
| 110 | IPV6_TARGETS=tracepath6 traceroute6 ping6 |
| 111 | TARGETS=$(IPV4_TARGETS) $(IPV6_TARGETS) |
| 112 | |
| 113 | CFLAGS=$(CCOPTOPT) $(CCOPT) $(GLIBCFIX) $(DEFINES) |
| 114 | LDLIBS=$(LDLIB) $(ADDLIB) |
| 115 | |
| 116 | UNAME_N:=$(shell uname -n) |
| 117 | LASTTAG:=$(shell git describe HEAD | sed -e 's/-.*//') |
| 118 | TODAY=$(shell date +%Y/%m/%d) |
| 119 | DATE=$(shell date --date $(TODAY) +%Y%m%d) |
| 120 | TAG:=$(shell date --date=$(TODAY) +s%Y%m%d) |
| 121 | |
| 122 | |
| 123 | # ------------------------------------- |
| 124 | .PHONY: all ninfod clean distclean man html check-kernel modules snapshot |
| 125 | |
| 126 | all: $(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 |
| 137 | DEF_arping = $(DEF_SYSFS) $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) |
| 138 | LIB_arping = $(LIB_SYSFS) $(LIB_CAP) $(LIB_IDN) |
| 139 | |
| 140 | ifneq ($(ARPING_DEFAULT_DEVICE),) |
| 141 | DEF_arping += -DDEFAULT_DEVICE=\"$(ARPING_DEFAULT_DEVICE)\" |
| 142 | endif |
| 143 | |
| 144 | # clockdiff |
| 145 | DEF_clockdiff = $(DEF_CAP) |
| 146 | LIB_clockdiff = $(LIB_CAP) |
| 147 | |
| 148 | # ping / ping6 |
| 149 | DEF_ping_common = $(DEF_CAP) $(DEF_IDN) |
| 150 | DEF_ping = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) |
| 151 | LIB_ping = $(LIB_CAP) $(LIB_IDN) |
| 152 | DEF_ping6 = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) $(DEF_ENABLE_PING6_RTHDR) $(DEF_CRYPTO) |
| 153 | LIB_ping6 = $(LIB_CAP) $(LIB_IDN) $(LIB_RESOLV) $(LIB_CRYPTO) |
| 154 | |
| 155 | ping: ping_common.o |
| 156 | ping6: ping_common.o |
| 157 | ping.o ping_common.o: ping_common.h |
| 158 | ping6.o: ping_common.h in6_flowlabel.h |
| 159 | |
| 160 | # rarpd |
| 161 | DEF_rarpd = |
| 162 | LIB_rarpd = |
| 163 | |
| 164 | # rdisc |
| 165 | DEF_rdisc = $(DEF_ENABLE_RDISC_SERVER) |
| 166 | LIB_rdisc = |
| 167 | |
| 168 | # tracepath |
| 169 | DEF_tracepath = $(DEF_IDN) |
| 170 | LIB_tracepath = $(LIB_IDN) |
| 171 | |
| 172 | # tracepath6 |
| 173 | DEF_tracepath6 = $(DEF_IDN) |
| 174 | LIB_tracepath6 = |
| 175 | |
| 176 | # traceroute6 |
| 177 | DEF_traceroute6 = $(DEF_CAP) $(DEF_IDN) |
| 178 | LIB_traceroute6 = $(LIB_CAP) $(LIB_IDN) |
| 179 | |
| 180 | # tftpd |
| 181 | DEF_tftpd = |
| 182 | DEF_tftpsubs = |
| 183 | LIB_tftpd = |
| 184 | |
| 185 | tftpd: tftpsubs.o |
| 186 | tftpd.o tftpsubs.o: tftp.h |
| 187 | |
| 188 | # ------------------------------------- |
| 189 | # ninfod |
| 190 | ninfod: |
| 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 |
| 201 | check-kernel: |
| 202 | ifeq ($(KERNEL_INCLUDE),) |
| 203 | @echo "Please, set correct KERNEL_INCLUDE"; false |
| 204 | else |
| 205 | @set -e; \ |
| 206 | if [ ! -r $(KERNEL_INCLUDE)/linux/autoconf.h ]; then \ |
| 207 | echo "Please, set correct KERNEL_INCLUDE"; false; fi |
| 208 | endif |
| 209 | |
| 210 | modules: check-kernel |
| 211 | $(MAKE) KERNEL_INCLUDE=$(KERNEL_INCLUDE) -C Modules |
| 212 | |
| 213 | # ------------------------------------- |
| 214 | man: |
| 215 | $(MAKE) -C doc man |
| 216 | |
| 217 | html: |
| 218 | $(MAKE) -C doc html |
| 219 | |
| 220 | clean: |
| 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 | |
| 229 | distclean: clean |
| 230 | @set -e; \ |
| 231 | if [ -f ninfod/Makefile ]; then \ |
| 232 | $(MAKE) -C ninfod distclean; \ |
| 233 | fi |
| 234 | |
| 235 | # ------------------------------------- |
| 236 | snapshot: |
| 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 | |