aboutsummaryrefslogtreecommitdiff
path: root/mk/lib.mk
blob: 41fc9f5ecb14275603bcf35670e91ee545ae4f72 (plain)
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
# 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
ifneq ($(sm),core) # User-mode
ifeq ($(CFG_ULIBS_GPROF),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)
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)
	@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)
$(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))

$(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 :=