forked from OP-TEE/optee_os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.mk
103 lines (92 loc) · 3.22 KB
/
lib.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Input
#
# 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
#
# updated cleanfiles and
# updated libfiles, libdirs, libnames and libdeps
subdirs = $(libdir)
include mk/subdir.mk
ifeq ($(filter $(sm), core ldelf),) # TA
ifeq ($(CFG_ULIBS_MCOUNT),y)
cflags-lib$(libname)-$(sm) += -pg
endif
endif
include mk/compile.mk
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)
ifneq (,$(objs))
libnames := $(libname) $(libnames)
libdeps := $(lib-libfile) $(libdeps)
endif
SIGN = scripts/sign_encrypt.py
TA_SIGN_KEY ?= keys/default_ta.pem
define process-lib
ifeq ($(lib-use-ld), y)
$(lib-libfile): $(objs)
@echo ' LD $$@'
@mkdir -p $$(dir $$@)
$$(q)$$(LD$(sm)) $(lib-ldflags) -o $$@ $$^
else
$(lib-libfile): $(objs)
@$(cmd-echo-silent) ' AR $$@'
@mkdir -p $$(dir $$@)
$$(q)rm -f $$@ && $$(AR$(sm)) rcs $$@ $$^
endif
ifeq ($(CFG_ULIBS_SHARED),y)
ifeq ($(sm)-$(CFG_TA_BTI),ta_arm64-y)
lib-ldflags$(lib-shlibfile) += $$(call ld-option,-z force-bti) --fatal-warnings
endif
$(lib-shlibfile): $(objs) $(lib-needed-so-files)
@$(cmd-echo-silent) ' LD $$@'
@mkdir -p $$(dir $$@)
$$(q)$$(LD$(sm)) $(lib-ldflags) -shared -z max-page-size=4096 \
$(call ld-option,-z separate-loadable-segments) \
$$(lib-ldflags$(lib-shlibfile)) \
--soname=$(libuuid) -o $$@ $$(filter-out %.so,$$^) $(lib-Ll-args)
$(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)$$(PYTHON3) $$(SIGN) --key $(TA_SIGN_KEY) --uuid $(libuuid) --in $$< --out $$@
$(lib-libuuidln): $(lib-shlibfile)
@$(cmd-echo-silent) ' LN $$@'
$$(q)ln -sf lib$(libname).so $$@
endif
endef #process-lib
$(eval $(call process-lib))
$(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 :=