blob: 3bd422d69eb3b4cf323c773f1dc859b144f58de8 [file] [log] [blame]
Pascal Brandb0104772014-06-12 15:56:20 +02001# Input
2#
Jerome Forissiere59b1342018-05-29 18:03:11 +02003# libname the name of the lib
4# libdir directory of lib which also is used as input to
Pascal Brandb0104772014-06-12 15:56:20 +02005# mk/subdir.mk
Jerome Forissierfe52b1f2014-11-06 17:54:51 +01006# conf-file [optional] if set, all objects will depend on $(conf-file)
Jerome Forissiere59b1342018-05-29 18:03:11 +02007# [if CFG_ULIBS_SHARED==y]
8# libuuid the UUID of the shared lib
9# libl other libraries this library depends on; used to generate the
10# proper link arguments (-Lxxx -lyyy) and to add dependencies
11# on the needed .so files
12# [endif]
Pascal Brandb0104772014-06-12 15:56:20 +020013#
14# Output
15#
16# updated cleanfiles and
17# updated libfiles, libdirs, libnames and libdeps
18
19
20subdirs = $(libdir)
21include mk/subdir.mk
Jens Wiklander7509ff72019-05-23 17:42:08 +020022ifeq ($(filter $(sm), core ldelf),) # TA
Sumit Garg735565d2019-05-16 18:49:30 +053023ifeq ($(CFG_ULIBS_MCOUNT),y)
Jerome Forissierb31756b2018-11-15 16:44:03 +010024cflags-lib$(libname)-$(sm) += -pg
25endif
26endif
Pascal Brandb0104772014-06-12 15:56:20 +020027include mk/compile.mk
28
Jerome Forissiere59b1342018-05-29 18:03:11 +020029lib-libfile := $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).a
30ifeq ($(CFG_ULIBS_SHARED),y)
31lib-shlibfile := $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).so
32lib-shlibstrippedfile := $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).stripped.so
33lib-shlibtafile := $(out-dir)/$(base-prefix)$(libdir)/$(libuuid).ta
34lib-libuuidln := $(out-dir)/$(base-prefix)$(libdir)/$(libuuid).elf
35lib-shlibfile-$(libname)-$(sm) := $(lib-shlibfile)
36lib-libdir-$(libname)-$(sm) := $(out-dir)/$(base-prefix)$(libdir)
37lib-needed-so-files := $(foreach l,$(libl),$(lib-shlibfile-$(l)-$(sm)))
38lib-Ll-args := $(foreach l,$(libl),-L$(lib-libdir-$(l)-$(sm)) -l$(l))
39endif
40cleanfiles := $(lib-libfile) $(lib-shlibfile) $(lib-shlibstrippedfile) $(lib-shlibtafile) $(lib-libuuidln) $(cleanfiles)
41libfiles := $(lib-libfile) $(lib-shlibfile) $(lib-shlibstrippedfile) $(lib-shlibtafile) $(lib-libuuidln) $(libfiles)
Jerome Forissier4334e8d2014-09-08 10:53:42 +020042libdirs := $(out-dir)/$(base-prefix)$(libdir) $(libdirs)
Pascal Brandb0104772014-06-12 15:56:20 +020043libnames := $(libname) $(libnames)
Pascal Brand0957bcc2015-05-19 13:57:25 +020044libdeps := $(lib-libfile) $(libdeps)
Pascal Brandb0104772014-06-12 15:56:20 +020045
Sumit Garg2de17fd2019-10-23 12:47:24 +053046SIGN = scripts/sign_encrypt.py
Jerome Forissiere59b1342018-05-29 18:03:11 +020047TA_SIGN_KEY ?= keys/default_ta.pem
48
Jerome Forissier699f50a2014-10-28 17:22:45 +010049define process-lib
50ifeq ($(lib-use-ld), y)
Pascal Brandb0104772014-06-12 15:56:20 +020051$(lib-libfile): $(objs)
Jerome Forissier699f50a2014-10-28 17:22:45 +010052 @echo ' LD $$@'
53 @mkdir -p $$(dir $$@)
Jens Wiklander1b4eb4f2015-02-02 09:19:18 +010054 $$(q)$$(LD$(sm)) $(lib-ldflags) -o $$@ $$^
Jerome Forissier699f50a2014-10-28 17:22:45 +010055else
56$(lib-libfile): $(objs)
Jens Wiklander62428632015-04-29 15:05:19 +020057 @$(cmd-echo-silent) ' AR $$@'
Jerome Forissier699f50a2014-10-28 17:22:45 +010058 @mkdir -p $$(dir $$@)
Jerome Forissier47093402015-09-22 18:02:47 -070059 $$(q)rm -f $$@ && $$(AR$(sm)) rcs $$@ $$^
Jerome Forissier699f50a2014-10-28 17:22:45 +010060endif
Jerome Forissiere59b1342018-05-29 18:03:11 +020061ifeq ($(CFG_ULIBS_SHARED),y)
62$(lib-shlibfile): $(objs) $(lib-needed-so-files)
63 @$(cmd-echo-silent) ' LD $$@'
64 @mkdir -p $$(dir $$@)
Jerome Forissier4e74e392020-03-18 11:37:18 +010065 $$(q)$$(LD$(sm)) $(lib-ldflags) -shared -z max-page-size=4096 \
Jerome Forissier8001ec62020-06-30 09:26:33 +020066 $(call ld-option,-z separate-loadable-segments) \
Jerome Forissier4e74e392020-03-18 11:37:18 +010067 --soname=$(libuuid) -o $$@ $$(filter-out %.so,$$^) $(lib-Ll-args)
Jerome Forissiere59b1342018-05-29 18:03:11 +020068
69$(lib-shlibstrippedfile): $(lib-shlibfile)
70 @$(cmd-echo-silent) ' OBJCOPY $$@'
71 $$(q)$$(OBJCOPY$(sm)) --strip-unneeded $$< $$@
72
73$(lib-shlibtafile): $(lib-shlibstrippedfile) $(TA_SIGN_KEY)
74 @$(cmd-echo-silent) ' SIGN $$@'
Dick Olssonb4faf482020-07-22 08:49:12 +020075 $$(q)$$(PYTHON3) $$(SIGN) --key $(TA_SIGN_KEY) --uuid $(libuuid) --in $$< --out $$@
Jerome Forissiere59b1342018-05-29 18:03:11 +020076
77$(lib-libuuidln): $(lib-shlibfile)
78 @$(cmd-echo-silent) ' LN $$@'
79 $$(q)ln -sf lib$(libname).so $$@
80endif
Jerome Forissier699f50a2014-10-28 17:22:45 +010081endef #process-lib
82
83$(eval $(call process-lib))
Pascal Brandb0104772014-06-12 15:56:20 +020084
Jerome Forissierfe52b1f2014-11-06 17:54:51 +010085$(objs): $(conf-file)
86
Pascal Brandb0104772014-06-12 15:56:20 +020087# Clean residues from processing
88objs :=
Jerome Forissier73dc7282014-09-25 16:04:03 +020089libname :=
Jerome Forissiere59b1342018-05-29 18:03:11 +020090libuuid :=
Jerome Forissier699f50a2014-10-28 17:22:45 +010091lib-use-ld :=
Jerome Forissiere59b1342018-05-29 18:03:11 +020092lib-shlibfile :=
93lib-shlibstrippedfile :=
94lib-shlibtafile :=
95lib-libuuidln :=
96lib-needed-so-files :=
97libl :=