Makefile 5.9 KB
Newer Older
1 2 3 4
include config.mk
include platform.mk

# Targets
5
all: info lib daemon client modules etc
6
install: lib-install daemon-install client-install modules-install etc-install
7
check: all tests
8 9
clean: contrib-clean lib-clean daemon-clean client-clean modules-clean \
	tests-clean doc-clean bench-clean
10
doc: doc-html
11
lint:
12 13 14 15 16 17 18 19 20 21 22 23 24
	luacheck --codes --formatter TAP .
coverage: $(wildcard */*/luacov.stats.out)
	@echo "# C coverage in gcov.c.info"
	@lcov --no-external --capture --directory . --output-file gcov.c.info > /dev/null
	@if [ ! -z "$^" ]; then \
		echo "# Lua coverage in luacov.stats.out and gcov.lua.info"; \
		cat $^ > luacov.stats.out; \
		./scripts/luacov_to_info.lua $^ > gcov.lua.info; \
		lcov --add-tracefile gcov.c.info --add-tracefile gcov.lua.info --output-file gcov.total.info; \
	else \
		lcov --add-tracefile gcov.c.info --output-file gcov.total.info; \
	fi

25
.PHONY: all install check clean doc info
26 27 28

# Options
ifdef COVERAGE
29
BUILD_CFLAGS += --coverage
30 31 32
endif

# Dependencies
33
KNOT_MINVER := 2.4.0
34 35 36
$(eval $(call find_lib,libknot,$(KNOT_MINVER),yes))
$(eval $(call find_lib,libdnssec,$(KNOT_MINVER),yes))
$(eval $(call find_lib,libzscanner,$(KNOT_MINVER),yes))
37
$(eval $(call find_lib,lmdb))
38 39
$(eval $(call find_lib,libuv,1.0,yes))
$(eval $(call find_lib,nettle,,yes))
40
$(eval $(call find_alt,lua,luajit))
41 42
$(eval $(call find_luapkg,ltn12))
$(eval $(call find_luapkg,ssl.https))
43
$(eval $(call find_lib,cmocka))
44 45
$(eval $(call find_bin,doxygen))
$(eval $(call find_bin,sphinx-build))
46
$(eval $(call find_pythonpkg,breathe))
47
$(eval $(call find_lib,libmemcached,1.0))
48
$(eval $(call find_lib,hiredis,,yes))
Grigorii Demidov's avatar
Grigorii Demidov committed
49
$(eval $(call find_lib,socket_wrapper))
50
$(eval $(call find_lib,libsystemd,227))
51
$(eval $(call find_lib,gnutls))
52
$(eval $(call find_lib,libedit))
53
$(eval $(call find_lib,libprotobuf-c,1))
vendemiat's avatar
vendemiat committed
54
$(eval $(call find_lib,libfstrm,0.2))
55
$(eval $(call find_bin,protoc-c))
56

57 58 59 60 61 62 63 64 65 66 67
# Lookup SONAME
$(eval $(call find_soname,libknot))
$(eval $(call find_soname,libzscanner))

ifeq ($(libknot_SONAME),)
  $(error "Unable to resolve libknot_SONAME, update find_soname in platform.mk")
endif
ifeq ($(libzscanner_SONAME),)
  $(error "Unable to resolve libzscanner_SONAME, update find_some in platform.mk")
endif

68 69 70 71 72 73 74 75
# Find Go version and platform
GO_VERSION := $(shell $(GO) version 2>/dev/null)
ifeq ($(GO_VERSION),)
        GO_VERSION := 0
else
        GO_PLATFORM := $(word 2,$(subst /, ,$(word 4,$(GO_VERSION))))
        GO_VERSION := $(subst .,,$(subst go,,$(word 3,$(GO_VERSION))))
endif
76 77
$(eval $(call find_ver,go,$(GO_VERSION),16))

78
# Check if Go is able to build shared libraries
79 80 81 82
ifeq ($(HAS_go),yes)
ifneq ($(GO_PLATFORM),$(filter $(GO_PLATFORM),amd64 386 arm arm64))
HAS_go := no
endif
83
else
84 85
$(eval $(call find_ver,go,$(GO_VERSION),15))
ifeq ($HAS_go,yes)
86
ifneq ($(GO_PLATFORM),$(filter $(GO_PLATFORM),arm amd64))
87
HAS_go := no
88
endif
89
endif
90
endif
91

vendemiat's avatar
vendemiat committed
92
# check for fstrm and protobuf for dnstap
93
ifeq ($(HAS_libfstrm)|$(HAS_libprotobuf-c)|$(HAS_protoc-c),yes|yes|yes)
vendemiat's avatar
vendemiat committed
94 95 96
ENABLE_DNSTAP := yes
endif

97 98
# Overview
info:
99
	$(info Target:     Knot DNS Resolver $(VERSION)-$(PLATFORM))
100
	$(info Compiler:   $(CC) $(BUILD_CFLAGS))
101 102 103
	$(info )
	$(info Variables)
	$(info ---------)
104 105 106
	$(info HARDENING:  $(HARDENING))
	$(info BUILDMODE:  $(BUILDMODE))
	$(info PREFIX:     $(PREFIX))
107
	$(info PREFIX:     $(PREFIX))
108
	$(info DESTDIR:    $(DESTDIR))
109
	$(info BINDIR:     $(BINDIR))
110
	$(info SBINDIR:    $(SBINDIR))
111
	$(info LIBDIR:     $(LIBDIR))
112
	$(info ETCDIR:     $(ETCDIR))
113 114 115
	$(info INCLUDEDIR: $(INCLUDEDIR))
	$(info MODULEDIR:  $(MODULEDIR))
	$(info )
116
	$(info Core Dependencies)
117 118
	$(info ------------)
	$(info [$(HAS_libknot)] libknot (lib))
119
	$(info [yes] $(if $(filter $(HAS_lmdb),yes),system,embedded) lmdb (lib))
120
	$(info [$(HAS_lua)] luajit (daemon))
121
	$(info [$(HAS_libuv)] libuv (daemon))
122
	$(info [$(HAS_gnutls)] libgnutls (daemon))
123 124 125 126
	$(info )
	$(info Optional)
	$(info --------)
	$(info [$(HAS_doxygen)] doxygen (doc))
127 128
	$(info [$(HAS_sphinx-build)] sphinx-build (doc))
	$(info [$(HAS_breathe)] python-breathe (doc))
129
	$(info [$(HAS_go)] go (modules/go, Go buildmode=c-shared support))
130 131 132
	$(info [$(HAS_libmemcached)] libmemcached (modules/memcached))
	$(info [$(HAS_hiredis)] hiredis (modules/redis))
	$(info [$(HAS_cmocka)] cmocka (tests/unit))
133
	$(info [$(HAS_libsystemd)] systemd (daemon))
134
	$(info [$(HAS_nettle)] nettle (modules/cookies))
135 136
	$(info [$(HAS_ltn12)] Lua socket ltn12 (trust anchor bootstrapping))
	$(info [$(HAS_ssl.https)] Lua ssl.https (trust anchor bootstrapping))
137
	$(info [$(HAS_libedit)] libedit (client))
vendemiat's avatar
vendemiat committed
138 139
	$(info [$(HAS_libfstrm)] libfstrm (modules/dnstap))
	$(info [$(HAS_libprotobuf-c)] libprotobuf-c (modules/dnstap))
140
	$(info [$(HAS_protoc-c)] proto-c (modules/dnstap))
141 142
	$(info )

143
# Verify required dependencies are met, as listed above
144
ifeq ($(HAS_libknot),no)
145
	$(error libknot >= $(KNOT_MINVER) required)
146 147
endif
ifeq ($(HAS_libzscanner),no)
148
	$(error libzscanner >= $(KNOT_MINVER) required)
149 150
endif
ifeq ($(HAS_libdnssec),no)
151
	$(error libdnssec >= $(KNOT_MINVER) required)
152
endif
153 154 155
ifeq ($(HAS_lua),no)
	$(error luajit required)
endif
156 157 158
ifeq ($(HAS_libuv),no)
	$(error libuv >= 1.0 required)
endif
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
ifeq ($(HAS_gnutls),no)
	$(error gnutls required)
endif


BUILD_CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(nettle_CFLAGS) $(cmocka_CFLAGS) $(lua_CFLAGS) $(libdnssec_CFLAGS) $(libsystemd_CFLAGS)
BUILD_CFLAGS += $(addprefix -I,$(wildcard contrib/ccan/*) contrib/murmurhash3)

# Work around luajit on OS X
ifeq ($(PLATFORM), Darwin)
ifneq (,$(findstring luajit, $(lua_LIBS)))
	lua_LIBS += -pagezero_size 10000 -image_base 100000000
endif
endif

# Check if it has libknot 2.3.0 and nettle to support DNS cookies
$(eval $(call find_alt,knot230,libknot,2.3))
ifeq ($(HAS_nettle)|$(HAS_knot230),yes|yes)
BUILD_CFLAGS += -DENABLE_COOKIES
ENABLE_COOKIES := yes
endif
180

181
# Installation directories
182
$(DESTDIR)$(MODULEDIR):
183
	$(INSTALL) -d $@
184
$(DESTDIR)$(ETCDIR):
185
	$(INSTALL) -m 0750 -d $@
186

187
# Sub-targets
188
include contrib/contrib.mk
189 190
include lib/lib.mk
include daemon/daemon.mk
191
include modules/modules.mk
192
include tests/tests.mk
193
include doc/doc.mk
194
include etc/etc.mk
195
include bench/bench.mk