From a10ef29b47123a60755b59befca9b2d45f3e29fa Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 21 Nov 2015 00:41:43 +0100 Subject: [PATCH] use system-wide libtalloc with --enable-system-talloc This introduces a new configure flag by which the libosmocore-internal talloc code is not compiled, but rather a system-wide libtalloc is used. When we started openbsc/libosmocore in 2008, libtalloc was not widely present on systems yet. This has changed meanwhile, and we should simply use the system-wide library --- configure.ac | 45 ++++++++++++++++++- include/Makefile.am | 15 ++++++- .../core/{talloc.h => talloc-internal.h} | 0 libosmocore.pc.in | 2 +- 4 files changed, 59 insertions(+), 3 deletions(-) rename include/osmocom/core/{talloc.h => talloc-internal.h} (100%) diff --git a/configure.ac b/configure.ac index 9a744b102..126e9a56a 100644 --- a/configure.ac +++ b/configure.ac @@ -97,11 +97,25 @@ AM_CONDITIONAL(ENABLE_PCSC, test "x$enable_pcsc" = "xyes") AC_ARG_ENABLE(talloc, [AS_HELP_STRING( [--disable-talloc], - [Disable building talloc memory allocator] + [Disable building libosmocore internal talloc memory allocator] )], [enable_talloc=$enableval], [enable_talloc="yes"]) AM_CONDITIONAL(ENABLE_TALLOC, [test x"$enable_talloc" = x"yes"]) +AC_ARG_ENABLE(system-talloc, + [AS_HELP_STRING( + [--enable-system-talloc], + [Enable using a system-level talloc library] + )], + [enable_system_talloc=$enableval], [enable_system_talloc="no"]) +AM_CONDITIONAL(ENABLE_SYSTEM_TALLOC, [test x"$enable_system_talloc" = x"yes"]) +if test x"$enable_system_talloc" = x"yes"; then + PKG_CHECK_MODULES(TALLOC, talloc) + if test x"$enable_talloc" = x"yes"; then + AC_MSG_ERROR([You cannot enable both internal and system talloc]) + fi +fi + AC_ARG_ENABLE(plugin, [AS_HELP_STRING( [--disable-plugin], @@ -191,6 +205,35 @@ then AC_DEFINE([PANIC_INFLOOP],[1],[Use infinite loop on panic rather than fprintf/abort]) fi +AC_OUTPUT_COMMANDS([ + if test -n "$CONFIG_FILES" && test -n "$CONFIG_HEADERS"; then + CONFIG_OTHER=${CONFIG_OTHER-include/osmocom/core/talloc.h} + fi + case "$CONFIG_OTHER" in + "include/osmocom/core/talloc.h") + outfile=include/osmocom/core/talloc.h + stampfile=include/stamp-talloc + tmpfile=${outfile}T + dirname="sed s,^.*/,,g" + + echo creating $outfile + cat > $outfile << _EOF_ +/* DO NOT EDIT THIS FILE! It has been automaticall generated from + * configure.ac on host: `(hostname || uname -n) 2>/dev/null | sed 1q` + */ +#pragma once +_EOF_ + if test x"$enable_system_talloc" = x"yes"; then + echo '#include ' >> $outfile + else + echo '#include ' >> $outfile + fi + esac +],[ + srcdir=$srcdir + enable_system_talloc=$enable_system_talloc +]) + AC_OUTPUT( libosmocore.pc diff --git a/include/Makefile.am b/include/Makefile.am index 207358003..b8739e02d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -35,6 +35,7 @@ nobase_include_HEADERS = \ osmocom/core/socket.h \ osmocom/core/statistics.h \ osmocom/core/strrb.h \ + osmocom/core/talloc.h \ osmocom/core/timer.h \ osmocom/core/utils.h \ osmocom/core/write_queue.h \ @@ -97,7 +98,7 @@ nobase_include_HEADERS += osmocom/core/plugin.h endif if ENABLE_TALLOC -nobase_include_HEADERS += osmocom/core/talloc.h +nobase_include_HEADERS += osmocom/core/talloc-internal.h endif if ENABLE_MSGFILE @@ -133,3 +134,15 @@ osmocom/core/bit%gen.h: osmocom/core/bitXXgen.h.tpl osmocom/core/crc%gen.h: osmocom/core/crcXXgen.h.tpl $(AM_V_GEN)$(MKDIR_P) $(dir $@) $(AM_V_GEN)sed -e's/XX/$*/g' $< > $@ + +# regenerate talloc.h with config.status every time config.status changes +osmocom/core/talloc.h: stamp-talloc + : + +stamp-talloc: $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=osmocom/core/talloc.h \ + $(SHELL) ./config.status + echo timestamp > $@ + +DISTCLEANFILES = stamp-talloc diff --git a/include/osmocom/core/talloc.h b/include/osmocom/core/talloc-internal.h similarity index 100% rename from include/osmocom/core/talloc.h rename to include/osmocom/core/talloc-internal.h diff --git a/libosmocore.pc.in b/libosmocore.pc.in index 7c298693a..0666e0c71 100644 --- a/libosmocore.pc.in +++ b/libosmocore.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: Osmocom Core Library Description: C Utility Library Version: @VERSION@ -Libs: -L${libdir} -losmocore +Libs: -L${libdir} @TALLOC_LIBS@ -losmocore Cflags: -I${includedir}/