[PATCH 3/5] build: allow using a system-provided talloc properly

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jan Engelhardt jengelh at inai.de
Sat Oct 4 09:10:23 UTC 2014


When --disable-talloc was given to configure, it would already link
libosmocore.so to libtalloc. Make it use pkg-config to discover
talloc's flags and location, and when the system talloc is used,
make sure to use its API header file too.
---
 .gitignore                                      |  1 +
 Makefile.am                                     |  2 ++
 configure.ac                                    | 16 +++++++++++++++-
 include/Makefile.am                             |  3 ++-
 include/osmocom/core/talloc.h.in                |  6 ++++++
 include/osmocom/core/{talloc.h => talloc_int.h} |  0
 libosmocore.pc.in                               |  2 +-
 src/Makefile.am                                 |  5 +++--
 src/gsm/Makefile.am                             |  8 +++-----
 tests/Makefile.am                               | 12 ++++++------
 10 files changed, 39 insertions(+), 16 deletions(-)
 create mode 100644 include/osmocom/core/talloc.h.in
 rename include/osmocom/core/{talloc.h => talloc_int.h} (100%)

diff --git a/.gitignore b/.gitignore
index 1299028..30707a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -92,6 +92,7 @@ doc/html.tar
 src/crc*gen.c
 include/osmocom/core/crc*gen.h
 include/osmocom/core/bit*gen.h
+/include/osmocom/core/talloc.h
 
 # vi files
 *.sw?
diff --git a/Makefile.am b/Makefile.am
index faf7a83..5144c87 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,6 +6,8 @@ pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libosmocore.pc libosmocodec.pc libosmovty.pc libosmogsm.pc \
 		 libosmogb.pc libosmoctrl.pc
 
+$(pkgconfig_DATA): $(top_builddir)/config.status
+
 BUILT_SOURCES = $(top_srcdir)/.version
 $(top_srcdir)/.version:
 	echo $(VERSION) > $@-t && mv $@-t $@
diff --git a/configure.ac b/configure.ac
index deaa8bf..f0d1206 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,10 +85,23 @@ AC_CONFIG_HEADER(config.h)
 AC_ARG_ENABLE(talloc,
 	[AS_HELP_STRING(
 		[--disable-talloc],
-		[Disable building talloc memory allocator]
+		[Disable using bundled talloc memory allocator]
 	)],
 	[enable_talloc=$enableval], [enable_talloc="yes"])
 AM_CONDITIONAL(ENABLE_TALLOC, [test x"$enable_talloc" = x"yes"])
+AS_IF([test x"$enable_talloc" = xno],
+	[
+		PKG_CHECK_MODULES([TALLOC], [talloc])
+		OSMOCORE_INTERNAL_TALLOC=0
+	],
+	[
+		TALLOC_CFLAGS=""
+		TALLOC_LIBS=""
+		OSMOCORE_INTERNAL_TALLOC=1
+		AC_SUBST([TALLOC_CFLAGS])
+		AC_SUBST([TALLOC_LIBS])
+	])
+AC_SUBST([OSMOCORE_INTERNAL_TALLOC])
 
 AC_ARG_ENABLE(plugin,
 	[AS_HELP_STRING(
@@ -188,6 +201,7 @@ AC_OUTPUT(
 	libosmogb.pc
 	libosmoctrl.pc
 	include/Makefile
+	include/osmocom/core/talloc.h
 	src/Makefile
 	src/vty/Makefile
 	src/codec/Makefile
diff --git a/include/Makefile.am b/include/Makefile.am
index c59f9b2..4d59a72 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -89,8 +89,9 @@ if ENABLE_PLUGIN
 nobase_include_HEADERS += osmocom/core/plugin.h
 endif
 
+nobase_nodist_include_HEADERS = osmocom/core/talloc.h
 if ENABLE_TALLOC
-nobase_include_HEADERS += osmocom/core/talloc.h
+nobase_include_HEADERS += osmocom/core/talloc_int.h
 endif
 
 if ENABLE_MSGFILE
diff --git a/include/osmocom/core/talloc.h.in b/include/osmocom/core/talloc.h.in
new file mode 100644
index 0000000..edbbb63
--- /dev/null
+++ b/include/osmocom/core/talloc.h.in
@@ -0,0 +1,6 @@
+#pragma once
+#if @OSMOCORE_INTERNAL_TALLOC@
+#include <osmocom/core/talloc_int.h>
+#else
+#include <talloc.h>
+#endif
diff --git a/include/osmocom/core/talloc.h b/include/osmocom/core/talloc_int.h
similarity index 100%
rename from include/osmocom/core/talloc.h
rename to include/osmocom/core/talloc_int.h
diff --git a/libosmocore.pc.in b/libosmocore.pc.in
index 7c29869..25832f6 100644
--- a/libosmocore.pc.in
+++ b/libosmocore.pc.in
@@ -8,4 +8,4 @@ Description: C Utility Library
 Version: @VERSION@
 Libs: -L${libdir} -losmocore
 Cflags: -I${includedir}/
-
+ at ENABLE_TALLOC_FALSE@Requires: talloc
diff --git a/src/Makefile.am b/src/Makefile.am
index 65494a5..3924330 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,8 @@
 # Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification
 LIBVERSION=5:0:0
 
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include \
+              $(TALLOC_CFLAGS)
 AM_CFLAGS = -Wall
 
 lib_LTLIBRARIES = libosmocore.la
@@ -29,7 +30,7 @@ endif
 if ENABLE_TALLOC
 libosmocore_la_SOURCES += talloc.c
 else
-libosmocore_la_LIBADD += -ltalloc
+libosmocore_la_LIBADD += $(TALLOC_LIBS)
 endif
 
 if ENABLE_MSGFILE
diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am
index b0cdea2..40a1821 100644
--- a/src/gsm/Makefile.am
+++ b/src/gsm/Makefile.am
@@ -2,7 +2,8 @@
 # Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification
 LIBVERSION=6:0:1
 
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include \
+              $(TALLOC_CFLAGS)
 AM_CFLAGS = -Wall ${GCC_FVISIBILITY_HIDDEN}
 
 # FIXME: this should eventually go into a milenage/Makefile.am
@@ -23,9 +24,6 @@ libosmogsm_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \
 			milenage/milenage.c gan.c ipa.c
 
 libosmogsm_la_LDFLAGS = $(LTLDFLAGS_OSMOGSM) -version-info $(LIBVERSION) -no-undefined
-libosmogsm_la_LIBADD = $(top_builddir)/src/libosmocore.la
-if !ENABLE_TALLOC
-libosmogsm_la_LIBADD += -ltalloc
-endif
+libosmogsm_la_LIBADD = $(top_builddir)/src/libosmocore.la $(TALLOC_LIBS)
 
 EXTRA_DIST = libosmogsm.map
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3f7db1f..9f034c0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include $(TALLOC_CFLAGS)
 AM_CFLAGS = -Wall
 
 check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test		\
@@ -45,7 +45,7 @@ lapd_lapd_test_SOURCES = lapd/lapd_test.c
 lapd_lapd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
 
 msgfile_msgfile_test_SOURCES = msgfile/msgfile_test.c
-msgfile_msgfile_test_LDADD = $(top_builddir)/src/libosmocore.la
+msgfile_msgfile_test_LDADD = $(top_builddir)/src/libosmocore.la $(TALLOC_LIBS)
 
 smscb_smscb_test_SOURCES = smscb/smscb_test.c
 smscb_smscb_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
@@ -54,13 +54,13 @@ sms_sms_test_SOURCES = sms/sms_test.c
 sms_sms_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
 
 timer_timer_test_SOURCES = timer/timer_test.c
-timer_timer_test_LDADD = $(top_builddir)/src/libosmocore.la
+timer_timer_test_LDADD = $(top_builddir)/src/libosmocore.la $(TALLOC_LIBS)
 
 ussd_ussd_test_SOURCES = ussd/ussd_test.c
 ussd_ussd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
 
 gb_bssgp_fc_test_SOURCES = gb/bssgp_fc_test.c
-gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la
+gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(TALLOC_LIBS)
 
 gb_gprs_ns_test_SOURCES = gb/gprs_ns_test.c
 gb_gprs_ns_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la $(LIBRARY_DL)
@@ -75,10 +75,10 @@ loggingrb_loggingrb_test_SOURCES = logging/logging_test.c
 loggingrb_loggingrb_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/vty/libosmovty.la
 
 strrb_strrb_test_SOURCES = strrb/strrb_test.c
-strrb_strrb_test_LDADD = $(top_builddir)/src/libosmocore.la
+strrb_strrb_test_LDADD = $(top_builddir)/src/libosmocore.la $(TALLOC_LIBS)
 
 vty_vty_test_SOURCES = vty/vty_test.c
-vty_vty_test_LDADD = $(top_builddir)/src/vty/libosmovty.la $(top_builddir)/src/libosmocore.la
+vty_vty_test_LDADD = $(top_builddir)/src/vty/libosmovty.la $(top_builddir)/src/libosmocore.la $(TALLOC_LIBS)
 
 
 # The `:;' works around a Bash 3.2 bug when the output is not writeable.
-- 
2.0.0





More information about the OpenBSC mailing list