1# 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#
9# Libraries listed in $(extra-libs-noinstall) are built, but not
10# installed.
11
12lib := $(firstword $(extra-libs-left))
13extra-libs-left := $(filter-out $(lib),$(extra-libs-left))
14
15object-suffixes-$(lib) := $(filter-out $($(lib)-inhibit-o),$(object-suffixes))
16
17ifneq (,$($(lib)-static-only-routines))
18ifneq (,$(filter yes%,$(build-shared)$($(lib).so-version)))
19object-suffixes-$(lib) += $(filter-out $($(lib)-inhibit-o),.oS)
20endif
21endif
22
23ifneq (,$(object-suffixes-$(lib)))
24
25# Make sure these are simply-expanded variables before we append to them,
26# since we want the expressions we append to be expanded right now.
27install-lib := $(install-lib)
28extra-objs := $(extra-objs)
29
30# The modules that go in $(lib).
31all-$(lib)-routines := $($(lib)-routines) $($(lib)-sysdep_routines)
32
33# Add each flavor of library to the lists of things to build and install.
34ifeq (,$(filter $(lib), $(extra-libs-noinstall)))
35install-lib += $(foreach o,$(object-suffixes-$(lib)),$(lib:lib%=$(libtype$o)))
36endif
37extra-objs += $(foreach o,$(filter-out .os .oS,$(object-suffixes-$(lib))),\
38			$(patsubst %,%$o,$(filter-out \
39					   $($(lib)-shared-only-routines),\
40					   $(all-$(lib)-routines))))
41ifneq (,$(filter .os,$(object-suffixes-$(lib))))
42extra-objs += $(patsubst %,%.os,$(filter-out $($(lib)-static-only-routines),\
43					     $(all-$(lib)-routines)))
44endif
45ifneq (,$(filter .oS,$(object-suffixes-$(lib))))
46extra-objs += $(patsubst %,%.oS,$(filter $($(lib)-static-only-routines),\
47					 $(all-$(lib)-routines)))
48endif
49alltypes-$(lib) := $(foreach o,$(object-suffixes-$(lib)),\
50			     $(objpfx)$(patsubst %,$(libtype$o),\
51			     $(lib:lib%=%)))
52
53ifeq (,$(filter $(lib),$(extra-libs-others)))
54lib-noranlib: $(alltypes-$(lib))
55ifeq (yes,$(build-shared))
56lib-noranlib: $(objpfx)$(lib).so$($(lib).so-version)
57endif
58else
59others: $(alltypes-$(lib))
60endif
61
62# The linked shared library is never a dependent of lib-noranlib,
63# because linking it will depend on libc.so already being built.
64ifneq (,$(filter .os,$(object-suffixes-$(lib))))
65others: $(objpfx)$(lib).so$($(lib).so-version)
66endif
67
68
69# Use o-iterator.mk to generate a rule for each flavor of library.
70ifneq (,$(filter-out .os .oS,$(object-suffixes-$(lib))))
71define o-iterator-doit
72$(objpfx)$(patsubst %,$(libtype$o),$(lib:lib%=%)): \
73  $(patsubst %,$(objpfx)%$o,\
74	     $(filter-out $($(lib)-shared-only-routines),\
75			  $(all-$(lib)-routines))); \
76	$$(build-extra-lib)
77endef
78object-suffixes-left = $(filter-out .os .oS,$(object-suffixes-$(lib)))
79include $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
80endif
81
82ifneq (,$(filter .os,$(object-suffixes-$(lib))))
83$(objpfx)$(patsubst %,$(libtype.os),$(lib:lib%=%)): \
84  $(patsubst %,$(objpfx)%.os,\
85	     $(filter-out $($(lib)-static-only-routines),\
86			  $(all-$(lib)-routines)))
87	$(build-extra-lib)
88endif
89
90ifneq (,$(filter .oS,$(object-suffixes-$(lib))))
91$(objpfx)$(patsubst %,$(libtype.oS),$(lib:lib%=%)): \
92  $(patsubst %,$(objpfx)%.oS,\
93	     $(filter $($(lib)-static-only-routines),\
94		      $(all-$(lib)-routines)))
95	$(build-extra-lib)
96endif
97
98ifeq ($(build-shared),yes)
99# Add the version script to the dependencies of the shared library.
100$(objpfx)$(lib).so: $(firstword $($(lib)-map) \
101				$(addprefix $(common-objpfx), \
102					    $(filter $(lib).map, \
103						     $(version-maps))))
104endif
105
106endif
107
108# This will define `libof-ROUTINE := LIB' for each of the routines.
109cpp-srcs-left := $($(lib)-routines) $($(lib)-sysdep_routines)
110ifneq (,$(cpp-srcs-left))
111include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
112endif
113