From: Marek VavruĊĦa Date: Wed, 9 Dec 2015 18:30:22 +0000 (+0100) Subject: contrib: compile to convenience static library X-Git-Tag: v1.0.0-beta3~42^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=374ed2caeb2182931072fa11444f5bbcf4e66964;p=thirdparty%2Fknot-resolver.git contrib: compile to convenience static library this is needed to make sure it always compiles with PIC --- diff --git a/Makefile b/Makefile index 3a69c9aab..93e16e43c 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include platform.mk all: info lib daemon modules install: lib-install daemon-install modules-install etc-install check: all tests -clean: lib-clean daemon-clean modules-clean tests-clean doc-clean +clean: contrib-clean lib-clean daemon-clean modules-clean tests-clean doc-clean doc: doc-html .PHONY: all install check clean doc info @@ -49,7 +49,9 @@ BUILD_CFLAGS += $(addprefix -I,$(wildcard contrib/ccan/*) contrib/murmurhash3) info: $(info Target: Knot DNS Resolver $(MAJOR).$(MINOR).$(PATCH)-$(PLATFORM)) $(info Compiler: $(CC) $(BUILD_CFLAGS)) - $(info Linker: $(LD) $(BUILD_LDFLAGS)) + $(info HARDENING: $(HARDENING)) + $(info BUILDMODE: $(BUILDMODE)) + $(info PREFIX: $(PREFIX)) $(info PREFIX: $(PREFIX)) $(info DESTDIR: $(DESTDIR)) $(info BINDIR: $(BINDIR)) @@ -72,7 +74,6 @@ info: $(info [$(HAS_libmemcached)] libmemcached (modules/memcached)) $(info [$(HAS_hiredis)] hiredis (modules/redis)) $(info [$(HAS_cmocka)] cmocka (tests/unit)) - $(info [$(HAS_socket_wrapper)] socket_wrapper (lib)) $(info ) # Installation directories @@ -82,6 +83,7 @@ $(DESTDIR)$(ETCDIR): $(INSTALL) -m 0750 -d $@ # Sub-targets +include contrib/contrib.mk include lib/lib.mk include daemon/daemon.mk include modules/modules.mk diff --git a/config.mk b/config.mk index 9c45b6a58..4a0719a54 100644 --- a/config.mk +++ b/config.mk @@ -2,6 +2,7 @@ MAJOR := 1 MINOR := 0 PATCH := 0-beta2 +HARDENING := yes # Paths PREFIX := /usr/local diff --git a/contrib/cleanup.h b/contrib/cleanup.h new file mode 100644 index 000000000..7dcd750b0 --- /dev/null +++ b/contrib/cleanup.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2015 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * Cleanup attributes. + * @cond internal + */ +#pragma once +#include +#include +#include + +#define auto_free __attribute__((cleanup(_cleanup_free))) +static inline void _cleanup_free(char **p) { + free(*p); +} +#define auto_close __attribute__((cleanup(_cleanup_close))) +static inline void _cleanup_close(int *p) { + if (*p > 0) close(*p); +} +#define auto_fclose __attribute__((cleanup(_cleanup_fclose))) +static inline void _cleanup_fclose(FILE **p) { + if (*p) fclose(*p); +} +/* @endcond */ \ No newline at end of file diff --git a/daemon/bindings.c b/daemon/bindings.c index 9c751146a..e97230c91 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -15,6 +15,7 @@ */ #include +#include #include #include "lib/cache.h" diff --git a/daemon/daemon.mk b/daemon/daemon.mk index 50a5c1b1f..b3ee60de9 100644 --- a/daemon/daemon.mk +++ b/daemon/daemon.mk @@ -1,7 +1,4 @@ -kresd_EMBED := \ - contrib/ccan/asprintf/asprintf.c kresd_SOURCES := \ - $(kresd_EMBED) \ daemon/io.c \ daemon/network.c \ daemon/engine.c \ @@ -9,6 +6,7 @@ kresd_SOURCES := \ daemon/bindings.c \ daemon/ffimodule.c \ daemon/main.c + kresd_DIST := daemon/lua/kres.lua daemon/lua/trust_anchors.lua # Embedded resources @@ -25,8 +23,8 @@ bindings-install: $(kresd_DIST) $(DESTDIR)$(MODULEDIR) $(INSTALL) -m 0644 $(kresd_DIST) $(DESTDIR)$(MODULEDIR) kresd_CFLAGS := -fPIE -kresd_DEPEND := $(libkres) -kresd_LIBS := $(libkres_TARGET) $(libknot_LIBS) $(libdnssec_LIBS) $(libuv_LIBS) $(lua_LIBS) +kresd_DEPEND := $(libkres) $(contrib) +kresd_LIBS := $(contrib_TARGET) $(libkres_TARGET) $(libknot_LIBS) $(libdnssec_LIBS) $(libuv_LIBS) $(lua_LIBS) # Make binary ifeq ($(HAS_lua)|$(HAS_libuv), yes|yes) diff --git a/daemon/engine.c b/daemon/engine.c index ac52ba059..2890c598f 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -14,6 +14,7 @@ along with this program. If not, see . */ +#include #include #include #include diff --git a/daemon/main.c b/daemon/main.c index ba653431e..f874a1f15 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -18,9 +18,10 @@ #include #include #include +#include +#include +#include -#include "contrib/ucw/mempool.h" -#include "contrib/ccan/asprintf/asprintf.h" #include "lib/defines.h" #include "lib/resolve.h" #include "lib/dnssec.h" diff --git a/lib/lib.mk b/lib/lib.mk index f068e23fd..d981e4f77 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -1,12 +1,4 @@ -ccan_EMBED := \ - contrib/ccan/ilog/ilog.c \ - contrib/ccan/isaac/isaac.c \ - contrib/ccan/json/json.c \ - contrib/ucw/mempool.c \ - contrib/murmurhash3/murmurhash3.c - libkres_SOURCES := \ - $(ccan_EMBED) \ lib/generic/map.c \ lib/layer/iterate.c \ lib/layer/validate.c \ @@ -47,9 +39,9 @@ libkres_HEADERS := \ lib/cache.h # Dependencies -libkres_DEPEND := +libkres_DEPEND := $(contrib) libkres_CFLAGS := -fvisibility=hidden -fPIC -libkres_LIBS := $(libknot_LIBS) $(libdnssec_LIBS) +libkres_LIBS := $(contrib_TARGET) $(libknot_LIBS) $(libdnssec_LIBS) libkres_TARGET := -L$(abspath lib) -lkres # Make library diff --git a/lib/module.c b/lib/module.c index 369be3aa2..cd075a8ee 100644 --- a/lib/module.c +++ b/lib/module.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include "lib/defines.h" #include "lib/utils.h" diff --git a/lib/utils.c b/lib/utils.c index d2715592a..22365787c 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -17,15 +17,15 @@ #include #include #include -#include #include #include #include +#include +#include #include #include #include -#include "ccan/isaac/isaac.h" #include "lib/defines.h" #include "lib/utils.h" #include "lib/generic/array.h" diff --git a/lib/utils.h b/lib/utils.h index a0f10bad8..a5b34dffc 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -23,18 +23,6 @@ #include "lib/generic/map.h" #include "lib/generic/array.h" -/* - * General-purpose attributes. - * @cond internal - */ -#define auto_free __attribute__((cleanup(_cleanup_free))) -extern void _cleanup_free(char **p); -#define auto_close __attribute__((cleanup(_cleanup_close))) -extern void _cleanup_close(int *p); -#define auto_fclose __attribute__((cleanup(_cleanup_fclose))) -extern void _cleanup_fclose(FILE **p); -/* @endcond */ - /* * Logging and debugging. */ diff --git a/modules/cachectl/cachectl.mk b/modules/cachectl/cachectl.mk index cb21be1bb..f39cfa60a 100644 --- a/modules/cachectl/cachectl.mk +++ b/modules/cachectl/cachectl.mk @@ -1,5 +1,5 @@ cachectl_CFLAGS := -fvisibility=hidden -fPIC cachectl_SOURCES := modules/cachectl/cachectl.c cachectl_DEPEND := $(libkres) -cachectl_LIBS := $(libkres_TARGET) $(libkres_LIBS) +cachectl_LIBS := $(contrib_TARGET) $(libkres_TARGET) $(libkres_LIBS) $(call make_c_module,cachectl) \ No newline at end of file diff --git a/modules/hints/hints.c b/modules/hints/hints.c index 776c8c6a1..03c13ce06 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "daemon/engine.h" #include "lib/zonecut.h" diff --git a/modules/hints/hints.mk b/modules/hints/hints.mk index 3573027f7..c7bb521be 100644 --- a/modules/hints/hints.mk +++ b/modules/hints/hints.mk @@ -1,5 +1,5 @@ hints_CFLAGS := -fvisibility=hidden -fPIC hints_SOURCES := modules/hints/hints.c hints_DEPEND := $(libkres) -hints_LIBS := $(libkres_TARGET) $(libkres_LIBS) +hints_LIBS := $(contrib_TARGET) $(libkres_TARGET) $(libkres_LIBS) $(call make_c_module,hints) \ No newline at end of file diff --git a/modules/kmemcached/kmemcached.mk b/modules/kmemcached/kmemcached.mk index 87462a707..148bd5952 100644 --- a/modules/kmemcached/kmemcached.mk +++ b/modules/kmemcached/kmemcached.mk @@ -1,4 +1,4 @@ -kmemcached_CFLAGS := -fvisibility=hidden +kmemcached_CFLAGS := -fvisibility=hidden -fPIC kmemcached_SOURCES := modules/kmemcached/kmemcached.c modules/kmemcached/namedb_memcached.c kmemcached_LIBS := $(libkres_TARGET) $(libkres_LIBS) $(libmemcached_LIBS) $(call make_c_module,kmemcached) diff --git a/modules/redis/redis.mk b/modules/redis/redis.mk index 765f231ae..2cb4463a7 100644 --- a/modules/redis/redis.mk +++ b/modules/redis/redis.mk @@ -1,4 +1,4 @@ -redis_CFLAGS := -fvisibility=hidden +redis_CFLAGS := -fvisibility=hidden -fPIC redis_SOURCES := modules/redis/redis.c modules/redis/namedb_redis.c redis_LIBS := $(libkres_TARGET) $(libkres_LIBS) $(hiredis_LIBS) $(libuv_LIBS) $(call make_c_module,redis) diff --git a/modules/stats/stats.c b/modules/stats/stats.c index 11c1c8a33..2b3e6219e 100644 --- a/modules/stats/stats.c +++ b/modules/stats/stats.c @@ -24,6 +24,7 @@ #include #include +#include #include "lib/layer/iterate.h" #include "lib/rplan.h" diff --git a/modules/stats/stats.mk b/modules/stats/stats.mk index b56c072a9..17e462472 100644 --- a/modules/stats/stats.mk +++ b/modules/stats/stats.mk @@ -1,5 +1,5 @@ stats_CFLAGS := -fvisibility=hidden -fPIC stats_SOURCES := modules/stats/stats.c -stats_DEPEND := $(libkres) -stats_LIBS := $(libkres_TARGET) $(libkres_LIBS) +stats_DEPEND := $(libkres) $(contrib) +stats_LIBS := $(contrib_TARGET) $(libkres_TARGET) $(libkres_LIBS) $(call make_c_module,stats)