aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Forissier <jerome.forissier@linaro.org>2018-05-29 18:03:11 +0200
committerJérôme Forissier <jerome.forissier@linaro.org>2019-03-05 12:54:55 +0100
commite59b134dc639b02af27ccbb21ecead810e5a1f75 (patch)
tree97032da431f5eb914e68f66038ab138f40ccb6cd
parent65fe41dbdc63557028cea7c43901326cbccc0cb1 (diff)
mk/lib.mk: add support for producing shared user libraries
This commit adds the infrastructure to build libutils, libmpa/ libmbedtls etc. as shared objects (.so). Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
-rw-r--r--mk/lib.mk56
1 files changed, 51 insertions, 5 deletions
diff --git a/mk/lib.mk b/mk/lib.mk
index bfe39528..41fc9f5e 100644
--- a/mk/lib.mk
+++ b/mk/lib.mk
@@ -1,9 +1,15 @@
# Input
#
-# libname tells the name of the lib and
-# libdir tells directory of lib which also is used as input to
+# libname the name of the lib
+# libdir directory of lib which also is used as input to
# mk/subdir.mk
# conf-file [optional] if set, all objects will depend on $(conf-file)
+# [if CFG_ULIBS_SHARED==y]
+# libuuid the UUID of the shared lib
+# libl other libraries this library depends on; used to generate the
+# proper link arguments (-Lxxx -lyyy) and to add dependencies
+# on the needed .so files
+# [endif]
#
# Output
#
@@ -20,13 +26,26 @@ endif
endif
include mk/compile.mk
-lib-libfile = $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).a
-cleanfiles := $(cleanfiles) $(lib-libfile)
-libfiles := $(lib-libfile) $(libfiles)
+lib-libfile := $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).a
+ifeq ($(CFG_ULIBS_SHARED),y)
+lib-shlibfile := $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).so
+lib-shlibstrippedfile := $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).stripped.so
+lib-shlibtafile := $(out-dir)/$(base-prefix)$(libdir)/$(libuuid).ta
+lib-libuuidln := $(out-dir)/$(base-prefix)$(libdir)/$(libuuid).elf
+lib-shlibfile-$(libname)-$(sm) := $(lib-shlibfile)
+lib-libdir-$(libname)-$(sm) := $(out-dir)/$(base-prefix)$(libdir)
+lib-needed-so-files := $(foreach l,$(libl),$(lib-shlibfile-$(l)-$(sm)))
+lib-Ll-args := $(foreach l,$(libl),-L$(lib-libdir-$(l)-$(sm)) -l$(l))
+endif
+cleanfiles := $(lib-libfile) $(lib-shlibfile) $(lib-shlibstrippedfile) $(lib-shlibtafile) $(lib-libuuidln) $(cleanfiles)
+libfiles := $(lib-libfile) $(lib-shlibfile) $(lib-shlibstrippedfile) $(lib-shlibtafile) $(lib-libuuidln) $(libfiles)
libdirs := $(out-dir)/$(base-prefix)$(libdir) $(libdirs)
libnames := $(libname) $(libnames)
libdeps := $(lib-libfile) $(libdeps)
+SIGN = scripts/sign.py
+TA_SIGN_KEY ?= keys/default_ta.pem
+
define process-lib
ifeq ($(lib-use-ld), y)
$(lib-libfile): $(objs)
@@ -39,6 +58,26 @@ $(lib-libfile): $(objs)
@mkdir -p $$(dir $$@)
$$(q)rm -f $$@ && $$(AR$(sm)) rcs $$@ $$^
endif
+ifeq ($(CFG_ULIBS_SHARED),y)
+$(lib-shlibfile): $(objs) $(lib-needed-so-files)
+ @$(cmd-echo-silent) ' LD $$@'
+ @mkdir -p $$(dir $$@)
+ $$(q)$$(LD$(sm)) $(lib-ldflags) $(lib-Ll-args) -shared \
+ --soname=$(libuuid) -o $$@ $$^
+
+$(lib-shlibstrippedfile): $(lib-shlibfile)
+ @$(cmd-echo-silent) ' OBJCOPY $$@'
+ $$(q)$$(OBJCOPY$(sm)) --strip-unneeded $$< $$@
+
+$(lib-shlibtafile): $(lib-shlibstrippedfile) $(TA_SIGN_KEY)
+ @$(cmd-echo-silent) ' SIGN $$@'
+ $$(q)$$(SIGN) --key $(TA_SIGN_KEY) --uuid $(libuuid) --version 0 \
+ --in $$< --out $$@
+
+$(lib-libuuidln): $(lib-shlibfile)
+ @$(cmd-echo-silent) ' LN $$@'
+ $$(q)ln -sf lib$(libname).so $$@
+endif
endef #process-lib
$(eval $(call process-lib))
@@ -48,4 +87,11 @@ $(objs): $(conf-file)
# Clean residues from processing
objs :=
libname :=
+libuuid :=
lib-use-ld :=
+lib-shlibfile :=
+lib-shlibstrippedfile :=
+lib-shlibtafile :=
+lib-libuuidln :=
+lib-needed-so-files :=
+libl :=