Skip to content
Snippets Groups Projects
Commit 15f40145 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

Merge branch 'makefile'

parents 217e72e2 0e337de0
No related branches found
No related tags found
No related merge requests found
......@@ -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
language: c
os:
- linux
- osx
compiler:
- gcc
- clang
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}/.local/lib/pkgconfig"
- LD_LIBRARY_PATH="${HOME}/.local/lib"
- CFLAGS="${CFLAGS} -O0 -g -DNDEBUG"
- MAKEOPTS="-j2"
before_script:
- ./scripts/bootstrap-depends.sh ${HOME}/fakeroot
- pip install --user travis -r tests/pydnstest/requirements.txt
- pip install --user travis cpp-coveralls
- ./scripts/bootstrap-depends.sh ${HOME}/.local
- pip install --user travis -r tests/pydnstest/requirements.txt 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 ${MAKEOPTS} check COVERAGE=1 LDFLAGS="-L${HOME}/.local/lib"
- coveralls -i lib -x ".c" --gcov-options '\-lp'
sudo: false
cache:
directories:
- ${HOME}/fakeroot
- ${HOME}/.pip-cache
- .autom4te.cache
- ${HOME}/.local
- ${HOME}/.cache/pip
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})
Makefile 0 → 100644
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) $(libknot_LIBS) $(libuv_LIBS)
# Make binary
$(eval $(call make_bin,kresolved,daemon))
help.mk 0 → 100644
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
// ADD PREDEFINED MACROS HERE!
[General]
Makefile.am
README
configure.ac
daemon/Makefile.am
daemon/layer/query.c
daemon/layer/query.h
daemon/main.c
daemon/tcp.c
daemon/tcp.h
daemon/udp.c
daemon/udp.h
daemon/worker.c
daemon/worker.h
lib/Makefile.am
lib/cache.c
lib/cache.h
lib/context.c
lib/context.h
lib/defines.h
lib/layer.h
lib/layer/iterate.c
lib/layer/iterate.h
lib/layer/itercache.c
lib/layer/itercache.h
lib/layer/static.c
lib/layer/static.h
lib/layer/stats.c
lib/layer/stats.h
lib/resolve.c
lib/resolve.h
lib/rplan.c
lib/rplan.h
lib/utils.c
lib/utils.h
lib/zonecut.c
lib/zonecut.h
tests/Makefile.am
tests/mock_calls.c
tests/pydnstest/__init__.py
tests/pydnstest/scenario.py
tests/pydnstest/test.py
tests/pydnstest/testserver.py
tests/test.h
tests/test_cache.c
tests/test_context.c
tests/test_integration.c
tests/test_integration.py
tests/test_resolve.c
tests/test_rplan.c
.
include
lib/layer
lib
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
#!/bin/sh
#!/bin/bash
set -e
CMOCKA_TAG="cmocka-0.4.1"
PKG_CONFIG_PATH="${1}/lib/pkgconfig"
URCU_TAG="v0.8.6"
LIBUV_TAG="v1.3.0"
KNOT_TAG="master"
if [ -z ${1} ]; then
echo "$0 <fakeroot>"
exit 1
fi
install -d ${1}
# prepare build env
PREFIX=${1}; [ -z ${PREFIX} ] && PREFIX="${HOME}/.local"
PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
install -d ${PREFIX}/{lib,libexec,include,bin,sbin,man,share,etc,info,doc,var}
[ ! -d .depend ] && mkdir .depend; cd .depend
# lmdb
if [ ! -e ${1}/include/lmdb.h ]; then
if [ ! -e ${PREFIX}/include/lmdb.h ]; then
git clone https://gitorious.org/mdb/mdb.git || true
cd mdb/libraries/liblmdb
make
install -d ${1}/lib ${1}/include
install -t ${1}/lib liblmdb.so
install -t ${1}/include lmdb.h
install -d ${PREFIX}/man/man1
make ${MAKEOPTS} CC="${CC}" && make install DESTDIR=${PREFIX} prefix=
cd ../../..
fi
# liburcu
if [ ! -e ${1}/include/urcu.h ]; then
git clone git://git.urcu.so/userspace-rcu.git || true
if [ ! -e ${PREFIX}/include/urcu.h ]; then
git clone -b ${URCU_TAG} git://git.urcu.so/userspace-rcu.git || true
cd userspace-rcu
./bootstrap
./configure --prefix=${1}
make
make install
./configure --prefix=${PREFIX} --disable-dependency-tracking --disable-rpath
( make ${MAKEOPTS} ; make install ) || true
cd ..
fi
# libknot
if [ ! -e ${1}/include/libknot ]; then
git clone https://github.com/CZNIC-Labs/knot.git || true
if [ ! -e ${PREFIX}/include/libknot ]; then
git clone -b ${KNOT_TAG} https://github.com/CZNIC-Labs/knot.git || true
cd knot
git checkout resolver_improvements
autoreconf -i
./configure --prefix=${1}
make
make install
if [ $(uname) == "Darwin" ]; then # Workaround for crypto version check on OS X
export libcrypto_CFLAGS="-I /usr/local/opt/openssl/include"
export libcrypto_LIBS="-L/usr/local/opt/openssl/lib -lcrypto"
fi
./configure --prefix=${PREFIX} --disable-fastparser --disable-dependency-tracking
make ${MAKEOPTS} && make install
cd ..
fi
# cmocka
if [ ! -e ${1}/include/cmocka.h ]; then
wget http://git.cryptomilk.org/projects/cmocka.git/snapshot/${CMOCKA_TAG}.tar.gz
tar xvzf ${CMOCKA_TAG}.tar.gz
cd ${CMOCKA_TAG}
if [ ! -e ${PREFIX}/include/cmocka.h ]; then
git clone -b ${CMOCKA_TAG} git://git.cryptomilk.org/projects/cmocka.git
cd cmocka
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${1} ..
make
make install
cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} ..
make ${MAKEOPTS} && make install
cd ../..
fi
# libuv
if [ ! -e ${1}/include/uv.h ]; then
git clone https://github.com/libuv/libuv.git || true
if [ ! -e ${PREFIX}/include/uv.h ]; then
git clone -b ${LIBUV_TAG} https://github.com/libuv/libuv.git || true
cd libuv
sh autogen.sh
./configure --prefix=${1}
make
make install
./configure --prefix=${PREFIX} --disable-dependency-tracking
make ${MAKEOPTS} && make install
fi
#!/usr/bin/python -Es
# vim: et:sw=4:ts=4:sts=4
#
# Script regenerates project file list from the list of files tracked by Git.
#
SOURCES = [
# documentation
"README", "KNOWN_ISSUES",
"Doxyfile*", "Doxy.file.h", "doc/*.rst",
# build-system
"*.ac", "*.am",
# sources
"lib/*.c", "lib/*.h", "lib/layer/*.h", "lib/layer/*.c",
"tests/*.c", "tests/*.h", "tests/*.py",
"daemon/*.c", "daemon/*.h", "daemon/layer/*.c", "daemon/layer/*.h"
]
OUTPUT_FILE = "knot-resolver.files"
# ----------------------------------------------------------------------------
from subprocess import Popen, PIPE
import os
import sys
def run(command):
p = Popen(command, stdout=PIPE, stderr=PIPE)
(out, errout) = p.communicate()
if p.returncode != 0:
raise Exception("Command %s failed.", command)
return out
print >>sys.stderr, "Updating %s." % OUTPUT_FILE
git_root = run(["git", "rev-parse", "--show-toplevel"]).strip()
os.chdir(git_root)
command = ["git", "ls-files"] + SOURCES
files = run(command).splitlines()
with open(OUTPUT_FILE, "w") as output:
output.write("\n".join(sorted(files)))
output.write("\n")
*.pyc
tmp*
test_cache
test_context
test_resolve
test_rplan
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment