]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
build: allow library to be built statically
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 7 Jun 2015 20:15:57 +0000 (22:15 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 7 Jun 2015 20:15:57 +0000 (22:15 +0200)
config.mk
lib/layer/iterate.h
lib/layer/rrcache.h [deleted file]
lib/lib.mk
lib/module.c
platform.mk

index 17ec10a4f7ee68184c0900effad0ca2a6f4d9b06..763ce785e2eae260d3c10e4ec42238cc790d37c2 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -12,7 +12,7 @@ MODULEDIR := $(LIBDIR)/kdns_modules
 
 # Tools
 CC     ?= cc
-CFLAGS += -std=c99 -D_GNU_SOURCE -Wall -fPIC -I$(abspath .) -I$(abspath lib/generic) -I$(abspath contrib)
+CFLAGS += -std=c99 -D_GNU_SOURCE -Wall -I$(abspath .) -I$(abspath lib/generic) -I$(abspath contrib)
 CFLAGS  += -DPACKAGE_VERSION="\"$(MAJOR).$(MINOR)\"" -DPREFIX="\"$(PREFIX)\"" -DMODULEDIR="\"$(MODULEDIR)\""
 RM     := rm -f
 LN      := ln -s
index 245c37a589b23aeb5c1ce9127c27dbb0c15827ae..44831b2ca7d1dbe13f1d6dad8413d819ebbb37a9 100644 (file)
@@ -33,6 +33,3 @@ int kr_response_classify(knot_pkt_t *pkt);
 
 /** Make next iterative query. */
 int kr_make_query(struct kr_query *query, knot_pkt_t *pkt);
-
-/* Processing module implementation. */
-const knot_layer_api_t *iterate_layer(struct kr_module *module);
diff --git a/lib/layer/rrcache.h b/lib/layer/rrcache.h
deleted file mode 100644 (file)
index 305adda..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*  Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
-
-    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 <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "lib/layer.h"
-
-/* Processing module implementation. */
-const knot_layer_api_t *rrcache_layer(struct kr_module *module);
index 323a8a1ecfd121cadfce17e359a2f834b90670c4..52445f3ed0a27592e18c4261d81508852c492753 100644 (file)
@@ -36,7 +36,7 @@ libkresolve_LIBS := $(libknot_LIBS)
 libkresolve_TARGET := -Wl,-rpath,lib -Llib -lkresolve
 
 # Make library
-$(eval $(call make_lib,libkresolve,lib))
+$(eval $(call make_static,libkresolve,lib))
 
 # Targets
 lib: $(libkresolve)
index 9464a46bb676ecf8e21b607dfede3e81976e6a8e..be472216855404bd308f25ee30f2aa88b2b1ee64 100644 (file)
 #include "lib/utils.h"
 #include "lib/module.h"
 
+/* List of embedded modules */
+const knot_layer_api_t *iterate_layer(struct kr_module *module);
+const knot_layer_api_t *rrcache_layer(struct kr_module *module);
+const knot_layer_api_t *pktcache_layer(struct kr_module *module);
+static const struct kr_module embedded_modules[] = {
+       { "iterate",  NULL, NULL, NULL, iterate_layer, NULL, NULL, NULL },
+       { "rrcache",  NULL, NULL, NULL, rrcache_layer, NULL, NULL, NULL },
+       { "pktcache", NULL, NULL, NULL, pktcache_layer, NULL, NULL, NULL },
+};
+
 /** Library extension. */
 #if defined(__APPLE__)
  #define LIBEXT ".dylib"
 #elif _WIN32
- #define LIBEXT ".lib"
+ #define LIBEXT ".dll"
 #else
  #define LIBEXT ".so"
 #endif
@@ -90,6 +100,18 @@ static int load_library(struct kr_module *module, const char *name, const char *
 /** Load C module symbols. */
 static int load_sym_c(struct kr_module *module, uint32_t api_required)
 {
+       /* Check if it's embedded first */
+       for (unsigned i = 0; i < sizeof(embedded_modules)/sizeof(embedded_modules[0]); ++i) {
+               const struct kr_module *embedded = &embedded_modules[i];
+               if (strcmp(module->name, embedded->name) == 0) {
+                       module->init = embedded->init;
+                       module->deinit = embedded->deinit;
+                       module->config = embedded->config;
+                       module->layer = embedded->layer;
+                       return kr_ok();
+               }
+       }
+       /* Load dynamic library module */
        auto_free char *module_prefix = kr_strcatdup(2, module->name, "_");
        ABI_CHECK(module, module_prefix, "api", api_required);
        ABI_LOAD(module, module_prefix, "init", "deinit", "config", "layer", "props");
index 50147cbb97b2189d82348d94db6ff854449523c1..edb3624dcb5b7acedd1d0aa8fa27d845c531c807 100644 (file)
@@ -4,8 +4,10 @@ CGO := go tool cgo
 GCCGO := gccgo
 LIBEXT := .so
 MODEXT := $(LIBEXT)
+AREXT  := .a
 LIBTYPE := shared
 MODTYPE := shared
+ARTYPE  := static
 BINEXT :=
 PLATFORM = Linux
 ifeq ($(OS),Windows_NT)
@@ -51,7 +53,11 @@ define make_target
 $$(eval $$(call make_objs,$(1)))
 $(1) := $(2)/$(1)$(3)
 $(2)/$(1)$(3): $$($(1)_OBJ) $$($(1)_DEPEND)
+ifeq ($(4),-$(ARTYPE))
+       $(call quiet,AR,$$@) rcs $$@ $$($(1)_OBJ)
+else
        $(call quiet,CCLD,$$@) $(CFLAGS) $$($(1)_OBJ) -o $$@ $(4) $(LDFLAGS) $$($(1)_LIBS)
+endif
 $(1)-clean:
        $(RM) $$($(1)_OBJ) $$($(1)_DEP) $(2)/$(1)$(3)
 $(1)-install: $(2)/$(1)$(3)
@@ -69,6 +75,7 @@ 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),$(LIBEXT),-$(LIBTYPE),$(MODULEDIR))
 make_shared = $(call make_target,$(1),$(2),$(MODEXT),-$(MODTYPE),$(LIBDIR))
+make_static = $(call make_target,$(1),$(2),$(AREXT),-$(ARTYPE),$(LIBDIR))
 
 # Evaluate library
 define have_lib