Commit 5e0fa4ac authored by Marek Vavruša's avatar Marek Vavruša

build: got rid of PHONY dep rules, added lua(5.1,5.2,jit) as daemon dep

the build system now doesn't always relink targets
parent 00ff09a7
......@@ -17,11 +17,23 @@ endif
# Dependencies
$(eval $(call find_lib,libknot))
$(eval $(call find_lib,libuv))
$(eval $(call find_alt,lua,luajit))
$(eval $(call find_alt,lua,lua5.2))
$(eval $(call find_alt,lua,lua))
$(eval $(call find_lib,cmocka))
$(eval $(call find_bin,doxygen))
$(eval $(call find_bin,sphinx-build))
$(eval $(call find_bin,gccgo))
$(eval $(call find_python))
CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(cmocka_CFLAGS) $(python_CFLAGS)
# Work around luajit on OS X
ifeq ($(PLATFORM), Darwin)
ifneq (,$(findstring luajit, $(lua_LIBS)))
lua_LIBS += -pagezero_size 10000 -image_base 100000000
endif
endif
CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(cmocka_CFLAGS) $(python_CFLAGS) $(lua_CFLAGS)
# Sub-targets
include help.mk
......
......@@ -11,12 +11,11 @@ INCLUDEDIR := /include
MODULEDIR := $(LIBDIR)/kdns_modules
# Tools
ifndef CC
CC := cc
endif
CC ?= cc
CFLAGS += -std=c99 -D_GNU_SOURCE -Wall -fPIC -I$(abspath .)
CFLAGS += -DPACKAGE_VERSION="\"$(MAJOR).$(MINOR)\"" -DPREFIX="\"$(PREFIX)\"" -DMODULEDIR="\"$(MODULEDIR)\""
RM := rm -f
LN := ln -s
LN := ln -s
XXD ?= xxd
INSTALL := install
PYTHON := python
PYTHON := python
......@@ -7,13 +7,16 @@ kresolved_SOURCES := \
daemon/main.c
# Dependencies
kresolved_DEPEND := libkresolve libknot libuv
kresolved_LIBS := $(libkresolve_TARGET) $(libknot_LIBS) $(libuv_LIBS)
kresolved_DEPEND := $(libkresolve)
kresolved_LIBS := $(libkresolve_TARGET) $(libknot_LIBS) $(libuv_LIBS) $(lua_LIBS)
# Make binary
ifeq ($(HAS_lua)|$(HAS_libuv), yes|yes)
$(eval $(call make_bin,kresolved,daemon))
endif
# Targets
daemon: kresolved
daemon: $(kresolved)
daemon-install: kresolved-install
daemon-clean: kresolved-clean
.PHONY: daemon daemon-install daemon-clean
info:
$(info )
$(info Target: Knot DNS Resolver $(MAJOR).$(MINOR)-$(PLATFORM))
$(info Target: Knot DNS Resolver $(MAJOR).$(MINOR).$(PATCH)-$(PLATFORM))
$(info Compiler: $(CC) $(CFLAGS))
$(info Linker: $(LD) $(LDFLAGS))
$(info PREFIX: $(PREFIX))
......@@ -9,12 +9,13 @@ info:
$(info INCLUDEDIR: $(INCLUDEDIR))
$(info MODULEDIR: $(MODULEDIR))
$(info )
$(info Features)
$(info --------)
$(info [$(HAS_doxygen)] API documentation (doxygen))
$(info [$(HAS_libknot)] library (libknot))
$(info [$(HAS_libuv)] daemon (libuv))
$(info [$(HAS_cmocka)] unit tests (libcmocka))
$(info [$(HAS_python)] integration tests (libpython))
$(info [$(HAS_gccgo)] golang modules (gccgo))
$(info Dependencies)
$(info ------------)
$(info [$(HAS_doxygen)] doxygen (doc))
$(info [$(HAS_libknot)] libknot (lib))
$(info [$(HAS_lua)] lua (daemon))
$(info [$(HAS_libuv)] libuv (daemon))
$(info [$(HAS_cmocka)] cmocka (tests/unit))
$(info [$(HAS_python)] Python (tests/integration))
$(info [$(HAS_gccgo)] GCCGO (modules/go))
$(info )
......@@ -22,7 +22,7 @@ libkresolve_HEADERS := \
lib/cache.h
# Dependencies
libkresolve_DEPEND := libknot
libkresolve_DEPEND :=
libkresolve_LIBS := $(libknot_LIBS)
libkresolve_TARGET := -Wl,-rpath,lib -Llib -lkresolve
......@@ -30,6 +30,8 @@ libkresolve_TARGET := -Wl,-rpath,lib -Llib -lkresolve
$(eval $(call make_lib,libkresolve,lib))
# Targets
lib: libkresolve
lib: $(libkresolve)
lib-install: libkresolve-install
lib-clean: libkresolve-clean
.PHONY: lib lib-install lib-clean
cachectl_SOURCES := modules/cachectl/cachectl.c
cachectl_DEPEND := libkresolve
cachectl_DEPEND := $(libkresolve)
cachectl_LIBS := $(libkresolve_TARGET) $(libkresolve_LIBS)
$(call make_c_module,cachectl)
\ No newline at end of file
gostats_SOURCES := modules/gostats/gostats.go
gostats_DEPEND := libkresolve
gostats_DEPEND := $(libkresolve)
gostats_LIBS := $(libkresolve_TARGET) $(libkresolve_LIBS)
$(call make_go_module,gostats)
\ No newline at end of file
hints_SOURCES := modules/hints/hints.c
hints_DEPEND := libkresolve
hints_DEPEND := $(libkresolve)
hints_LIBS := $(libkresolve_TARGET) $(libkresolve_LIBS)
$(call make_c_module,hints)
\ No newline at end of file
......@@ -3,7 +3,6 @@ modules_TARGETS := hints \
cachectl
# List of Golang modules
$(eval $(call find_bin,gccgo))
ifeq ($(HAS_gccgo),yes)
modules_TARGETS += gostats
endif
......@@ -13,33 +12,38 @@ define make_c_module
$(eval $(call make_module,$(1),modules/$(1)))
endef
# Make Go module
define make_go_module
$(eval $(call go_target,$(1),modules/$(1)))
endef
# Go target definition
define go_target
$(1)_OBJS := $(addprefix $(2)/_obj/,_cgo_defun.o _cgo_export.o $(subst /,_,$(2))_$(1).cgo2.o)
define go_target
$(1) := $(2)/$(1)$(LIBEXT)
$(1)_OBJS := $(addprefix $(2)/_obj/,_cgo_defun.c _cgo_export.c $(subst /,_,$(2))_$(1).cgo2.c)
$(1)_GOBJS := $(addprefix $(2)/_obj/,_cgo_gotypes.go $(subst /,_,$(2))_$(1).cgo1.go)
$(2)/_obj/_cgo_export.h: $$($(1)_SOURCES)
@$(INSTALL) -d $(2)/_obj
$(call quiet,CGO,$$^) -gccgo=true -objdir=$(2)/_obj -- $(CFLAGS) $$^
$(2)/$(1).o: $(2)/_obj/_cgo_export.h $$($(1)_GOBJS)
$(2)/$(1).o: $(2)/_obj/_cgo_export.h
$(call quiet,GCCGO,$$@) -I$(2)/_obj -c -fPIC $$($(1)_GOBJS) -o $$@
$(2)/$(1)$(LIBEXT): $(2)/_obj/_cgo_export.h $(2)/$(1).o $$($(1)_OBJS) $$($(1)_DEPEND)
$(call quiet,GCCGO,$$@) -g -fPIC -I$(2)/_obj $(2)/$(1).o $$($(1)_OBJS) -o $$@ -$(LIBTYPE) -lgcc -lgo $$($(1)_LIBS)
$(1): $(2)/_obj/_cgo_export.h $(2)/$(1)$(LIBEXT)
$(2)/$(1)$(LIBEXT): $(2)/$(1).o $$($(1)_DEPEND)
$(call quiet,GCCGO,$$@) -g -fPIC $(CFLAGS) -I$(2)/_obj $(2)/$(1).o $$($(1)_OBJS) -o $$@ -$(LIBTYPE) -lgcc -lgo $$($(1)_LIBS)
$(1)-clean:
$(RM) -r $(2)/_obj $(2)/$(1)$(LIBEXT)
$(1)-install: $(2)/$(1)$(LIBEXT)
$(INSTALL) -d $(PREFIX)/$(MODULEDIR)
$(INSTALL) $$^ $(PREFIX)/$(MODULEDIR)
.PHONY: $(1) $(1)-clean $(1)-install
.PHONY: $(1)-clean $(1)-install
endef
# Make Go module
define make_go_module
$(eval $(call go_target,$(1),modules/$(1)))
endef
# Include modules
$(foreach module,$(modules_TARGETS),$(eval include modules/$(module)/$(module).mk))
$(eval modules = $(foreach module,$(modules_TARGETS),$$($(module))))
# Build rules
modules: $(modules_TARGETS)
# Targets
modules: $(modules)
modules-clean: $(addsuffix -clean,$(modules_TARGETS))
modules-install: $(addsuffix -install,$(modules_TARGETS))
$(foreach module,$(modules_TARGETS),$(eval include modules/$(module)/$(module).mk))
.PHONY: modules modules-clean modules-install
......@@ -21,8 +21,8 @@ else
LIBEXT := .dylib
MODTYPE := dynamiclib
else
PLATFORM := POSIX
LDFLAGS += -pthread
PLATFORM := POSIX
LDFLAGS += -pthread
endif
endif
......@@ -46,7 +46,7 @@ endef
# Make target (name,path,ext,ldflags,dst)
define make_target
$$(eval $$(call make_objs,$(1)))
$(1): $(2)/$(1)$(3)
$(1) := $(2)/$(1)$(3)
$(2)/$(1)$(3): $$($(1)_OBJ) $$($(1)_DEPEND)
$(call quiet,CCLD,$$@) $(CFLAGS) $$($(1)_OBJ) -o $$@ $(4) $(LDFLAGS) $$($(1)_LIBS)
$(1)-clean:
......@@ -58,7 +58,7 @@ ifneq ($$(strip $$($(1)_HEADERS)),)
$(INSTALL) -d $(PREFIX)/$(INCLUDEDIR)/$(1)
$(INSTALL) $$($(1)_HEADERS) $(PREFIX)/$(INCLUDEDIR)/$(1)
endif
.PHONY: $(1) $(1)-clean $(1)-install
.PHONY: $(1)-clean $(1)-install
endef
# Make targets (name,path)
......@@ -73,20 +73,27 @@ ifeq ($$(strip $$($(1)_LIBS)),)
HAS_$(1) := no
else
HAS_$(1) := yes
$(1):
.PHONY: $(1)
endif
endef
# Find library (pkg-config)
define find_lib
ifeq ($$(strip $$($(1)_LIBS)),)
$(1)_CFLAGS := $(shell pkg-config --cflags $(1))
$(1)_CFLAGS := $(shell pkg-config --cflags $(1) --silence-errors)
$(1)_LIBS := $(shell pkg-config --libs $(1) --silence-errors)
endif
$(call have_lib,$(1))
endef
# Find library alternative (pkg-config)
define find_alt
ifeq ($$(strip $$($(1)_LIBS)),)
$(1)_CFLAGS := $(shell pkg-config --cflags $(2) --silence-errors)
$(1)_LIBS := $(shell pkg-config --libs $(2) --silence-errors)
$(call have_lib,$(1))
endif
endef
# Find binary
define find_bin
ifeq ($$(strip $$($(1)_BIN)),)
......
#
# Integration tests
#
# Mocked calls library
libmock_calls_SOURCES := tests/mock_calls.c
libmock_calls_LIBS := $(tests_LIBS) $(python_LIBS)
libmock_calls_DEPEND := $(libkresolve)
$(eval $(call make_lib,libmock_calls,tests))
# Python module for tests
_test_integration_SOURCES := tests/test_integration.c
_test_integration_LIBS := -Ltests -lmock_calls $(libmock_calls_LIBS)
_test_integration_DEPEND := $(libmock_calls)
$(eval $(call make_shared,_test_integration,tests))
# Targets
check-integration: $(libmock_calls) $(_test_integration)
$(call preload_LIBS) tests/test_integration.py tests/testdata
.PHONY: check-integration
#
# Unit tests
#
tests_BIN := \
test_generics \
test_utils \
test_module \
test_rplan \
test_cache \
test_resolve
mock_cmodule_SOURCES := tests/mock_cmodule.c
$(eval $(call make_lib,mock_cmodule,tests))
mock_gomodule_SOURCES := tests/mock_gomodule.c
$(eval $(call make_lib,mock_gomodule,tests))
# Dependencies
tests_DEPEND := $(libkresolve) $(mock_cmodule) $(mock_gomodule)
tests_LIBS := $(libkresolve_TARGET) $(libkresolve_LIBS) $(cmocka_LIBS)
# Make test binaries
define make_test
$(1)_SOURCES := tests/$(1).c
$(1)_LIBS := $(tests_LIBS)
$(1)_DEPEND := $(tests_DEPEND)
$(call make_bin,$(1),tests)
$(1)-run: $$($(1))
$(call preload_LIBS) $$<
.PHONY: $(1)-run
endef
# Targets
$(foreach test,$(tests_BIN),$(eval $(call make_test,$(test))))
check-unit: $(foreach test,$(tests_BIN),$(test)-run)
.PHONY: check-unit
#
# Unit tests
#
tests_BIN := \
test_utils \
test_module \
test_context \
test_rplan \
test_cache \
test_resolve
# Mock modules
mock_cmodule_SOURCES := tests/mock_cmodule.c
$(eval $(call make_lib,mock_cmodule,tests))
mock_gomodule_SOURCES := tests/mock_gomodule.c
$(eval $(call make_lib,mock_gomodule,tests))
# Dependencies
tests_DEPEND := libkresolve cmocka mock_cmodule mock_gomodule
tests_LIBS := $(libkresolve_TARGET) $(libkresolve_LIBS) $(cmocka_LIBS)
# Preload mock library
# Preload libraries
preload_PATH := tests
ifeq ($(PLATFORM),Darwin)
preload_LIBS := @DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_LIBRARY_PATH="$(preload_PATH):${DYLD_LIBRARY_PATH}"
......@@ -28,38 +6,17 @@ else
preload_LIBS := @LD_LIBRARY_PATH="$(preload_PATH):${LD_LIBRARY_PATH}"
endif
# Make test binaries
define make_test
$(1)_SOURCES := tests/$(1).c
$(1)_LIBS := $(tests_LIBS)
$(1)_DEPEND := $(tests_DEPEND)
$(call make_bin,$(1),tests)
$(1)-run: $(1)
$(call preload_LIBS) tests/$$<
endef
$(foreach test,$(tests_BIN),$(eval $(call make_test,$(test))))
#
# Unit tests
ifeq ($(HAS_cmocka), yes)
include tests.unit.mk
# Integration tests
#
# Mocked calls library
libmock_calls_SOURCES := tests/mock_calls.c
libmock_calls_LIBS := $(tests_LIBS) $(python_LIBS)
libmock_calls_DEPEND := libkresolve
$(eval $(call make_lib,libmock_calls,tests))
# Python module for tests
_test_integration_SOURCES := tests/test_integration.c
_test_integration_LIBS := -Ltests -lmock_calls $(libmock_calls_LIBS)
_test_integration_DEPEND := libmock_calls
$(eval $(call make_shared,_test_integration,tests))
ifeq ($(HAS_python), yes)
include tests.integration.mk
endif # HAS_python
endif # HAS_cmocka
# Targets
.PHONY: check-integration check-unit tests tests-clean
check-integration: libmock_calls _test_integration
$(call preload_LIBS) tests/test_integration.py tests/testdata
check-unit: $(foreach test,$(tests_BIN),$(test)-run)
tests: check-unit check-integration
tests-clean: $(foreach test,$(tests_BIN),$(test)-clean) libmock_calls-clean _test_integration-clean
.PHONY: tests tests-clean
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment