Commit 16b6dab1 authored by Marek Vavruša's avatar Marek Vavruša

build: allow library to be built statically

parent d5807047
......@@ -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
......
......@@ -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);
/* 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);
......@@ -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)
......
......@@ -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");
......
......@@ -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
......
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