Commit e69d6114 authored by Marek Vavruša's avatar Marek Vavruša

build: Makefile

parent 217e72e2
......@@ -2,28 +2,26 @@
*.a
*.so
*.so.*
*.dylib
*.dylib.*
*.lo
*.la
*.in
*.Plo
*.swp
*.d
.dirstamp
.libs
.deps
autom4te.cache/*
config.*
config.log
config.h
config.status
configure
ar-lib
Makefile
libtool
missing
compile
depcomp
install-sh
stamp-h1
# CMake files
/CMakeCache.txt
/CMakeFiles
/Makefile
/cmake_install.cmake
......@@ -3,26 +3,20 @@ compiler:
- gcc
env:
global:
- PKG_CONFIG_PATH="${HOME}/fakeroot/lib/pkgconfig"
- LDFLAGS="-L${HOME}/fakeroot/lib"
- PIP_DOWNLOAD_CACHE="${HOME}/.pip-cache"
- CFLAGS="${CFLAGS} -DNDEBUG"
- PATH="${PATH}:${HOME}/.local/bin"
- PKG_CONFIG_PATH="${HOME}/fakeroot/lib/pkgconfig"
- LD_LIBRARY_PATH="${HOME}/fakeroot/lib"
- CFLAGS="${CFLAGS} -O0 -g -DNDEBUG"
before_script:
- ./scripts/bootstrap-depends.sh ${HOME}/fakeroot
- pip install --user travis -r tests/pydnstest/requirements.txt
- pip install --user travis cpp-coveralls
script:
- ./bootstrap
- ./configure --enable-integration-tests --enable-code-coverage
- make
- make check
after_script:
- cd lib
- coveralls -x ".c" --gcov-options '\-lp'
- make check COVERAGE=1 LDFLAGS="-L${HOME}/fakeroot/lib"
- coveralls -i lib -x ".c" --gcov-options '\-lp'
sudo: false
cache:
directories:
- ${HOME}/fakeroot
- ${HOME}/.pip-cache
- .autom4te.cache
cmake_minimum_required(VERSION 2.8)
project(resolver C)
set(RESOLVER_VERSION 0.0.1)
set(LIBS_VERSION 0.0.1)
# Compiler flags
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type specified, setting to 'Release'.")
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -g")
set(CMAKE_C_FLAGS_DEBUG "-O0")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
# Modules compilation
include_directories(include)
set(resolver_sources
lib/context.c
lib/info.c
)
add_library(resolver SHARED ${resolver_sources})
set_target_properties(resolver PROPERTIES VERSION ${LIBS_VERSION})
include config.mk
include platform.mk
# Targets
all: info libkresolve kresolved
install: libkresolve-install kresolved-install
check: all tests-check
clean: libkresolve-clean kresolved-clean tests-clean
.PHONY: all install check clean
# Options
ifdef COVERAGE
CFLAGS += --coverage
endif
# Dependencies
$(eval $(call find_lib,libknot))
$(eval $(call find_lib,libuv))
$(eval $(call find_lib,cmocka))
$(eval $(call find_python))
CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(cmocka_CFLAGS) $(python_CFLAGS)
# Sub-targets
include help.mk
include lib/libkresolve.mk
include daemon/kresolved.mk
include tests/tests.mk
\ No newline at end of file
# Project
MAJOR := 15
MINOR := 04
# Paths
PREFIX := /usr/local
BINDIR := /bin
LIBDIR := /lib
INCLUDEDIR = /include
# Tools
ifndef CC
CC := cc
endif
CFLAGS += -std=c99 -D_GNU_SOURCE -Wall -fPIC -I$(abspath .) -DPACKAGE_VERSION="\"$(MAJOR).$(MINOR)\""
RM := rm -f
LN := ln -s
INSTALL := install
PYTHON := python
\ No newline at end of file
kresolved_SOURCES := \
daemon/layer/query.c \
daemon/udp.c \
daemon/tcp.c \
daemon/worker.c \
daemon/main.c
# Dependencies
kresolved_DEPEND := libkresolve libknot libuv
kresolved_LIBS := $(libkresolve_TARGET) $(libuv_LIBS) $(libknot_LIBS)
# Make binary
$(eval $(call make_bin,kresolved,daemon))
\ No newline at end of file
info:
$(info )
$(info Target: Knot DNS Resolver $(MAJOR).$(MINOR)-$(PLATFORM))
$(info Compiler: $(CC))
$(info CFLAGS: $(CFLAGS))
$(info LDFLAGS: $(LDFLAGS))
$(info PREFIX: $(PREFIX))
$(info BINDIR: $(BINDIR))
$(info LIBDIR: $(LIBDIR))
$(info INCLUDEDIR: $(INCLUDEDIR))
$(info )
$(info Features)
$(info --------)
$(info [$(HAS_libknot)] library (libknot))
$(info [$(HAS_libuv)] daemon (libuv))
$(info [$(HAS_cmocka)] unit tests (libcmocka))
$(info [$(HAS_python)] integration tests (libpython))
$(info )
\ No newline at end of file
libkresolve_SOURCES := \
lib/layer/iterate.c \
lib/layer/itercache.c \
lib/layer/static.c \
lib/layer/stats.c \
lib/context.c \
lib/resolve.c \
lib/zonecut.c \
lib/rplan.c \
lib/cache.c
libkresolve_HEADERS := \
lib/layer/iterate.h \
lib/layer/itercache.h \
lib/layer/static.h \
lib/layer/stats.h \
lib/layer.h \
lib/context.h \
lib/resolve.h \
lib/zonecut.h \
lib/rplan.h \
lib/cache.h
# Dependencies
libkresolve_DEPEND := libknot
libkresolve_LIBS := $(libknot_LIBS)
libkresolve_TARGET := -Wl,-rpath,lib -Llib -lkresolve
# Make library
$(eval $(call make_lib,libkresolve,lib))
\ No newline at end of file
......@@ -14,8 +14,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/time.h>
#include <libknot/descriptor.h>
#include <libknot/processing/layer.h>
#include <libknot/errcode.h>
......
......@@ -16,6 +16,8 @@
#pragma once
#include <sys/time.h>
#include <libknot/dname.h>
#include <libknot/internal/lists.h>
#include <libknot/internal/namedb/namedb.h>
......
# Platform-specific
CCLD := $(CC)
LIBEXT := .so
MODEXT := $(LIBEXT)
LIBTYPE := shared
MODTYPE := shared
BINEXT :=
PLATFORM = Linux
ifeq ($(OS),Windows_NT)
PLATFORM := Windows
RM := del
LN := link
LIBEXT := .lib
BINEXT := .exe
else
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
PLATFORM := Darwin
LIBEXT := .dylib
MODTYPE := dynamiclib
else
PLATFORM := POSIX
LDFLAGS += -pthread
endif
endif
# Silent compilation
ifeq ($(V),1)
quiet = $($1)
else
quiet = @echo " $1 $2"; $($1)
endif
%.o: %.c
$(call quiet,CC,$<) $(CFLAGS) -MMD -MP -c $< -o $@
# Make objects and depends (name)
define make_objs
$(1)_OBJ := $$($(1)_SOURCES:.c=.o)
$(1)_DEP := $$($(1)_SOURCES:.c=.d)
-include $$($(1)_DEP)
endef
# Make target (name,path,ext,ldflags,dst)
define make_target
$$(eval $$(call make_objs,$(1)))
$(1): $(2)/$(1)$(3)
$(2)/$(1)$(3): $$($(1)_OBJ) $$($(1)_DEPEND)
$(call quiet,CCLD,$$@) $(CFLAGS) $$($(1)_OBJ) -o $$@ $(4) $(LDFLAGS) $$($(1)_LIBS)
$(1)-clean:
$(RM) $$($(1)_OBJ) $$($(1)_DEP) $(2)/$(1)$(3)
$(1)-install: $(2)/$(1)$(3)
$(INSTALL) $$^ $(PREFIX)/$(5)
ifneq ($$(strip $$($(1)_HEADERS)),)
$(INSTALL) -d $(PREFIX)/$(INCLUDEDIR)/$(1)
$(INSTALL) $$($(1)_HEADERS) $(PREFIX)/$(INCLUDEDIR)/$(1)
endif
.PHONY: $(1) $(1)-clean $(1)-install
endef
# Make targets (name,path)
make_bin = $(call make_target,$(1),$(2),$(BINEXT),,$(BINDIR))
make_lib = $(call make_target,$(1),$(2),$(LIBEXT),-$(LIBTYPE),$(LIBDIR))
make_module = $(call make_target,$(1),$(2),$(MODEXT),-$(MODTYPE),$(LIBDIR))
# Evaluate library
define have_lib
ifeq ($$(strip $$($(1)_LIBS)),)
HAS_$(1) := no
else
HAS_$(1) := yes
$(1):
endif
endef
# Find library (pkg-config)
define find_lib
ifeq ($$(strip $$($(1)_LIBS)),)
$(1)_CFLAGS := $(shell pkg-config --cflags $(1))
$(1)_LIBS := $(shell pkg-config --libs $(1) --silence-errors)
endif
$(call have_lib,$(1))
endef
# Find Python
define find_python
python_CFLAGS := $(shell $(PYTHON) -c "from distutils import sysconfig as c;print('-I%s' % c.get_python_inc())")
python_LIBS := $(shell $(PYTHON) -c "from distutils import sysconfig as c;print('-L%s -lpython%s' % (c.get_config_var('LIBDIR'), c.get_config_var('VERSION')))")
$(call have_lib,python)
endef
\ No newline at end of file
......@@ -37,7 +37,6 @@ fi
if [ ! -e ${1}/include/libknot ]; then
git clone https://github.com/CZNIC-Labs/knot.git || true
cd knot
git checkout resolver_improvements
autoreconf -i
./configure --prefix=${1}
make
......@@ -60,7 +59,7 @@ fi
# libuv
if [ ! -e ${1}/include/uv.h ]; then
git clone https://github.com/libuv/libuv.git || true
git clone -b v1.3.0 https://github.com/libuv/libuv.git || true
cd libuv
sh autogen.sh
./configure --prefix=${1}
......
......@@ -65,7 +65,7 @@ static PyObject* init(PyObject* self, PyObject* args)
global_context.options |= QUERY_NO_MINIMIZE;
}
return Py_BuildValue("s", PACKAGE_STRING " (integration tests)");
return Py_BuildValue("");
}
static PyObject* deinit(PyObject* self, PyObject* args)
......
#
# Unit tests
#
tests_BIN := \
test_context \
test_rplan \
test_cache \
test_resolve
# Dependencies
tests_DEPEND := libkresolve cmocka
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)
endef
$(foreach test,$(tests_BIN),$(eval $(call make_test,$(test))))
#
# 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 := -Wl,-rpath,tests -Ltests -lmock_calls $(libmock_calls_LIBS)
_test_integration_DEPEND := libmock_calls
$(eval $(call make_module,_test_integration,tests))
# Preload mock library
ifeq ($(PLATFORM),Darwin)
preload_libs := @DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=tests/libmock_calls$(LIBEXT)
else
preload_libs := @LD_PRELOAD=tests/libmock_calls$(LIBEXT)
endif
# Targets
.PHONY: tests-check-integration tests-check-unit tests-check tests-clean
tests-check-integration: libmock_calls _test_integration
$(call preload_libs) tests/test_integration.py tests/testdata
tests-check-unit: $(tests_BIN)
tests/runtests -b tests $^
tests-check: tests-check-unit tests-check-integration
tests-clean: $(foreach test,$(tests_BIN),$(test)-clean) libmock_calls-clean _test_integration-clean
\ No newline at end of file
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