From 16b6dab1348ad62c6db39634c69679a8fcc5cb17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavru=C5=A1a?= Date: Sun, 7 Jun 2015 22:15:57 +0200 Subject: [PATCH] build: allow library to be built statically --- config.mk | 2 +- lib/layer/iterate.h | 3 --- lib/layer/rrcache.h | 22 ---------------------- lib/lib.mk | 2 +- lib/module.c | 24 +++++++++++++++++++++++- platform.mk | 7 +++++++ 6 files changed, 32 insertions(+), 28 deletions(-) delete mode 100644 lib/layer/rrcache.h diff --git a/config.mk b/config.mk index 17ec10a4f..763ce785e 100644 --- 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 diff --git a/lib/layer/iterate.h b/lib/layer/iterate.h index 245c37a58..44831b2ca 100644 --- a/lib/layer/iterate.h +++ b/lib/layer/iterate.h @@ -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 index 305addaff..000000000 --- a/lib/layer/rrcache.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2014 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 . - */ - -#pragma once - -#include "lib/layer.h" - -/* Processing module implementation. */ -const knot_layer_api_t *rrcache_layer(struct kr_module *module); diff --git a/lib/lib.mk b/lib/lib.mk index 323a8a1ec..52445f3ed 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -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) diff --git a/lib/module.c b/lib/module.c index 9464a46bb..be4722168 100644 --- a/lib/module.c +++ b/lib/module.c @@ -23,11 +23,21 @@ #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"); diff --git a/platform.mk b/platform.mk index 50147cbb9..edb3624dc 100644 --- a/platform.mk +++ b/platform.mk @@ -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 -- 2.47.3