blob: 029260d7af8bf3133793d5363b72fccf83ddb9ea [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)
Jerome Forissier48685b62021-12-16 19:08:41 +010062ifeq ($(sm)-$(CFG_TA_BTI),ta_arm64-y)
Jerome Forissierb489a612023-01-25 16:41:36 +010063lib-ldflags$(lib-shlibfile) += $$(call ld-option,-z force-bti) --fatal-warnings
Jerome Forissier48685b62021-12-16 19:08:41 +010064endif
Jerome Forissiere59b1342018-05-29 18:03:11 +020065$(lib-shlibfile): $(objs) $(lib-needed-so-files)
66 @$(cmd-echo-silent) ' LD $$@'
67 @mkdir -p $$(dir $$@)
Jerome Forissier4e74e392020-03-18 11:37:18 +010068 $$(q)$$(LD$(sm)) $(lib-ldflags) -shared -z max-page-size=4096 \
Jerome Forissier8001ec62020-06-30 09:26:33 +020069 $(call ld-option,-z separate-loadable-segments) \
Jerome Forissierb489a612023-01-25 16:41:36 +010070 $$(lib-ldflags$(lib-shlibfile)) \
Jerome Forissier4e74e392020-03-18 11:37:18 +010071 --soname=$(libuuid) -o $$@ $$(filter-out %.so,$$^) $(lib-Ll-args)
Jerome Forissiere59b1342018-05-29 18:03:11 +020072
73$(lib-shlibstrippedfile): $(lib-shlibfile)
74 @$(cmd-echo-silent) ' OBJCOPY $$@'
75 $$(q)$$(OBJCOPY$(sm)) --strip-unneeded $$< $$@
76
77$(lib-shlibtafile): $(lib-shlibstrippedfile) $(TA_SIGN_KEY)
78 @$(cmd-echo-silent) ' SIGN $$@'
Dick Olssonb4faf482020-07-22 08:49:12 +020079 $$(q)$$(PYTHON3) $$(SIGN) --key $(TA_SIGN_KEY) --uuid $(libuuid) --in $$< --out $$@
Jerome Forissiere59b1342018-05-29 18:03:11 +020080
81$(lib-libuuidln): $(lib-shlibfile)
82 @$(cmd-echo-silent) ' LN $$@'
83 $$(q)ln -sf lib$(libname).so $$@
84endif
Jerome Forissier699f50a2014-10-28 17:22:45 +010085endef #process-lib
86
87$(eval $(call process-lib))
Pascal Brandb0104772014-06-12 15:56:20 +020088
Jerome Forissierfe52b1f2014-11-06 17:54:51 +010089$(objs): $(conf-file)
90
Pascal Brandb0104772014-06-12 15:56:20 +020091# Clean residues from processing
92objs :=
Jerome Forissier73dc7282014-09-25 16:04:03 +020093libname :=
Jerome Forissiere59b1342018-05-29 18:03:11 +020094libuuid :=
Jerome Forissier699f50a2014-10-28 17:22:45 +010095lib-use-ld :=
Jerome Forissiere59b1342018-05-29 18:03:11 +020096lib-shlibfile :=
97lib-shlibstrippedfile :=
98lib-shlibtafile :=
99lib-libuuidln :=
100lib-needed-so-files :=
101libl :=