blob: b10748d185caf5f299cc0871b54f0b2c6b1cd040 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001# This file is included several times in a row, once
2# for each element of $(extra-libs). $(extra-libs-left)
3# is initialized first to $(extra-libs) so that with each
4# inclusion, we advance $(lib) to the next library name (e.g. libfoo).
5# The variable $($(lib)-routines) defines the list of modules
6# to be included in that library. A sysdep Makefile can add to
7# $(lib)-sysdep_routines to include additional modules.
8
9lib := $(firstword $(extra-libs-left))
10extra-libs-left := $(filter-out $(lib),$(extra-libs-left))
11
12object-suffixes-$(lib) := $(filter-out $($(lib)-inhibit-o),$(object-suffixes))
13
14ifneq (,$($(lib)-static-only-routines))
15ifneq (,$(filter yes%,$(build-shared)$($(lib).so-version)))
16object-suffixes-$(lib) += $(filter-out $($(lib)-inhibit-o),.oS)
17endif
18endif
19
20ifneq (,$(object-suffixes-$(lib)))
21
22# Make sure these are simply-expanded variables before we append to them,
23# since we want the expressions we append to be expanded right now.
24install-lib := $(install-lib)
25extra-objs := $(extra-objs)
26
27# The modules that go in $(lib).
28all-$(lib)-routines := $($(lib)-routines) $($(lib)-sysdep_routines)
29
30# Add each flavor of library to the lists of things to build and install.
31install-lib += $(foreach o,$(object-suffixes-$(lib)),$(lib:lib%=$(libtype$o)))
32extra-objs += $(foreach o,$(filter-out .os .oS,$(object-suffixes-$(lib))),\
33 $(patsubst %,%$o,$(filter-out \
34 $($(lib)-shared-only-routines),\
35 $(all-$(lib)-routines))))
36ifneq (,$(filter .os,$(object-suffixes-$(lib))))
37extra-objs += $(patsubst %,%.os,$(filter-out $($(lib)-static-only-routines),\
38 $(all-$(lib)-routines)))
39endif
40ifneq (,$(filter .oS,$(object-suffixes-$(lib))))
41extra-objs += $(patsubst %,%.oS,$(filter $($(lib)-static-only-routines),\
42 $(all-$(lib)-routines)))
43endif
44alltypes-$(lib) := $(foreach o,$(object-suffixes-$(lib)),\
45 $(objpfx)$(patsubst %,$(libtype$o),\
46 $(lib:lib%=%)))
47
48ifeq (,$(filter $(lib),$(extra-libs-others)))
49lib-noranlib: $(alltypes-$(lib))
50ifeq (yes,$(build-shared))
51lib-noranlib: $(objpfx)$(lib).so$($(lib).so-version)
52endif
53else
54others: $(alltypes-$(lib))
55endif
56
57# The linked shared library is never a dependent of lib-noranlib,
58# because linking it will depend on libc.so already being built.
59ifneq (,$(filter .os,$(object-suffixes-$(lib))))
60others: $(objpfx)$(lib).so$($(lib).so-version)
61endif
62
63
64# Use o-iterator.mk to generate a rule for each flavor of library.
65ifneq (,$(filter-out .os .oS,$(object-suffixes-$(lib))))
66define o-iterator-doit
67$(objpfx)$(patsubst %,$(libtype$o),$(lib:lib%=%)): \
68 $(patsubst %,$(objpfx)%$o,\
69 $(filter-out $($(lib)-shared-only-routines),\
70 $(all-$(lib)-routines))); \
71 $$(build-extra-lib)
72endef
73object-suffixes-left = $(filter-out .os .oS,$(object-suffixes-$(lib)))
74include $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
75endif
76
77ifneq (,$(filter .os,$(object-suffixes-$(lib))))
78$(objpfx)$(patsubst %,$(libtype.os),$(lib:lib%=%)): \
79 $(patsubst %,$(objpfx)%.os,\
80 $(filter-out $($(lib)-static-only-routines),\
81 $(all-$(lib)-routines)))
82 $(build-extra-lib)
83endif
84
85ifneq (,$(filter .oS,$(object-suffixes-$(lib))))
86$(objpfx)$(patsubst %,$(libtype.oS),$(lib:lib%=%)): \
87 $(patsubst %,$(objpfx)%.oS,\
88 $(filter $($(lib)-static-only-routines),\
89 $(all-$(lib)-routines)))
90 $(build-extra-lib)
91endif
92
93ifeq ($(build-shared),yes)
94# Add the version script to the dependencies of the shared library.
95$(objpfx)$(lib).so: $(firstword $($(lib)-map) \
96 $(addprefix $(common-objpfx), \
97 $(filter $(lib).map, \
98 $(version-maps))))
99endif
100
101endif
102
103# This will define `libof-ROUTINE := LIB' for each of the routines.
104cpp-srcs-left := $($(lib)-routines) $($(lib)-sysdep_routines)
105ifneq (,$(cpp-srcs-left))
106include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
107endif