Blob Blame Raw
From 66a7e479f86336a1df9d06ad13e818dbc38191b3 Mon Sep 17 00:00:00 2001
From: Zygmunt Krynicki <me@zygoon.pl>
Date: Mon, 6 Mar 2017 20:26:26 +0100
Subject: [PATCH] cmd: use libtool for the internal library

This just cuts some hassle integration with how the helper library is
built. I could never get to pass the right -fPIC/-fpie combination
otherwise.

Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
---
 cmd/Makefile.am  | 30 +++++++++++++++---------------
 cmd/configure.ac |  3 ++-
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/cmd/Makefile.am b/cmd/Makefile.am
index 371d81273..f88c84041 100644
--- a/cmd/Makefile.am
+++ b/cmd/Makefile.am
@@ -68,12 +68,12 @@ snap-seccomp/snap-seccomp: snap-seccomp/*.go
 	cd snap-seccomp && GOPATH=$(or $(GOPATH),$(realpath $(srcdir)/../../../../..)) go build -i -v
 
 ##
-## libsnap-confine-private.a
+## libsnap-confine-private.la
 ##
 
-noinst_LIBRARIES += libsnap-confine-private.a
+noinst_LTLIBRARIES = libsnap-confine-private.la
 
-libsnap_confine_private_a_SOURCES = \
+libsnap_confine_private_la_SOURCES = \
 	libsnap-confine-private/cgroup-freezer-support.c \
 	libsnap-confine-private/cgroup-freezer-support.h \
 	libsnap-confine-private/classic.c \
@@ -100,11 +100,11 @@ libsnap_confine_private_a_SOURCES = \
 	libsnap-confine-private/string-utils.h \
 	libsnap-confine-private/utils.c \
 	libsnap-confine-private/utils.h
-libsnap_confine_private_a_CFLAGS = $(CHECK_CFLAGS)
+libsnap_confine_private_la_CFLAGS = $(CHECK_CFLAGS)
 
-noinst_LIBRARIES += libsnap-confine-private-debug.a
-libsnap_confine_private_debug_a_SOURCES = $(libsnap_confine_private_a_SOURCES)
-libsnap_confine_private_debug_a_CFLAGS = $(CHECK_CFLAGS) -DSNAP_CONFINE_DEBUG_BUILD=1
+noinst_LTLIBRARIES += libsnap-confine-private-debug.la
+libsnap_confine_private_debug_la_SOURCES = $(libsnap_confine_private_la_SOURCES)
+libsnap_confine_private_debug_la_CFLAGS = $(CHECK_CFLAGS) -DSNAP_CONFINE_DEBUG_BUILD=1
 
 if WITH_UNIT_TESTS
 noinst_PROGRAMS += libsnap-confine-private/unit-tests
@@ -153,7 +153,7 @@ noinst_PROGRAMS += decode-mount-opts/decode-mount-opts
 
 decode_mount_opts_decode_mount_opts_SOURCES = \
 	decode-mount-opts/decode-mount-opts.c
-decode_mount_opts_decode_mount_opts_LDADD = libsnap-confine-private.a
+decode_mount_opts_decode_mount_opts_LDADD = libsnap-confine-private.la
 decode_mount_opts_decode_mount_opts_STATIC =
 
 if STATIC_LIBCAP
@@ -207,7 +207,7 @@ snap_confine_snap_confine_SOURCES = \
 
 snap_confine_snap_confine_CFLAGS = $(CHECK_CFLAGS) $(AM_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -DNATIVE_LIBDIR=\"$(libdir)\"
 snap_confine_snap_confine_LDFLAGS = $(AM_LDFLAGS)
-snap_confine_snap_confine_LDADD = libsnap-confine-private.a
+snap_confine_snap_confine_LDADD = libsnap-confine-private.la
 snap_confine_snap_confine_CFLAGS += $(LIBUDEV_CFLAGS)
 snap_confine_snap_confine_LDADD += $(snap_confine_snap_confine_extra_libs)
 # _STATIC is where we collect statically linked in libraries
@@ -263,7 +263,7 @@ noinst_PROGRAMS += snap-confine/snap-confine-debug
 snap_confine_snap_confine_debug_SOURCES = $(snap_confine_snap_confine_SOURCES)
 snap_confine_snap_confine_debug_CFLAGS = $(snap_confine_snap_confine_CFLAGS)
 snap_confine_snap_confine_debug_LDFLAGS = $(snap_confine_snap_confine_LDFLAGS)
-snap_confine_snap_confine_debug_LDADD = libsnap-confine-private-debug.a $(snap_confine_snap_confine_extra_libs)
+snap_confine_snap_confine_debug_LDADD = libsnap-confine-private-debug.la $(snap_confine_snap_confine_extra_libs)
 snap_confine_snap_confine_debug_CFLAGS += -DSNAP_CONFINE_DEBUG_BUILD=1
 snap_confine_snap_confine_debug_STATIC = $(snap_confine_snap_confine_STATIC)
 
@@ -388,7 +388,7 @@ snap_discard_ns_snap_discard_ns_SOURCES = \
 	snap-discard-ns/snap-discard-ns.c
 snap_discard_ns_snap_discard_ns_CFLAGS = $(CHECK_CFLAGS) $(AM_CFLAGS)
 snap_discard_ns_snap_discard_ns_LDFLAGS = $(AM_LDFLAGS)
-snap_discard_ns_snap_discard_ns_LDADD = libsnap-confine-private.a
+snap_discard_ns_snap_discard_ns_LDADD = libsnap-confine-private.la
 snap_discard_ns_snap_discard_ns_STATIC =
 
 if APPARMOR
@@ -429,7 +429,7 @@ system_shutdown_system_shutdown_SOURCES = \
 	system-shutdown/system-shutdown-utils.c \
 	system-shutdown/system-shutdown-utils.h \
 	system-shutdown/system-shutdown.c
-system_shutdown_system_shutdown_LDADD = libsnap-confine-private.a
+system_shutdown_system_shutdown_LDADD = libsnap-confine-private.la
 system_shutdown_system_shutdown_CFLAGS = $(CHECK_CFLAGS) $(filter-out -fPIE -pie,$(CFLAGS)) -static
 system_shutdown_system_shutdown_LDFLAGS = $(filter-out -fPIE -pie,$(LDFLAGS)) -static
 
@@ -439,7 +439,7 @@ system_shutdown_unit_tests_SOURCES = \
 	libsnap-confine-private/unit-tests-main.c \
 	libsnap-confine-private/unit-tests.c \
 	system-shutdown/system-shutdown-utils-test.c
-system_shutdown_unit_tests_LDADD = libsnap-confine-private.a
+system_shutdown_unit_tests_LDADD = libsnap-confine-private.la
 system_shutdown_unit_tests_CFLAGS = $(GLIB_CFLAGS)
 system_shutdown_unit_tests_LDADD +=  $(GLIB_LIBS)
 endif
@@ -453,7 +453,7 @@ libexec_PROGRAMS += snap-gdb-shim/snap-gdb-shim
 snap_gdb_shim_snap_gdb_shim_SOURCES = \
 	snap-gdb-shim/snap-gdb-shim.c
 
-snap_gdb_shim_snap_gdb_shim_LDADD = libsnap-confine-private.a
+snap_gdb_shim_snap_gdb_shim_LDADD = libsnap-confine-private.la
 
 ##
 ## snapd-generator
@@ -462,4 +462,4 @@ snap_gdb_shim_snap_gdb_shim_LDADD = libsnap-confine-private.a
 libexec_PROGRAMS += snapd-generator/snapd-generator
 
 snapd_generator_snapd_generator_SOURCES = snapd-generator/main.c
-snapd_generator_snapd_generator_LDADD = libsnap-confine-private.a
+snapd_generator_snapd_generator_LDADD = libsnap-confine-private.la
diff --git a/cmd/configure.ac b/cmd/configure.ac
index 14c0e92d1..92eb496ad 100644
--- a/cmd/configure.ac
+++ b/cmd/configure.ac
@@ -11,7 +11,8 @@ AC_PROG_CC_C99
 AC_PROG_CPP
 AC_PROG_INSTALL
 AC_PROG_MAKE_SET
-AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+AC_CONFIG_MACRO_DIR([m4])
 
 AC_LANG([C])
 # Checks for libraries.
-- 
2.14.3